JSObjectRef CYObjectMakeArray(JSContextRef context, size_t length, const JSValueRef values[]) {
if (JSObjectMakeArray$ != NULL)
return _jsccall(*JSObjectMakeArray$, context, length, values);
- else {
- JSObjectRef Array(CYGetCachedObject(context, CYJSString("Array")));
- JSValueRef value(CYCallAsFunction(context, Array, NULL, length, values));
- return CYCastJSObject(context, value);
- }
+ JSObjectRef Array(CYGetCachedObject(context, CYJSString("Array")));
+ bool wat(length == 1 && JSValueGetType(context, values[0]) == kJSTypeNumber);
+ JSValueRef value(CYCallAsFunction(context, Array, NULL, wat ? 0 : length, values));
+ JSObjectRef object(CYCastJSObject(context, value));
+ if (wat) CYArrayPush(context, object, 1, values);
+ return object;
}
static JSClassRef All_;
#define CYFromFFI_(Type_) \
template <> \
JSValueRef Primitive<Type_>::FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const { \
- return CYCastJSValue(context, *reinterpret_cast<Type_ *>(data)); \
+ JSValueRef value(CYCastJSValue(context, *reinterpret_cast<Type_ *>(data))); \
+ JSObjectRef typed(_jsccall(JSObjectCallAsConstructor, context, CYGetCachedObject(context, CYJSString("Number")), 1, &value)); \
+ CYSetProperty(context, typed, cyt_s, CYMakeType(context, *this), kJSPropertyAttributeDontEnum); \
+ return typed; \
}
-CYFromFFI_(bool)
CYFromFFI_(wchar_t)
CYFromFFI_(float)
CYFromFFI_(double)
CYFromFFI_(unsigned __int128)
#endif
+template <>
+JSValueRef Primitive<bool>::FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const {
+ return CYCastJSValue(context, *reinterpret_cast<bool *>(data));
+}
+
template <>
JSValueRef Primitive<char>::FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const {
uint16_t string(uint8_t(*reinterpret_cast<char *>(data)));
type->PoolFFI(buffer, context, ffi, data, arguments[0]);
JSValueRef value(type->FromFFI(context, ffi, data, false, buffer));
-
- if (JSValueGetType(context, value) == kJSTypeNumber) {
- JSObjectRef typed(_jsccall(JSObjectCallAsConstructor, context, CYGetCachedObject(context, CYJSString("Number")), 1, &value));
- CYSetProperty(context, typed, cyt_s, object, kJSPropertyAttributeDontEnum);
- value = typed;
- }
-
return value;
} CYCatch(NULL) }