Jsctypes/api: Difference between revisions

m
(→‎Calling types: make new t(ref) extremely strict)
Line 180: Line 180:
:'''''t''(''ref'')''' - If ''ref'' refers to an object that is not of type ''t'', throw a <code>TypeError</code> as above. Otherwise, if the object referred to by ''ref'' can be precisely represented as a JavaScript primitive value or a ctypes pointer, return that. Otherwise return a new <code>Reference</code>, exactly as for <code>new ''t''(''ref'')</code>.
:'''''t''(''ref'')''' - If ''ref'' refers to an object that is not of type ''t'', throw a <code>TypeError</code> as above. Otherwise, if the object referred to by ''ref'' can be precisely represented as a JavaScript primitive value or a ctypes pointer, return that. Otherwise return a new <code>Reference</code>, exactly as for <code>new ''t''(''ref'')</code>.


:'''new ''t(''val'')''' - With an argument that is any other JavaScript value, this converts the value to type ''t'', throwing a <code>TypeError</code> if the conversion is impossible, then creates a new <code>Buffer</code> and <code>Reference</code> as above, populating the new buffer with the converted value.  Details of conversion depend on the type.
:'''new ''t''(''val'')''' - With an argument that is any other JavaScript value, this converts the value to type ''t'', throwing a <code>TypeError</code> if the conversion is impossible, then creates a new <code>Buffer</code> and <code>Reference</code> as above, populating the new buffer with the converted value.  Details of conversion depend on the type.


:'''''t''(''val'')''' - Convert ''val'' to type ''t'' as above. If the result can be precisely represented as a JavaScript primitive value or a ctypes pointer, return that. Otherwise return a new Reference, exactly as for <code>new ''t''(''val'')</code>.
:'''''t''(''val'')''' - Convert ''val'' to type ''t'' as above. If the result can be precisely represented as a JavaScript primitive value or a ctypes pointer, return that. Otherwise return a new Reference, exactly as for <code>new ''t''(''val'')</code>.


The special type <code>ctypes.void_t</code> throws a <code>TypeError</code> if called with <code>new</code>, but <code>ctypes.void_t()</code> and <code>ctypes.void_t(''x'')</code> are allowed. Both return <code>undefined</code>.
The special type <code>ctypes.void_t</code> throws a <code>TypeError</code> if called with <code>new</code>, but <code>ctypes.void_t()</code> and <code>ctypes.void_t(''x'')</code> are allowed. Both return <code>undefined</code>.
638

edits