From 21a1fbe68ed12247ccb27e81d88f4063a8b87603 Mon Sep 17 00:00:00 2001
From: Leonardo Balter <leonardo.balter@gmail.com>
Date: Tue, 2 Jun 2015 19:14:17 -0400
Subject: [PATCH] Proxy: get

---
 .../get/accessor-get-is-undefined-throws.js   | 36 ++++++++++++++++
 test/built-ins/Proxy/get/call-parameters.js   | 41 +++++++++++++++++++
 ...onfigurable-false-writable-false-throws.js | 37 +++++++++++++++++
 test/built-ins/Proxy/get/null-handler.js      | 21 ++++++++++
 test/built-ins/Proxy/get/return-is-abrupt.js  | 27 ++++++++++++
 .../return-trap-result-accessor-property.js   | 25 +++++++++++
 ...result-configurable-false-writable-true.js | 25 +++++++++++
 ...onfigurable-true-assessor-get-undefined.js | 24 +++++++++++
 ...result-configurable-true-writable-false.js | 25 +++++++++++
 ...value-configurable-false-writable-false.js | 34 +++++++++++++++
 .../built-ins/Proxy/get/return-trap-result.js | 24 +++++++++++
 .../Proxy/get/trap-is-not-callable.js         | 28 +++++++++++++
 .../get/trap-is-undefined-no-property.js      | 19 +++++++++
 test/built-ins/Proxy/get/trap-is-undefined.js | 20 +++++++++
 14 files changed, 386 insertions(+)
 create mode 100644 test/built-ins/Proxy/get/accessor-get-is-undefined-throws.js
 create mode 100644 test/built-ins/Proxy/get/call-parameters.js
 create mode 100644 test/built-ins/Proxy/get/not-same-value-configurable-false-writable-false-throws.js
 create mode 100644 test/built-ins/Proxy/get/null-handler.js
 create mode 100644 test/built-ins/Proxy/get/return-is-abrupt.js
 create mode 100644 test/built-ins/Proxy/get/return-trap-result-accessor-property.js
 create mode 100644 test/built-ins/Proxy/get/return-trap-result-configurable-false-writable-true.js
 create mode 100644 test/built-ins/Proxy/get/return-trap-result-configurable-true-assessor-get-undefined.js
 create mode 100644 test/built-ins/Proxy/get/return-trap-result-configurable-true-writable-false.js
 create mode 100644 test/built-ins/Proxy/get/return-trap-result-same-value-configurable-false-writable-false.js
 create mode 100644 test/built-ins/Proxy/get/return-trap-result.js
 create mode 100644 test/built-ins/Proxy/get/trap-is-not-callable.js
 create mode 100644 test/built-ins/Proxy/get/trap-is-undefined-no-property.js
 create mode 100644 test/built-ins/Proxy/get/trap-is-undefined.js

diff --git a/test/built-ins/Proxy/get/accessor-get-is-undefined-throws.js b/test/built-ins/Proxy/get/accessor-get-is-undefined-throws.js
new file mode 100644
index 0000000000..15a3cebd1b
--- /dev/null
+++ b/test/built-ins/Proxy/get/accessor-get-is-undefined-throws.js
@@ -0,0 +1,36 @@
+// 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.8
+description: >
+    [[Get]] (P, Receiver)
+
+    if trap result is not undefined, then proxy must report the same value for a
+    non-configurable accessor property with an undefined get.
+info: >
+    13. If targetDesc is not undefined, then
+        b. If IsAccessorDescriptor(targetDesc) and targetDesc.[[Configurable]]
+        is false and targetDesc.[[Get]] is undefined, then
+            i. If trapResult is not undefined, throw a TypeError exception.
+
+---*/
+
+var target = {};
+var p = new Proxy(target, {
+    get: function() {
+        return 2;
+    }
+});
+
+Object.defineProperty(target, 'attr', {
+    configurable: false,
+    get: undefined
+});
+
+assert.throws(TypeError, function() {
+    p.attr;
+});
+
+assert.throws(TypeError, function() {
+    p['attr'];
+});
diff --git a/test/built-ins/Proxy/get/call-parameters.js b/test/built-ins/Proxy/get/call-parameters.js
new file mode 100644
index 0000000000..55f7e71fcf
--- /dev/null
+++ b/test/built-ins/Proxy/get/call-parameters.js
@@ -0,0 +1,41 @@
+// 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.8
+description: >
+    [[Get]] (P, Receiver)
+
+    9. Let trapResult be Call(trap, handler, «target, P, Receiver»).
+info: >
+    6.1.7.2 Object Internal Methods and Internal Slots
+
+    (...) Receiver is used as the this value when evaluating the code
+---*/
+
+var _target, _handler, _prop, _receiver;
+var target = {
+    attr: 1
+};
+var handler = {
+    get: function(t, prop, receiver) {
+        _handler = this;
+        _target = t;
+        _prop = prop;
+        _receiver = receiver;
+    }
+};
+var p = new Proxy(target, handler);
+
+p.attr;
+
+assert.sameValue(_handler, handler);
+assert.sameValue(_target, target);
+assert.sameValue(_prop, "attr");
+assert.sameValue(_receiver, p, "receiver is the Proxy object");
+
+_prop = null;
+p["attr"];
+assert.sameValue(
+    _prop, "attr",
+    "trap is triggered both by p.attr and p['attr']"
+);
diff --git a/test/built-ins/Proxy/get/not-same-value-configurable-false-writable-false-throws.js b/test/built-ins/Proxy/get/not-same-value-configurable-false-writable-false-throws.js
new file mode 100644
index 0000000000..97eff7da68
--- /dev/null
+++ b/test/built-ins/Proxy/get/not-same-value-configurable-false-writable-false-throws.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.8
+description: >
+    Throws if proxy return has not the same value for a non-writable,
+    non-configurable property
+info: >
+    [[Get]] (P, Receiver)
+
+    13. If targetDesc is not undefined, then
+        a. If IsDataDescriptor(targetDesc) and targetDesc.[[Configurable]] is
+        false and targetDesc.[[Writable]] is false, then
+            i. If SameValue(trapResult, targetDesc.[[Value]]) is false, throw a
+            TypeError exception.
+---*/
+
+var target = {};
+var p = new Proxy(target, {
+    get: function() {
+        return 2;
+    }
+});
+
+Object.defineProperty(target, 'attr', {
+    configurable: false,
+    writable: false,
+    value: 1
+});
+
+assert.throws(TypeError, function() {
+    p.attr;
+});
+
+assert.throws(TypeError, function() {
+    p['attr'];
+});
diff --git a/test/built-ins/Proxy/get/null-handler.js b/test/built-ins/Proxy/get/null-handler.js
new file mode 100644
index 0000000000..82dc3a187c
--- /dev/null
+++ b/test/built-ins/Proxy/get/null-handler.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.8
+description: >
+    [[Get]] (P, Receiver)
+
+    2. If handler is null, throw a TypeError exception.
+---*/
+
+var p = Proxy.revocable({}, {});
+
+p.revoke();
+
+assert.throws(TypeError, function() {
+    p.proxy.attr;
+});
+
+assert.throws(TypeError, function() {
+    p.proxy['attr'];
+});
diff --git a/test/built-ins/Proxy/get/return-is-abrupt.js b/test/built-ins/Proxy/get/return-is-abrupt.js
new file mode 100644
index 0000000000..ea6a7c4bb5
--- /dev/null
+++ b/test/built-ins/Proxy/get/return-is-abrupt.js
@@ -0,0 +1,27 @@
+// 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.8
+description: >
+    Trap returns abrupt.
+info: >
+    [[Get]] (P, Receiver)
+
+    9. Let trapResult be Call(trap, handler, «target, P, Receiver»).
+    10. ReturnIfAbrupt(trapResult).
+includes: [Test262Error.js]
+---*/
+
+var p = new Proxy({}, {
+    get: function() {
+        throw new Test262Error();
+    }
+});
+
+assert.throws(Test262Error, function() {
+    p.attr;
+});
+
+assert.throws(Test262Error, function() {
+    p["attr"];
+});
diff --git a/test/built-ins/Proxy/get/return-trap-result-accessor-property.js b/test/built-ins/Proxy/get/return-trap-result-accessor-property.js
new file mode 100644
index 0000000000..560bd56506
--- /dev/null
+++ b/test/built-ins/Proxy/get/return-trap-result-accessor-property.js
@@ -0,0 +1,25 @@
+// 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.8
+description: >
+    [[Get]] (P, Receiver)
+
+    14. Return trapResult.
+---*/
+
+var target = {};
+var p = new Proxy(target, {
+    get: function() {
+        return 2;
+    }
+});
+
+Object.defineProperty(target, 'attr', {
+    get: function() {
+        return 1;
+    }
+});
+
+assert.sameValue(p.attr, 2);
+assert.sameValue(p['attr'], 2);
diff --git a/test/built-ins/Proxy/get/return-trap-result-configurable-false-writable-true.js b/test/built-ins/Proxy/get/return-trap-result-configurable-false-writable-true.js
new file mode 100644
index 0000000000..46ddaeff0b
--- /dev/null
+++ b/test/built-ins/Proxy/get/return-trap-result-configurable-false-writable-true.js
@@ -0,0 +1,25 @@
+// 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.8
+description: >
+    [[Get]] (P, Receiver)
+
+    14. Return trapResult.
+---*/
+
+var target = {};
+var p = new Proxy(target, {
+    get: function() {
+        return 2;
+    }
+});
+
+Object.defineProperty(target, 'attr', {
+    configurable: false,
+    writable: true,
+    value: 1
+});
+
+assert.sameValue(p.attr, 2);
+assert.sameValue(p['attr'], 2);
diff --git a/test/built-ins/Proxy/get/return-trap-result-configurable-true-assessor-get-undefined.js b/test/built-ins/Proxy/get/return-trap-result-configurable-true-assessor-get-undefined.js
new file mode 100644
index 0000000000..930265b6e6
--- /dev/null
+++ b/test/built-ins/Proxy/get/return-trap-result-configurable-true-assessor-get-undefined.js
@@ -0,0 +1,24 @@
+// 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.8
+description: >
+    [[Get]] (P, Receiver)
+
+    14. Return trapResult.
+---*/
+
+var target = {};
+var p = new Proxy(target, {
+    get: function() {
+        return 2;
+    }
+});
+
+Object.defineProperty(target, 'attr', {
+    configurable: true,
+    get: undefined
+});
+
+assert.sameValue(p.attr, 2);
+assert.sameValue(p['attr'], 2);
diff --git a/test/built-ins/Proxy/get/return-trap-result-configurable-true-writable-false.js b/test/built-ins/Proxy/get/return-trap-result-configurable-true-writable-false.js
new file mode 100644
index 0000000000..1ad1eca0a6
--- /dev/null
+++ b/test/built-ins/Proxy/get/return-trap-result-configurable-true-writable-false.js
@@ -0,0 +1,25 @@
+// 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.8
+description: >
+    [[Get]] (P, Receiver)
+
+    14. Return trapResult.
+---*/
+
+var target = {};
+var p = new Proxy(target, {
+    get: function() {
+        return 2;
+    }
+});
+
+Object.defineProperty(target, 'attr', {
+    configurable: true,
+    writable: false,
+    value: 1
+});
+
+assert.sameValue(p.attr, 2);
+assert.sameValue(p['attr'], 2);
diff --git a/test/built-ins/Proxy/get/return-trap-result-same-value-configurable-false-writable-false.js b/test/built-ins/Proxy/get/return-trap-result-same-value-configurable-false-writable-false.js
new file mode 100644
index 0000000000..bec57837e9
--- /dev/null
+++ b/test/built-ins/Proxy/get/return-trap-result-same-value-configurable-false-writable-false.js
@@ -0,0 +1,34 @@
+// 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.8
+description: >
+    Proxy must report the same value for a non-writable, non-configurable
+    property.
+info: >
+    [[Get]] (P, Receiver)
+
+    13. If targetDesc is not undefined, then
+        a. If IsDataDescriptor(targetDesc) and targetDesc.[[Configurable]] is
+        false and targetDesc.[[Writable]] is false, then
+            i. If SameValue(trapResult, targetDesc.[[Value]]) is false, throw a
+            TypeError exception.
+        ...
+    14. Return trapResult.
+---*/
+
+var target = {};
+var p = new Proxy(target, {
+    get: function() {
+        return 1;
+    }
+});
+
+Object.defineProperty(target, 'attr', {
+    configurable: false,
+    writable: false,
+    value: 1
+});
+
+assert.sameValue(p.attr, 1);
+assert.sameValue(p['attr'], 1);
diff --git a/test/built-ins/Proxy/get/return-trap-result.js b/test/built-ins/Proxy/get/return-trap-result.js
new file mode 100644
index 0000000000..d045e14927
--- /dev/null
+++ b/test/built-ins/Proxy/get/return-trap-result.js
@@ -0,0 +1,24 @@
+// 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.8
+description: >
+    [[Get]] (P, Receiver)
+
+    14. Return trapResult.
+---*/
+
+var target = {
+    attr: 1
+};
+var p = new Proxy(target, {
+    get: function() {
+        return 2;
+    }
+});
+
+assert.sameValue(p.attr, 2);
+assert.sameValue(p.foo, 2);
+
+assert.sameValue(p['attr'], 2);
+assert.sameValue(p['foo'], 2);
diff --git a/test/built-ins/Proxy/get/trap-is-not-callable.js b/test/built-ins/Proxy/get/trap-is-not-callable.js
new file mode 100644
index 0000000000..9ea5caed59
--- /dev/null
+++ b/test/built-ins/Proxy/get/trap-is-not-callable.js
@@ -0,0 +1,28 @@
+// 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.8
+description: >
+    Trap is not callable.
+info: >
+    [[Get]] (P, Receiver)
+
+    6. Let trap be GetMethod(handler, "get").
+    ...
+
+    7.3.9 GetMethod (O, P)
+
+    5. If IsCallable(func) is false, throw a TypeError exception.
+---*/
+
+var p = new Proxy({}, {
+    get: {}
+});
+
+assert.throws(TypeError, function() {
+    p.attr;
+});
+
+assert.throws(TypeError, function() {
+    p["attr"];
+});
diff --git a/test/built-ins/Proxy/get/trap-is-undefined-no-property.js b/test/built-ins/Proxy/get/trap-is-undefined-no-property.js
new file mode 100644
index 0000000000..c9d107f592
--- /dev/null
+++ b/test/built-ins/Proxy/get/trap-is-undefined-no-property.js
@@ -0,0 +1,19 @@
+// 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.8
+description: >
+    [[Get]] (P, Receiver)
+
+    8. If trap is undefined, then return target.[[Get]](P, Receiver).
+---*/
+
+var target = {
+    attr: 1
+};
+var p = new Proxy(target, {});
+
+assert.sameValue(p.attr, 1, 'return target.attr');
+assert.sameValue(p.foo, undefined, 'return target.foo');
+assert.sameValue(p['attr'], 1, 'return target.attr');
+assert.sameValue(p['foo'], undefined, 'return target.foo');
diff --git a/test/built-ins/Proxy/get/trap-is-undefined.js b/test/built-ins/Proxy/get/trap-is-undefined.js
new file mode 100644
index 0000000000..4c2257aa61
--- /dev/null
+++ b/test/built-ins/Proxy/get/trap-is-undefined.js
@@ -0,0 +1,20 @@
+// 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.8
+description: >
+    [[Get]] (P, Receiver)
+
+    8. If trap is undefined, then return target.[[Get]](P, Receiver).
+
+---*/
+
+var target = {
+    attr: 1
+};
+var p = new Proxy(target, {
+    get: undefined
+});
+
+assert.sameValue(p.attr, 1, 'return target.attr');
+assert.sameValue(p.foo, undefined, 'return target.foo');
-- 
GitLab