Reviewers: adamk, rossberg,
Message:
PTAL
Description:
[es6] Object.getOwnPropertyDescriptor should wrap primitives
In ES6 Object.getOwnPropertyDescriptor should call ToObject, which
means that primitive values will return descriptors from the wrapper.
BUG=v8:3964
LOG=N
R=adamk, [email protected]
Please review this at https://codereview.chromium.org/998163004/
Base URL: https://chromium.googlesource.com/v8/v8.git@master
Affected files (+36, -6 lines):
M src/v8natives.js
A test/mjsunit/get-own-property-descriptor-non-objects.js
Index: src/v8natives.js
diff --git a/src/v8natives.js b/src/v8natives.js
index
4ba546b0fbca1765dd631af96f2c7ec0ef81759a..498667bfdb035e54d5bdffdd298fb7388c710eba
100644
--- a/src/v8natives.js
+++ b/src/v8natives.js
@@ -1000,13 +1000,9 @@ function ObjectSetPrototypeOf(obj, proto) {
}
-// ES5 section 15.2.3.3
+// ES6 section 19.1.2.6
function ObjectGetOwnPropertyDescriptor(obj, p) {
- if (!IS_SPEC_OBJECT(obj)) {
- throw MakeTypeError("called_on_non_object",
- ["Object.getOwnPropertyDescriptor"]);
- }
- var desc = GetOwnPropertyJS(obj, p);
+ var desc = GetOwnPropertyJS(TO_OBJECT_INLINE(obj), p);
return FromPropertyDescriptor(desc);
}
Index: test/mjsunit/get-own-property-descriptor-non-objects.js
diff --git a/test/mjsunit/get-own-property-descriptor-non-objects.js
b/test/mjsunit/get-own-property-descriptor-non-objects.js
new file mode 100644
index
0000000000000000000000000000000000000000..ee8bf44ded98dc8bb2bcc13a8dc7f4c561b2111c
--- /dev/null
+++ b/test/mjsunit/get-own-property-descriptor-non-objects.js
@@ -0,0 +1,34 @@
+// Copyright 2015 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.
+
+assertThrows(function() {
+ Object.getOwnPropertyDescriptor(null, 'x');
+}, TypeError);
+
+
+assertThrows(function() {
+ Object.getOwnPropertyDescriptor(undefined, 'x');
+}, TypeError);
+
+
+assertEquals({
+ configurable: false,
+ enumerable: false,
+ value: 3,
+ writable: false,
+}, Object.getOwnPropertyDescriptor('abc', 'length'));
+
+
+assertEquals({
+ configurable: false,
+ enumerable: true,
+ value: 'a',
+ writable: false,
+}, Object.getOwnPropertyDescriptor('abc', 0));
+
+
+assertSame(undefined, Object.getOwnPropertyDescriptor(42, 'x'));
+assertSame(undefined, Object.getOwnPropertyDescriptor(true, 'x'));
+assertSame(undefined, Object.getOwnPropertyDescriptor(false, 'x'));
+assertSame(undefined, Object.getOwnPropertyDescriptor(Symbol(), 'x'));
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.