void jsB_initstring(js_State *J) { J->String_prototype->u.s.string = ""; J->String_prototype->u.s.length = 0; js_pushobject(J, J->String_prototype); { jsB_propf(J, "toString", Sp_toString, 0); jsB_propf(J, "valueOf", Sp_valueOf, 0); jsB_propf(J, "charAt", Sp_charAt, 1); jsB_propf(J, "charCodeAt", Sp_charCodeAt, 1); jsB_propf(J, "concat", Sp_concat, 1); jsB_propf(J, "indexOf", Sp_indexOf, 1); jsB_propf(J, "lastIndexOf", Sp_lastIndexOf, 1); jsB_propf(J, "localeCompare", Sp_localeCompare, 1); jsB_propf(J, "match", Sp_match, 1); jsB_propf(J, "replace", Sp_replace, 2); jsB_propf(J, "search", Sp_search, 1); jsB_propf(J, "slice", Sp_slice, 2); jsB_propf(J, "split", Sp_split, 2); jsB_propf(J, "substring", Sp_substring, 2); jsB_propf(J, "toLowerCase", Sp_toLowerCase, 0); jsB_propf(J, "toLocaleLowerCase", Sp_toLowerCase, 0); jsB_propf(J, "toUpperCase", Sp_toUpperCase, 0); jsB_propf(J, "toLocaleUpperCase", Sp_toUpperCase, 0); /* ES5 */ jsB_propf(J, "trim", Sp_trim, 0); } js_newcconstructor(J, jsB_String, jsB_new_String, 1); { jsB_propf(J, "fromCharCode", S_fromCharCode, 1); } js_defglobal(J, "String", JS_DONTENUM); }
void jsB_initobject(js_State *J) { js_pushobject(J, J->Object_prototype); { jsB_propf(J, "Object.prototype.toString", Op_toString, 0); jsB_propf(J, "Object.prototype.toLocaleString", Op_toString, 0); jsB_propf(J, "Object.prototype.valueOf", Op_valueOf, 0); jsB_propf(J, "Object.prototype.hasOwnProperty", Op_hasOwnProperty, 1); jsB_propf(J, "Object.prototype.isPrototypeOf", Op_isPrototypeOf, 1); jsB_propf(J, "Object.prototype.propertyIsEnumerable", Op_propertyIsEnumerable, 1); } js_newcconstructor(J, jsB_Object, jsB_new_Object, "Object", 1); { /* ES5 */ jsB_propf(J, "Object.getPrototypeOf", O_getPrototypeOf, 1); jsB_propf(J, "Object.getOwnPropertyDescriptor", O_getOwnPropertyDescriptor, 2); jsB_propf(J, "Object.getOwnPropertyNames", O_getOwnPropertyNames, 1); jsB_propf(J, "Object.create", O_create, 2); jsB_propf(J, "Object.defineProperty", O_defineProperty, 3); jsB_propf(J, "Object.defineProperties", O_defineProperties, 2); jsB_propf(J, "Object.seal", O_seal, 1); jsB_propf(J, "Object.freeze", O_freeze, 1); jsB_propf(J, "Object.preventExtensions", O_preventExtensions, 1); jsB_propf(J, "Object.isSealed", O_isSealed, 1); jsB_propf(J, "Object.isFrozen", O_isFrozen, 1); jsB_propf(J, "Object.isExtensible", O_isExtensible, 1); jsB_propf(J, "Object.keys", O_keys, 1); } js_defglobal(J, "Object", JS_DONTENUM); }
void jsB_initarray(js_State *J) { js_pushobject(J, J->Array_prototype); { jsB_propf(J, "toString", Ap_toString, 0); jsB_propf(J, "concat", Ap_concat, 1); jsB_propf(J, "join", Ap_join, 1); jsB_propf(J, "pop", Ap_pop, 0); jsB_propf(J, "push", Ap_push, 1); jsB_propf(J, "reverse", Ap_reverse, 0); jsB_propf(J, "shift", Ap_shift, 0); jsB_propf(J, "slice", Ap_slice, 2); jsB_propf(J, "sort", Ap_sort, 1); jsB_propf(J, "splice", Ap_splice, 2); jsB_propf(J, "unshift", Ap_unshift, 1); /* ES5 */ jsB_propf(J, "indexOf", Ap_indexOf, 1); jsB_propf(J, "lastIndexOf", Ap_lastIndexOf, 1); jsB_propf(J, "every", Ap_every, 1); jsB_propf(J, "some", Ap_some, 1); jsB_propf(J, "forEach", Ap_forEach, 1); jsB_propf(J, "map", Ap_map, 1); jsB_propf(J, "filter", Ap_filter, 1); jsB_propf(J, "reduce", Ap_reduce, 1); jsB_propf(J, "reduceRight", Ap_reduceRight, 1); } js_newcconstructor(J, jsB_new_Array, jsB_new_Array, "Array", 1); { /* ES5 */ jsB_propf(J, "isArray", A_isArray, 1); } js_defglobal(J, "Array", JS_DONTENUM); }
void jsB_initarray(js_State *J) { js_pushobject(J, J->Array_prototype); { jsB_propf(J, "Array.prototype.toString", Ap_toString, 0); jsB_propf(J, "Array.prototype.concat", Ap_concat, 0); /* 1 */ jsB_propf(J, "Array.prototype.join", Ap_join, 1); jsB_propf(J, "Array.prototype.pop", Ap_pop, 0); jsB_propf(J, "Array.prototype.push", Ap_push, 0); /* 1 */ jsB_propf(J, "Array.prototype.reverse", Ap_reverse, 0); jsB_propf(J, "Array.prototype.shift", Ap_shift, 0); jsB_propf(J, "Array.prototype.slice", Ap_slice, 2); jsB_propf(J, "Array.prototype.sort", Ap_sort, 1); jsB_propf(J, "Array.prototype.splice", Ap_splice, 0); /* 2 */ jsB_propf(J, "Array.prototype.unshift", Ap_unshift, 0); /* 1 */ /* ES5 */ jsB_propf(J, "Array.prototype.indexOf", Ap_indexOf, 1); jsB_propf(J, "Array.prototype.lastIndexOf", Ap_lastIndexOf, 1); jsB_propf(J, "Array.prototype.every", Ap_every, 1); jsB_propf(J, "Array.prototype.some", Ap_some, 1); jsB_propf(J, "Array.prototype.forEach", Ap_forEach, 1); jsB_propf(J, "Array.prototype.map", Ap_map, 1); jsB_propf(J, "Array.prototype.filter", Ap_filter, 1); jsB_propf(J, "Array.prototype.reduce", Ap_reduce, 1); jsB_propf(J, "Array.prototype.reduceRight", Ap_reduceRight, 1); } js_newcconstructor(J, jsB_new_Array, jsB_new_Array, "Array", 0); /* 1 */ { /* ES5 */ jsB_propf(J, "Array.isArray", A_isArray, 1); } js_defglobal(J, "Array", JS_DONTENUM); }
void jsB_initboolean(js_State *J) { J->Boolean_prototype->u.boolean = 0; js_pushobject(J, J->Boolean_prototype); { jsB_propf(J, "toString", Bp_toString, 0); jsB_propf(J, "valueOf", Bp_valueOf, 0); } js_newcconstructor(J, jsB_Boolean, jsB_new_Boolean, 1); js_defglobal(J, "Boolean", JS_DONTENUM); }
void jsB_initfunction(js_State *J) { J->Function_prototype->u.c.function = jsB_Function_prototype; J->Function_prototype->u.c.constructor = NULL; js_pushobject(J, J->Function_prototype); { jsB_propf(J, "toString", Fp_toString, 2); jsB_propf(J, "apply", Fp_apply, 2); jsB_propf(J, "call", Fp_call, 1); jsB_propf(J, "bind", Fp_bind, 1); } js_newcconstructor(J, jsB_Function, jsB_Function, "Function", 1); js_defglobal(J, "Function", JS_DONTENUM); }
static void Fp_bind(js_State *J) { unsigned int i, top = js_gettop(J); unsigned int n; if (!js_iscallable(J, 0)) js_typeerror(J, "not a function"); n = js_getlength(J, 0); if (n > top - 2) n -= top - 2; else n = 0; js_newcconstructor(J, callbound, constructbound, "[bind]", n); /* Reuse target function's prototype for HasInstance check. */ js_getproperty(J, 0, "prototype"); js_defproperty(J, -2, "prototype", JS_READONLY | JS_DONTENUM | JS_DONTCONF); /* target function */ js_copy(J, 0); js_defproperty(J, -2, "__TargetFunction__", JS_READONLY | JS_DONTENUM | JS_DONTCONF); /* bound this */ js_copy(J, 1); js_defproperty(J, -2, "__BoundThis__", JS_READONLY | JS_DONTENUM | JS_DONTCONF); /* bound arguments */ js_newarray(J); for (i = 2; i < top; ++i) { js_copy(J, i); js_setindex(J, -2, i - 2); } js_defproperty(J, -2, "__BoundArguments__", JS_READONLY | JS_DONTENUM | JS_DONTCONF); }