Bug 1637424 - Part 1.1: Make some functions to access uncloned self-hosted values infallible. r=tcampbell.

Differential Revision: https://phabricator.services.mozilla.com/D79360
This commit is contained in:
Jason Orendorff 2020-06-17 19:25:54 +00:00
Родитель e32265c6f1
Коммит 07a260678e
5 изменённых файлов: 34 добавлений и 59 удалений

Просмотреть файл

@ -295,10 +295,8 @@ JSFunction* js::MakeDefaultConstructor(JSContext* cx, HandleScript script,
cx, derived ? cx->names().DefaultDerivedClassConstructor
: cx->names().DefaultBaseClassConstructor);
RootedFunction sourceFun(
cx, cx->runtime()->getUnclonedSelfHostedFunction(cx, selfHostedName));
if (!sourceFun) {
return nullptr;
}
cx, cx->runtime()->getUnclonedSelfHostedFunction(selfHostedName.get()));
MOZ_ASSERT(sourceFun);
RootedScript sourceScript(cx, sourceFun->nonLazyScript());
// Create the new class constructor function.

Просмотреть файл

@ -1674,11 +1674,10 @@ bool JSFunction::delazifySelfHostedLazyFunction(JSContext* cx,
/* Lazily cloned self-hosted script. */
MOZ_ASSERT(fun->isSelfHostedBuiltin());
RootedAtom funAtom(cx, GetClonedSelfHostedFunctionName(fun));
if (!funAtom) {
Rooted<PropertyName*> funName(cx, GetClonedSelfHostedFunctionName(fun));
if (!funName) {
return false;
}
Rooted<PropertyName*> funName(cx, funAtom->asPropertyName());
return cx->runtime()->cloneSelfHostedFunctionScript(cx, funName, fun);
}
@ -1742,7 +1741,7 @@ js::GeneratorKind JSFunction::clonedSelfHostedGeneratorKind() const {
// `this->flags_` does not contain the generator kind. Consult the
// implementation in the self-hosting realm, which has a BaseScript.
MOZ_RELEASE_ASSERT(isExtended());
JSAtom* name = GetClonedSelfHostedFunctionName(this);
PropertyName* name = GetClonedSelfHostedFunctionName(this);
return runtimeFromMainThread()->getSelfHostedFunctionGeneratorKind(name);
}

Просмотреть файл

@ -592,10 +592,8 @@ struct JSRuntime {
static js::GlobalObject* createSelfHostingGlobal(JSContext* cx);
public:
bool getUnclonedSelfHostedValue(JSContext* cx, js::HandlePropertyName name,
js::MutableHandleValue vp);
JSFunction* getUnclonedSelfHostedFunction(JSContext* cx,
js::HandlePropertyName name);
void getUnclonedSelfHostedValue(js::PropertyName* name, JS::Value* vp);
JSFunction* getUnclonedSelfHostedFunction(js::PropertyName* name);
MOZ_MUST_USE bool createJitRuntime(JSContext* cx);
js::jit::JitRuntime* jitRuntime() const { return jitRuntime_.ref(); }

Просмотреть файл

@ -937,7 +937,7 @@ bool js::intrinsic_NewRegExpStringIterator(JSContext* cx, unsigned argc,
return true;
}
static JSAtom* GetUnclonedSelfHostedFunctionName(JSFunction* fun) {
static js::PropertyName* GetUnclonedSelfHostedFunctionName(JSFunction* fun) {
if (!fun->isExtended()) {
return nullptr;
}
@ -945,10 +945,10 @@ static JSAtom* GetUnclonedSelfHostedFunctionName(JSFunction* fun) {
if (!name.isString()) {
return nullptr;
}
return &name.toString()->asAtom();
return name.toString()->asAtom().asPropertyName();
}
JSAtom* js::GetClonedSelfHostedFunctionName(const JSFunction* fun) {
js::PropertyName* js::GetClonedSelfHostedFunctionName(const JSFunction* fun) {
if (!fun->isExtended()) {
return nullptr;
}
@ -956,15 +956,15 @@ JSAtom* js::GetClonedSelfHostedFunctionName(const JSFunction* fun) {
if (!name.isString()) {
return nullptr;
}
return &name.toString()->asAtom();
return name.toString()->asAtom().asPropertyName();
}
JSAtom* js::GetClonedSelfHostedFunctionNameOffMainThread(JSFunction* fun) {
js::PropertyName* js::GetClonedSelfHostedFunctionNameOffMainThread(JSFunction* fun) {
Value name = fun->getExtendedSlotOffMainThread(LAZY_FUNCTION_NAME_SLOT);
if (!name.isString()) {
return nullptr;
}
return &name.toString()->asAtom();
return name.toString()->asAtom().asPropertyName();
}
bool js::IsExtendedUnclonedSelfHostedFunctionName(JSAtom* name) {
@ -2789,28 +2789,21 @@ void JSRuntime::traceSelfHostingGlobal(JSTracer* trc) {
}
GeneratorKind JSRuntime::getSelfHostedFunctionGeneratorKind(JSAtom* name) {
NativeObject* selfHostedObject = selfHostingGlobal_.ref();
Shape* shape = selfHostedObject->lookupPure(JS::PropertyKey::fromNonIntAtom(name));
MOZ_RELEASE_ASSERT(shape);
MOZ_ASSERT(shape->isDataProperty());
Value funVal = selfHostedObject->getSlot(shape->slot());
MOZ_RELEASE_ASSERT(funVal.isObject());
return funVal.toObject().as<JSFunction>().generatorKind();
JSFunction* fun = getUnclonedSelfHostedFunction(name->asPropertyName());
return fun->generatorKind();
}
static bool CloneValue(JSContext* cx, HandleValue selfHostedValue,
MutableHandleValue vp);
static bool GetUnclonedValue(JSContext* cx, HandleNativeObject selfHostedObject,
HandleId id, MutableHandleValue vp) {
vp.setUndefined();
static void GetUnclonedValue(NativeObject* selfHostedObject,
const JS::PropertyKey& id, Value* vp) {
if (JSID_IS_INT(id)) {
size_t index = JSID_TO_INT(id);
if (index < selfHostedObject->getDenseInitializedLength() &&
!selfHostedObject->getDenseElement(index).isMagic(JS_ELEMENTS_HOLE)) {
vp.set(selfHostedObject->getDenseElement(JSID_TO_INT(id)));
return true;
*vp = selfHostedObject->getDenseElement(JSID_TO_INT(id));
return;
}
}
@ -2821,11 +2814,10 @@ static bool GetUnclonedValue(JSContext* cx, HandleNativeObject selfHostedObject,
// non-permanent atoms here should be impossible.
MOZ_ASSERT_IF(JSID_IS_STRING(id), JSID_TO_STRING(id)->isPermanentAtom());
RootedShape shape(cx, selfHostedObject->lookupPure(id));
Shape* shape = selfHostedObject->lookupPure(id);
MOZ_ASSERT(shape);
MOZ_ASSERT(shape->isDataProperty());
vp.set(selfHostedObject->getSlot(shape->slot()));
return true;
*vp = selfHostedObject->getSlot(shape->slot());
}
static bool CloneProperties(JSContext* cx, HandleNativeObject selfHostedObject,
@ -2874,9 +2866,7 @@ static bool CloneProperties(JSContext* cx, HandleNativeObject selfHostedObject,
RootedValue selfHostedValue(cx);
for (uint32_t i = 0; i < ids.length(); i++) {
id = ids[i];
if (!GetUnclonedValue(cx, selfHostedObject, id, &selfHostedValue)) {
return false;
}
GetUnclonedValue(selfHostedObject, id, selfHostedValue.address());
if (!CloneValue(cx, selfHostedValue, &val) ||
!JS_DefinePropertyById(cx, clone, id, val, attrs[i])) {
return false;
@ -3079,7 +3069,7 @@ bool JSRuntime::createLazySelfHostedFunctionClone(
MOZ_ASSERT(newKind != GenericObject);
RootedAtom funName(cx, name);
JSFunction* selfHostedFun = getUnclonedSelfHostedFunction(cx, selfHostedName);
JSFunction* selfHostedFun = getUnclonedSelfHostedFunction(selfHostedName);
if (!selfHostedFun) {
return false;
}
@ -3107,7 +3097,7 @@ bool JSRuntime::createLazySelfHostedFunctionClone(
bool JSRuntime::cloneSelfHostedFunctionScript(JSContext* cx,
HandlePropertyName name,
HandleFunction targetFun) {
RootedFunction sourceFun(cx, getUnclonedSelfHostedFunction(cx, name));
RootedFunction sourceFun(cx, getUnclonedSelfHostedFunction(name));
if (!sourceFun) {
return false;
}
@ -3159,31 +3149,21 @@ bool JSRuntime::cloneSelfHostedFunctionScript(JSContext* cx,
return true;
}
bool JSRuntime::getUnclonedSelfHostedValue(JSContext* cx,
HandlePropertyName name,
MutableHandleValue vp) {
RootedId id(cx, NameToId(name));
return GetUnclonedValue(
cx, HandleNativeObject::fromMarkedLocation(&selfHostingGlobal_.ref()), id,
vp);
void JSRuntime::getUnclonedSelfHostedValue(PropertyName* name, Value* vp) {
JS::PropertyKey id = NameToId(name);
GetUnclonedValue(selfHostingGlobal_, id, vp);
}
JSFunction* JSRuntime::getUnclonedSelfHostedFunction(JSContext* cx,
HandlePropertyName name) {
RootedValue selfHostedValue(cx);
if (!getUnclonedSelfHostedValue(cx, name, &selfHostedValue)) {
return nullptr;
}
JSFunction* JSRuntime::getUnclonedSelfHostedFunction(PropertyName* name) {
Value selfHostedValue;
getUnclonedSelfHostedValue(name, &selfHostedValue);
return &selfHostedValue.toObject().as<JSFunction>();
}
bool JSRuntime::cloneSelfHostedValue(JSContext* cx, HandlePropertyName name,
MutableHandleValue vp) {
RootedValue selfHostedValue(cx);
if (!getUnclonedSelfHostedValue(cx, name, &selfHostedValue)) {
return false;
}
getUnclonedSelfHostedValue(name, selfHostedValue.address());
/*
* We don't clone if we're operating in the self-hosting global, as that
@ -3201,7 +3181,7 @@ bool JSRuntime::cloneSelfHostedValue(JSContext* cx, HandlePropertyName name,
void JSRuntime::assertSelfHostedFunctionHasCanonicalName(
JSContext* cx, HandlePropertyName name) {
#ifdef DEBUG
JSFunction* selfHostedFun = getUnclonedSelfHostedFunction(cx, name);
JSFunction* selfHostedFun = getUnclonedSelfHostedFunction(name);
MOZ_ASSERT(selfHostedFun);
MOZ_ASSERT(GetUnclonedSelfHostedFunctionName(selfHostedFun) == name);
#endif

Просмотреть файл

@ -26,7 +26,7 @@ bool IsSelfHostedFunctionWithName(JSFunction* fun, JSAtom* name);
* This returns a non-null value only when this is a top level function
* declaration in the self-hosted global.
*/
JSAtom* GetClonedSelfHostedFunctionName(const JSFunction* fun);
PropertyName* GetClonedSelfHostedFunctionName(const JSFunction* fun);
/*
* Same as GetClonedSelfHostedFunctionName, but `fun` is guaranteed to be an
@ -38,7 +38,7 @@ JSAtom* GetClonedSelfHostedFunctionName(const JSFunction* fun);
*
* See Also: WrappedFunction.isExtended_
*/
JSAtom* GetClonedSelfHostedFunctionNameOffMainThread(JSFunction* fun);
PropertyName* GetClonedSelfHostedFunctionNameOffMainThread(JSFunction* fun);
/*
* Uncloned self-hosted functions with `$` prefix are allocated as