Skip to content

Commit ac74992

Browse files
committed
Bug 1703469: Add more robust testcase r=jandem
Differential Revision: https://phabricator.services.mozilla.com/D252610
1 parent 26b36bd commit ac74992

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed

js/src/builtin/TestingFunctions.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6764,6 +6764,40 @@ static bool ObjectAddress(JSContext* cx, unsigned argc, Value* vp) {
67646764
return ReturnStringCopy(cx, args, buffer);
67656765
}
67666766

6767+
static bool ScriptAddressForFunction(JSContext* cx, unsigned argc, Value* vp) {
6768+
CallArgs args = CallArgsFromVp(argc, vp);
6769+
6770+
if (js::SupportDifferentialTesting()) {
6771+
RootedObject callee(cx, &args.callee());
6772+
ReportUsageErrorASCII(cx, callee,
6773+
"Function unavailable in differential testing mode.");
6774+
return false;
6775+
}
6776+
6777+
if (args.length() != 1) {
6778+
RootedObject callee(cx, &args.callee());
6779+
ReportUsageErrorASCII(cx, callee, "Wrong number of arguments");
6780+
return false;
6781+
}
6782+
if (!args[0].isObject() || !args[0].toObject().is<JSFunction>()) {
6783+
RootedObject callee(cx, &args.callee());
6784+
ReportUsageErrorASCII(cx, callee, "Expected function");
6785+
return false;
6786+
}
6787+
6788+
RootedFunction function(cx, &args[0].toObject().as<JSFunction>());
6789+
if (!function->hasBytecode()) {
6790+
RootedObject callee(cx, &args.callee());
6791+
ReportUsageErrorASCII(cx, callee, "Expected non-lazy scripted function");
6792+
return false;
6793+
}
6794+
6795+
void* ptr = function->nonLazyScript();
6796+
args.rval().setPrivate(ptr);
6797+
6798+
return true;
6799+
}
6800+
67676801
static bool SharedAddress(JSContext* cx, unsigned argc, Value* vp) {
67686802
CallArgs args = CallArgsFromVp(argc, vp);
67696803

@@ -10515,6 +10549,10 @@ JS_FOR_WASM_FEATURES(WASM_FEATURE)
1051510549
" Return the current address of the object. For debugging only--this\n"
1051610550
" address may change during a moving GC."),
1051710551

10552+
JS_FN_HELP("scriptAddressForFunction", ScriptAddressForFunction, 1, 0,
10553+
"scriptAddressForFunction(fun)",
10554+
" Return the current address of a function's script."),
10555+
1051810556
JS_FN_HELP("sharedAddress", SharedAddress, 1, 0,
1051910557
"sharedAddress(obj)",
1052010558
" Return the address of the shared storage of a SharedArrayBuffer."),
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
with ({}) {}
2+
3+
function makeObjWithFunctionGetter(n) {
4+
var o = {};
5+
Object.defineProperty(o, "x", {
6+
get() { return n; }
7+
});
8+
9+
return o;
10+
}
11+
12+
function makeObjWithBoundGetter() {
13+
// Use a testing function to leak the address of the script
14+
// so that we can circumvent the GuardFunctionScript.
15+
let orig = makeObjWithFunctionGetter(0);
16+
let getter = Object.getOwnPropertyDescriptor(orig, "x").get;
17+
let getterAddress = scriptAddressForFunction(getter);
18+
19+
var inner = () => "bound";
20+
var bound = inner.bind(getterAddress);
21+
22+
let o = {};
23+
Object.defineProperty(o, "x", {
24+
get: bound
25+
});
26+
return o;
27+
}
28+
29+
function foo(o) { return o.x; }
30+
31+
for (var i = 0; i < 100; i++) {
32+
foo(makeObjWithFunctionGetter(i));
33+
}
34+
35+
assertEq(foo(makeObjWithBoundGetter()), "bound");

0 commit comments

Comments
 (0)