From 3ce00cf5e34d10af6305f679a6dc0eb8c01ba79d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andr=C3=A9=20Bargull?= <andre.bargull@gmail.com>
Date: Fri, 8 Dec 2017 13:20:33 -0800
Subject: [PATCH] Add tests for uninitialized bindings when accessed through
 Object methods and for-in

---
 .../internals/enumerate-binding-uninit.js     | 42 +++++++++++++++++
 .../object-hasOwnProperty-binding-uninit.js   | 42 +++++++++++++++++
 .../internals/object-keys-binding-uninit.js   | 45 +++++++++++++++++++
 ...ect-propertyIsEnumerable-binding-uninit.js | 38 ++++++++++++++++
 4 files changed, 167 insertions(+)
 create mode 100644 test/language/module-code/namespace/internals/enumerate-binding-uninit.js
 create mode 100644 test/language/module-code/namespace/internals/object-hasOwnProperty-binding-uninit.js
 create mode 100644 test/language/module-code/namespace/internals/object-keys-binding-uninit.js
 create mode 100644 test/language/module-code/namespace/internals/object-propertyIsEnumerable-binding-uninit.js

diff --git a/test/language/module-code/namespace/internals/enumerate-binding-uninit.js b/test/language/module-code/namespace/internals/enumerate-binding-uninit.js
new file mode 100644
index 0000000000..a56408e8d8
--- /dev/null
+++ b/test/language/module-code/namespace/internals/enumerate-binding-uninit.js
@@ -0,0 +1,42 @@
+// Copyright (C) 2017 André Bargull. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+id: sec-enumerate-object-properties
+info: >
+  Test for-in enumeration with uninitialized binding.
+description: |
+  13.7.5.15 EnumerateObjectProperties (O)
+    ...
+    EnumerateObjectProperties must obtain the own property keys of the
+    target object by calling its [[OwnPropertyKeys]] internal method.
+    Property attributes of the target object must be obtained by
+    calling its [[GetOwnProperty]] internal method.
+
+  9.4.6.4 [[GetOwnProperty]] (P)
+    ...
+    4. Let value be ? O.[[Get]](P, O).
+    ...
+
+  9.4.6.7 [[Get]] (P, Receiver)
+    ...
+    12. Let targetEnvRec be targetEnv's EnvironmentRecord.
+    13. Return ? targetEnvRec.GetBindingValue(binding.[[BindingName]], true).
+
+  8.1.1.1.6 GetBindingValue ( N, S )
+    ...
+    If the binding for N in envRec is an uninitialized binding, throw a ReferenceError exception.
+    ...
+
+flags: [module]
+---*/
+
+import* as self from "./enumerate-binding-uninit.js";
+
+assert.throws(ReferenceError, function() {
+  for (var key in self) {
+    throw new Test262Error();
+  }
+});
+
+export default 0;
diff --git a/test/language/module-code/namespace/internals/object-hasOwnProperty-binding-uninit.js b/test/language/module-code/namespace/internals/object-hasOwnProperty-binding-uninit.js
new file mode 100644
index 0000000000..fc90814fbb
--- /dev/null
+++ b/test/language/module-code/namespace/internals/object-hasOwnProperty-binding-uninit.js
@@ -0,0 +1,42 @@
+// Copyright (C) 2017 André Bargull. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+id: sec-object.prototype.hasownproperty
+info: >
+  Test Object.prototype.hasOwnProperty() with uninitialized binding.
+description: |
+  19.1.3.2 Object.prototype.hasOwnProperty ( V )
+    ...
+    3. Return ? HasOwnProperty(O, P).
+
+  7.3.11 HasOwnProperty ( O, P )
+    ...
+    3. Let desc be ? O.[[GetOwnProperty]](P).
+    ...
+
+  9.4.6.4 [[GetOwnProperty]] (P)
+    ...
+    4. Let value be ? O.[[Get]](P, O).
+    ...
+
+  9.4.6.7 [[Get]] (P, Receiver)
+    ...
+    12. Let targetEnvRec be targetEnv's EnvironmentRecord.
+    13. Return ? targetEnvRec.GetBindingValue(binding.[[BindingName]], true).
+
+  8.1.1.1.6 GetBindingValue ( N, S )
+    ...
+    If the binding for N in envRec is an uninitialized binding, throw a ReferenceError exception.
+    ...
+
+flags: [module]
+---*/
+
+import* as self from "./object-hasOwnProperty-binding-uninit.js";
+
+assert.throws(ReferenceError, function() {
+  Object.prototype.hasOwnProperty.call(self, "default");
+});
+
+export default 0;
diff --git a/test/language/module-code/namespace/internals/object-keys-binding-uninit.js b/test/language/module-code/namespace/internals/object-keys-binding-uninit.js
new file mode 100644
index 0000000000..842ae50d6e
--- /dev/null
+++ b/test/language/module-code/namespace/internals/object-keys-binding-uninit.js
@@ -0,0 +1,45 @@
+// Copyright (C) 2017 André Bargull. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+id: sec-object.keys
+info: >
+  Test Object.keys() with uninitialized binding.
+description: |
+  19.1.2.16 Object.keys ( O )
+    ...
+    2. Let nameList be ? EnumerableOwnProperties(obj, "key").
+    ...
+
+  7.3.21 EnumerableOwnProperties ( O, kind )
+    ...
+    4. For each element key of ownKeys in List order, do
+      a. If Type(key) is String, then
+        i. Let desc be ? O.[[GetOwnProperty]](key).
+        ...
+
+  9.4.6.4 [[GetOwnProperty]] (P)
+    ...
+    4. Let value be ? O.[[Get]](P, O).
+    ...
+
+  9.4.6.7 [[Get]] (P, Receiver)
+    ...
+    12. Let targetEnvRec be targetEnv's EnvironmentRecord.
+    13. Return ? targetEnvRec.GetBindingValue(binding.[[BindingName]], true).
+
+  8.1.1.1.6 GetBindingValue ( N, S )
+    ...
+    If the binding for N in envRec is an uninitialized binding, throw a ReferenceError exception.
+    ...
+
+flags: [module]
+---*/
+
+import* as self from "./object-keys-binding-uninit.js";
+
+assert.throws(ReferenceError, function() {
+  Object.keys(self);
+});
+
+export default 0;
diff --git a/test/language/module-code/namespace/internals/object-propertyIsEnumerable-binding-uninit.js b/test/language/module-code/namespace/internals/object-propertyIsEnumerable-binding-uninit.js
new file mode 100644
index 0000000000..285a6c9af2
--- /dev/null
+++ b/test/language/module-code/namespace/internals/object-propertyIsEnumerable-binding-uninit.js
@@ -0,0 +1,38 @@
+// Copyright (C) 2017 André Bargull. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+id: sec-object.prototype.propertyisenumerable
+info: >
+  Test Object.prototype.propertyIsEnumerable() with uninitialized binding.
+description: |
+  19.1.3.4 Object.prototype.propertyIsEnumerable ( V )
+    ...
+    3. Let desc be ? O.[[GetOwnProperty]](P).
+    ...
+
+  9.4.6.4 [[GetOwnProperty]] (P)
+    ...
+    4. Let value be ? O.[[Get]](P, O).
+    ...
+
+  9.4.6.7 [[Get]] (P, Receiver)
+    ...
+    12. Let targetEnvRec be targetEnv's EnvironmentRecord.
+    13. Return ? targetEnvRec.GetBindingValue(binding.[[BindingName]], true).
+
+  8.1.1.1.6 GetBindingValue ( N, S )
+    ...
+    If the binding for N in envRec is an uninitialized binding, throw a ReferenceError exception.
+    ...
+
+flags: [module]
+---*/
+
+import* as self from "./object-propertyIsEnumerable-binding-uninit.js";
+
+assert.throws(ReferenceError, function() {
+  Object.prototype.propertyIsEnumerable.call(self, "default");
+});
+
+export default 0;
-- 
GitLab