<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[197711] trunk/Source/JavaScriptCore</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/197711">197711</a></dd>
<dt>Author</dt> <dd>sbarati@apple.com</dd>
<dt>Date</dt> <dd>2016-03-07 15:27:44 -0800 (Mon, 07 Mar 2016)</dd>
</dl>
<h3>Log Message</h3>
<pre>[ES6] Implement Proxy.[[GetPrototypeOf]]
https://bugs.webkit.org/show_bug.cgi?id=155099
Reviewed by Mark Lam.
This patch is a straight forward implementation of Proxy.[[GetPrototypeOf]]
with respect to section 9.5.1 of the ECMAScript spec.
https://tc39.github.io/ecma262/#sec-proxy-object-internal-methods-and-internal-slots-getprototypeof
* runtime/ProxyObject.cpp:
(JSC::performProxyGet):
(JSC::ProxyObject::setPrototype):
(JSC::ProxyObject::performGetPrototype):
(JSC::ProxyObject::getPrototype):
(JSC::ProxyObject::visitChildren):
* runtime/ProxyObject.h:
* tests/es6.yaml:
* tests/stress/proxy-get-prototype-of.js: Added.
(assert):
(throw.new.Error.let.handler.get getPrototypeOf):
(throw.new.Error.get let):
(throw.new.Error.get catch):
(throw.new.Error):
(assert.let.handler.getPrototypeOf):
(assert.get let):
(assert.get catch):
(assert.):
(let.handler.getPrototypeOf):
(get let):
(let.handler.has):</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceJavaScriptCoreChangeLog">trunk/Source/JavaScriptCore/ChangeLog</a></li>
<li><a href="#trunkSourceJavaScriptCoreruntimeProxyObjectcpp">trunk/Source/JavaScriptCore/runtime/ProxyObject.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoreruntimeProxyObjecth">trunk/Source/JavaScriptCore/runtime/ProxyObject.h</a></li>
<li><a href="#trunkSourceJavaScriptCoretestses6yaml">trunk/Source/JavaScriptCore/tests/es6.yaml</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li><a href="#trunkSourceJavaScriptCoretestsstressproxygetprototypeofjs">trunk/Source/JavaScriptCore/tests/stress/proxy-get-prototype-of.js</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ChangeLog (197710 => 197711)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ChangeLog        2016-03-07 23:24:47 UTC (rev 197710)
+++ trunk/Source/JavaScriptCore/ChangeLog        2016-03-07 23:27:44 UTC (rev 197711)
</span><span class="lines">@@ -1,3 +1,36 @@
</span><ins>+2016-03-07 Saam barati <sbarati@apple.com>
+
+ [ES6] Implement Proxy.[[GetPrototypeOf]]
+ https://bugs.webkit.org/show_bug.cgi?id=155099
+
+ Reviewed by Mark Lam.
+
+ This patch is a straight forward implementation of Proxy.[[GetPrototypeOf]]
+ with respect to section 9.5.1 of the ECMAScript spec.
+ https://tc39.github.io/ecma262/#sec-proxy-object-internal-methods-and-internal-slots-getprototypeof
+
+ * runtime/ProxyObject.cpp:
+ (JSC::performProxyGet):
+ (JSC::ProxyObject::setPrototype):
+ (JSC::ProxyObject::performGetPrototype):
+ (JSC::ProxyObject::getPrototype):
+ (JSC::ProxyObject::visitChildren):
+ * runtime/ProxyObject.h:
+ * tests/es6.yaml:
+ * tests/stress/proxy-get-prototype-of.js: Added.
+ (assert):
+ (throw.new.Error.let.handler.get getPrototypeOf):
+ (throw.new.Error.get let):
+ (throw.new.Error.get catch):
+ (throw.new.Error):
+ (assert.let.handler.getPrototypeOf):
+ (assert.get let):
+ (assert.get catch):
+ (assert.):
+ (let.handler.getPrototypeOf):
+ (get let):
+ (let.handler.has):
+
</ins><span class="cx"> 2016-03-07 Brian Burg <bburg@apple.com>
</span><span class="cx">
</span><span class="cx"> Web Inspector: rename generated *EnumConversionHelpers.h to *TypeConversions.h
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreruntimeProxyObjectcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/runtime/ProxyObject.cpp (197710 => 197711)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/runtime/ProxyObject.cpp        2016-03-07 23:24:47 UTC (rev 197710)
+++ trunk/Source/JavaScriptCore/runtime/ProxyObject.cpp        2016-03-07 23:27:44 UTC (rev 197711)
</span><span class="lines">@@ -101,6 +101,9 @@
</span><span class="cx"> ProxyObject* proxyObject = jsCast<ProxyObject*>(proxyObjectAsObject);
</span><span class="cx"> JSObject* target = proxyObject->target();
</span><span class="cx">
</span><ins>+ if (propertyName == vm.propertyNames->underscoreProto)
+ return JSValue::encode(proxyObject->performGetPrototype(exec));
+
</ins><span class="cx"> auto performDefaultGet = [&] {
</span><span class="cx"> return JSValue::encode(target->get(exec, propertyName));
</span><span class="cx"> };
</span><span class="lines">@@ -1021,6 +1024,60 @@
</span><span class="cx"> return jsCast<ProxyObject*>(object)->performSetPrototype(exec, prototype, shouldThrowIfCantSet);
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+JSValue ProxyObject::performGetPrototype(ExecState* exec)
+{
+ VM& vm = exec->vm();
+
+ JSValue handlerValue = this->handler();
+ if (handlerValue.isNull()) {
+ throwVMTypeError(exec, ASCIILiteral("Proxy 'handler' is null. It should be an Object."));
+ return JSValue();
+ }
+
+ JSObject* handler = jsCast<JSObject*>(handlerValue);
+ CallData callData;
+ CallType callType;
+ JSValue getPrototypeOfMethod = handler->getMethod(exec, callData, callType, makeIdentifier(vm, "getPrototypeOf"), ASCIILiteral("'getPrototypeOf' property of a Proxy's handler should be callable."));
+ if (vm.exception())
+ return JSValue();
+
+ JSObject* target = this->target();
+ if (getPrototypeOfMethod.isUndefined())
+ return target->getPrototype(vm, exec);
+
+ MarkedArgumentBuffer arguments;
+ arguments.append(target);
+ JSValue trapResult = call(exec, getPrototypeOfMethod, callType, callData, handler, arguments);
+ if (vm.exception())
+ return JSValue();
+
+ if (!trapResult.isObject() && !trapResult.isNull()) {
+ throwVMTypeError(exec, ASCIILiteral("Proxy handler's 'getPrototypeOf' trap should either return an object or null."));
+ return JSValue();
+ }
+
+ bool targetIsExtensible = target->isExtensible(exec);
+ if (vm.exception())
+ return JSValue();
+ if (targetIsExtensible)
+ return trapResult;
+
+ JSValue targetPrototype = target->getPrototype(vm, exec);
+ if (vm.exception())
+ return JSValue();
+ if (!sameValue(exec, targetPrototype, trapResult)) {
+ throwVMTypeError(exec, ASCIILiteral("Proxy's 'getPrototypeOf' trap for a non-extensible target should return the same value as the target's prototype."));
+ return JSValue();
+ }
+
+ return trapResult;
+}
+
+JSValue ProxyObject::getPrototype(JSObject* object, ExecState* exec)
+{
+ return jsCast<ProxyObject*>(object)->performGetPrototype(exec);
+}
+
</ins><span class="cx"> void ProxyObject::visitChildren(JSCell* cell, SlotVisitor& visitor)
</span><span class="cx"> {
</span><span class="cx"> ProxyObject* thisObject = jsCast<ProxyObject*>(cell);
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreruntimeProxyObjecth"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/runtime/ProxyObject.h (197710 => 197711)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/runtime/ProxyObject.h        2016-03-07 23:24:47 UTC (rev 197710)
+++ trunk/Source/JavaScriptCore/runtime/ProxyObject.h        2016-03-07 23:27:44 UTC (rev 197711)
</span><span class="lines">@@ -65,6 +65,7 @@
</span><span class="cx"> static void put(JSCell*, ExecState*, PropertyName, JSValue, PutPropertySlot&);
</span><span class="cx"> static void putByIndex(JSCell*, ExecState*, unsigned propertyName, JSValue, bool shouldThrow);
</span><span class="cx"> void putByIndexCommon(ExecState*, JSValue thisValue, unsigned propertyName, JSValue putValue, bool shouldThrow);
</span><ins>+ JSValue performGetPrototype(ExecState*);
</ins><span class="cx">
</span><span class="cx"> private:
</span><span class="cx"> ProxyObject(VM&, Structure*);
</span><span class="lines">@@ -84,6 +85,7 @@
</span><span class="cx"> static NO_RETURN_DUE_TO_CRASH void getStructurePropertyNames(JSObject*, ExecState*, PropertyNameArray&, EnumerationMode);
</span><span class="cx"> static NO_RETURN_DUE_TO_CRASH void getGenericPropertyNames(JSObject*, ExecState*, PropertyNameArray&, EnumerationMode);
</span><span class="cx"> static bool setPrototype(JSObject*, ExecState*, JSValue prototype, bool shouldThrowIfCantSet);
</span><ins>+ static JSValue getPrototype(JSObject*, ExecState*);
</ins><span class="cx"> static void visitChildren(JSCell*, SlotVisitor&);
</span><span class="cx">
</span><span class="cx"> bool getOwnPropertySlotCommon(ExecState*, PropertyName, PropertySlot&);
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoretestses6yaml"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/tests/es6.yaml (197710 => 197711)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/tests/es6.yaml        2016-03-07 23:24:47 UTC (rev 197710)
+++ trunk/Source/JavaScriptCore/tests/es6.yaml        2016-03-07 23:27:44 UTC (rev 197711)
</span><span class="lines">@@ -927,7 +927,7 @@
</span><span class="cx"> - path: es6/Proxy_getOwnPropertyDescriptor_handler.js
</span><span class="cx"> cmd: runES6 :normal
</span><span class="cx"> - path: es6/Proxy_getPrototypeOf_handler.js
</span><del>- cmd: runES6 :fail
</del><ins>+ cmd: runES6 :normal
</ins><span class="cx"> - path: es6/Proxy_has_handler.js
</span><span class="cx"> cmd: runES6 :normal
</span><span class="cx"> - path: es6/Proxy_has_handler_instances_of_proxies.js
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoretestsstressproxygetprototypeofjs"></a>
<div class="addfile"><h4>Added: trunk/Source/JavaScriptCore/tests/stress/proxy-get-prototype-of.js (0 => 197711)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/tests/stress/proxy-get-prototype-of.js         (rev 0)
+++ trunk/Source/JavaScriptCore/tests/stress/proxy-get-prototype-of.js        2016-03-07 23:27:44 UTC (rev 197711)
</span><span class="lines">@@ -0,0 +1,442 @@
</span><ins>+function assert(b) {
+ if (!b)
+ throw new Error("Bad assertion.");
+}
+
+{
+ let target = {};
+ let error = null;
+ let handler = {
+ get getPrototypeOf() {
+ error = new Error;
+ throw error;
+ }
+ };
+
+ let proxy = new Proxy(target, handler);
+ for (let i = 0; i < 500; i++) {
+ let getters = [
+ () => Reflect.getPrototypeOf(proxy),
+ () => Object.getPrototypeOf(proxy),
+ () => proxy.__proto__,
+ ];
+ for (let get of getters) {
+ let threw = false;
+ try {
+ get();
+ } catch(e) {
+ assert(e === error);
+ threw = true;
+ }
+ assert(threw);
+ }
+ }
+}
+
+{
+ let target = {};
+ let error = null;
+ let handler = {
+ getPrototypeOf: function() {
+ error = new Error;
+ throw error;
+ }
+ };
+
+ let proxy = new Proxy(target, handler);
+ for (let i = 0; i < 500; i++) {
+ let getters = [
+ () => Reflect.getPrototypeOf(proxy),
+ () => Object.getPrototypeOf(proxy),
+ () => proxy.__proto__,
+ ];
+ for (let get of getters) {
+ let threw = false;
+ try {
+ get();
+ } catch(e) {
+ assert(e === error);
+ threw = true;
+ }
+ assert(threw);
+ }
+ }
+}
+
+{
+ let error = null;
+ let target = new Proxy({}, {
+ isExtensible: function() {
+ error = new Error;
+ throw error;
+ }
+ });
+
+ let handler = {
+ getPrototypeOf: function() {
+ return target.__proto__;
+ }
+ };
+
+ let proxy = new Proxy(target, handler);
+ for (let i = 0; i < 500; i++) {
+ let getters = [
+ () => Reflect.getPrototypeOf(proxy),
+ () => Object.getPrototypeOf(proxy),
+ () => proxy.__proto__,
+ ];
+ for (let get of getters) {
+ let threw = false;
+ try {
+ get();
+ } catch(e) {
+ assert(e === error);
+ threw = true;
+ }
+ assert(threw);
+ }
+ }
+}
+
+{
+ let target = {};
+ let handler = {
+ getPrototypeOf: 25
+ };
+
+ let proxy = new Proxy(target, handler);
+ for (let i = 0; i < 500; i++) {
+ let getters = [
+ () => Reflect.getPrototypeOf(proxy),
+ () => Object.getPrototypeOf(proxy),
+ () => proxy.__proto__,
+ ];
+ for (let get of getters) {
+ let threw = false;
+ try {
+ get();
+ } catch(e) {
+ assert(e.toString() === "TypeError: 'getPrototypeOf' property of a Proxy's handler should be callable.");
+ threw = true;
+ }
+ assert(threw);
+ }
+ }
+}
+
+{
+ let target = {};
+ let handler = {
+ getPrototypeOf: function() {
+ return 25;
+ }
+ };
+
+ let proxy = new Proxy(target, handler);
+ for (let i = 0; i < 500; i++) {
+ let getters = [
+ () => Reflect.getPrototypeOf(proxy),
+ () => Object.getPrototypeOf(proxy),
+ () => proxy.__proto__,
+ ];
+ for (let get of getters) {
+ let threw = false;
+ try {
+ get();
+ } catch(e) {
+ assert(e.toString() === "TypeError: Proxy handler's 'getPrototypeOf' trap should either return an object or null.");
+ threw = true;
+ }
+ assert(threw);
+ }
+ }
+}
+
+{
+ let target = {};
+ let handler = {
+ getPrototypeOf: function() {
+ return Symbol();
+ }
+ };
+
+ let proxy = new Proxy(target, handler);
+ for (let i = 0; i < 500; i++) {
+ let getters = [
+ () => Reflect.getPrototypeOf(proxy),
+ () => Object.getPrototypeOf(proxy),
+ () => proxy.__proto__,
+ ];
+ for (let get of getters) {
+ let threw = false;
+ try {
+ get();
+ } catch(e) {
+ assert(e.toString() === "TypeError: Proxy handler's 'getPrototypeOf' trap should either return an object or null.");
+ threw = true;
+ }
+ assert(threw);
+ }
+ }
+}
+
+{
+ let target = {};
+ Reflect.preventExtensions(target);
+ let handler = {
+ getPrototypeOf: function() {
+ return null;
+ }
+ };
+
+ let proxy = new Proxy(target, handler);
+ for (let i = 0; i < 500; i++) {
+ let getters = [
+ () => Reflect.getPrototypeOf(proxy),
+ () => Object.getPrototypeOf(proxy),
+ () => proxy.__proto__,
+ ];
+ for (let get of getters) {
+ let threw = false;
+ try {
+ get();
+ } catch(e) {
+ assert(e.toString() === "TypeError: Proxy's 'getPrototypeOf' trap for a non-extensible target should return the same value as the target's prototype.");
+ threw = true;
+ }
+ assert(threw);
+ }
+ }
+}
+
+{
+ let notProto = {};
+ let target = {};
+ Reflect.preventExtensions(target);
+ let handler = {
+ getPrototypeOf: function() {
+ return notProto;
+ }
+ };
+
+ let proxy = new Proxy(target, handler);
+ for (let i = 0; i < 500; i++) {
+ let getters = [
+ () => Reflect.getPrototypeOf(proxy),
+ () => Object.getPrototypeOf(proxy),
+ () => proxy.__proto__,
+ ];
+ for (let get of getters) {
+ let threw = false;
+ try {
+ get();
+ } catch(e) {
+ assert(e.toString() === "TypeError: Proxy's 'getPrototypeOf' trap for a non-extensible target should return the same value as the target's prototype.");
+ threw = true;
+ }
+ assert(threw);
+ }
+ }
+}
+
+{
+ let target = {};
+ Reflect.preventExtensions(target);
+ let called = false;
+ let handler = {
+ getPrototypeOf: function() {
+ called = true;
+ return Object.prototype;
+ }
+ };
+
+ let proxy = new Proxy(target, handler);
+ for (let i = 0; i < 500; i++) {
+ let getters = [
+ () => Reflect.getPrototypeOf(proxy),
+ () => Object.getPrototypeOf(proxy),
+ () => proxy.__proto__,
+ ];
+ for (let get of getters) {
+ let result = get();
+ assert(result === Object.prototype);
+ assert(called);
+ called = false;
+ }
+ }
+}
+
+{
+ let target = {};
+ let theProto = {x: 45};
+ target.__proto__ = theProto;
+ Reflect.preventExtensions(target);
+ let called = false;
+ let handler = {
+ getPrototypeOf: function(theTarget) {
+ assert(theTarget === target);
+ called = true;
+ return Reflect.getPrototypeOf(theTarget);
+ }
+ };
+
+ let proxy = new Proxy(target, handler);
+ for (let i = 0; i < 500; i++) {
+ let getters = [
+ () => Reflect.getPrototypeOf(proxy),
+ () => Object.getPrototypeOf(proxy),
+ () => proxy.__proto__,
+ ];
+ for (let get of getters) {
+ let result = get();
+ assert(result === theProto);
+ assert(called);
+ called = false;
+ }
+ }
+}
+
+{
+ let target = {};
+ let handler = {
+ getPrototypeOf: null
+ };
+
+ let proxy = new Proxy(target, handler);
+ for (let i = 0; i < 500; i++) {
+ let proto = Object.prototype;
+ let getters = [
+ () => Reflect.getPrototypeOf(proxy),
+ () => Object.getPrototypeOf(proxy),
+ () => proxy.__proto__,
+ ];
+ for (let get of getters) {
+ assert(get() === proto);
+ }
+ }
+}
+
+{
+ let target = {};
+ let proto = {};
+ let called = false;
+ let handler = {
+ getPrototypeOf: function(theTarget) {
+ assert(theTarget === target);
+ called = true;
+ return proto;
+ }
+ };
+
+ let proxy = new Proxy(target, handler);
+ for (let i = 0; i < 500; i++) {
+ let getters = [
+ () => Reflect.getPrototypeOf(proxy),
+ () => Object.getPrototypeOf(proxy),
+ () => proxy.__proto__,
+ ];
+ for (let get of getters) {
+ assert(get() === proto);
+ assert(called);
+ called = false;
+ }
+ }
+}
+
+{
+ let target = {};
+ let proto = null;
+ let called = false;
+ let handler = {
+ getPrototypeOf: function(theTarget) {
+ assert(theTarget === target);
+ called = true;
+ return proto;
+ }
+ };
+
+ let proxy = new Proxy(target, handler);
+ for (let i = 0; i < 500; i++) {
+ let getters = [
+ () => Reflect.getPrototypeOf(proxy),
+ () => Object.getPrototypeOf(proxy),
+ () => proxy.__proto__,
+ ];
+ for (let get of getters) {
+ assert(get() === proto);
+ assert(called);
+ called = false;
+ }
+ }
+}
+
+{
+ let target = {};
+ let proto = null;
+ let called = false;
+ let handler = {
+ getPrototypeOf: function(theTarget) {
+ assert(theTarget === target);
+ called = true;
+ return proto;
+ }
+ };
+
+ let proxy = new Proxy(target, handler);
+ for (let i = 0; i < 500; i++) {
+ let getters = [
+ () => Reflect.getPrototypeOf(proxy),
+ () => Object.getPrototypeOf(proxy),
+ () => proxy.__proto__,
+ ];
+ for (let get of getters) {
+ assert(get() === proto);
+ assert(called);
+ called = false;
+ }
+ }
+}
+
+{
+ let target = {};
+ let proto = null;
+ let called = false;
+ let handler = {
+ getPrototypeOf: function(theTarget) {
+ assert(theTarget === target);
+ called = true;
+ return proto;
+ },
+ has: function() {
+ return false;
+ }
+ };
+
+ let proxy = new Proxy(target, handler);
+ for (let i = 0; i < 500; i++) {
+ let result = "x" in proxy;
+ assert(called);
+ called = false;
+ }
+}
+
+{
+ let target = {};
+ let proto = null;
+ let called = false;
+ let handler = {
+ getPrototypeOf: function(theTarget) {
+ called = true;
+ return proto;
+ },
+ has: function() {
+ return true;
+ }
+ };
+
+ let proxy = new Proxy(target, handler);
+ for (let i = 0; i < 500; i++) {
+ let result = "x" in proxy;
+ assert(!called);
+ }
+}
</ins></span></pre>
</div>
</div>
</body>
</html>