зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1466501 part 3 - Add an objectGlobal(obj) testing function. r=luke
This commit is contained in:
Родитель
3c1a7769ea
Коммит
418cdb8d25
|
@ -5103,6 +5103,29 @@ ScriptedCallerGlobal(JSContext* cx, unsigned argc, Value* vp)
|
|||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
ObjectGlobal(JSContext* cx, unsigned argc, Value* vp)
|
||||
{
|
||||
CallArgs args = CallArgsFromVp(argc, vp);
|
||||
RootedObject callee(cx, &args.callee());
|
||||
|
||||
if (!args.get(0).isObject()) {
|
||||
ReportUsageErrorASCII(cx, callee, "Argument must be an object");
|
||||
return false;
|
||||
}
|
||||
|
||||
RootedObject obj(cx, &args[0].toObject());
|
||||
if (IsWrapper(obj)) {
|
||||
args.rval().setNull();
|
||||
return true;
|
||||
}
|
||||
|
||||
obj = ToWindowProxyIfWindow(&obj->global());
|
||||
|
||||
args.rval().setObject(*obj);
|
||||
return true;
|
||||
}
|
||||
|
||||
JSScript*
|
||||
js::TestingFunctionArgumentToScript(JSContext* cx,
|
||||
HandleValue v,
|
||||
|
@ -5898,6 +5921,10 @@ gc::ZealModeHelpText),
|
|||
"scriptedCallerGlobal()",
|
||||
" Get the caller's global (or null). See JS::GetScriptedCallerGlobal.\n"),
|
||||
|
||||
JS_FN_HELP("objectGlobal", ObjectGlobal, 1, 0,
|
||||
"objectGlobal(obj)",
|
||||
" Returns the object's global object or null if the object is a wrapper.\n"),
|
||||
|
||||
JS_FN_HELP("baselineCompile", BaselineCompile, 2, 0,
|
||||
"baselineCompile([fun/code], forceDebugInstrumentation=false)",
|
||||
" Baseline-compiles the given JS function or script.\n"
|
||||
|
|
|
@ -2,3 +2,9 @@ var g1 = newGlobal({sameCompartmentAs: this});
|
|||
var g2 = newGlobal({sameCompartmentAs: g1});
|
||||
g2.x = g1;
|
||||
gc();
|
||||
assertEq(objectGlobal(Math), this);
|
||||
assertEq(objectGlobal(g1.print), g1);
|
||||
assertEq(objectGlobal(g2.x), g1);
|
||||
|
||||
// Different-compartment realms have wrappers.
|
||||
assertEq(objectGlobal(newGlobal().Math), null);
|
||||
|
|
Загрузка…
Ссылка в новой задаче