Bug 1120235. Various promise resolve/reject functions should actually return undefined instead of ending up accidentally returning their callee. r=nsm

This commit is contained in:
Boris Zbarsky 2015-01-12 22:35:33 -05:00
parent ab55cdde55
commit 04d9ab9054
3 changed files with 46 additions and 1 deletions

View File

@ -418,6 +418,7 @@ Promise::JSCallback(JSContext* aCx, unsigned aArgc, JS::Value* aVp)
}
}
args.rval().setUndefined();
return true;
}
@ -434,6 +435,7 @@ Promise::ThenableResolverCommon(JSContext* aCx, uint32_t aTask,
JS::Rooted<JSObject*> thisFunc(aCx, &args.callee());
if (!MarkAsCalledIfNotCalledBefore(aCx, thisFunc)) {
// A function from this pair has been called before.
args.rval().setUndefined();
return true;
}
@ -445,6 +447,8 @@ Promise::ThenableResolverCommon(JSContext* aCx, uint32_t aTask,
} else {
promise->RejectInternal(aCx, args.get(0));
}
args.rval().setUndefined();
return true;
}

View File

@ -1,7 +1,8 @@
[DEFAULT]
[test_abortable_promise.html]
[test_bug883683.html]
[test_promise.html]
[test_promise_utils.html]
[test_resolve.html]
[test_abortable_promise.html]
[test_resolver_return_value.html]

View File

@ -0,0 +1,40 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1120235
-->
<head>
<meta charset="utf-8">
<title>Test for Bug 1120235</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
<script type="application/javascript">
/** Test for Bug 1120235 **/
var res, rej;
var p = new Promise(function(resolve, reject) { res = resolve; rej = reject; });
ise(res(1), undefined, "Resolve function should return undefined");
ise(rej(2), undefined, "Reject function should return undefined");
var thenable = {
then: function(resolve, reject) {
ise(resolve(3), undefined, "Thenable resolve argument should return undefined");
ise(reject(4), undefined, "Thenable reject argument should return undefined");
SimpleTest.finish();
}
};
SimpleTest.waitForExplicitFinish();
p = Promise.resolve(thenable);
</script>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1120235">Mozilla Bug 1120235</a>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
</pre>
</body>
</html>