Bug 1083648 part 1. Add a way to pass an enclosing static scope to CompileFunction. r=shu

This commit is contained in:
Boris Zbarsky 2014-10-25 00:50:28 -04:00
Родитель 96fe2231a2
Коммит f6f2036023
6 изменённых файлов: 34 добавлений и 14 удалений

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

@ -821,7 +821,8 @@ HandleDynamicLinkFailure(JSContext *cx, CallArgs args, AsmJSModule &module, Hand
? SourceBufferHolder::GiveOwnership
: SourceBufferHolder::NoOwnership;
SourceBufferHolder srcBuf(chars, end - begin, ownership);
if (!frontend::CompileFunctionBody(cx, &fun, options, formals, srcBuf))
if (!frontend::CompileFunctionBody(cx, &fun, options, formals, srcBuf,
/* enclosingScope = */ NullPtr()))
return false;
// Call the function we just recompiled.

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

@ -515,7 +515,7 @@ frontend::CompileLazyFunction(JSContext *cx, Handle<LazyScript*> lazy, const cha
static bool
CompileFunctionBody(JSContext *cx, MutableHandleFunction fun, const ReadOnlyCompileOptions &options,
const AutoNameVector &formals, SourceBufferHolder &srcBuf,
GeneratorKind generatorKind)
HandleObject enclosingScope, GeneratorKind generatorKind)
{
js::TraceLogger *logger = js::TraceLoggerForMainThread(cx->runtime());
uint32_t logId = js::TraceLogCreateTextId(logger, options);
@ -611,7 +611,7 @@ CompileFunctionBody(JSContext *cx, MutableHandleFunction fun, const ReadOnlyComp
if (fn->pn_funbox->function()->isInterpreted()) {
MOZ_ASSERT(fun == fn->pn_funbox->function());
Rooted<JSScript*> script(cx, JSScript::Create(cx, js::NullPtr(), false, options,
Rooted<JSScript*> script(cx, JSScript::Create(cx, enclosingScope, false, options,
/* staticLevel = */ 0, sourceObject,
/* sourceStart = */ 0, srcBuf.length()));
if (!script)
@ -650,9 +650,11 @@ CompileFunctionBody(JSContext *cx, MutableHandleFunction fun, const ReadOnlyComp
bool
frontend::CompileFunctionBody(JSContext *cx, MutableHandleFunction fun,
const ReadOnlyCompileOptions &options,
const AutoNameVector &formals, JS::SourceBufferHolder &srcBuf)
const AutoNameVector &formals, JS::SourceBufferHolder &srcBuf,
HandleObject enclosingStaticScope)
{
return CompileFunctionBody(cx, fun, options, formals, srcBuf, NotGenerator);
return CompileFunctionBody(cx, fun, options, formals, srcBuf,
enclosingStaticScope, NotGenerator);
}
bool
@ -660,5 +662,5 @@ frontend::CompileStarGeneratorBody(JSContext *cx, MutableHandleFunction fun,
const ReadOnlyCompileOptions &options, const AutoNameVector &formals,
JS::SourceBufferHolder &srcBuf)
{
return CompileFunctionBody(cx, fun, options, formals, srcBuf, StarGenerator);
return CompileFunctionBody(cx, fun, options, formals, srcBuf, NullPtr(), StarGenerator);
}

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

@ -31,10 +31,15 @@ CompileScript(ExclusiveContext *cx, LifoAlloc *alloc,
bool
CompileLazyFunction(JSContext *cx, Handle<LazyScript*> lazy, const char16_t *chars, size_t length);
/*
* enclosingStaticScope is a static enclosing scope (e.g. a StaticWithObject).
* Must be null if the enclosing scope is a global.
*/
bool
CompileFunctionBody(JSContext *cx, MutableHandleFunction fun,
const ReadOnlyCompileOptions &options,
const AutoNameVector &formals, JS::SourceBufferHolder &srcBuf);
const AutoNameVector &formals, JS::SourceBufferHolder &srcBuf,
HandleObject enclosingStaticScope);
bool
CompileStarGeneratorBody(JSContext *cx, MutableHandleFunction fun,
const ReadOnlyCompileOptions &options,

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

@ -4537,7 +4537,8 @@ JS_GetFunctionScript(JSContext *cx, HandleFunction fun)
JS_PUBLIC_API(bool)
JS::CompileFunction(JSContext *cx, HandleObject obj, const ReadOnlyCompileOptions &options,
const char *name, unsigned nargs, const char *const *argnames,
SourceBufferHolder &srcBuf, MutableHandleFunction fun)
SourceBufferHolder &srcBuf, MutableHandleFunction fun,
HandleObject enclosingStaticScope)
{
MOZ_ASSERT(!cx->runtime()->isAtomsCompartment(cx->compartment()));
AssertHeapIsIdle(cx);
@ -4564,7 +4565,8 @@ JS::CompileFunction(JSContext *cx, HandleObject obj, const ReadOnlyCompileOption
if (!fun)
return false;
if (!frontend::CompileFunctionBody(cx, fun, options, formals, srcBuf))
if (!frontend::CompileFunctionBody(cx, fun, options, formals, srcBuf,
enclosingStaticScope))
return false;
if (obj && funAtom && options.defineOnScope) {
@ -4580,10 +4582,12 @@ JS::CompileFunction(JSContext *cx, HandleObject obj, const ReadOnlyCompileOption
JS_PUBLIC_API(bool)
JS::CompileFunction(JSContext *cx, HandleObject obj, const ReadOnlyCompileOptions &options,
const char *name, unsigned nargs, const char *const *argnames,
const char16_t *chars, size_t length, MutableHandleFunction fun)
const char16_t *chars, size_t length, MutableHandleFunction fun,
HandleObject enclosingStaticScope)
{
SourceBufferHolder srcBuf(chars, length, SourceBufferHolder::NoOwnership);
return JS::CompileFunction(cx, obj, options, name, nargs, argnames, srcBuf, fun);
return JS::CompileFunction(cx, obj, options, name, nargs, argnames, srcBuf,
fun, enclosingStaticScope);
}
JS_PUBLIC_API(bool)

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

@ -3931,10 +3931,16 @@ CompileOffThread(JSContext *cx, const ReadOnlyCompileOptions &options,
extern JS_PUBLIC_API(JSScript *)
FinishOffThreadScript(JSContext *maybecx, JSRuntime *rt, void *token);
/*
* enclosingStaticScope is a static enclosing scope, if any (e.g. a
* StaticWithObject). If the enclosing scope is the global scope, this must be
* null.
*/
extern JS_PUBLIC_API(bool)
CompileFunction(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options,
const char *name, unsigned nargs, const char *const *argnames,
SourceBufferHolder &srcBuf, JS::MutableHandleFunction fun);
SourceBufferHolder &srcBuf, JS::MutableHandleFunction fun,
HandleObject enclosingStaticScope = NullPtr());
extern JS_PUBLIC_API(bool)
CompileFunction(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options,
@ -3944,7 +3950,8 @@ CompileFunction(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOption
extern JS_PUBLIC_API(bool)
CompileFunction(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options,
const char *name, unsigned nargs, const char *const *argnames,
const char16_t *chars, size_t length, JS::MutableHandleFunction fun);
const char16_t *chars, size_t length, JS::MutableHandleFunction fun,
HandleObject enclosingStaticScope = NullPtr());
} /* namespace JS */

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

@ -1908,7 +1908,8 @@ FunctionConstructor(JSContext *cx, unsigned argc, Value *vp, GeneratorKind gener
if (isStarGenerator)
ok = frontend::CompileStarGeneratorBody(cx, &fun, options, formals, srcBuf);
else
ok = frontend::CompileFunctionBody(cx, &fun, options, formals, srcBuf);
ok = frontend::CompileFunctionBody(cx, &fun, options, formals, srcBuf,
/* enclosingScope = */ NullPtr());
args.rval().setObject(*fun);
return ok;
}