static JSFunction * NewExportedFunction(JSContext *cx, const AsmJSModule::ExportedFunction &func, HandleObject moduleObj, unsigned exportIndex) { RootedPropertyName name(cx, func.name()); JSFunction *fun = NewFunction(cx, NullPtr(), CallAsmJS, func.numArgs(), JSFunction::NATIVE_FUN, cx->global(), name, JSFunction::ExtendedFinalizeKind); if (!fun) return nullptr; fun->setExtendedSlot(ASM_MODULE_SLOT, ObjectValue(*moduleObj)); fun->setExtendedSlot(ASM_EXPORT_INDEX_SLOT, Int32Value(exportIndex)); return fun; }
bool GlobalObject::getSelfHostedFunction(JSContext *cx, HandleAtom selfHostedName, HandleAtom name, unsigned nargs, MutableHandleValue funVal) { RootedId shId(cx, AtomToId(selfHostedName)); RootedObject holder(cx, cx->global()->intrinsicsHolder()); if (HasDataProperty(cx, holder, shId, funVal.address())) return true; if (!cx->runtime()->maybeWrappedSelfHostedFunction(cx, shId, funVal)) return false; if (!funVal.isUndefined()) return true; JSFunction *fun = NewFunction(cx, NullPtr(), nullptr, nargs, JSFunction::INTERPRETED_LAZY, holder, name, JSFunction::ExtendedFinalizeKind, SingletonObject); if (!fun) return false; fun->setIsSelfHostedBuiltin(); fun->setExtendedSlot(0, StringValue(selfHostedName)); funVal.setObject(*fun); return JSObject::defineGeneric(cx, holder, shId, funVal, nullptr, nullptr, 0); }
static JSFunction * NewExportedFunction(JSContext *cx, const AsmJSModule::ExportedFunction &func, HandleObject moduleObj, unsigned exportIndex) { RootedPropertyName name(cx, func.name()); unsigned numArgs = func.isChangeHeap() ? 1 : func.numArgs(); JSFunction *fun = NewNativeConstructor(cx, CallAsmJS, numArgs, name, JSFunction::ExtendedFinalizeKind, GenericObject, JSFunction::ASMJS_CTOR); if (!fun) return nullptr; fun->setExtendedSlot(ASM_MODULE_SLOT, ObjectValue(*moduleObj)); fun->setExtendedSlot(ASM_EXPORT_INDEX_SLOT, Int32Value(exportIndex)); return fun; }
static JSFunction* NewExportedFunction(JSContext* cx, Handle<WasmModuleObject*> moduleObj, const ExportMap& exportMap, uint32_t exportIndex) { unsigned numArgs = moduleObj->module().exports()[exportIndex].sig().args().length(); const char* chars = exportMap.exportNames[exportIndex].get(); RootedAtom name(cx, AtomizeUTF8Chars(cx, chars, strlen(chars))); if (!name) return nullptr; JSFunction* fun = NewNativeConstructor(cx, WasmCall, numArgs, name, gc::AllocKind::FUNCTION_EXTENDED, GenericObject, JSFunction::ASMJS_CTOR); if (!fun) return nullptr; fun->setExtendedSlot(FunctionExtended::WASM_MODULE_SLOT, ObjectValue(*moduleObj)); fun->setExtendedSlot(FunctionExtended::WASM_EXPORT_INDEX_SLOT, Int32Value(exportIndex)); return fun; }
JSFunction * js::NewAsmJSModuleFunction(ExclusiveContext *cx, JSFunction *origFun, HandleObject moduleObj) { RootedPropertyName name(cx, origFun->name()); JSFunction *moduleFun = NewFunction(cx, NullPtr(), LinkAsmJS, origFun->nargs(), JSFunction::NATIVE_FUN, NullPtr(), name, JSFunction::ExtendedFinalizeKind, TenuredObject); if (!moduleFun) return nullptr; moduleFun->setExtendedSlot(MODULE_FUN_SLOT, ObjectValue(*moduleObj)); return moduleFun; }
static JSFunction* NewExportedFunction(JSContext* cx, HandleWasmInstanceObject instanceObj, uint32_t funcExportIndex) { Instance& instance = instanceObj->instance(); const Metadata& metadata = instance.metadata(); const FuncExport& fe = metadata.funcExports[funcExportIndex]; unsigned numArgs = fe.sig().args().length(); RootedAtom name(cx, instance.getFuncAtom(cx, fe.funcIndex())); if (!name) return nullptr; JSFunction* fun = NewNativeConstructor(cx, WasmCall, numArgs, name, gc::AllocKind::FUNCTION_EXTENDED, GenericObject, JSFunction::ASMJS_CTOR); if (!fun) return nullptr; fun->setExtendedSlot(FunctionExtended::WASM_INSTANCE_SLOT, ObjectValue(*instanceObj)); fun->setExtendedSlot(FunctionExtended::WASM_EXPORT_INDEX_SLOT, Int32Value(funcExportIndex)); return fun; }
JSFunction * js::NewAsmJSModuleFunction(ExclusiveContext *cx, JSFunction *origFun, HandleObject moduleObj) { RootedPropertyName name(cx, origFun->name()); JSFunction::Flags flags = origFun->isLambda() ? JSFunction::ASMJS_LAMBDA_CTOR : JSFunction::ASMJS_CTOR; JSFunction *moduleFun = NewNativeConstructor(cx, LinkAsmJS, origFun->nargs(), name, JSFunction::ExtendedFinalizeKind, TenuredObject, flags); if (!moduleFun) return nullptr; moduleFun->setExtendedSlot(MODULE_FUN_SLOT, ObjectValue(*moduleObj)); return moduleFun; }
/* static */ bool GlobalObject::getSelfHostedFunction(JSContext* cx, Handle<GlobalObject*> global, HandlePropertyName selfHostedName, HandleAtom name, unsigned nargs, MutableHandleValue funVal) { if (GlobalObject::maybeGetIntrinsicValue(cx, global, selfHostedName, funVal)) return true; JSFunction* fun = NewScriptedFunction(cx, nargs, JSFunction::INTERPRETED_LAZY, name, gc::AllocKind::FUNCTION_EXTENDED, SingletonObject); if (!fun) return false; fun->setIsSelfHostedBuiltin(); fun->setExtendedSlot(0, StringValue(selfHostedName)); funVal.setObject(*fun); return GlobalObject::addIntrinsicValue(cx, global, selfHostedName, funVal); }
bool GlobalObject::getSelfHostedFunction(JSContext* cx, HandleAtom selfHostedName, HandleAtom name, unsigned nargs, MutableHandleValue funVal) { RootedId shId(cx, AtomToId(selfHostedName)); RootedObject holder(cx, cx->global()->intrinsicsHolder()); if (cx->global()->maybeGetIntrinsicValue(shId, funVal.address())) return true; JSFunction* fun = NewScriptedFunction(cx, nargs, JSFunction::INTERPRETED_LAZY, name, JSFunction::ExtendedFinalizeKind, SingletonObject); if (!fun) return false; fun->setIsSelfHostedBuiltin(); fun->setExtendedSlot(0, StringValue(selfHostedName)); funVal.setObject(*fun); return cx->global()->addIntrinsicValue(cx, shId, funVal); }