Bug 935203: Provide introductionType information for all sources of JS in SpiderMonkey. r=djvj

This commit is contained in:
Jim Blandy 2014-02-24 15:31:47 -08:00
Родитель f21ef61c65
Коммит fd29d2c80f
6 изменённых файлов: 109 добавлений и 13 удалений

Просмотреть файл

@ -0,0 +1 @@
debugger;

Просмотреть файл

@ -1,9 +1,11 @@
// Check that scripts' introduction types are properly marked.
var g = newGlobal();
var dbg = new Debugger(g);
var dbg = new Debugger();
var gDO = dbg.addDebuggee(g);
var log;
// (Indirect) eval.
dbg.onDebuggerStatement = function (frame) {
log += 'd';
assertEq(frame.script.source.introductionType, 'eval');
@ -12,6 +14,7 @@ log = '';
g.eval('debugger;');
assertEq(log, 'd');
// Function constructor.
dbg.onDebuggerStatement = function (frame) {
log += 'd';
assertEq(frame.script.source.introductionType, 'Function');
@ -20,6 +23,7 @@ log = '';
g.Function('debugger;')();
assertEq(log, 'd');
// GeneratorFunction constructor.
dbg.onDebuggerStatement = function (frame) {
log += 'd';
assertEq(frame.script.source.introductionType, 'GeneratorFunction');
@ -28,11 +32,86 @@ log = '';
g.eval('(function*() {})').constructor('debugger;')().next();
assertEq(log, 'd');
// Shell 'evaluate' function
dbg.onDebuggerStatement = function (frame) {
log += 'd';
assertEq(frame.script.source.introductionType, undefined);
assertEq(frame.script.source.introductionType, "js shell evaluate");
};
log = '';
g.evaluate('debugger;');
assertEq(log, 'd');
// Shell 'load' function
dbg.onDebuggerStatement = function (frame) {
log += 'd';
assertEq(frame.script.source.introductionType, "js shell load");
};
log = '';
g.load(scriptdir + 'Source-introductionType-data');
assertEq(log, 'd');
// Shell 'run' function
dbg.onDebuggerStatement = function (frame) {
log += 'd';
assertEq(frame.script.source.introductionType, "js shell run");
};
log = '';
g.run(scriptdir + 'Source-introductionType-data');
assertEq(log, 'd');
// Shell 'offThreadCompileScript' function.
dbg.onDebuggerStatement = function (frame) {
log += 'd';
assertEq(frame.script.source.introductionType, "js shell offThreadCompileScript");
};
log = '';
g.offThreadCompileScript('debugger;');
g.runOffThreadScript();
assertEq(log, 'd');
// Debugger.Frame.prototype.eval
dbg.onDebuggerStatement = function (frame) {
log += 'o';
dbg.onDebuggerStatement = innerHandler;
frame.eval('debugger');
function innerHandler(frame) {
log += 'i';
assertEq(frame.script.source.introductionType, "debugger eval");
}
};
log = '';
g.eval('debugger;');
assertEq(log, 'oi');
// Debugger.Frame.prototype.evalWithBindings
dbg.onDebuggerStatement = function (frame) {
log += 'o';
dbg.onDebuggerStatement = innerHandler;
frame.evalWithBindings('debugger', { x: 42 });
function innerHandler(frame) {
log += 'i';
assertEq(frame.script.source.introductionType, "debugger eval");
}
};
log = '';
g.eval('debugger;');
assertEq(log, 'oi');
// Debugger.Object.evalInGlobal
dbg.onDebuggerStatement = function (frame) {
log += 'd';
assertEq(frame.script.source.introductionType, "debugger eval");
};
log = '';
gDO.evalInGlobal('debugger;');
assertEq(log, 'd');
// Debugger.Object.evalInGlobalWithBindings
dbg.onDebuggerStatement = function (frame) {
log += 'd';
assertEq(frame.script.source.introductionType, "debugger eval");
};
log = '';
gDO.evalInGlobalWithBindings('debugger;', { x: 42 });
assertEq(log, 'd');

Просмотреть файл

@ -3624,6 +3624,7 @@ class JS_FRIEND_API(OwningCompileOptions) : public ReadOnlyCompileOptions
OwningCompileOptions &setSelfHostingMode(bool shm) { selfHostingMode = shm; return *this; }
OwningCompileOptions &setCanLazilyParse(bool clp) { canLazilyParse = clp; return *this; }
OwningCompileOptions &setSourcePolicy(SourcePolicy sp) { sourcePolicy = sp; return *this; }
OwningCompileOptions &setIntroductionType(const char *t) { introductionType = t; return *this; }
bool setIntroductionInfo(JSContext *cx, const char *introducerFn, const char *intro,
unsigned line, uint32_t offset)
{
@ -3701,6 +3702,7 @@ class MOZ_STACK_CLASS JS_FRIEND_API(CompileOptions) : public ReadOnlyCompileOpti
CompileOptions &setSelfHostingMode(bool shm) { selfHostingMode = shm; return *this; }
CompileOptions &setCanLazilyParse(bool clp) { canLazilyParse = clp; return *this; }
CompileOptions &setSourcePolicy(SourcePolicy sp) { sourcePolicy = sp; return *this; }
CompileOptions &setIntroductionType(const char *t) { introductionType = t; return *this; }
CompileOptions &setIntroductionInfo(const char *introducerFn, const char *intro,
unsigned line, uint32_t offset)
{

Просмотреть файл

@ -392,7 +392,8 @@ RunFile(JSContext *cx, Handle<JSObject*> obj, const char *filename, FILE *file,
JS::ContextOptionsRef(cx).setNoScriptRval(true);
CompileOptions options(cx);
options.setUTF8(true)
options.setIntroductionType("js shell file")
.setUTF8(true)
.setFileAndLine(filename, 1)
.setCompileAndGo(true);
@ -422,7 +423,8 @@ EvalAndPrint(JSContext *cx, Handle<JSObject*> global, const char *bytes, size_t
{
// Eval.
JS::CompileOptions options(cx);
options.setUTF8(true)
options.setIntroductionType("js shell interactive")
.setUTF8(true)
.setCompileAndGo(true)
.setFileAndLine("typein", lineno);
RootedScript script(cx);
@ -747,7 +749,10 @@ LoadScript(JSContext *cx, unsigned argc, jsval *vp, bool scriptRelative)
return false;
errno = 0;
CompileOptions opts(cx);
opts.setUTF8(true).setCompileAndGo(true).setNoScriptRval(true);
opts.setIntroductionType("js shell load")
.setUTF8(true)
.setCompileAndGo(true)
.setNoScriptRval(true);
if ((compileOnly && !Compile(cx, thisobj, opts, filename.ptr())) ||
!Evaluate(cx, thisobj, opts, filename.ptr(), nullptr))
{
@ -1045,7 +1050,8 @@ Evaluate(JSContext *cx, unsigned argc, jsval *vp)
bool assertEqBytecode = false;
RootedObject callerGlobal(cx, cx->global());
options.setFileAndLine("@evaluate", 1);
options.setIntroductionType("js shell evaluate")
.setFileAndLine("@evaluate", 1);
global = JS_GetGlobalForObject(cx, &args.callee());
if (!global)
@ -1363,7 +1369,8 @@ Run(JSContext *cx, unsigned argc, jsval *vp)
JS::ContextOptionsRef(cx).setNoScriptRval(true);
JS::CompileOptions options(cx);
options.setFileAndLine(filename.ptr(), 1)
options.setIntroductionType("js shell run")
.setFileAndLine(filename.ptr(), 1)
.setCompileAndGo(true);
script = JS_CompileUCScript(cx, thisobj, ucbuf, buflen, options);
if (!script)
@ -2202,7 +2209,8 @@ DisassFile(JSContext *cx, unsigned argc, jsval *vp)
JS::ContextOptionsRef(cx).setNoScriptRval(true);
CompileOptions options(cx);
options.setUTF8(true)
options.setIntroductionType("js shell disFile")
.setUTF8(true)
.setFileAndLine(filename.ptr(), 1)
.setCompileAndGo(true);
@ -3382,7 +3390,8 @@ Compile(JSContext *cx, unsigned argc, jsval *vp)
JS::AutoSaveContextOptions asco(cx);
JS::ContextOptionsRef(cx).setNoScriptRval(true);
JS::CompileOptions options(cx);
options.setFileAndLine("<string>", 1)
options.setIntroductionType("js shell compile")
.setFileAndLine("<string>", 1)
.setCompileAndGo(true);
bool ok = JS_CompileUCScript(cx, global, JS_GetStringCharsZ(cx, scriptContents),
JS_GetStringLength(scriptContents), options);
@ -3410,7 +3419,8 @@ Parse(JSContext *cx, unsigned argc, jsval *vp)
JSString *scriptContents = args[0].toString();
CompileOptions options(cx);
options.setFileAndLine("<string>", 1)
options.setIntroductionType("js shell parse")
.setFileAndLine("<string>", 1)
.setCompileAndGo(false);
Parser<FullParseHandler> parser(cx, &cx->tempLifoAlloc(), options,
JS_GetStringCharsZ(cx, scriptContents),
@ -3448,7 +3458,8 @@ SyntaxParse(JSContext *cx, unsigned argc, jsval *vp)
JSString *scriptContents = args[0].toString();
CompileOptions options(cx);
options.setFileAndLine("<string>", 1)
options.setIntroductionType("js shell syntaxParse")
.setFileAndLine("<string>", 1)
.setCompileAndGo(false);
const jschar *chars = JS_GetStringCharsZ(cx, scriptContents);
@ -3578,7 +3589,8 @@ OffThreadCompileScript(JSContext *cx, unsigned argc, jsval *vp)
JSAutoByteString fileNameBytes;
CompileOptions options(cx);
options.setFileAndLine("<string>", 1);
options.setIntroductionType("js shell offThreadCompileScript")
.setFileAndLine("<string>", 1);
if (args.length() >= 2) {
if (args[1].isPrimitive()) {

Просмотреть файл

@ -4452,7 +4452,8 @@ js::EvaluateInEnv(JSContext *cx, Handle<Env*> env, HandleValue thisv, AbstractFr
.setForEval(true)
.setNoScriptRval(false)
.setFileAndLine(filename, lineno)
.setCanLazilyParse(false);
.setCanLazilyParse(false)
.setIntroductionType("debugger eval");
RootedScript callerScript(cx, frame ? frame.script() : nullptr);
RootedScript script(cx, frontend::CompileScript(cx, &cx->tempLifoAlloc(), env, callerScript,
options, chars.get(), length,

Просмотреть файл

@ -784,6 +784,7 @@ js::FillSelfHostingCompileOptions(CompileOptions &options)
* is supported, for which bytecode is emitted that invokes |fun| with
* |receiver| as the this-object and ...args as the arguments.
*/
options.setIntroductionType("self-hosted");
options.setFileAndLine("self-hosted", 1);
options.setSelfHostingMode(true);
options.setCanLazilyParse(false);