void BasicBlock_init (ejsval exports) { basicblock_specops = _ejs_Object_specops; basicblock_specops.class_name = "LLVMBasicBlock"; basicblock_specops.allocate = BasicBlock_allocate; _ejs_gc_add_root (&_ejs_BasicBlock_proto); _ejs_BasicBlock_proto = _ejs_object_new(_ejs_Object_prototype, &basicblock_specops); _ejs_BasicBlock = _ejs_function_new_utf8_with_proto (_ejs_null, "LLVMBasicBlock", (EJSClosureFunc)BasicBlock_impl, _ejs_BasicBlock_proto); _ejs_object_setprop_utf8 (exports, "BasicBlock", _ejs_BasicBlock); #define PROTO_METHOD(x) EJS_INSTALL_ATOM_FUNCTION(_ejs_BasicBlock_proto, x, BasicBlock_prototype_##x) #define PROTO_ACCESSOR(x) EJS_INSTALL_ATOM_GETTER(_ejs_BasicBlock_proto, x, BasicBlock_prototype_get_##x) PROTO_ACCESSOR(name); PROTO_ACCESSOR(parent); PROTO_METHOD(dump); PROTO_METHOD(toString); #undef PROTO_METHOD #undef PROTO_ACCESSOR }
ejsval BasicBlock_new(llvm::BasicBlock* llvm_bb) { ejsval result = _ejs_object_new (_ejs_BasicBlock_proto, &basicblock_specops); ((BasicBlock*)EJSVAL_TO_OBJECT(result))->llvm_bb = llvm_bb; return result; }
static ejsval _ejs_Process_get_env (ejsval env, ejsval _this, uint32_t argc, ejsval *args) { ejsval env_obj = _ejs_object_new(_ejs_null, &_ejs_Object_specops); char** p = environ; while (*p) { char *env_entry = strdup(*p); char *eq = strchr(env_entry, '='); if (!eq) { free (env_entry); p++; continue; } *eq = '\0'; ejsval k = _ejs_string_new_utf8(env_entry); ejsval v = _ejs_string_new_utf8(eq+1); _ejs_object_define_value_property (env_obj, k, v, EJS_PROP_ENUMERABLE | EJS_PROP_NOT_CONFIGURABLE | EJS_PROP_NOT_WRITABLE); free (env_entry); p++; } return env_obj; }
void _ejs_process_init(ejsval global, uint32_t argc, char **argv) { _ejs_Process = _ejs_object_new (_ejs_null, &_ejs_Object_specops); _ejs_object_setprop (global, _ejs_atom_process, _ejs_Process); ejsval _argv = _ejs_array_new (argc, EJS_FALSE); _ejs_object_setprop (_ejs_Process, _ejs_atom_argv, _argv); for (int i = 0; i < argc; i ++) _ejs_object_setprop (_argv, NUMBER_TO_EJSVAL(i), _ejs_string_new_utf8(argv[i])); #define OBJ_PROP(x) EJS_INSTALL_ATOM_GETTER(_ejs_Process, x, _ejs_Process_get_##x) #define OBJ_METHOD(x) EJS_INSTALL_ATOM_FUNCTION(_ejs_Process, x, _ejs_Process_##x) OBJ_PROP(env); OBJ_METHOD(exit); OBJ_METHOD(chdir); OBJ_METHOD(cwd); #undef OBJ_PROP #undef OBJ_METHOD }
ejsval LoadInst_new(llvm::LoadInst* llvm_load) { ejsval result = _ejs_object_new (_ejs_LoadInst_prototype, &_ejs_LoadInst_specops); ((LoadInst*)EJSVAL_TO_OBJECT(result))->llvm_load = llvm_load; return result; }
void Invoke_init (ejsval exports) { _ejs_Invoke_specops = _ejs_Object_specops; _ejs_Invoke_specops.class_name = "LLVMInvoke"; _ejs_Invoke_specops.Allocate = Invoke_allocate; _ejs_gc_add_root (&_ejs_Invoke_prototype); _ejs_Invoke_prototype = _ejs_object_new(_ejs_Object_prototype, &_ejs_Invoke_specops); _ejs_Invoke = _ejs_function_new_utf8_with_proto (_ejs_null, "LLVMInvoke", (EJSClosureFunc)Invoke_impl, _ejs_Invoke_prototype); _ejs_object_setprop_utf8 (exports, "Invoke", _ejs_Invoke); #define PROTO_METHOD(x) EJS_INSTALL_ATOM_FUNCTION(_ejs_Invoke_prototype, x, Invoke_prototype_##x) PROTO_METHOD(setOnlyReadsMemory); PROTO_METHOD(setDoesNotAccessMemory); PROTO_METHOD(setDoesNotThrow); PROTO_METHOD(setStructRet); PROTO_METHOD(dump); PROTO_METHOD(toString); #undef PROTO_METHOD }
ejsval Invoke_new(llvm::InvokeInst* llvm_invoke) { ejsval result = _ejs_object_new (_ejs_Invoke_prototype, &_ejs_Invoke_specops); ((Invoke*)EJSVAL_TO_OBJECT(result))->llvm_invoke = llvm_invoke; return result; }
void _ejs_weakset_init(ejsval global) { _ejs_gc_add_root (&_ejs_WeakSetData_symbol); _ejs_WeakSetData_symbol = _ejs_symbol_new(_ejs_atom_WeakSetData); _ejs_WeakSet = _ejs_function_new_without_proto (_ejs_null, _ejs_atom_WeakSet, _ejs_WeakSet_impl); _ejs_object_setprop (global, _ejs_atom_WeakSet, _ejs_WeakSet); _ejs_gc_add_root (&_ejs_WeakSet_prototype); _ejs_WeakSet_prototype = _ejs_object_new (_ejs_Object_prototype, &_ejs_Object_specops); _ejs_object_setprop (_ejs_WeakSet, _ejs_atom_prototype, _ejs_WeakSet_prototype); #define OBJ_METHOD(x) EJS_INSTALL_ATOM_FUNCTION(_ejs_WeakSet, x, _ejs_WeakSet_##x) #define PROTO_METHOD(x) EJS_INSTALL_ATOM_FUNCTION_FLAGS(_ejs_WeakSet_prototype, x, _ejs_WeakSet_prototype_##x, EJS_PROP_NOT_ENUMERABLE | EJS_PROP_WRITABLE | EJS_PROP_CONFIGURABLE) #define PROTO_GETTER(x) EJS_INSTALL_ATOM_GETTER(_ejs_WeakSet_prototype, x, _ejs_WeakSet_prototype_get_##x) PROTO_METHOD(add); // XXX (ES6 23.4.3.2) WeakSet.prototype.constructor PROTO_METHOD(delete); PROTO_METHOD(has); _ejs_object_define_value_property (_ejs_WeakSet_prototype, _ejs_Symbol_toStringTag, _ejs_atom_WeakSet, EJS_PROP_NOT_ENUMERABLE | EJS_PROP_NOT_WRITABLE | EJS_PROP_CONFIGURABLE); #undef OBJ_METHOD #undef PROTO_METHOD }
void ArrayType_init (ejsval exports) { _ejs_ArrayType_specops = _ejs_Object_specops; _ejs_ArrayType_specops.class_name = "LLVMArray"; _ejs_ArrayType_specops.Allocate = ArrayType_allocate; _ejs_gc_add_root (&_ejs_ArrayType_prototype); _ejs_ArrayType_prototype = _ejs_object_new(_ejs_Object_prototype, &_ejs_ArrayType_specops); _ejs_ArrayType = _ejs_function_new_utf8_with_proto (_ejs_null, "LLVMArrayType", (EJSClosureFunc)ArrayType_impl, _ejs_ArrayType_prototype); _ejs_object_setprop_utf8 (exports, "ArrayType", _ejs_ArrayType); #define OBJ_METHOD(x) EJS_INSTALL_ATOM_FUNCTION(_ejs_ArrayType, x, ArrayType_##x) #define PROTO_METHOD(x) EJS_INSTALL_ATOM_FUNCTION(_ejs_ArrayType_prototype, x, ArrayType_prototype_##x) OBJ_METHOD(get); PROTO_METHOD(dump); PROTO_METHOD(toString); #undef PROTO_METHOD #undef OBJ_METHOD }
void Call_init (ejsval exports) { _ejs_Call_specops = _ejs_Object_specops; _ejs_Call_specops.class_name = "LLVMCall"; _ejs_Call_specops.Allocate = Call_allocate; _ejs_gc_add_root (&_ejs_Call_prototype); _ejs_Call_prototype = _ejs_object_new(_ejs_Object_prototype, &_ejs_Call_specops); ejsval tmpobj = _ejs_function_new_utf8 (_ejs_null, "LLVMCall", (EJSClosureFunc)Call_impl); _ejs_Call = tmpobj; #define PROTO_METHOD(x) EJS_INSTALL_ATOM_FUNCTION(_ejs_Call_prototype, x, Call_prototype_##x) _ejs_object_setprop (_ejs_Call, _ejs_atom_prototype, _ejs_Call_prototype); PROTO_METHOD(setOnlyReadsMemory); PROTO_METHOD(setDoesNotAccessMemory); PROTO_METHOD(setDoesNotThrow); PROTO_METHOD(setStructRet); PROTO_METHOD(dump); PROTO_METHOD(toString); #undef PROTO_METHOD _ejs_object_setprop_utf8 (exports, "Call", _ejs_Call); }
void _ejs_symbol_init(ejsval global) { _ejs_Symbol = _ejs_function_new_without_proto (_ejs_null, _ejs_atom_Symbol, _ejs_Symbol_impl); _ejs_object_setprop (global, _ejs_atom_Symbol, _ejs_Symbol); _ejs_gc_add_root (&_ejs_Symbol_prototype); _ejs_Symbol_prototype = _ejs_object_new(_ejs_null, &_ejs_Object_specops); // XXX _ejs_object_setprop (_ejs_Symbol, _ejs_atom_prototype, _ejs_Symbol_prototype); PROTO_METHOD(toString); PROTO_METHOD(valueOf); OBJ_METHOD(for); OBJ_METHOD(keyFor); WELL_KNOWN_SYMBOL(hasInstance); WELL_KNOWN_SYMBOL(isConcatSpreadable); WELL_KNOWN_SYMBOL(species); WELL_KNOWN_SYMBOL(iterator); WELL_KNOWN_SYMBOL(toPrimitive); WELL_KNOWN_SYMBOL(toStringTag); WELL_KNOWN_SYMBOL(unscopables); WELL_KNOWN_SYMBOL(match); WELL_KNOWN_SYMBOL(replace); WELL_KNOWN_SYMBOL(split); WELL_KNOWN_SYMBOL(search); _ejs_object_define_value_property (_ejs_Symbol_prototype, _ejs_Symbol_toStringTag, _ejs_atom_Symbol, EJS_PROP_NOT_ENUMERABLE | EJS_PROP_NOT_WRITABLE | EJS_PROP_CONFIGURABLE); }
ejsval ArrayType_new(llvm::ArrayType* llvm_ty) { ejsval result = _ejs_object_new (_ejs_ArrayType_prototype, &_ejs_ArrayType_specops); ((ArrayType*)EJSVAL_TO_OBJECT(result))->type = llvm_ty; return result; }
ejsval AllocaInst_new(llvm::AllocaInst* llvm_alloca) { ejsval result = _ejs_object_new (_ejs_AllocaInst_proto, &allocainst_specops); ((AllocaInst*)EJSVAL_TO_OBJECT(result))->llvm_alloca = llvm_alloca; return result; }
ejsval LandingPad_new(llvm::LandingPadInst* llvm_landingpad) { ejsval result = _ejs_object_new (_ejs_LandingPad_prototype, &_ejs_LandingPad_specops); ((LandingPad*)EJSVAL_TO_OBJECT(result))->llvm_landing_pad = llvm_landingpad; return result; }
void Module_init (ejsval exports) { _ejs_Module_specops = _ejs_Object_specops; _ejs_Module_specops.class_name = "LLVMModule"; _ejs_Module_specops.Allocate = Module_allocate; _ejs_Module_specops.Finalize = Module_finalize; _ejs_gc_add_root (&_ejs_Module_prototype); _ejs_Module_prototype = _ejs_object_new(_ejs_Object_prototype, &_ejs_Module_specops); _ejs_Module = _ejs_function_new_utf8_with_proto (_ejs_null, "LLVMModule", (EJSClosureFunc)Module_impl, _ejs_Module_prototype); _ejs_object_setprop_utf8 (exports, "Module", _ejs_Module); #define PROTO_METHOD(x) EJS_INSTALL_ATOM_FUNCTION(_ejs_Module_prototype, x, Module_prototype_##x) PROTO_METHOD(getGlobalVariable); PROTO_METHOD(getOrInsertIntrinsic); PROTO_METHOD(getOrInsertFunction); PROTO_METHOD(getOrInsertGlobal); PROTO_METHOD(getOrInsertExternalFunction); PROTO_METHOD(getFunction); PROTO_METHOD(dump); PROTO_METHOD(toString); PROTO_METHOD(writeToFile); PROTO_METHOD(writeBitcodeToFile); PROTO_METHOD(setDataLayout); PROTO_METHOD(setTriple); #undef PROTO_METHOD EJS_INSTALL_SYMBOL_FUNCTION_FLAGS (_ejs_Module, create, Module_create, EJS_PROP_NOT_ENUMERABLE); }
ejsval Call_new(llvm::CallInst* llvm_call) { ejsval result = _ejs_object_new (_ejs_Call_prototype, &_ejs_Call_specops); ((Call*)EJSVAL_TO_OBJECT(result))->llvm_call = llvm_call; return result; }
ejsval Function_new(llvm::Function* llvm_fun) { ejsval result = _ejs_object_new (_ejs_Function_proto, &function_specops); ((Function*)EJSVAL_TO_OBJECT(result))->llvm_fun = llvm_fun; return result; }
void _ejs_reflect_init(ejsval global) { _ejs_Reflect = _ejs_object_new (_ejs_Object_prototype, &_ejs_Object_specops); _ejs_object_setprop (global, _ejs_atom_Reflect, _ejs_Reflect); #define OBJ_METHOD(x) EJS_INSTALL_ATOM_FUNCTION(_ejs_Reflect, x, _ejs_Reflect_##x) OBJ_METHOD(apply); OBJ_METHOD(construct); OBJ_METHOD(defineProperty); OBJ_METHOD(deleteProperty); OBJ_METHOD(enumerate); OBJ_METHOD(get); OBJ_METHOD(getOwnPropertyDescriptor); OBJ_METHOD(getPrototypeOf); OBJ_METHOD(has); OBJ_METHOD(isExtensible); OBJ_METHOD(ownKeys); OBJ_METHOD(preventExtensions); OBJ_METHOD(set); OBJ_METHOD(setPrototypeOf); #undef OBJ_METHOD }
void _ejs_promise_init(ejsval global) { _ejs_Promise = _ejs_function_new_without_proto (_ejs_null, _ejs_atom_Promise, (EJSClosureFunc)_ejs_Promise_impl); _ejs_object_setprop (global, _ejs_atom_Promise, _ejs_Promise); _ejs_gc_add_root (&_ejs_Promise_prototype); _ejs_Promise_prototype = _ejs_object_new(_ejs_null, &_ejs_Object_specops); _ejs_object_setprop (_ejs_Promise, _ejs_atom_prototype, _ejs_Promise_prototype); _ejs_object_define_value_property (_ejs_Promise_prototype, _ejs_atom_constructor, _ejs_Promise, EJS_PROP_NOT_ENUMERABLE | EJS_PROP_CONFIGURABLE | EJS_PROP_WRITABLE); #define PROTO_METHOD(x) EJS_INSTALL_ATOM_FUNCTION_FLAGS (_ejs_Promise_prototype, x, _ejs_Promise_prototype_##x, EJS_PROP_NOT_ENUMERABLE) #define OBJ_METHOD(x) EJS_INSTALL_ATOM_FUNCTION_FLAGS (_ejs_Promise, x, _ejs_Promise_##x, EJS_PROP_NOT_ENUMERABLE) PROTO_METHOD(catch); PROTO_METHOD(then); _ejs_object_define_value_property (_ejs_Promise_prototype, _ejs_Symbol_toStringTag, _ejs_atom_Promise, EJS_PROP_NOT_ENUMERABLE | EJS_PROP_NOT_WRITABLE | EJS_PROP_CONFIGURABLE); OBJ_METHOD(all); OBJ_METHOD(race); OBJ_METHOD(reject); OBJ_METHOD(resolve); #undef PROTO_METHOD EJS_INSTALL_SYMBOL_FUNCTION_FLAGS (_ejs_Promise, create, _ejs_Promise_create, EJS_PROP_NOT_ENUMERABLE); _ejs_gc_add_root(&_ejs_identity_function); _ejs_identity_function = _ejs_function_new_anon(_ejs_undefined, identity); _ejs_gc_add_root(&_ejs_thrower_function); _ejs_thrower_function = _ejs_function_new_anon(_ejs_undefined, thrower); }
void _ejs_iterator_init_proto() { _ejs_gc_add_root (&_ejs_Generator_prototype); _ejs_Iterator_prototype = _ejs_object_new(_ejs_Object_prototype, &_ejs_Object_specops); ejsval _iterator = _ejs_function_new_native (_ejs_null, _ejs_Symbol_iterator, _ejs_Iterator_prototype_iterator); _ejs_object_define_value_property (_ejs_Iterator_prototype, _ejs_Symbol_iterator, _iterator, EJS_PROP_NOT_ENUMERABLE); }
void _ejs_generator_init(ejsval global) { _ejs_gc_add_root (&_ejs_Generator_prototype); _ejs_Generator_prototype = _ejs_object_new(_ejs_Object_prototype, &_ejs_Generator_specops); #define PROTO_METHOD(x) EJS_INSTALL_ATOM_FUNCTION_FLAGS (_ejs_Generator_prototype, x, _ejs_Generator_prototype_##x, EJS_PROP_NOT_ENUMERABLE | EJS_PROP_WRITABLE | EJS_PROP_CONFIGURABLE) PROTO_METHOD(next); PROTO_METHOD(return); PROTO_METHOD(throw); }
void _ejs_iterator_wrapper_init (ejsval global) { _ejs_gc_add_root (&_ejs_IteratorWrapper_prototype); _ejs_IteratorWrapper_prototype = _ejs_object_new(_ejs_Object_prototype, &_ejs_Object_specops); #define PROTO_METHOD(x) EJS_INSTALL_ATOM_FUNCTION_FLAGS (_ejs_IteratorWrapper_prototype, x, _ejs_IteratorWrapper_prototype_##x, EJS_PROP_NOT_ENUMERABLE | EJS_PROP_WRITABLE | EJS_PROP_CONFIGURABLE) PROTO_METHOD(getNextValue); PROTO_METHOD(getRest); #undef PROTO_METHOD }
static ejsval _ejs_RegExp_impl (ejsval env, ejsval _this, uint32_t argc, ejsval *args) { EJSRegExp *re; if (EJSVAL_IS_UNDEFINED(_this)) { // called as a function _this = _ejs_object_new(_ejs_RegExp_prototype, &_ejs_RegExp_specops); } re = (EJSRegExp*)EJSVAL_TO_OBJECT(_this); re->pattern = _ejs_undefined; re->flags = _ejs_undefined; if (argc > 0) re->pattern = args[0]; if (argc > 1) re->flags = args[1]; if (!EJSVAL_IS_STRING(re->pattern)) EJS_NOT_IMPLEMENTED(); EJSPrimString *flat_pattern = _ejs_string_flatten (re->pattern); jschar* chars = flat_pattern->data.flat; const unsigned char* pcre16_tables = pcre16_maketables(); const char *pcre_error; int pcre_erroffset; re->compiled_pattern = pcre16_compile(chars, PCRE_UTF16 | PCRE_NO_UTF16_CHECK, &pcre_error, &pcre_erroffset, pcre16_tables); _ejs_object_define_value_property (_this, _ejs_atom_source, re->pattern, EJS_PROP_NOT_ENUMERABLE | EJS_PROP_NOT_CONFIGURABLE | EJS_PROP_NOT_WRITABLE); if (EJSVAL_IS_STRING(re->flags)) { EJSPrimString *flat_flags = _ejs_string_flatten(re->flags); chars = flat_flags->data.flat; for (int i = 0; i < flat_flags->length; i ++) { if (chars[i] == 'g' && !re->global) { re->global = EJS_TRUE; continue; } else if (chars[i] == 'i' && !re->ignoreCase) { re->ignoreCase = EJS_TRUE; continue; } else if (chars[i] == 'm' && !re->multiline) { re->multiline = EJS_TRUE; continue; } else if (chars[i] == 'y' && !re->sticky) { re->sticky = EJS_TRUE; continue; } else if (chars[i] == 'u' && !re->unicode) { re->unicode = EJS_TRUE; continue; } _ejs_throw_nativeerror_utf8 (EJS_SYNTAX_ERROR, "Invalid flag supplied to RegExp constructor"); } } return _this; }
ejsval ToObject(ejsval exp) { if (EJSVAL_IS_BOOLEAN(exp)) { ejsval new_boolean = _ejs_object_new (_ejs_Boolean_proto, &_ejs_Boolean_specops); _ejs_invoke_closure (_ejs_Boolean, new_boolean, 1, &exp); return new_boolean; } else if (EJSVAL_IS_NUMBER(exp)) { ejsval new_number = _ejs_object_new (_ejs_Number_proto, &_ejs_Number_specops); _ejs_invoke_closure (_ejs_Number, new_number, 1, &exp); return new_number; } else if (EJSVAL_IS_STRING(exp)) { ejsval new_str = _ejs_object_new (_ejs_String_prototype, &_ejs_String_specops); _ejs_invoke_closure (_ejs_String, new_str, 1, &exp); return new_str; } else if (EJSVAL_IS_UNDEFINED(exp)) return exp; // XXX else if (EJSVAL_IS_OBJECT(exp)) return exp; else EJS_NOT_IMPLEMENTED(); }
EJSBool require_builtin_module (const char* name, ejsval *module) { int i; for (i = 0; i < num_builtin_modules; i ++) { if (!strcmp (builtin_module_map[i].name, name)) { if (EJSVAL_IS_NULL(builtin_module_map[i].cached_exports)) { // printf ("require'ing %s.\n", EJSVAL_TO_FLAT_STRING(arg)); _ejs_gc_add_root (&builtin_module_map[i].cached_exports); builtin_module_map[i].cached_exports = _ejs_object_new(_ejs_null, &_ejs_Object_specops); builtin_module_map[i].func(_ejs_null, _ejs_undefined, 1, &builtin_module_map[i].cached_exports); } *module = builtin_module_map[i].cached_exports; return EJS_TRUE; } } return EJS_FALSE; }
void GlobalVariable_init (ejsval exports) { _ejs_gc_add_root (&_ejs_GlobalVariable_proto); _ejs_GlobalVariable_proto = _ejs_object_new(_ejs_Object_prototype, &_ejs_Object_specops); _ejs_GlobalVariable = _ejs_function_new_utf8_with_proto (_ejs_null, "LLVMGlobalVariable", (EJSClosureFunc)GlobalVariable_impl, _ejs_GlobalVariable_proto); _ejs_object_setprop_utf8 (exports, "GlobalVariable", _ejs_GlobalVariable); #define PROTO_METHOD(x) EJS_INSTALL_ATOM_FUNCTION(_ejs_GlobalVariable_proto, x, GlobalVariable_prototype_##x) PROTO_METHOD(setAlignment); PROTO_METHOD(setInitializer); PROTO_METHOD(dump); PROTO_METHOD(toString); #undef PROTO_METHOD }
ejsval _ejs_function_new (ejsval env, ejsval name, EJSClosureFunc func) { EJSFunction *rv = _ejs_gc_new(EJSFunction); _ejs_init_object ((EJSObject*)rv, _ejs_Function__proto__, &_ejs_Function_specops); rv->func = func; rv->env = env; ejsval fun = OBJECT_TO_EJSVAL(rv); // ECMA262: 15.3.2.1 ejsval fun_proto = _ejs_object_new (_ejs_Object_prototype, &_ejs_Object_specops); _ejs_object_define_value_property (fun, _ejs_atom_prototype, fun_proto, EJS_PROP_NOT_ENUMERABLE | EJS_PROP_CONFIGURABLE | EJS_PROP_WRITABLE); _ejs_object_define_value_property (fun_proto, _ejs_atom_constructor, fun, EJS_PROP_NOT_ENUMERABLE | EJS_PROP_CONFIGURABLE | EJS_PROP_WRITABLE); _ejs_object_define_value_property (fun, _ejs_atom_name, name, EJS_PROP_NOT_ENUMERABLE | EJS_PROP_NOT_CONFIGURABLE | EJS_PROP_NOT_WRITABLE); return fun; }
void Function_init (ejsval exports) { function_specops = _ejs_Object_specops; function_specops.class_name = "LLVMFunction"; function_specops.allocate = Function_allocate; _ejs_gc_add_root (&_ejs_Function_proto); _ejs_Function_proto = _ejs_object_new(_ejs_Object_prototype, &function_specops); _ejs_Function = _ejs_function_new_utf8_with_proto (_ejs_null, "LLVMFunction", (EJSClosureFunc)Function_impl, _ejs_Function_proto); _ejs_object_setprop_utf8 (exports, "Function", _ejs_Function); #define PROTO_METHOD(x) EJS_INSTALL_ATOM_FUNCTION(_ejs_Function_proto, x, Function_prototype_##x) #define PROTO_ACCESSOR(x) EJS_INSTALL_ATOM_GETTER(_ejs_Function_proto, x, Function_prototype_get_##x) PROTO_ACCESSOR(args); PROTO_ACCESSOR(argSize); PROTO_ACCESSOR(name); PROTO_ACCESSOR(returnType); PROTO_ACCESSOR(type); PROTO_ACCESSOR(doesNotThrow); PROTO_ACCESSOR(onlyReadsMemory); PROTO_ACCESSOR(doesNotAccessMemory); PROTO_METHOD(dump); PROTO_METHOD(setOnlyReadsMemory); PROTO_METHOD(setDoesNotAccessMemory); PROTO_METHOD(setDoesNotThrow); PROTO_METHOD(setGC); PROTO_METHOD(setExternalLinkage); PROTO_METHOD(setInternalLinkage); PROTO_METHOD(toString); PROTO_METHOD(hasStructRetAttr); PROTO_METHOD(setStructRet); #undef PROTO_METHOD #undef PROTO_ACCESSOR }
EJSBool require_user_module (const char* name, ejsval *module) { int i = 0; while (1) { EJSRequire* map = &_ejs_require_map[i]; if (!map->name) { return EJS_FALSE; } if (!strcmp (map->name, name)) { if (EJSVAL_IS_NULL(map->cached_exports)) { _ejs_gc_add_root (&map->cached_exports); map->cached_exports = _ejs_object_new(_ejs_null, &_ejs_Object_specops); map->func (_ejs_null, _ejs_undefined, 1, &map->cached_exports); } *module = map->cached_exports; return EJS_TRUE; } i++; } }
EJSBool require_external_module (const char* name, ejsval *module) { int i = 0; while (1) { if (!_ejs_external_module_require_map[i].name) { return EJS_FALSE; } if (!strcmp (_ejs_external_module_require_map[i].name, name)) { if (EJSVAL_IS_NULL(_ejs_external_module_require_map[i].cached_exports)) { _ejs_gc_add_root (&_ejs_external_module_require_map[i].cached_exports); _ejs_external_module_require_map[i].cached_exports = _ejs_object_new(_ejs_null, &_ejs_Object_specops); _ejs_external_module_require_map[i].func(_ejs_external_module_require_map[i].cached_exports); } *module = _ejs_external_module_require_map[i].cached_exports; return EJS_TRUE; } i++; } }