mirror of
https://github.com/nodejs/node.git
synced 2025-05-15 14:41:29 +00:00

PR-URL: https://github.com/nodejs/node/pull/39469 Reviewed-By: Jiawen Geng <technicalcute@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
32 lines
1.4 KiB
JavaScript
32 lines
1.4 KiB
JavaScript
// Copyright 2021 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.
|
|
|
|
let {session, contextGroup, Protocol} =
|
|
InspectorTest.start('Tests side-effect-free Runtime.callFunctionOn()');
|
|
|
|
async function check(callable, object, ...args) {
|
|
const functionDeclaration = callable.toString();
|
|
const {result:{exceptionDetails}} = await Protocol.Runtime.callFunctionOn({
|
|
objectId: object.objectId,
|
|
functionDeclaration,
|
|
arguments: args.map(arg => (arg && arg.objectId) ? {objectId: arg.objectId} : {value: arg}),
|
|
throwOnSideEffect: true,
|
|
});
|
|
InspectorTest.log(`${functionDeclaration}: ${exceptionDetails ? 'throws' : 'ok'}`);
|
|
};
|
|
|
|
InspectorTest.runAsyncTestSuite([
|
|
async function testCallFunctionOnSideEffectFree() {
|
|
await Protocol.Runtime.enable();
|
|
const {result: {result: object}} = await Protocol.Runtime.evaluate({ expression: '({a: 1, b: ""})'});
|
|
await check(function getA() { return this.a; }, object);
|
|
await check(function setA(a) { this.a = a; }, object, 1);
|
|
await check(function getB() { return this.b; }, object);
|
|
await check(function setB(b) { this.b = b; }, object, "lala");
|
|
await check(function setSomeGlobal() { globalThis.someGlobal = this; }, object);
|
|
await check(function localSideEffect() { const date = new Date(); date.setDate(this.a); return date; }, object);
|
|
await Protocol.Runtime.disable();
|
|
}
|
|
]);
|