summaryrefslogtreecommitdiffstats
path: root/js/src/jsscript.h
diff options
context:
space:
mode:
authorGaming4JC <g4jc@hyperbola.info>2019-07-13 21:33:52 -0400
committerGaming4JC <g4jc@hyperbola.info>2019-07-18 22:38:41 -0400
commit53e46b1e12ef01ccaabb3256738ea1eac74b7941 (patch)
treed6d90d717876c7c15b8d851ee9ffaa6fd394939e /js/src/jsscript.h
parentd1c146adf23e317facd03cd5c097f12a69947392 (diff)
downloadUXP-53e46b1e12ef01ccaabb3256738ea1eac74b7941.tar
UXP-53e46b1e12ef01ccaabb3256738ea1eac74b7941.tar.gz
UXP-53e46b1e12ef01ccaabb3256738ea1eac74b7941.tar.lz
UXP-53e46b1e12ef01ccaabb3256738ea1eac74b7941.tar.xz
UXP-53e46b1e12ef01ccaabb3256738ea1eac74b7941.zip
1216630 - Print class source when calling toString on the constructor.
This is accomplished in the following ways. LazyScripts and JSScripts now have 4 offsets: - Source begin and end for the actual source. This is used for lazy parsing. - toString begin and end for toString. Some kinds of functions, like async, only have a different begin offset. Class constructors have different offsets for both begin and end. For syntactically present (i.e. non-default) constructors, the class source span is remembered directly on the LazyScript or JSScript. The toString implementation then splices out the substring directly. For default constructors, a new SRC_CLASS SrcNote type is added. It's binary and has as its arguments the begin and end offsets of the class expression or statement. MakeDefaultConstructor reads the note and overrides the cloned self-hosted function's source object. This is probably the least intrusive way to accomplish this.
Diffstat (limited to 'js/src/jsscript.h')
-rw-r--r--js/src/jsscript.h39
1 files changed, 32 insertions, 7 deletions
diff --git a/js/src/jsscript.h b/js/src/jsscript.h
index 62502a3c7..8a21d394a 100644
--- a/js/src/jsscript.h
+++ b/js/src/jsscript.h
@@ -863,9 +863,19 @@ class JSScript : public js::gc::TenuredCell
// |
// preludeStart_
//
+ // And, in the case of class constructors, an additional postlude offset
+ // is used for use with toString.
+ //
+ // class C { constructor() { this.field = 42; } }
+ // ^ ^ ^ ^
+ // | | | `---------`
+ // | sourceStart_ sourceEnd_ |
+ // | |
+ // preludeStart_ postludeEnd_
uint32_t sourceStart_;
uint32_t sourceEnd_;
uint32_t preludeStart_;
+ uint32_t postludeEnd_;
// 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
@@ -1027,7 +1037,7 @@ class JSScript : public js::gc::TenuredCell
// instead of private to suppress -Wunused-private-field compiler warnings.
protected:
#if JS_BITS_PER_WORD == 32
- uint32_t padding;
+ // Currently no padding is needed.
#endif
//
@@ -1037,8 +1047,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, uint32_t preludeStart);
+ js::HandleObject sourceObject,
+ uint32_t sourceStart, uint32_t sourceEnd,
+ uint32_t preludeStart, uint32_t postludeEnd);
void initCompartment(js::ExclusiveContext* cx);
@@ -1185,10 +1196,14 @@ class JSScript : public js::gc::TenuredCell
return sourceEnd_;
}
- size_t preludeStart() const {
+ uint32_t preludeStart() const {
return preludeStart_;
}
+ uint32_t postludeEnd() const {
+ return postludeEnd_;
+ }
+
bool noScriptRval() const {
return noScriptRval_;
}
@@ -1519,7 +1534,7 @@ class JSScript : public js::gc::TenuredCell
bool mayReadFrameArgsDirectly();
static JSFlatString* sourceData(JSContext* cx, JS::HandleScript script);
- static JSFlatString* sourceDataWithPrelude(JSContext* cx, JS::HandleScript script);
+ static JSFlatString* sourceDataForToString(JSContext* cx, JS::HandleScript script);
static bool loadSource(JSContext* cx, js::ScriptSource* ss, bool* worked);
@@ -1534,6 +1549,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' */
@@ -1939,8 +1956,7 @@ class LazyScript : public gc::TenuredCell
// instead of private to suppress -Wunused-private-field compiler warnings.
protected:
#if JS_BITS_PER_WORD == 32
- // uint32_t padding;
- // Currently no padding is needed.
+ uint32_t padding;
#endif
private:
@@ -1989,6 +2005,7 @@ class LazyScript : public gc::TenuredCell
uint32_t begin_;
uint32_t end_;
uint32_t preludeStart_;
+ uint32_t postludeEnd_;
// Line and column of |begin_| position, that is the position where we
// start parsing.
uint32_t lineno_;
@@ -2213,6 +2230,9 @@ class LazyScript : public gc::TenuredCell
uint32_t preludeStart() const {
return preludeStart_;
}
+ uint32_t postludeEnd() const {
+ return postludeEnd_;
+ }
uint32_t lineno() const {
return lineno_;
}
@@ -2220,6 +2240,11 @@ class LazyScript : public gc::TenuredCell
return column_;
}
+ void setPostludeEnd(uint32_t postludeEnd) {
+ MOZ_ASSERT(postludeEnd_ >= end_);
+ postludeEnd_ = postludeEnd;
+ }
+
bool hasUncompiledEnclosingScript() const;
friend class GCMarker;