Skip to content
This repository has been archived by the owner on Aug 4, 2022. It is now read-only.

Commit

Permalink
Bug 1347984 - Check for dead object proxies in TriggerPromiseReaction…
Browse files Browse the repository at this point in the history
…s. r=till
  • Loading branch information
jandem committed Oct 6, 2017
1 parent 7993484 commit 0d8f604
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
6 changes: 5 additions & 1 deletion js/src/builtin/Promise.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1052,8 +1052,12 @@ TriggerPromiseReactions(JSContext* cx, HandleValue reactionsVal, JS::PromiseStat
RootedObject reactions(cx, &reactionsVal.toObject());
RootedObject reaction(cx);

if (reactions->is<PromiseReactionRecord>() || IsWrapper(reactions))
if (reactions->is<PromiseReactionRecord>() ||
IsWrapper(reactions) ||
JS_IsDeadWrapper(reactions))
{
return EnqueuePromiseReactionJob(cx, reactions, valueOrReason, state);
}

RootedNativeObject reactionsList(cx, &reactions->as<NativeObject>());
size_t reactionsCount = reactionsList->getDenseInitializedLength();
Expand Down
1 change: 1 addition & 0 deletions js/src/jit-test/tests/basic/bug908915.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ var blacklist = {
'readline': true,
'terminate': true,
'nestedShell': true,
'nukeAllCCWs': true,
};

function f(y) {}
Expand Down
6 changes: 6 additions & 0 deletions js/src/jit-test/tests/promise/bug1347984.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// |jit-test| error:dead object
var g = newGlobal();
var p = new Promise(() => {});
g.Promise.prototype.then.call(p, () => void 0);
g.eval("nukeAllCCWs()");
resolvePromise(p, 9);
21 changes: 21 additions & 0 deletions js/src/shell/js.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5071,6 +5071,23 @@ NukeCCW(JSContext* cx, unsigned argc, Value* vp)
return true;
}

static bool
NukeAllCCWs(JSContext* cx, unsigned argc, Value* vp)
{
CallArgs args = CallArgsFromVp(argc, vp);

if (args.length() != 0) {
JS_ReportErrorNumberASCII(cx, my_GetErrorMessage, nullptr, JSSMSG_INVALID_ARGS,
"nukeAllCCWs");
return false;
}

NukeCrossCompartmentWrappers(cx, AllCompartments(), cx->compartment(),
NukeWindowReferences, NukeAllReferences);
args.rval().setUndefined();
return true;
}

static bool
GetMaxArgs(JSContext* cx, unsigned argc, Value* vp)
{
Expand Down Expand Up @@ -6578,6 +6595,10 @@ static const JSFunctionSpecWithHelp shell_functions[] = {
"nukeCCW(wrapper)",
" Nuke a CrossCompartmentWrapper, which turns it into a DeadProxyObject."),

JS_FN_HELP("nukeAllCCWs", NukeAllCCWs, 0, 0,
"nukeAllCCWs()",
" Like nukeCCW, but for all CrossCompartmentWrappers targeting the current compartment."),

JS_FN_HELP("createMappedArrayBuffer", CreateMappedArrayBuffer, 1, 0,
"createMappedArrayBuffer(filename, [offset, [size]])",
" Create an array buffer that mmaps the given file."),
Expand Down

0 comments on commit 0d8f604

Please sign in to comment.