summaryrefslogtreecommitdiffstats
path: root/js/src/jsscript.h
diff options
context:
space:
mode:
Diffstat (limited to 'js/src/jsscript.h')
-rw-r--r--js/src/jsscript.h109
1 files changed, 92 insertions, 17 deletions
diff --git a/js/src/jsscript.h b/js/src/jsscript.h
index 87da79901..85eb2938d 100644
--- a/js/src/jsscript.h
+++ b/js/src/jsscript.h
@@ -575,10 +575,6 @@ class ScriptSource
introductionOffset_ = offset;
hasIntroductionOffset_ = true;
}
-
- uint32_t parameterListEnd() const {
- return parameterListEnd_;
- }
};
class ScriptSourceHolder
@@ -857,9 +853,36 @@ class JSScript : public js::gc::TenuredCell
uint32_t bodyScopeIndex_; /* index into the scopes array of the body scope */
- /* Range of characters in scriptSource which contains this script's source. */
+ // Range of characters in scriptSource which contains this script's
+ // source, that is, the range used by the Parser to produce this script.
+ //
+ // Most scripted functions have sourceStart_ == toStringStart_ and
+ // sourceEnd_ == toStringEnd_. However, for functions with extra
+ // qualifiers (e.g. generators, async) and for class constructors (which
+ // need to return the entire class source), their values differ.
+ //
+ // Each field points the following locations.
+ //
+ // function * f(a, b) { return a + b; }
+ // ^ ^ ^
+ // | | |
+ // | sourceStart_ sourceEnd_
+ // | |
+ // toStringStart_ toStringEnd_
+ //
+ // And, in the case of class constructors, an additional toStringEnd
+ // offset is used.
+ //
+ // class C { constructor() { this.field = 42; } }
+ // ^ ^ ^ ^
+ // | | | `---------`
+ // | sourceStart_ sourceEnd_ |
+ // | |
+ // toStringStart_ toStringEnd_
uint32_t sourceStart_;
uint32_t sourceEnd_;
+ uint32_t toStringStart_;
+ uint32_t toStringEnd_;
// Number of times the script has been called or has had backedges taken.
// When running in ion, also increased for any inlined scripts. Reset if
@@ -1015,6 +1038,7 @@ class JSScript : public js::gc::TenuredCell
bool isAsync_:1;
bool hasRest_:1;
+ bool isExprBody_:1;
// Add padding so JSScript is gc::Cell aligned. Make padding protected
// instead of private to suppress -Wunused-private-field compiler warnings.
@@ -1030,8 +1054,9 @@ class JSScript : public js::gc::TenuredCell
public:
static JSScript* Create(js::ExclusiveContext* cx,
const JS::ReadOnlyCompileOptions& options,
- js::HandleObject sourceObject, uint32_t sourceStart,
- uint32_t sourceEnd);
+ js::HandleObject sourceObject,
+ uint32_t sourceStart, uint32_t sourceEnd,
+ uint32_t toStringStart, uint32_t toStringEnd);
void initCompartment(js::ExclusiveContext* cx);
@@ -1178,6 +1203,14 @@ class JSScript : public js::gc::TenuredCell
return sourceEnd_;
}
+ uint32_t toStringStart() const {
+ return toStringStart_;
+ }
+
+ uint32_t toStringEnd() const {
+ return toStringEnd_;
+ }
+
bool noScriptRval() const {
return noScriptRval_;
}
@@ -1319,6 +1352,13 @@ class JSScript : public js::gc::TenuredCell
hasRest_ = true;
}
+ bool isExprBody() const {
+ return isExprBody_;
+ }
+ void setIsExprBody() {
+ isExprBody_ = true;
+ }
+
void setNeedsHomeObject() {
needsHomeObject_ = true;
}
@@ -1454,6 +1494,7 @@ class JSScript : public js::gc::TenuredCell
bool isRelazifiable() const {
return (selfHosted() || lazyScript) && !hasInnerFunctions_ && !types_ &&
!isGenerator() && !hasBaselineScript() && !hasAnyIonScript() &&
+ !isDefaultClassConstructor() &&
!doNotRelazify_;
}
void setLazyScript(js::LazyScript* lazy) {
@@ -1481,7 +1522,7 @@ class JSScript : public js::gc::TenuredCell
* De-lazifies the canonical function. Must be called before entering code
* that expects the function to be non-lazy.
*/
- inline void ensureNonLazyCanonicalFunction(JSContext* cx);
+ inline void ensureNonLazyCanonicalFunction();
js::ModuleObject* module() const {
if (bodyScope()->is<js::ModuleScope>())
@@ -1500,8 +1541,9 @@ class JSScript : public js::gc::TenuredCell
// directly, via lazy arguments or a rest parameter.
bool mayReadFrameArgsDirectly();
- JSFlatString* sourceData(JSContext* cx);
-
+ static JSFlatString* sourceData(JSContext* cx, JS::HandleScript script);
+ static JSFlatString* sourceDataForToString(JSContext* cx, JS::HandleScript script);
+
static bool loadSource(JSContext* cx, js::ScriptSource* ss, bool* worked);
void setSourceObject(JSObject* object);
@@ -1515,6 +1557,8 @@ class JSScript : public js::gc::TenuredCell
const char* filename() const { return scriptSource()->filename(); }
const char* maybeForwardedFilename() const { return maybeForwardedScriptSource()->filename(); }
+ void setDefaultClassConstructorSpan(JSObject* sourceObject, uint32_t start, uint32_t end);
+
public:
/* Return whether this script was compiled for 'eval' */
@@ -1924,7 +1968,7 @@ class LazyScript : public gc::TenuredCell
#endif
private:
- static const uint32_t NumClosedOverBindingsBits = 21;
+ static const uint32_t NumClosedOverBindingsBits = 20;
static const uint32_t NumInnerFunctionsBits = 20;
struct PackedView {
@@ -1934,7 +1978,12 @@ class LazyScript : public gc::TenuredCell
uint32_t shouldDeclareArguments : 1;
uint32_t hasThisBinding : 1;
uint32_t isAsync : 1;
+ uint32_t isExprBody : 1;
+
uint32_t numClosedOverBindings : NumClosedOverBindingsBits;
+
+ // -- 32bit boundary --
+
uint32_t numInnerFunctions : NumInnerFunctionsBits;
uint32_t generatorKindBits : 2;
@@ -1960,20 +2009,26 @@ class LazyScript : public gc::TenuredCell
};
// Source location for the script.
+ // See the comment in JSScript for the details.
uint32_t begin_;
uint32_t end_;
+ uint32_t toStringStart_;
+ uint32_t toStringEnd_;
+ // Line and column of |begin_| position, that is the position where we
+ // start parsing.
uint32_t lineno_;
uint32_t column_;
LazyScript(JSFunction* fun, void* table, uint64_t packedFields,
- uint32_t begin, uint32_t end, uint32_t lineno, uint32_t column);
+ uint32_t begin, uint32_t end, uint32_t toStringStart,
+ uint32_t lineno, uint32_t column);
// Create a LazyScript without initializing the closedOverBindings and the
// innerFunctions. To be GC-safe, the caller must initialize both vectors
// with valid atoms and functions.
static LazyScript* CreateRaw(ExclusiveContext* cx, HandleFunction fun,
uint64_t packedData, uint32_t begin, uint32_t end,
- uint32_t lineno, uint32_t column);
+ uint32_t toStringStart, uint32_t lineno, uint32_t column);
public:
static const uint32_t NumClosedOverBindingsLimit = 1 << NumClosedOverBindingsBits;
@@ -1985,7 +2040,7 @@ class LazyScript : public gc::TenuredCell
const frontend::AtomVector& closedOverBindings,
Handle<GCVector<JSFunction*, 8>> innerFunctions,
JSVersion version, uint32_t begin, uint32_t end,
- uint32_t lineno, uint32_t column);
+ uint32_t toStringStart, uint32_t lineno, uint32_t column);
// Create a LazyScript and initialize the closedOverBindings and the
// innerFunctions with dummy values to be replaced in a later initialization
@@ -2000,11 +2055,11 @@ class LazyScript : public gc::TenuredCell
HandleScript script, HandleScope enclosingScope,
HandleScript enclosingScript,
uint64_t packedData, uint32_t begin, uint32_t end,
- uint32_t lineno, uint32_t column);
+ uint32_t toStringStart, uint32_t lineno, uint32_t column);
void initRuntimeFields(uint64_t packedFields);
- inline JSFunction* functionDelazifying(JSContext* cx) const;
+ static inline JSFunction* functionDelazifying(JSContext* cx, Handle<LazyScript*>);
JSFunction* functionNonDelazifying() const {
return function_;
}
@@ -2087,6 +2142,13 @@ class LazyScript : public gc::TenuredCell
p_.hasRest = true;
}
+ bool isExprBody() const {
+ return p_.isExprBody;
+ }
+ void setIsExprBody() {
+ p_.isExprBody = true;
+ }
+
bool strict() const {
return p_.strict;
}
@@ -2173,6 +2235,12 @@ class LazyScript : public gc::TenuredCell
uint32_t end() const {
return end_;
}
+ uint32_t toStringStart() const {
+ return toStringStart_;
+ }
+ uint32_t toStringEnd() const {
+ return toStringEnd_;
+ }
uint32_t lineno() const {
return lineno_;
}
@@ -2180,6 +2248,12 @@ class LazyScript : public gc::TenuredCell
return column_;
}
+ void setToStringEnd(uint32_t toStringEnd) {
+ MOZ_ASSERT(toStringStart_ <= toStringEnd);
+ MOZ_ASSERT(toStringEnd_ >= end_);
+ toStringEnd_ = toStringEnd;
+ }
+
bool hasUncompiledEnclosingScript() const;
friend class GCMarker;
@@ -2199,7 +2273,8 @@ class LazyScript : public gc::TenuredCell
};
/* If this fails, add/remove padding within LazyScript. */
-JS_STATIC_ASSERT(sizeof(LazyScript) % js::gc::CellSize == 0);
+static_assert(sizeof(LazyScript) % js::gc::CellSize == 0,
+ "Size of LazyScript must be an integral multiple of js::gc::CellSize");
struct ScriptAndCounts
{