зеркало из https://github.com/mozilla/gecko-dev.git
Bug 814729 - Add getSelfHostedValue function to JS shell. r=shu
This commit is contained in:
Родитель
d4c5256e4c
Коммит
38f26d4ead
|
@ -444,8 +444,7 @@ JSRuntime::cloneSelfHostedFunctionScript(JSContext *cx, Handle<PropertyName*> na
|
|||
}
|
||||
|
||||
bool
|
||||
JSRuntime::cloneSelfHostedValue(JSContext *cx, Handle<PropertyName*> name, HandleObject holder,
|
||||
MutableHandleValue vp)
|
||||
JSRuntime::cloneSelfHostedValue(JSContext *cx, Handle<PropertyName*> name, MutableHandleValue vp)
|
||||
{
|
||||
RootedValue funVal(cx);
|
||||
if (!getUnclonedSelfHostedValue(cx, name, &funVal))
|
||||
|
@ -458,15 +457,15 @@ JSRuntime::cloneSelfHostedValue(JSContext *cx, Handle<PropertyName*> name, Handl
|
|||
*/
|
||||
if (cx->global() == selfHostedGlobal_) {
|
||||
vp.set(funVal);
|
||||
} else if (funVal.toObject().isFunction()){
|
||||
} else if (funVal.isObject() && funVal.toObject().isFunction()) {
|
||||
RootedFunction fun(cx, funVal.toObject().toFunction());
|
||||
RootedObject clone(cx, CloneFunctionObject(cx, fun, cx->global(), fun->getAllocKind()));
|
||||
if (!clone)
|
||||
return false;
|
||||
vp.set(ObjectValue(*clone));
|
||||
} else {
|
||||
vp.set(UndefinedValue());
|
||||
}
|
||||
DebugOnly<bool> ok = JS_DefinePropertyById(cx, holder, NameToId(name), vp, NULL, NULL, 0);
|
||||
JS_ASSERT(ok);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -560,7 +560,7 @@ struct JSRuntime : js::RuntimeFriendFields
|
|||
bool cloneSelfHostedFunctionScript(JSContext *cx, js::Handle<js::PropertyName*> name,
|
||||
js::Handle<JSFunction*> targetFun);
|
||||
bool cloneSelfHostedValue(JSContext *cx, js::Handle<js::PropertyName*> name,
|
||||
js::HandleObject holder, js::MutableHandleValue vp);
|
||||
js::MutableHandleValue vp);
|
||||
|
||||
/* Base address of the native stack for the current thread. */
|
||||
uintptr_t nativeStackBase;
|
||||
|
|
|
@ -3582,6 +3582,23 @@ GetMaxArgs(JSContext *cx, unsigned arg, jsval *vp)
|
|||
return true;
|
||||
}
|
||||
|
||||
static JSBool
|
||||
GetSelfHostedValue(JSContext *cx, unsigned argc, jsval *vp)
|
||||
{
|
||||
CallArgs args = CallArgsFromVp(argc, vp);
|
||||
|
||||
if (argc != 1 || !args[0].isString()) {
|
||||
JS_ReportErrorNumber(cx, my_GetErrorMessage, NULL, JSSMSG_INVALID_ARGS,
|
||||
"getSelfHostedValue");
|
||||
return false;
|
||||
}
|
||||
RootedAtom srcAtom(cx, ToAtom(cx, args[0]));
|
||||
if (!srcAtom)
|
||||
return false;
|
||||
RootedPropertyName srcName(cx, srcAtom->asPropertyName());
|
||||
return cx->runtime->cloneSelfHostedValue(cx, srcName, args.rval());
|
||||
}
|
||||
|
||||
static JSFunctionSpecWithHelp shell_functions[] = {
|
||||
JS_FN_HELP("version", Version, 0, 0,
|
||||
"version([number])",
|
||||
|
@ -3894,6 +3911,11 @@ static JSFunctionSpecWithHelp shell_functions[] = {
|
|||
" rooting hazards. This is helpful to reduce the time taken when interpreting\n"
|
||||
" heavily numeric code."),
|
||||
|
||||
JS_FN_HELP("getSelfHostedValue", GetSelfHostedValue, 1, 0,
|
||||
"getSelfHostedValue()",
|
||||
" Get a self-hosted value by its name. Note that these values don't get \n"
|
||||
" cached, so repeatedly getting the same value creates multiple distinct clones."),
|
||||
|
||||
JS_FS_HELP_END
|
||||
};
|
||||
#ifdef MOZ_PROFILING
|
||||
|
|
|
@ -393,7 +393,11 @@ class GlobalObject : public JSObject
|
|||
if (HasDataProperty(cx, holder, id, value.address()))
|
||||
return true;
|
||||
Rooted<PropertyName*> rootedName(cx, name);
|
||||
return cx->runtime->cloneSelfHostedValue(cx, rootedName, holder, value);
|
||||
if (!cx->runtime->cloneSelfHostedValue(cx, rootedName, value))
|
||||
return false;
|
||||
mozilla::DebugOnly<bool> ok = JS_DefinePropertyById(cx, holder, id, value, NULL, NULL, 0);
|
||||
JS_ASSERT(ok);
|
||||
return true;
|
||||
}
|
||||
|
||||
inline RegExpStatics *getRegExpStatics() const;
|
||||
|
|
Загрузка…
Ссылка в новой задаче