node/deps/v8/test/mjsunit/wasm/array-copy-errors.js
Michaël Zasso 9d7cd9b864
deps: update V8 to 12.8.374.13
PR-URL: https://github.com/nodejs/node/pull/54077
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
Reviewed-By: Richard Lau <rlau@redhat.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
2024-08-16 16:03:01 +02:00

62 lines
2.5 KiB
JavaScript

// Copyright 2024 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
d8.file.execute("test/mjsunit/wasm/wasm-module-builder.js");
(function TestArrayCopyErrorReasons() {
var builder = new WasmModuleBuilder();
let array = builder.addArray(kWasmI32, true);
// The array.copy has two different reasons to trap. (null dereference, oob)
// All compilers should emit the same reason in all cases. Which one doesn't
// really matter and could be changed in the future, e.g. if it improves
// generated code.
builder.addFunction("tgtNullSrcNull", kSig_v_v)
.addBody([
kExprRefNull, array, // target array (nullptr)
kExprI32Const, 2, // target index
kExprRefNull, array, // source array (nullptr)
kExprI32Const, 2, // source index
kExprI32Const, 2, // length
kGCPrefix, kExprArrayCopy, array, array,
]).exportFunc();
builder.addFunction("tgtOobSrcNull", kSig_v_v)
.addBody([
kExprI32Const, 4, kGCPrefix, kExprArrayNewDefault, array, // target array
kExprI32Const, 42, // target index (out of bounds)
kExprRefNull, array, // source array (nullptr)
kExprI32Const, 2, // source index
kExprI32Const, 2, // length
kGCPrefix, kExprArrayCopy, array, array,
]).exportFunc();
builder.addFunction("tgtNullSrcOob", kSig_v_v)
.addBody([
kExprRefNull, array, // target array (nullptr)
kExprI32Const, 2, // target index
kExprI32Const, 4, kGCPrefix, kExprArrayNewDefault, array, // source array
kExprI32Const, 42, // source index (out of bounds)
kExprI32Const, 2, // length
kGCPrefix, kExprArrayCopy, array, array,
]).exportFunc();
builder.addFunction("tgtOobSrcOob", kSig_v_v)
.addBody([
kExprI32Const, 4, kGCPrefix, kExprArrayNewDefault, array, // target array
kExprI32Const, 42, // target index (out of bounds)
kExprI32Const, 4, kGCPrefix, kExprArrayNewDefault, array, // source array
kExprI32Const, 42, // source index (out of bounds)
kExprI32Const, 2, // length
kGCPrefix, kExprArrayCopy, array, array,
]).exportFunc();
let wasm = builder.instantiate().exports;
assertTraps(kTrapNullDereference, wasm.tgtNullSrcNull);
assertTraps(kTrapArrayOutOfBounds, wasm.tgtOobSrcNull);
assertTraps(kTrapNullDereference, wasm.tgtNullSrcOob);
assertTraps(kTrapArrayOutOfBounds, wasm.tgtOobSrcOob);
})();