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 */ 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); }