From 2fd8a7f6b87a33d5c753dc4464f101b0352d3235 Mon Sep 17 00:00:00 2001 From: "dslomov@chromium.org" Date: Thu, 9 Oct 2014 13:19:02 +0000 Subject: [PATCH] Convert `obj` ToObject in Object.keys() BUG=v8:3587 LOG=Y R=arv@chromium.org, dslomov@chromium.org Review URL: https://codereview.chromium.org/585373003 Patch from Caitlin Potter . git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@24495 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- AUTHORS | 1 + src/v8natives.js | 4 +--- test/mjsunit/third_party/object-keys.js | 4 ++-- test/test262/test262.status | 6 ++++++ 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/AUTHORS b/AUTHORS index bb14936ea..d406a6c23 100644 --- a/AUTHORS +++ b/AUTHORS @@ -27,6 +27,7 @@ Andreas Anyuru Baptiste Afsa Bert Belder Burcu Dogan +Caitlin Potter Craig Schlenter Chunyang Dai Daniel Andersson diff --git a/src/v8natives.js b/src/v8natives.js index 5adbca25b..1d2e03000 100644 --- a/src/v8natives.js +++ b/src/v8natives.js @@ -325,9 +325,7 @@ function ObjectLookupSetter(name) { function ObjectKeys(obj) { - if (!IS_SPEC_OBJECT(obj)) { - throw MakeTypeError("called_on_non_object", ["Object.keys"]); - } + obj = ToObject(obj); if (%IsJSProxy(obj)) { var handler = %GetHandler(obj); var names = CallTrap0(handler, "keys", DerivedKeysTrap); diff --git a/test/mjsunit/third_party/object-keys.js b/test/mjsunit/third_party/object-keys.js index d09265c6f..c8003745c 100644 --- a/test/mjsunit/third_party/object-keys.js +++ b/test/mjsunit/third_party/object-keys.js @@ -31,8 +31,8 @@ // Based on LayoutTests/fast/js/Object-keys.html -assertThrows(function () { Object.keys(2) }, TypeError); -assertThrows(function () { Object.keys("foo") }, TypeError); +assertEquals(Object.keys(2), []); +assertEquals(Object.keys("foo"), ["0", "1", "2"]); assertThrows(function () { Object.keys(null) }, TypeError); assertThrows(function () { Object.keys(undefined) }, TypeError); diff --git a/test/test262/test262.status b/test/test262/test262.status index 86663130a..8dd90f5a8 100644 --- a/test/test262/test262.status +++ b/test/test262/test262.status @@ -87,6 +87,12 @@ 'S15.9.3.1_A5_T5': [PASS, FAIL_OK], 'S15.9.3.1_A5_T6': [PASS, FAIL_OK], + # ObjectKeys() no longer throws TypeError when passed a primitive value which + # is not null or undefined (per ES6). + '15.2.3.14-1-1': [SKIP], + '15.2.3.14-1-2': [SKIP], + '15.2.3.14-1-3': [SKIP], + ############################ SKIPPED TESTS ############################# # These tests take a looong time to run in debug mode. -- 2.34.1