mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 784400 - Give self-hosted code access to standard builtins. r=luke
This commit is contained in:
parent
cc53d6ba3e
commit
9c3f9146e0
@ -5001,6 +5001,16 @@ JS_DefineFunctions(JSContext *cx, JSObject *objArg, JSFunctionSpec *fs)
|
||||
fun->setExtendedSlot(0, PrivateValue(fs));
|
||||
}
|
||||
|
||||
/*
|
||||
* During creation of the self-hosting global, we ignore all
|
||||
* self-hosted functions, as that means we're currently setting up
|
||||
* the global object that that the self-hosted code is then compiled
|
||||
* in. Self-hosted functions can access each other via their names,
|
||||
* but not via the builtin classes they get installed into.
|
||||
*/
|
||||
if (fs->selfHostedName && cx->runtime->isSelfHostedGlobal(cx->global()))
|
||||
return JS_TRUE;
|
||||
|
||||
fun = js_DefineFunction(cx, obj, id, fs->call.op, fs->nargs, flags, fs->selfHostedName);
|
||||
if (!fun)
|
||||
return JS_FALSE;
|
||||
|
@ -242,6 +242,7 @@ selfHosting_ErrorReporter(JSContext *cx, const char *message, JSErrorReport *rep
|
||||
{
|
||||
PrintError(cx, stderr, message, report, true);
|
||||
}
|
||||
|
||||
static JSClass self_hosting_global_class = {
|
||||
"self-hosting-global", JSCLASS_GLOBAL_FLAGS,
|
||||
JS_PropertyStub, JS_PropertyStub,
|
||||
@ -249,6 +250,7 @@ static JSClass self_hosting_global_class = {
|
||||
JS_EnumerateStub, JS_ResolveStub,
|
||||
JS_ConvertStub, NULL
|
||||
};
|
||||
|
||||
bool
|
||||
JSRuntime::initSelfHosting(JSContext *cx)
|
||||
{
|
||||
@ -257,7 +259,6 @@ JSRuntime::initSelfHosting(JSContext *cx)
|
||||
if (!(selfHostedGlobal_ = JS_NewGlobalObject(cx, &self_hosting_global_class, NULL)))
|
||||
return false;
|
||||
JS_SetGlobalObject(cx, selfHostedGlobal_);
|
||||
RootedObject shg(cx, selfHostedGlobal_);
|
||||
|
||||
CompileOptions options(cx);
|
||||
options.setFileAndLine("self-hosted", 1);
|
||||
@ -269,6 +270,7 @@ JSRuntime::initSelfHosting(JSContext *cx)
|
||||
* and we don't want errors in self-hosted code to be silently swallowed.
|
||||
*/
|
||||
JSErrorReporter oldReporter = JS_SetErrorReporter(cx, selfHosting_ErrorReporter);
|
||||
RootedObject shg(cx, selfHostedGlobal_);
|
||||
Value rv;
|
||||
bool ok;
|
||||
|
||||
|
@ -471,6 +471,9 @@ struct JSRuntime : js::RuntimeFriendFields
|
||||
|
||||
bool initSelfHosting(JSContext *cx);
|
||||
void markSelfHostedGlobal(JSTracer *trc);
|
||||
bool isSelfHostedGlobal(js::HandleObject global) {
|
||||
return global == selfHostedGlobal_;
|
||||
}
|
||||
JSFunction *getSelfHostedFunction(JSContext *cx, const char *name);
|
||||
bool cloneSelfHostedValueById(JSContext *cx, js::HandleId id, js::HandleObject holder,
|
||||
js::MutableHandleValue vp);
|
||||
|
@ -1568,6 +1568,7 @@ js_DefineFunction(JSContext *cx, HandleObject obj, HandleId id, Native native,
|
||||
obj, atom, kind);
|
||||
} else {
|
||||
JS_ASSERT(attrs & JSFUN_INTERPRETED);
|
||||
JS_ASSERT(!cx->runtime->isSelfHostedGlobal(cx->global()));
|
||||
fun = cx->runtime->getSelfHostedFunction(cx, selfHostedName);
|
||||
fun->initAtom(JSID_TO_ATOM(id));
|
||||
}
|
||||
|
@ -456,6 +456,14 @@ GlobalObject::initFunctionAndObjectClasses(JSContext *cx)
|
||||
self->setIntrinsicsHolder(intrinsicsHolder);
|
||||
if (!JS_DefineFunctions(cx, intrinsicsHolder, intrinsic_functions))
|
||||
return NULL;
|
||||
/* Define a property 'global' with the current global as its value. */
|
||||
RootedValue global(cx, OBJECT_TO_JSVAL(self));
|
||||
if (!JSObject::defineProperty(cx, intrinsicsHolder, cx->names().global,
|
||||
global, JS_PropertyStub, JS_StrictPropertyStub,
|
||||
JSPROP_PERMANENT | JSPROP_READONLY))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* The global object should have |Object.prototype| as its [[Prototype]].
|
||||
|
Loading…
Reference in New Issue
Block a user