diff options
Diffstat (limited to 'js/src/jsfun.cpp')
-rw-r--r-- | js/src/jsfun.cpp | 58 |
1 files changed, 42 insertions, 16 deletions
diff --git a/js/src/jsfun.cpp b/js/src/jsfun.cpp index be1d39cd19..0d0a899b03 100644 --- a/js/src/jsfun.cpp +++ b/js/src/jsfun.cpp @@ -339,11 +339,11 @@ CallerSetterImpl(JSContext* cx, const CallArgs& args) { MOZ_ASSERT(IsFunction(args.thisv())); - // We just have to return |undefined|, but first we call CallerGetterImpl
- // because we need the same strict-mode and security checks.
-
+ // We just have to return |undefined|, but first we call CallerGetterImpl + // because we need the same strict-mode and security checks. + if (!CallerGetterImpl(cx, args)) { - return false;
+ return false; } args.rval().setUndefined(); @@ -498,9 +498,12 @@ fun_resolve(JSContext* cx, HandleObject obj, HandleId id, bool* resolvedp) if (fun->hasResolvedName()) return true; + RootedAtom name(cx); + if (!JSFunction::getUnresolvedName(cx, fun, &name)) + return false; + // Don't define an own .name property for unnamed functions. - JSAtom* name = fun->getUnresolvedName(cx); - if (name == nullptr) + if (!name) return true; v.setString(name); @@ -997,7 +1000,7 @@ js::FunctionToString(JSContext* cx, HandleFunction fun, bool prettyPrint) return nullptr; } - auto AppendPrelude = [&out, &fun]() { + auto AppendPrelude = [cx, &out, &fun]() { if (fun->isAsync()) { if (!out.append("async ")) return false; @@ -1016,6 +1019,10 @@ js::FunctionToString(JSContext* cx, HandleFunction fun, bool prettyPrint) if (fun->explicitName()) { if (!out.append(' ')) return false; + if (fun->isBoundFunction()) { + if (!out.append(cx->names().boundWithSpace)) + return false; + } if (!out.append(fun->explicitName())) return false; } @@ -1327,23 +1334,42 @@ JSFunction::getUnresolvedLength(JSContext* cx, HandleFunction fun, MutableHandle return true; } -JSAtom* -JSFunction::getUnresolvedName(JSContext* cx) +/* static */ bool +JSFunction::getUnresolvedName(JSContext* cx, HandleFunction fun, MutableHandleAtom v) { - MOZ_ASSERT(!IsInternalFunctionObject(*this)); - MOZ_ASSERT(!hasResolvedName()); + MOZ_ASSERT(!IsInternalFunctionObject(*fun)); + MOZ_ASSERT(!fun->hasResolvedName()); - if (isClassConstructor()) { + JSAtom* name = fun->explicitOrCompileTimeName(); + if (fun->isClassConstructor()) { // It's impossible to have an empty named class expression. We use // empty as a sentinel when creating default class constructors. - MOZ_ASSERT(explicitOrCompileTimeName() != cx->names().empty); + MOZ_ASSERT(name != cx->names().empty); // Unnamed class expressions should not get a .name property at all. - return explicitOrCompileTimeName(); + if (name) + v.set(name); + return true; } - return explicitOrCompileTimeName() != nullptr ? explicitOrCompileTimeName() - : cx->names().empty; + if (fun->isBoundFunction()) { + // Bound functions are never unnamed. + MOZ_ASSERT(name); + + StringBuffer sb(cx); + if (!sb.append(cx->names().boundWithSpace) || !sb.append(name)) + return false; + + JSAtom* boundName = sb.finishAtom(); + if (!boundName) + return false; + + v.set(boundName); + return true; + } + + v.set(name != nullptr ? name : cx->names().empty); + return true; } static const js::Value& |