зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1566803 - Move sourceStart, etc to js::BaseScript. r=jandem,jimb
Move various fields for source positions to BaseScript. The lineno/column have minimal treatment because it is a larger project to make the two more uniformly set in the frontend. Add a DebuggerScript::getReferenceScript() method to use for the various BaseScript helper methods that the debugger will need to use. Differential Revision: https://phabricator.services.mozilla.com/D38506 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
a4674b34fb
Коммит
76395d15fe
|
@ -28,4 +28,11 @@ js::DebuggerScriptReferent js::DebuggerScript::getReferent() const {
|
|||
return mozilla::AsVariant(static_cast<JSScript*>(nullptr));
|
||||
}
|
||||
|
||||
js::BaseScript* js::DebuggerScript::getReferentScript() const {
|
||||
gc::Cell* cell = getReferentCell();
|
||||
|
||||
MOZ_ASSERT(cell->is<JSScript>() || cell->is<LazyScript>());
|
||||
return static_cast<js::BaseScript*>(cell);
|
||||
}
|
||||
|
||||
#endif /* debugger_Script_inl_h */
|
||||
|
|
|
@ -412,8 +412,7 @@ bool DebuggerScript::getSource(JSContext* cx, unsigned argc, Value* vp) {
|
|||
bool DebuggerScript::getSourceStart(JSContext* cx, unsigned argc, Value* vp) {
|
||||
THIS_DEBUGSCRIPT_SCRIPT_MAYBE_LAZY(cx, argc, vp, "(get sourceStart)", args,
|
||||
obj);
|
||||
args.rval().setNumber(uint32_t(
|
||||
CallScriptMethod(obj, &JSScript::sourceStart, &LazyScript::sourceStart)));
|
||||
args.rval().setNumber(uint32_t(obj->getReferentScript()->sourceStart()));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -421,8 +420,7 @@ bool DebuggerScript::getSourceStart(JSContext* cx, unsigned argc, Value* vp) {
|
|||
bool DebuggerScript::getSourceLength(JSContext* cx, unsigned argc, Value* vp) {
|
||||
THIS_DEBUGSCRIPT_SCRIPT_MAYBE_LAZY(cx, argc, vp, "(get sourceEnd)", args,
|
||||
obj);
|
||||
args.rval().setNumber(uint32_t(CallScriptMethod(obj, &JSScript::sourceLength,
|
||||
&LazyScript::sourceLength)));
|
||||
args.rval().setNumber(uint32_t(obj->getReferentScript()->sourceLength()));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -45,6 +45,7 @@ class DebuggerScript : public NativeObject {
|
|||
static void trace(JSTracer* trc, JSObject* obj);
|
||||
|
||||
inline gc::Cell* getReferentCell() const;
|
||||
inline js::BaseScript* getReferentScript() const;
|
||||
inline DebuggerScriptReferent getReferent() const;
|
||||
|
||||
static DebuggerScript* check(JSContext* cx, HandleValue v,
|
||||
|
|
|
@ -3793,18 +3793,10 @@ JSScript::JSScript(JS::Realm* realm, uint8_t* stubEntry,
|
|||
HandleScriptSourceObject sourceObject, uint32_t sourceStart,
|
||||
uint32_t sourceEnd, uint32_t toStringStart,
|
||||
uint32_t toStringEnd)
|
||||
: js::BaseScript(stubEntry, sourceObject),
|
||||
realm_(realm),
|
||||
sourceStart_(sourceStart),
|
||||
sourceEnd_(sourceEnd),
|
||||
toStringStart_(toStringStart),
|
||||
toStringEnd_(toStringEnd) {
|
||||
: js::BaseScript(stubEntry, sourceObject, sourceStart, sourceEnd,
|
||||
toStringStart, toStringEnd),
|
||||
realm_(realm) {
|
||||
MOZ_ASSERT(JS::GetCompartmentForRealm(realm) == sourceObject->compartment());
|
||||
|
||||
// See JSScript.h for further details.
|
||||
MOZ_ASSERT(toStringStart <= sourceStart);
|
||||
MOZ_ASSERT(sourceStart <= sourceEnd);
|
||||
MOZ_ASSERT(sourceEnd <= toStringEnd);
|
||||
}
|
||||
|
||||
/* static */
|
||||
|
@ -5470,23 +5462,19 @@ LazyScript::LazyScript(JSFunction* fun, uint8_t* stubEntry,
|
|||
uint32_t immutableFlags, uint32_t sourceStart,
|
||||
uint32_t sourceEnd, uint32_t toStringStart,
|
||||
uint32_t lineno, uint32_t column)
|
||||
: BaseScript(stubEntry, &sourceObject),
|
||||
: BaseScript(stubEntry, &sourceObject, sourceStart, sourceEnd,
|
||||
toStringStart, sourceEnd),
|
||||
script_(nullptr),
|
||||
function_(fun),
|
||||
lazyData_(data),
|
||||
immutableFlags_(immutableFlags),
|
||||
mutableFlags_(0),
|
||||
sourceStart_(sourceStart),
|
||||
sourceEnd_(sourceEnd),
|
||||
toStringStart_(toStringStart),
|
||||
toStringEnd_(sourceEnd),
|
||||
lineno_(lineno),
|
||||
column_(column) {
|
||||
mutableFlags_(0) {
|
||||
MOZ_ASSERT(function_);
|
||||
MOZ_ASSERT(sourceObject_);
|
||||
MOZ_ASSERT(function_->compartment() == sourceObject_->compartment());
|
||||
MOZ_ASSERT(sourceStart <= sourceEnd);
|
||||
MOZ_ASSERT(toStringStart <= sourceStart);
|
||||
|
||||
lineno_ = lineno;
|
||||
column_ = column;
|
||||
|
||||
if (data) {
|
||||
AddCellMemory(this, data->allocationSize(), MemoryUse::LazyScriptData);
|
||||
|
|
|
@ -1403,8 +1403,51 @@ class BaseScript : public gc::TenuredCell {
|
|||
// The ScriptSourceObject for this script.
|
||||
GCPtr<ScriptSourceObject*> sourceObject_ = {};
|
||||
|
||||
BaseScript(uint8_t* stubEntry, ScriptSourceObject* sourceObject)
|
||||
: jitCodeRaw_(stubEntry), sourceObject_(sourceObject) {}
|
||||
// Range of characters in scriptSource which contains this script's source,
|
||||
// that is, the range used by the Parser to produce this script.
|
||||
//
|
||||
// For most functions the fields point to the following locations.
|
||||
//
|
||||
// function * f(a, b) { return a + b; }
|
||||
// ^ ^ ^
|
||||
// | | |
|
||||
// | sourceStart_ sourceEnd_
|
||||
// | |
|
||||
// toStringStart_ toStringEnd_
|
||||
//
|
||||
// For the special case of class constructors, the spec requires us to use an
|
||||
// alternate definition of toStringStart_ / toStringEnd_.
|
||||
//
|
||||
// class C { constructor() { this.field = 42; } }
|
||||
// ^ ^ ^ ^
|
||||
// | | | `---------`
|
||||
// | sourceStart_ sourceEnd_ |
|
||||
// | |
|
||||
// toStringStart_ toStringEnd_
|
||||
//
|
||||
// NOTE: These are counted in Code Units from the start of the script source.
|
||||
uint32_t sourceStart_ = 0;
|
||||
uint32_t sourceEnd_ = 0;
|
||||
uint32_t toStringStart_ = 0;
|
||||
uint32_t toStringEnd_ = 0;
|
||||
|
||||
// Line and column of |sourceStart_| position.
|
||||
uint32_t lineno_ = 0;
|
||||
uint32_t column_ = 0; // Count of Code Points
|
||||
|
||||
BaseScript(uint8_t* stubEntry, ScriptSourceObject* sourceObject,
|
||||
uint32_t sourceStart, uint32_t sourceEnd, uint32_t toStringStart,
|
||||
uint32_t toStringEnd)
|
||||
: jitCodeRaw_(stubEntry),
|
||||
sourceObject_(sourceObject),
|
||||
sourceStart_(sourceStart),
|
||||
sourceEnd_(sourceEnd),
|
||||
toStringStart_(toStringStart),
|
||||
toStringEnd_(toStringEnd) {
|
||||
MOZ_ASSERT(toStringStart <= sourceStart);
|
||||
MOZ_ASSERT(sourceStart <= sourceEnd);
|
||||
MOZ_ASSERT(sourceEnd <= toStringEnd);
|
||||
}
|
||||
|
||||
public:
|
||||
uint8_t* jitCodeRaw() const { return jitCodeRaw_; }
|
||||
|
@ -1420,6 +1463,15 @@ class BaseScript : public gc::TenuredCell {
|
|||
return maybeForwardedScriptSource()->filename();
|
||||
}
|
||||
|
||||
uint32_t sourceStart() const { return sourceStart_; }
|
||||
uint32_t sourceEnd() const { return sourceEnd_; }
|
||||
uint32_t sourceLength() const { return sourceEnd_ - sourceStart_; }
|
||||
uint32_t toStringStart() const { return toStringStart_; }
|
||||
uint32_t toStringEnd() const { return toStringEnd_; }
|
||||
|
||||
uint32_t lineno() const { return lineno_; }
|
||||
uint32_t column() const { return column_; }
|
||||
|
||||
void traceChildren(JSTracer* trc);
|
||||
|
||||
// JIT accessors
|
||||
|
@ -1976,43 +2028,6 @@ class JSScript : public js::BaseScript {
|
|||
/* Size of the used part of the data array. */
|
||||
uint32_t dataSize_ = 0;
|
||||
|
||||
/* Base line number of script. */
|
||||
uint32_t lineno_ = 0;
|
||||
|
||||
/* Base column of script, optionally set. */
|
||||
uint32_t column_ = 0;
|
||||
|
||||
// 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_ = 0;
|
||||
uint32_t sourceEnd_ = 0;
|
||||
uint32_t toStringStart_ = 0;
|
||||
uint32_t toStringEnd_ = 0;
|
||||
|
||||
// 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
|
||||
// the script's JIT code is forcibly discarded.
|
||||
|
@ -2381,10 +2396,6 @@ class JSScript : public js::BaseScript {
|
|||
|
||||
size_t mainOffset() const { return immutableScriptData()->mainOffset; }
|
||||
|
||||
uint32_t lineno() const { return lineno_; }
|
||||
|
||||
uint32_t column() const { return column_; }
|
||||
|
||||
void setColumn(size_t column) { column_ = column; }
|
||||
|
||||
// The fixed part of a stack frame is comprised of vars (in function and
|
||||
|
@ -2443,16 +2454,6 @@ class JSScript : public js::BaseScript {
|
|||
|
||||
size_t funLength() const { return immutableScriptData()->funLength; }
|
||||
|
||||
uint32_t sourceStart() const { return sourceStart_; }
|
||||
|
||||
uint32_t sourceEnd() const { return sourceEnd_; }
|
||||
|
||||
uint32_t sourceLength() const { return sourceEnd_ - sourceStart_; }
|
||||
|
||||
uint32_t toStringStart() const { return toStringStart_; }
|
||||
|
||||
uint32_t toStringEnd() const { return toStringEnd_; }
|
||||
|
||||
bool noScriptRval() const { return hasFlag(ImmutableFlags::NoScriptRval); }
|
||||
|
||||
bool strict() const { return hasFlag(ImmutableFlags::Strict); }
|
||||
|
@ -3368,17 +3369,6 @@ class LazyScript : public BaseScript {
|
|||
}
|
||||
void setFlag(ImmutableFlags flag) { immutableFlags_ |= uint32_t(flag); }
|
||||
|
||||
// Source location for the script.
|
||||
// See the comment in JSScript for the details
|
||||
uint32_t sourceStart_;
|
||||
uint32_t sourceEnd_;
|
||||
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, uint8_t* stubEntry,
|
||||
ScriptSourceObject& sourceObject, LazyScriptData* data,
|
||||
uint32_t immutableFlags, uint32_t sourceStart, uint32_t sourceEnd,
|
||||
|
@ -3586,14 +3576,6 @@ class LazyScript : public BaseScript {
|
|||
return lazyData_->fieldInitializers_;
|
||||
}
|
||||
|
||||
uint32_t sourceStart() const { return sourceStart_; }
|
||||
uint32_t sourceEnd() const { return sourceEnd_; }
|
||||
uint32_t sourceLength() const { return sourceEnd_ - sourceStart_; }
|
||||
uint32_t toStringStart() const { return toStringStart_; }
|
||||
uint32_t toStringEnd() const { return toStringEnd_; }
|
||||
uint32_t lineno() const { return lineno_; }
|
||||
uint32_t column() const { return column_; }
|
||||
|
||||
void setToStringEnd(uint32_t toStringEnd) {
|
||||
MOZ_ASSERT(toStringStart_ <= toStringEnd);
|
||||
MOZ_ASSERT(toStringEnd_ >= sourceEnd_);
|
||||
|
|
Загрузка…
Ссылка в новой задаче