From d012f5c6802e2a257a66ba88c7e72c069282c23a Mon Sep 17 00:00:00 2001
From: Leonardo Balter <leonardo.balter@gmail.com>
Date: Tue, 2 Jun 2015 17:34:51 -0400
Subject: [PATCH] Proxy: getPrototypeOf

---
 .../Proxy/getPrototypeOf/call-parameters.js   | 31 ++++++++++++++
 .../extensible-target-return-handlerproto.js  | 32 +++++++++++++++
 .../not-extensible-not-same-proto-throws.js   | 40 +++++++++++++++++++
 .../not-extensible-same-proto.js              | 37 +++++++++++++++++
 .../Proxy/getPrototypeOf/null-handler.js      | 15 +++++++
 .../Proxy/getPrototypeOf/return-is-abrupt.js  | 21 ++++++++++
 .../getPrototypeOf/trap-is-not-callable.js    | 15 +++++++
 .../Proxy/getPrototypeOf/trap-is-undefined.js | 12 ++++++
 ...-neither-object-nor-null-throws-boolean.js | 17 ++++++++
 ...t-neither-object-nor-null-throws-number.js | 17 ++++++++
 ...t-neither-object-nor-null-throws-string.js | 17 ++++++++
 ...t-neither-object-nor-null-throws-symbol.js | 18 +++++++++
 ...either-object-nor-null-throws-undefined.js | 17 ++++++++
 13 files changed, 289 insertions(+)
 create mode 100644 test/built-ins/Proxy/getPrototypeOf/call-parameters.js
 create mode 100644 test/built-ins/Proxy/getPrototypeOf/extensible-target-return-handlerproto.js
 create mode 100644 test/built-ins/Proxy/getPrototypeOf/not-extensible-not-same-proto-throws.js
 create mode 100644 test/built-ins/Proxy/getPrototypeOf/not-extensible-same-proto.js
 create mode 100644 test/built-ins/Proxy/getPrototypeOf/null-handler.js
 create mode 100644 test/built-ins/Proxy/getPrototypeOf/return-is-abrupt.js
 create mode 100644 test/built-ins/Proxy/getPrototypeOf/trap-is-not-callable.js
 create mode 100644 test/built-ins/Proxy/getPrototypeOf/trap-is-undefined.js
 create mode 100644 test/built-ins/Proxy/getPrototypeOf/trap-result-neither-object-nor-null-throws-boolean.js
 create mode 100644 test/built-ins/Proxy/getPrototypeOf/trap-result-neither-object-nor-null-throws-number.js
 create mode 100644 test/built-ins/Proxy/getPrototypeOf/trap-result-neither-object-nor-null-throws-string.js
 create mode 100644 test/built-ins/Proxy/getPrototypeOf/trap-result-neither-object-nor-null-throws-symbol.js
 create mode 100644 test/built-ins/Proxy/getPrototypeOf/trap-result-neither-object-nor-null-throws-undefined.js

diff --git a/test/built-ins/Proxy/getPrototypeOf/call-parameters.js b/test/built-ins/Proxy/getPrototypeOf/call-parameters.js
new file mode 100644
index 0000000000..8476b7c4aa
--- /dev/null
+++ b/test/built-ins/Proxy/getPrototypeOf/call-parameters.js
@@ -0,0 +1,31 @@
+// Copyright (C) 2015 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+es6id: 9.5.1
+description: >
+    Trap is called with handler as context and target as the first parameter.
+info: >
+    [[GetPrototypeOf]] ( )
+
+    ...
+    8. Let handlerProto be Call(trap, handler, «target»).
+    ...
+
+---*/
+
+var _handler, _target;
+var target = {};
+var handler = {
+  getPrototypeOf: function(t) {
+    _handler = this;
+    _target = t;
+    return {};
+  }
+};
+
+var p = new Proxy(target, handler);
+
+Object.getPrototypeOf(p);
+
+assert.sameValue(_handler, handler);
+assert.sameValue(_target, target);
diff --git a/test/built-ins/Proxy/getPrototypeOf/extensible-target-return-handlerproto.js b/test/built-ins/Proxy/getPrototypeOf/extensible-target-return-handlerproto.js
new file mode 100644
index 0000000000..10ee96187e
--- /dev/null
+++ b/test/built-ins/Proxy/getPrototypeOf/extensible-target-return-handlerproto.js
@@ -0,0 +1,32 @@
+// Copyright (C) 2015 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+es6id: 9.5.1
+description: >
+    Return trap result if it's an Object and target is extensible.
+info: >
+    [[GetPrototypeOf]] ( )
+
+    ...
+    1. Let handler be the value of the [[ProxyHandler]] internal slot of O.
+    ...
+    4. Let target be the value of the [[ProxyTarget]] internal slot of O.
+    5. Let trap be GetMethod(handler, "getPrototypeOf").
+    ...
+    8. Let handlerProto be Call(trap, handler, «target»).
+    ...
+    11. Let extensibleTarget be IsExtensible(target).
+    12. ReturnIfAbrupt(extensibleTarget).
+    13. If extensibleTarget is true, return handlerProto.
+    ...
+
+---*/
+
+var prot = { foo: 1 };
+var p = new Proxy({}, {
+  getPrototypeOf: function() {
+    return prot;
+  }
+});
+
+assert.sameValue(Object.getPrototypeOf(p), prot);
diff --git a/test/built-ins/Proxy/getPrototypeOf/not-extensible-not-same-proto-throws.js b/test/built-ins/Proxy/getPrototypeOf/not-extensible-not-same-proto-throws.js
new file mode 100644
index 0000000000..7a31e7fb92
--- /dev/null
+++ b/test/built-ins/Proxy/getPrototypeOf/not-extensible-not-same-proto-throws.js
@@ -0,0 +1,40 @@
+// Copyright (C) 2015 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+es6id: 9.5.1
+description: >
+    Throws a TypeError if the target is not extensible and the trap result is
+    not the same as the target.[[GetPrototypeOf]] result.
+info: >
+    [[GetPrototypeOf]] ( )
+
+    ...
+    1. Let handler be the value of the [[ProxyHandler]] internal slot of O.
+    ...
+    4. Let target be the value of the [[ProxyTarget]] internal slot of O.
+    5. Let trap be GetMethod(handler, "getPrototypeOf").
+    ...
+    8. Let handlerProto be Call(trap, handler, «target»).
+    ...
+    11. Let extensibleTarget be IsExtensible(target).
+    ...
+    14. Let targetProto be target.[[GetPrototypeOf]]().
+    15. ReturnIfAbrupt(targetProto).
+    16. If SameValue(handlerProto, targetProto) is false, throw a TypeError
+    exception.
+    ...
+---*/
+
+var target = Object.create({ foo: 1 });
+
+var p = new Proxy(target, {
+  getPrototypeOf: function() {
+    return {};
+  }
+});
+
+Object.preventExtensions(target);
+
+assert.throws(TypeError, function() {
+    Object.getPrototypeOf(p);
+});
diff --git a/test/built-ins/Proxy/getPrototypeOf/not-extensible-same-proto.js b/test/built-ins/Proxy/getPrototypeOf/not-extensible-same-proto.js
new file mode 100644
index 0000000000..c9143a014b
--- /dev/null
+++ b/test/built-ins/Proxy/getPrototypeOf/not-extensible-same-proto.js
@@ -0,0 +1,37 @@
+// Copyright (C) 2015 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+es6id: 9.5.1
+description: >
+    Return trap result is target is not extensible, but trap result has the same
+    value as target.[[GetPrototypeOf]] result.
+info: >
+    [[GetPrototypeOf]] ( )
+
+    ...
+    1. Let handler be the value of the [[ProxyHandler]] internal slot of O.
+    ...
+    4. Let target be the value of the [[ProxyTarget]] internal slot of O.
+    5. Let trap be GetMethod(handler, "getPrototypeOf").
+    ...
+    8. Let handlerProto be Call(trap, handler, «target»).
+    ...
+    11. Let extensibleTarget be IsExtensible(target).
+    ...
+    14. Let targetProto be target.[[GetPrototypeOf]]().
+    ...
+    17. Return handlerProto.
+
+---*/
+
+var target = Object.create(Array.prototype);
+
+var p = new Proxy(target, {
+  getPrototypeOf: function() {
+    return Array.prototype;
+  }
+});
+
+Object.preventExtensions(target);
+
+assert.sameValue(Object.getPrototypeOf(p), Array.prototype);
diff --git a/test/built-ins/Proxy/getPrototypeOf/null-handler.js b/test/built-ins/Proxy/getPrototypeOf/null-handler.js
new file mode 100644
index 0000000000..38c8e7e493
--- /dev/null
+++ b/test/built-ins/Proxy/getPrototypeOf/null-handler.js
@@ -0,0 +1,15 @@
+// Copyright (C) 2015 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+es6id: 9.5.1
+description: >
+    Throws a TypeError exception if handler is null.
+---*/
+
+var p = Proxy.revocable({}, {});
+
+p.revoke();
+
+assert.throws(TypeError, function() {
+    Object.getPrototypeOf(p.proxy);
+});
diff --git a/test/built-ins/Proxy/getPrototypeOf/return-is-abrupt.js b/test/built-ins/Proxy/getPrototypeOf/return-is-abrupt.js
new file mode 100644
index 0000000000..88a46a7a43
--- /dev/null
+++ b/test/built-ins/Proxy/getPrototypeOf/return-is-abrupt.js
@@ -0,0 +1,21 @@
+// Copyright (C) 2015 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+es6id: 9.5.1
+description: >
+    Trap returns abrupt.
+info: >
+    8. Let handlerProto be Call(trap, handler, «target»).
+    9. ReturnIfAbrupt(handlerProto).
+includes: [Test262Error.js]
+---*/
+
+var p = new Proxy({}, {
+  getPrototypeOf: function() {
+    throw new Test262Error();
+  }
+});
+
+assert.throws(Test262Error, function() {
+    Object.getPrototypeOf(p);
+});
diff --git a/test/built-ins/Proxy/getPrototypeOf/trap-is-not-callable.js b/test/built-ins/Proxy/getPrototypeOf/trap-is-not-callable.js
new file mode 100644
index 0000000000..e6335e46a5
--- /dev/null
+++ b/test/built-ins/Proxy/getPrototypeOf/trap-is-not-callable.js
@@ -0,0 +1,15 @@
+// Copyright (C) 2015 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+es6id: 9.5.1
+description: >
+    Throws if trap is not callable.
+---*/
+
+var p = new Proxy({}, {
+    getPrototypeOf: {}
+});
+
+assert.throws(TypeError, function() {
+    Object.getPrototypeOf(p);
+});
diff --git a/test/built-ins/Proxy/getPrototypeOf/trap-is-undefined.js b/test/built-ins/Proxy/getPrototypeOf/trap-is-undefined.js
new file mode 100644
index 0000000000..efa9dcd100
--- /dev/null
+++ b/test/built-ins/Proxy/getPrototypeOf/trap-is-undefined.js
@@ -0,0 +1,12 @@
+// Copyright (C) 2015 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+es6id: 9.5.1
+description: >
+    Return target.[[GetPrototypeOf]]() if trap is undefined.
+---*/
+
+var target = Object.create(Array.prototype);
+var p = new Proxy(target, {});
+
+assert.sameValue(Object.getPrototypeOf(p), Array.prototype);
diff --git a/test/built-ins/Proxy/getPrototypeOf/trap-result-neither-object-nor-null-throws-boolean.js b/test/built-ins/Proxy/getPrototypeOf/trap-result-neither-object-nor-null-throws-boolean.js
new file mode 100644
index 0000000000..c8c0543ba8
--- /dev/null
+++ b/test/built-ins/Proxy/getPrototypeOf/trap-result-neither-object-nor-null-throws-boolean.js
@@ -0,0 +1,17 @@
+// Copyright (C) 2015 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+es6id: 9.5.1
+description: >
+    Throw a TypeError exception if trap result is false.
+---*/
+
+var p = new Proxy({}, {
+  getPrototypeOf: function() {
+    return false;
+  }
+});
+
+assert.throws(TypeError, function() {
+    Object.getPrototypeOf(p);
+});
diff --git a/test/built-ins/Proxy/getPrototypeOf/trap-result-neither-object-nor-null-throws-number.js b/test/built-ins/Proxy/getPrototypeOf/trap-result-neither-object-nor-null-throws-number.js
new file mode 100644
index 0000000000..d0533f518c
--- /dev/null
+++ b/test/built-ins/Proxy/getPrototypeOf/trap-result-neither-object-nor-null-throws-number.js
@@ -0,0 +1,17 @@
+// Copyright (C) 2015 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+es6id: 9.5.1
+description: >
+    Throw a TypeError exception if trap result is a Number.
+---*/
+
+var p = new Proxy({}, {
+  getPrototypeOf: function() {
+    return 0;
+  }
+});
+
+assert.throws(TypeError, function() {
+    Object.getPrototypeOf(p);
+});
diff --git a/test/built-ins/Proxy/getPrototypeOf/trap-result-neither-object-nor-null-throws-string.js b/test/built-ins/Proxy/getPrototypeOf/trap-result-neither-object-nor-null-throws-string.js
new file mode 100644
index 0000000000..34bea0d5fc
--- /dev/null
+++ b/test/built-ins/Proxy/getPrototypeOf/trap-result-neither-object-nor-null-throws-string.js
@@ -0,0 +1,17 @@
+// Copyright (C) 2015 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+es6id: 9.5.1
+description: >
+    throw a TypeError exception if trap result is a String.
+---*/
+
+var p = new Proxy({}, {
+  getPrototypeOf: function() {
+    return "";
+  }
+});
+
+assert.throws(TypeError, function() {
+    Object.getPrototypeOf(p);
+});
diff --git a/test/built-ins/Proxy/getPrototypeOf/trap-result-neither-object-nor-null-throws-symbol.js b/test/built-ins/Proxy/getPrototypeOf/trap-result-neither-object-nor-null-throws-symbol.js
new file mode 100644
index 0000000000..9b47cf9a9f
--- /dev/null
+++ b/test/built-ins/Proxy/getPrototypeOf/trap-result-neither-object-nor-null-throws-symbol.js
@@ -0,0 +1,18 @@
+// Copyright (C) 2015 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+es6id: 9.5.1
+description: >
+    Throw a TypeError exception if trap result is a Symbol.
+features: [Symbol]
+---*/
+
+var p = new Proxy({}, {
+  getPrototypeOf: function() {
+    return Symbol();
+  }
+});
+
+assert.throws(TypeError, function() {
+    Object.getPrototypeOf(p);
+});
diff --git a/test/built-ins/Proxy/getPrototypeOf/trap-result-neither-object-nor-null-throws-undefined.js b/test/built-ins/Proxy/getPrototypeOf/trap-result-neither-object-nor-null-throws-undefined.js
new file mode 100644
index 0000000000..8e5143d3d8
--- /dev/null
+++ b/test/built-ins/Proxy/getPrototypeOf/trap-result-neither-object-nor-null-throws-undefined.js
@@ -0,0 +1,17 @@
+// Copyright (C) 2015 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+es6id: 9.5.1
+description: >
+    Throw a TypeError exception if trap result is undefined.
+---*/
+
+var p = new Proxy({}, {
+  getPrototypeOf: function() {
+    return undefined;
+  }
+});
+
+assert.throws(TypeError, function() {
+    Object.getPrototypeOf(p);
+});
-- 
GitLab