Commit be7b0e82 authored by Yang Guo's avatar Yang Guo Committed by V8 LUCI CQ

Mark Reflect methods as side-effect free

R=bmeurer@chromium.org

Fixed: chromium:1295387
Change-Id: I64461b7360f904fe5e0163263163db48a1c7c69c
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3460404
Auto-Submit: Yang Guo <yangguo@chromium.org>
Reviewed-by: 's avatarBenedikt Meurer <bmeurer@chromium.org>
Commit-Queue: Benedikt Meurer <bmeurer@chromium.org>
Cr-Commit-Position: refs/heads/main@{#79065}
parent ba94a6c1
......@@ -831,12 +831,22 @@ DebugInfo::SideEffectState BuiltinGetSideEffectState(Builtin id) {
case Builtin::kErrorConstructor:
// RegExp builtins.
case Builtin::kRegExpConstructor:
// Reflect builtins.
case Builtin::kReflectApply:
case Builtin::kReflectConstruct:
case Builtin::kReflectGetOwnPropertyDescriptor:
case Builtin::kReflectGetPrototypeOf:
case Builtin::kReflectHas:
case Builtin::kReflectIsExtensible:
case Builtin::kReflectOwnKeys:
// Internal.
case Builtin::kStrictPoisonPillThrower:
case Builtin::kAllocateInYoungGeneration:
case Builtin::kAllocateInOldGeneration:
case Builtin::kAllocateRegularInYoungGeneration:
case Builtin::kAllocateRegularInOldGeneration:
case Builtin::kConstructVarargs:
case Builtin::kConstructWithArrayLike:
return DebugInfo::kHasNoSideEffect;
#ifdef V8_INTL_SUPPORT
......
......@@ -7,6 +7,7 @@
Debug = debug.Debug
var exception = null;
var object = {"foo": "bar"};
var object_with_symbol_key = {[Symbol("a")]: 1};
var object_with_callbacks = { toString: () => "string", valueOf: () => 3};
var symbol_for_a = Symbol.for("a");
......@@ -14,6 +15,8 @@ var typed_array = new Uint8Array([1, 2, 3]);
var array_buffer = new ArrayBuffer(3);
var data_view = new DataView(new ArrayBuffer(8), 0, 8);
var array = [1,2,3];
var pure_function = function(x) { return x * x; };
var unpure_function = function(x) { array.push(x); };
function listener(event, exec_state, event_data, data) {
if (event != Debug.DebugEvent.Break) return;
......@@ -219,6 +222,22 @@ function listener(event, exec_state, event_data, data) {
success("a", `Symbol.keyFor(symbol_for_a)`);
success("Symbol(a)", `symbol_for_a.valueOf().toString()`);
success("Symbol(a)", `symbol_for_a[Symbol.toPrimitive]().toString()`);
// Test Reflect functions.
success(4, `Reflect.apply(pure_function, undefined, [2])`);
fail(`Reflect.apply(unpure_function, undefined, [2])`);
success("foo", `Reflect.construct(String, ["foo"]).toString()`);
fail(`Reflect.construct(unpure_function, ["foo"])`);
success("bar", `Reflect.getOwnPropertyDescriptor(object, "foo").value`);
success(true, `Reflect.getPrototypeOf(object) === Object.prototype`);
success(true, `Reflect.has(object, "foo")`);
success(true, `Reflect.isExtensible(object)`);
success("foo", `Reflect.ownKeys(object)[0]`);
fail(`Reflect.defineProperty(object, "baz", {})`);
fail(`Reflect.deleteProperty(object, "foo")`);
fail(`Reflect.preventExtensions(object)`);
fail(`Reflect.set(object, "great", "expectations")`);
fail(`Reflect.setPrototypeOf(object, Array.prototype)`);
} catch (e) {
exception = e;
print(e, e.stack);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment