summaryrefslogtreecommitdiffstats
path: root/js/src/jsscript.cpp
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.cpp
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.cpp')
-rw-r--r--js/src/jsscript.cpp34
1 files changed, 29 insertions, 5 deletions
diff --git a/js/src/jsscript.cpp b/js/src/jsscript.cpp
index ddc98ef3f..ad4cb2338 100644
--- a/js/src/jsscript.cpp
+++ b/js/src/jsscript.cpp
@@ -236,6 +236,7 @@ XDRRelazificationInfo(XDRState<mode>* xdr, HandleFunction fun, HandleScript scri
uint32_t begin = script->sourceStart();
uint32_t end = script->sourceEnd();
uint32_t preludeStart = script->preludeStart();
+ uint32_t postludeEnd = script->postludeEnd();
uint32_t lineno = script->lineno();
uint32_t column = script->column();
@@ -244,6 +245,7 @@ XDRRelazificationInfo(XDRState<mode>* xdr, HandleFunction fun, HandleScript scri
MOZ_ASSERT(begin == lazy->begin());
MOZ_ASSERT(end == lazy->end());
MOZ_ASSERT(preludeStart == lazy->preludeStart());
+ MOZ_ASSERT(postludeEnd == lazy->postludeEnd());
MOZ_ASSERT(lineno == lazy->lineno());
MOZ_ASSERT(column == lazy->column());
// We can assert we have no inner functions because we don't
@@ -259,6 +261,11 @@ XDRRelazificationInfo(XDRState<mode>* xdr, HandleFunction fun, HandleScript scri
lazy.set(LazyScript::Create(cx, fun, script, enclosingScope, script,
packedFields, begin, end, preludeStart, lineno, column));
+ if (!lazy)
+ return false;
+
+ lazy->setPostludeEnd(postludeEnd);
+
// As opposed to XDRLazyScript, we need to restore the runtime bits
// of the script, as we are trying to match the fact this function
// has already been parsed and that it would need to be re-lazified.
@@ -522,7 +529,7 @@ js::XDRScript(XDRState<mode>* xdr, HandleScope scriptEnclosingScope, HandleScrip
sourceObject = &enclosingScript->sourceObject()->as<ScriptSourceObject>();
}
- script = JSScript::Create(cx, options, sourceObject, 0, 0, 0);
+ script = JSScript::Create(cx, options, sourceObject, 0, 0, 0, 0);
if (!script)
return false;
@@ -609,6 +616,8 @@ js::XDRScript(XDRState<mode>* xdr, HandleScope scriptEnclosingScope, HandleScrip
return false;
if (!xdr->codeUint32(&script->preludeStart_))
return false;
+ if (!xdr->codeUint32(&script->postludeEnd_))
+ return false;
if (!xdr->codeUint32(&lineno) ||
!xdr->codeUint32(&column) ||
@@ -940,6 +949,7 @@ js::XDRLazyScript(XDRState<mode>* xdr, HandleScope enclosingScope, HandleScript
uint32_t begin;
uint32_t end;
uint32_t preludeStart;
+ uint32_t postludeEnd;
uint32_t lineno;
uint32_t column;
uint64_t packedFields;
@@ -954,6 +964,7 @@ js::XDRLazyScript(XDRState<mode>* xdr, HandleScope enclosingScope, HandleScript
begin = lazy->begin();
end = lazy->end();
preludeStart = lazy->preludeStart();
+ postludeEnd = lazy->postludeEnd();
lineno = lazy->lineno();
column = lazy->column();
packedFields = lazy->packedFields();
@@ -961,6 +972,7 @@ js::XDRLazyScript(XDRState<mode>* xdr, HandleScope enclosingScope, HandleScript
if (!xdr->codeUint32(&begin) || !xdr->codeUint32(&end) ||
!xdr->codeUint32(&preludeStart) ||
+ !xdr->codeUint32(&postludeEnd) ||
!xdr->codeUint32(&lineno) || !xdr->codeUint32(&column) ||
!xdr->codeUint64(&packedFields))
{
@@ -972,6 +984,7 @@ js::XDRLazyScript(XDRState<mode>* xdr, HandleScope enclosingScope, HandleScript
packedFields, begin, end, preludeStart, lineno, column));
if (!lazy)
return false;
+ lazy->setPostludeEnd(postludeEnd);
fun->initLazyScript(lazy);
}
}
@@ -1015,6 +1028,15 @@ JSScript::setSourceObject(JSObject* object)
sourceObject_ = object;
}
+void
+JSScript::setDefaultClassConstructorSpan(JSObject* sourceObject, uint32_t start, uint32_t end)
+{
+ MOZ_ASSERT(isDefaultClassConstructor());
+ setSourceObject(sourceObject);
+ preludeStart_ = start;
+ postludeEnd_ = end;
+}
+
js::ScriptSourceObject&
JSScript::scriptSourceUnwrap() const {
return UncheckedUnwrap(sourceObject())->as<ScriptSourceObject>();
@@ -1443,10 +1465,10 @@ JSScript::sourceData(JSContext* cx, HandleScript script)
}
/* static */ JSFlatString*
-JSScript::sourceDataWithPrelude(JSContext* cx, HandleScript script)
+JSScript::sourceDataForToString(JSContext* cx, HandleScript script)
{
MOZ_ASSERT(script->scriptSource()->hasSourceData());
- return script->scriptSource()->substring(cx, script->preludeStart(), script->sourceEnd());
+ return script->scriptSource()->substring(cx, script->preludeStart(), script->postludeEnd());
}
UncompressedSourceCache::AutoHoldEntry::AutoHoldEntry()
@@ -2448,7 +2470,7 @@ JSScript::initCompartment(ExclusiveContext* cx)
/* static */ JSScript*
JSScript::Create(ExclusiveContext* cx, const ReadOnlyCompileOptions& options,
HandleObject sourceObject, uint32_t bufStart, uint32_t bufEnd,
- uint32_t preludeStart)
+ uint32_t preludeStart, uint32_t postludeEnd)
{
MOZ_ASSERT(bufStart <= bufEnd);
@@ -2471,6 +2493,7 @@ JSScript::Create(ExclusiveContext* cx, const ReadOnlyCompileOptions& options,
script->sourceStart_ = bufStart;
script->sourceEnd_ = bufEnd;
script->preludeStart_ = preludeStart;
+ script->postludeEnd_ = postludeEnd;
return script;
}
@@ -3407,7 +3430,7 @@ CreateEmptyScriptForClone(JSContext* cx, HandleScript src)
.setVersion(src->getVersion());
return JSScript::Create(cx, options, sourceObject, src->sourceStart(), src->sourceEnd(),
- src->preludeStart());
+ src->preludeStart(), src->postludeEnd());
}
JSScript*
@@ -3968,6 +3991,7 @@ LazyScript::LazyScript(JSFunction* fun, void* table, uint64_t packedFields,
begin_(begin),
end_(end),
preludeStart_(preludeStart),
+ postludeEnd_(end),
lineno_(lineno),
column_(column)
{