Skip to content

Commit

Permalink
Bug 1875114 - Fix argument validation in stencil testing functions. r…
Browse files Browse the repository at this point in the history
…=bthrall

Differential Revision: https://phabricator.services.mozilla.com/D198908
  • Loading branch information
arai-a committed Jan 22, 2024
1 parent 1461e4a commit dc42d67
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
9 changes: 5 additions & 4 deletions js/src/builtin/TestingFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7218,13 +7218,13 @@ static bool EvalStencil(JSContext* cx, uint32_t argc, Value* vp) {

/* Prepare the input byte array. */
if (!args[0].isObject()) {
JS_ReportErrorASCII(cx, "evalStencil: Object expected");
JS_ReportErrorASCII(cx, "evalStencil: Stencil object expected");
return false;
}
Rooted<js::StencilObject*> stencilObj(
cx, args[0].toObject().maybeUnwrapIf<js::StencilObject>());
if (!stencilObj) {
JS_ReportErrorASCII(cx, "evalStencil: Stencil expected");
JS_ReportErrorASCII(cx, "evalStencil: Stencil object expected");
return false;
}

Expand Down Expand Up @@ -7395,12 +7395,13 @@ static bool EvalStencilXDR(JSContext* cx, uint32_t argc, Value* vp) {

/* Prepare the input byte array. */
if (!args[0].isObject()) {
JS_ReportErrorASCII(cx, "evalStencilXDR: stencil XDR object expected");
JS_ReportErrorASCII(cx, "evalStencilXDR: Stencil XDR object expected");
return false;
}
Rooted<StencilXDRBufferObject*> xdrObj(
cx, args[0].toObject().maybeUnwrapIf<StencilXDRBufferObject>());
if (!xdrObj) {
JS_ReportErrorASCII(cx, "evalStencilXDR: stencil XDR object expected");
JS_ReportErrorASCII(cx, "evalStencilXDR: Stencil XDR object expected");
return false;
}
MOZ_ASSERT(xdrObj->hasBuffer());
Expand Down
21 changes: 21 additions & 0 deletions js/src/jit-test/tests/xdr/stencil-arg.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const tests = [
() => evalStencil(1),
() => evalStencil({}),
() => evalStencilXDR(1),
() => evalStencilXDR({}),
() => instantiateModuleStencil(1),
() => instantiateModuleStencil({}),
() => instantiateModuleStencilXDR(1),
() => instantiateModuleStencilXDR({}),
];

for (const test of tests) {
let caught = false;
try {
test();
} catch (e) {
assertEq(/Stencil( XDR)? object expected/.test(e.message), true);
caught = true;
}
assertEq(caught, true);
}
5 changes: 3 additions & 2 deletions js/src/shell/js.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5256,6 +5256,7 @@ static bool InstantiateModuleStencil(JSContext* cx, uint32_t argc, Value* vp) {
if (!args[0].isObject()) {
JS_ReportErrorASCII(cx,
"instantiateModuleStencil: Stencil object expected");
return false;
}
Rooted<js::StencilObject*> stencilObj(
cx, args[0].toObject().maybeUnwrapIf<js::StencilObject>());
Expand Down Expand Up @@ -5326,14 +5327,14 @@ static bool InstantiateModuleStencilXDR(JSContext* cx, uint32_t argc,
/* Prepare the input byte array. */
if (!args[0].isObject()) {
JS_ReportErrorASCII(
cx, "instantiateModuleStencilXDR: stencil XDR object expected");
cx, "instantiateModuleStencilXDR: Stencil XDR object expected");
return false;
}
Rooted<StencilXDRBufferObject*> xdrObj(
cx, args[0].toObject().maybeUnwrapIf<StencilXDRBufferObject>());
if (!xdrObj) {
JS_ReportErrorASCII(
cx, "instantiateModuleStencilXDR: stencil XDR object expected");
cx, "instantiateModuleStencilXDR: Stencil XDR object expected");
return false;
}
MOZ_ASSERT(xdrObj->hasBuffer());
Expand Down

0 comments on commit dc42d67

Please sign in to comment.