Bug 1251090 - Shell functions should check whether an off main thread compilation is for a script or a module r=shu

This commit is contained in:
Jon Coppeard 2016-02-26 11:04:15 +00:00
Родитель 6ca62e9a7f
Коммит fac88e025d
2 изменённых файлов: 21 добавлений и 8 удалений

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

@ -0,0 +1,3 @@
// |jit-test| error: Error
offThreadCompileScript("");
finishOffThreadModule();

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

@ -3590,18 +3590,26 @@ SyntaxParse(JSContext* cx, unsigned argc, Value* vp)
return true;
}
enum class ScriptKind
{
Script,
Module
};
class OffThreadState {
public:
enum State {
IDLE, /* ready to work; no token, no source */
COMPILING, /* working; no token, have source */
DONE /* compilation done: have token and source */
};
public:
OffThreadState() : monitor(), state(IDLE), token(), source(nullptr) { }
bool init() { return monitor.init(); }
bool startIfIdle(JSContext* cx, ScopedJSFreePtr<char16_t>& newSource) {
bool startIfIdle(JSContext* cx, ScriptKind kind,
ScopedJSFreePtr<char16_t>& newSource)
{
AutoLockMonitor alm(monitor);
if (state != IDLE)
return false;
@ -3610,6 +3618,7 @@ class OffThreadState {
source = newSource.forget();
scriptKind = kind;
state = COMPILING;
return true;
}
@ -3638,9 +3647,9 @@ class OffThreadState {
alm.notify();
}
void* waitUntilDone(JSContext* cx) {
void* waitUntilDone(JSContext* cx, ScriptKind kind) {
AutoLockMonitor alm(monitor);
if (state == IDLE)
if (state == IDLE || scriptKind != kind)
return nullptr;
if (state == COMPILING) {
@ -3661,6 +3670,7 @@ class OffThreadState {
private:
Monitor monitor;
ScriptKind scriptKind;
State state;
void* token;
char16_t* source;
@ -3747,7 +3757,7 @@ OffThreadCompileScript(JSContext* cx, unsigned argc, Value* vp)
return false;
}
if (!offThreadState.startIfIdle(cx, ownedChars)) {
if (!offThreadState.startIfIdle(cx, ScriptKind::Script, ownedChars)) {
JS_ReportError(cx, "called offThreadCompileScript without calling runOffThreadScript"
" to receive prior off-thread compilation");
return false;
@ -3773,7 +3783,7 @@ runOffThreadScript(JSContext* cx, unsigned argc, Value* vp)
if (OffThreadParsingMustWaitForGC(rt))
gc::AutoFinishGC finishgc(rt);
void* token = offThreadState.waitUntilDone(cx);
void* token = offThreadState.waitUntilDone(cx, ScriptKind::Script);
if (!token) {
JS_ReportError(cx, "called runOffThreadScript when no compilation is pending");
return false;
@ -3849,7 +3859,7 @@ OffThreadCompileModule(JSContext* cx, unsigned argc, Value* vp)
return false;
}
if (!offThreadState.startIfIdle(cx, ownedChars)) {
if (!offThreadState.startIfIdle(cx, ScriptKind::Module, ownedChars)) {
JS_ReportError(cx, "called offThreadCompileModule without receiving prior off-thread "
"compilation");
return false;
@ -3875,7 +3885,7 @@ FinishOffThreadModule(JSContext* cx, unsigned argc, Value* vp)
if (OffThreadParsingMustWaitForGC(rt))
gc::AutoFinishGC finishgc(rt);
void* token = offThreadState.waitUntilDone(cx);
void* token = offThreadState.waitUntilDone(cx, ScriptKind::Module);
if (!token) {
JS_ReportError(cx, "called finishOffThreadModule when no compilation is pending");
return false;