[jsdbg] Debugger argument checking should not use gnarly macros
Categories
(Core :: JavaScript Engine, task, P3)
Tracking
()
Tracking | Status | |
---|---|---|
firefox71 | --- | fixed |
People
(Reporter: jimb, Assigned: bhackett1024)
References
(Blocks 1 open bug)
Details
(Whiteboard: [debugger-mvp])
Attachments
(2 files)
(deleted),
patch
|
Details | Diff | Splinter Review | |
(deleted),
text/x-phabricator-request
|
Details |
The Debugger
implementation uses multi-line preprocessor macros for common argument validation code. These should be replaced with utility classes, for legibility and better error checking.
Updated•5 years ago
|
Updated•5 years ago
|
Assignee | ||
Updated•5 years ago
|
Updated•5 years ago
|
Assignee | ||
Comment 1•5 years ago
|
||
This patch removes the THIS_DEBUGSOURCE_* macros from Source.cpp, replacing them with a system that I think is pretty clean. Instead of source accessors/functions being static methods on DebuggerSource, they are instance methods on a new structure, DebuggerSource::CallData. The CallData class is a stack-allocated class which holds everything a method being called on a source needs: the JSContext, CallArgs, handle to the Debugger.Object and handle to its referent. For methods which only operate on ScriptSourceObject Debugger.Sources, CallData also provides an ensureSourceObject() method that fills in another member with the SSO. This required a separate macro before, but the CallData struct makes it easy to cleanly deal with using normal C++.
For an example of how the implementation changes, here is the before/after for Debugger.Source.introductionOffset:
Before:
// class DebuggerSource
static bool getIntroductionOffset(JSContext* cx, unsigned argc, Value* vp);
// DebuggerSource::properties_
JS_PSG("introductionOffset", getIntroductionOffset, 0),
/* static */
bool DebuggerSource::getIntroductionOffset(JSContext* cx, unsigned argc,
Value* vp) {
THIS_DEBUGSOURCE_REFERENT(cx, argc, vp, "(get introductionOffset)", args, obj,
referent);
DebuggerGetIntroductionOffsetMatcher matcher;
args.rval().set(referent.match(matcher));
return true;
}
After:
// struct CallData
bool getIntroductionOffset();
// DebuggerSource::properties_
SOURCE_PSG("introductionOffset", getIntroductionOffset),
bool DebuggerSource::CallData::getIntroductionOffset() {
DebuggerGetIntroductionOffsetMatcher matcher;
args.rval().set(referent.match(matcher));
return true;
}
I wasn't able to avoid custom macros entirely. CallData has a templated ToNative member which creates a native that initializes the CallData and does the checking which the THIS_DEBUGSOURCE_* macros used to do. Specifying this explicitly in the property/method specifier for Debugger.Source is pretty ugly, so we have a few simple macros like the one below to improve readability:
#define SOURCE_PSG(Name, Getter) \
JS_PSG(Name, CallData::ToNative<&CallData::Getter>, 0)
Assignee | ||
Comment 2•5 years ago
|
||
Reporter | ||
Comment 3•5 years ago
|
||
Still reviewing, but I like the approach overall. The elimination of all macros wasn't really a goal; making the bodies of these functions easier to follow and more strictly checked was.
It'd be nice if we could still get the method names; couldn't that be another template argument to ToNative
, passed by the macros?
Assignee | ||
Comment 4•5 years ago
|
||
(In reply to Jim Blandy :jimb from comment #3)
It'd be nice if we could still get the method names; couldn't that be another template argument to
ToNative
, passed by the macros?
I tried this, but C++ doesn't allow you to use string literals as template arguments. There are complicated workarounds which I started looking into, but then I realized that these method names are only used if people do goofy stuff like Debugger.Object.prototype.getOwnPropertyNames.call([])
. Fixing this so that the method name is included just didn't seem like a good use of time.
Comment 6•5 years ago
|
||
bugherder |
Comment 7•5 years ago
|
||
Backed out for conflicting with the backout of Bug 1576776
Assignee | ||
Updated•5 years ago
|
Comment 9•5 years ago
|
||
bugherder |
Description
•