summaryrefslogtreecommitdiff
path: root/js/src/jsfun.h
diff options
context:
space:
mode:
Diffstat (limited to 'js/src/jsfun.h')
-rw-r--r--js/src/jsfun.h38
1 files changed, 31 insertions, 7 deletions
diff --git a/js/src/jsfun.h b/js/src/jsfun.h
index 38cc832800..481f062080 100644
--- a/js/src/jsfun.h
+++ b/js/src/jsfun.h
@@ -59,6 +59,9 @@ class JSFunction : public js::NativeObject
BOUND_FUN = 0x0008, /* function was created with Function.prototype.bind. */
HAS_GUESSED_ATOM = 0x0020, /* function had no explicit name, but a
name was guessed for it anyway */
+ HAS_BOUND_FUNCTION_NAME_PREFIX = 0x0020, /* bound functions reuse the HAS_GUESSED_ATOM
+ flag to track if atom_ already contains the
+ "bound " function name prefix */
LAMBDA = 0x0040, /* function comes from a FunctionExpression, ArrowFunction, or
Function() call (not a FunctionDeclaration or nonstandard
function-statement) */
@@ -99,8 +102,8 @@ class JSFunction : public js::NativeObject
INTERPRETED_GENERATOR_OR_ASYNC = INTERPRETED,
NO_XDR_FLAGS = RESOLVED_LENGTH | RESOLVED_NAME,
- STABLE_ACROSS_CLONES = CONSTRUCTOR | HAS_GUESSED_ATOM | LAMBDA |
- SELF_HOSTED | HAS_COMPILE_TIME_NAME | FUNCTION_KIND_MASK
+ STABLE_ACROSS_CLONES = CONSTRUCTOR | LAMBDA | SELF_HOSTED | HAS_COMPILE_TIME_NAME |
+ FUNCTION_KIND_MASK
};
static_assert((INTERPRETED | INTERPRETED_LAZY) == js::JS_FUNCTION_INTERPRETED_BITS,
@@ -186,10 +189,20 @@ class JSFunction : public js::NativeObject
bool isAsmJSNative() const { return kind() == AsmJS; }
/* Possible attributes of an interpreted function: */
+ bool isBoundFunction() const { return flags() & BOUND_FUN; }
bool hasCompileTimeName() const { return flags() & HAS_COMPILE_TIME_NAME; }
- bool hasGuessedAtom() const { return flags() & HAS_GUESSED_ATOM; }
+ bool hasGuessedAtom() const {
+ static_assert(HAS_GUESSED_ATOM == HAS_BOUND_FUNCTION_NAME_PREFIX,
+ "HAS_GUESSED_ATOM is unused for bound functions");
+ return (flags() & (HAS_GUESSED_ATOM | BOUND_FUN)) == HAS_GUESSED_ATOM;
+ }
+ bool hasBoundFunctionNamePrefix() const {
+ static_assert(HAS_BOUND_FUNCTION_NAME_PREFIX == HAS_GUESSED_ATOM,
+ "HAS_BOUND_FUNCTION_NAME_PREFIX is only used for bound functions");
+ MOZ_ASSERT(isBoundFunction());
+ return flags() & HAS_BOUND_FUNCTION_NAME_PREFIX;
+ }
bool isLambda() const { return flags() & LAMBDA; }
- bool isBoundFunction() const { return flags() & BOUND_FUN; }
bool isInterpretedLazy() const { return flags() & INTERPRETED_LAZY; }
bool hasScript() const { return flags() & INTERPRETED; }
@@ -310,7 +323,8 @@ class JSFunction : public js::NativeObject
static bool getUnresolvedLength(JSContext* cx, js::HandleFunction fun,
js::MutableHandleValue v);
- JSAtom* getUnresolvedName(JSContext* cx);
+ static bool getUnresolvedName(JSContext* cx, js::HandleFunction fun,
+ js::MutableHandleAtom v);
JSAtom* explicitName() const {
return (hasCompileTimeName() || hasGuessedAtom()) ? nullptr : atom_.get();
@@ -346,16 +360,26 @@ class JSFunction : public js::NativeObject
MOZ_ASSERT(atom);
MOZ_ASSERT(!hasCompileTimeName());
MOZ_ASSERT(!hasGuessedAtom());
+ MOZ_ASSERT(!isBoundFunction());
+ MOZ_ASSERT(js::AtomIsMarked(zone(), atom));
atom_ = atom;
flags_ |= HAS_GUESSED_ATOM;
}
void clearGuessedAtom() {
MOZ_ASSERT(hasGuessedAtom());
+ MOZ_ASSERT(!isBoundFunction());
MOZ_ASSERT(atom_);
atom_ = nullptr;
flags_ &= ~HAS_GUESSED_ATOM;
}
+ void setPrefixedBoundFunctionName(JSAtom* atom) {
+ MOZ_ASSERT(!hasBoundFunctionNamePrefix());
+ MOZ_ASSERT(atom);
+ flags_ |= HAS_BOUND_FUNCTION_NAME_PREFIX;
+ atom_ = atom;
+ }
+
/* uint16_t representation bounds number of call object dynamic slots. */
enum { MAX_ARGS_AND_VARS = 2 * ((1U << 16) - 1) };
@@ -646,7 +670,7 @@ static_assert(sizeof(JSFunction) == sizeof(js::shadow::Function),
"shadow interface must match actual interface");
extern JSString*
-fun_toStringHelper(JSContext* cx, js::HandleObject obj, unsigned indent);
+fun_toStringHelper(JSContext* cx, js::HandleObject obj, bool isToSource);
namespace js {
@@ -851,7 +875,7 @@ JSFunction::getExtendedSlot(size_t which) const
namespace js {
-JSString* FunctionToString(JSContext* cx, HandleFunction fun, bool prettyPring);
+JSString* FunctionToString(JSContext* cx, HandleFunction fun, bool isToSource);
template<XDRMode mode>
bool