v8/test/mjsunit/es6/global-proto-proxy.js
Mythri A b8ac4eb4dc [runtime] Correctly handle global stores when global object has proxies
When global object has proxies we should first call hasProperty and
then call SetProperty if has property returns true. This cl fixes both
StoreGlobal and StoreLookupGlobal to correctly handle these cases.

Bug: chromium:1018871
Change-Id: I140514e2119c6bab2125abcdc1b19d46526be5ff
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1889885
Commit-Queue: Mythri Alle <mythria@chromium.org>
Reviewed-by: Toon Verwaest <verwaest@chromium.org>
Cr-Commit-Position: refs/heads/master@{#64687}
2019-10-31 15:53:30 +00:00

44 lines
1.3 KiB
JavaScript

// Copyright 2017 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.
var global = this;
;(function () {
var calledDelete = false;
var calledGet = false;
var calledHas = false;
var calledSet = false;
var target = {getGlobal: 1};
var assertEquals = global.assertEquals;
var proxy = new Proxy(target, {
has(target, property) {
calledHas = true;
if (property == 'makeGlobal') return true;
return Reflect.has(target, property);
},
get(target, property, receiver) {
calledGet = true;
return Reflect.get(target, property, receiver);
},
set(targer, property, value, receiver) {
calledSet = true;
return Reflect.set(target, property, value, receiver);
},
delete(target, property, receiver) {
calledDelete = true;
return Reflect.delete(target, property, receiver);
}
});
Object.setPrototypeOf(global, proxy);
getGlobal;
assertTrue(calledGet);
makeGlobal = 2;
assertTrue(calledSet);
"findGlobal" in global;
assertTrue(calledHas);
assertEquals("number", typeof(makeGlobal));
var deletedOwn = delete makeGlobal;
assertTrue(deletedOwn);
assertEquals("undefined", typeof(makeGlobal));
})();