WebKit Bugzilla
Attachment 346967 Details for
Bug 188481
: Implement Object.fromEntries
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch
bug-188481-20180812045516.patch (text/plain), 10.93 KB, created by
Yusuke Suzuki
on 2018-08-11 12:55:17 PDT
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Yusuke Suzuki
Created:
2018-08-11 12:55:17 PDT
Size:
10.93 KB
patch
obsolete
>Subversion Revision: 234783 >diff --git a/Source/JavaScriptCore/ChangeLog b/Source/JavaScriptCore/ChangeLog >index 812ab3ef9b09f5797542dfc9e81527c4e05a8a19..663d9cc305b1d6b61cc7d858178d821e6584b537 100644 >--- a/Source/JavaScriptCore/ChangeLog >+++ b/Source/JavaScriptCore/ChangeLog >@@ -1,3 +1,18 @@ >+2018-08-11 Yusuke Suzuki <yusukesuzuki@slowstart.org> >+ >+ Implement Object.fromEntries >+ https://bugs.webkit.org/show_bug.cgi?id=188481 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ Object.fromEntries becomes stage 3[1]. This patch implements it by using builtin JS. >+ >+ [1]: https://tc39.github.io/proposal-object-from-entries/ >+ >+ * builtins/ObjectConstructor.js: >+ (fromEntries): >+ * runtime/ObjectConstructor.cpp: >+ > 2018-08-10 Joseph Pecoraro <pecoraro@apple.com> > > Web Inspector: console.log fires getters for deep properties >diff --git a/Source/JavaScriptCore/builtins/ObjectConstructor.js b/Source/JavaScriptCore/builtins/ObjectConstructor.js >index ada0eca2b4180b1f5229c82d0165b50851eb7a8b..c9d52f8cf01091650c43eb9ab486ff081720fea0 100644 >--- a/Source/JavaScriptCore/builtins/ObjectConstructor.js >+++ b/Source/JavaScriptCore/builtins/ObjectConstructor.js >@@ -1,6 +1,7 @@ > /* > * Copyright (C) 2016 Oleksandr Skachkov <gskachkov@gmail.com>. > * Copyright (C) 2015 Jordan Harband. All rights reserved. >+ * Copyright (C) 2018 Yusuke Suzuki <yusukesuzuki@slowstart.org>. > * > * Redistribution and use in source and binary forms, with or without > * modification, are permitted provided that the following conditions >@@ -39,3 +40,20 @@ function entries(object) > > return properties; > } >+ >+function fromEntries(iterable) >+{ >+ "use strict"; >+ >+ var object = {}; >+ >+ for (var entry of iterable) { >+ if (!@isObject(entry)) >+ @throwTypeError("Object.fromEntries requires the first iterable parameter yields objects"); >+ var key = entry[0]; >+ var value = entry[1]; >+ @putByValDirect(object, key, value); >+ } >+ >+ return object; >+} >diff --git a/Source/JavaScriptCore/runtime/ObjectConstructor.cpp b/Source/JavaScriptCore/runtime/ObjectConstructor.cpp >index b3a29646e06fc51fddecfd91d25d2cf72bd714c2..3f9f81c34fd296ce27bfbd70c197eba08290be03 100644 >--- a/Source/JavaScriptCore/runtime/ObjectConstructor.cpp >+++ b/Source/JavaScriptCore/runtime/ObjectConstructor.cpp >@@ -87,6 +87,7 @@ const ClassInfo ObjectConstructor::s_info = { "Function", &InternalFunction::s_i > assign objectConstructorAssign DontEnum|Function 2 > values objectConstructorValues DontEnum|Function 1 > entries JSBuiltin DontEnum|Function 1 >+ fromEntries JSBuiltin DontEnum|Function 1 > @end > */ > >diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog >index d4e6fed9d05b1dc08d9f88b9ca8467ee2aada5fd..712de164581ab46ecce8b6f6e37cb820de783e6e 100644 >--- a/LayoutTests/ChangeLog >+++ b/LayoutTests/ChangeLog >@@ -1,3 +1,13 @@ >+2018-08-11 Yusuke Suzuki <yusukesuzuki@slowstart.org> >+ >+ Implement Object.fromEntries >+ https://bugs.webkit.org/show_bug.cgi?id=188481 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ * js/Object-getOwnPropertyNames-expected.txt: >+ * js/script-tests/Object-getOwnPropertyNames.js: >+ > 2018-08-10 Joseph Pecoraro <pecoraro@apple.com> > > Web Inspector: console.log fires getters for deep properties >diff --git a/LayoutTests/js/Object-getOwnPropertyNames-expected.txt b/LayoutTests/js/Object-getOwnPropertyNames-expected.txt >index 99c039a25f0d495fde69ec2a6424ed6de9914549..565258e04361365f4145e863aa496a97d1fab3b7 100644 >--- a/LayoutTests/js/Object-getOwnPropertyNames-expected.txt >+++ b/LayoutTests/js/Object-getOwnPropertyNames-expected.txt >@@ -42,7 +42,7 @@ PASS getSortedOwnPropertyNames(decodeURI) is ['length', 'name'] > PASS getSortedOwnPropertyNames(decodeURIComponent) is ['length', 'name'] > PASS getSortedOwnPropertyNames(encodeURI) is ['length', 'name'] > PASS getSortedOwnPropertyNames(encodeURIComponent) is ['length', 'name'] >-PASS getSortedOwnPropertyNames(Object) is ['assign', 'create', 'defineProperties', 'defineProperty', 'entries', 'freeze', 'getOwnPropertyDescriptor', 'getOwnPropertyDescriptors', 'getOwnPropertyNames', 'getOwnPropertySymbols', 'getPrototypeOf', 'is', 'isExtensible', 'isFrozen', 'isSealed', 'keys', 'length', 'name', 'preventExtensions', 'prototype', 'seal', 'setPrototypeOf', 'values'] >+PASS getSortedOwnPropertyNames(Object) is ['assign', 'create', 'defineProperties', 'defineProperty', 'entries', 'freeze', 'fromEntries', 'getOwnPropertyDescriptor', 'getOwnPropertyDescriptors', 'getOwnPropertyNames', 'getOwnPropertySymbols', 'getPrototypeOf', 'is', 'isExtensible', 'isFrozen', 'isSealed', 'keys', 'length', 'name', 'preventExtensions', 'prototype', 'seal', 'setPrototypeOf', 'values'] > PASS getSortedOwnPropertyNames(Object.prototype) is ['__defineGetter__', '__defineSetter__', '__lookupGetter__', '__lookupSetter__', '__proto__', 'constructor', 'hasOwnProperty', 'isPrototypeOf', 'propertyIsEnumerable', 'toLocaleString', 'toString', 'valueOf'] > PASS getSortedOwnPropertyNames(Function) is ['length', 'name', 'prototype'] > PASS getSortedOwnPropertyNames(Function.prototype) is ['apply', 'arguments', 'bind', 'call', 'caller', 'constructor', 'length', 'name', 'toString'] >diff --git a/LayoutTests/js/script-tests/Object-getOwnPropertyNames.js b/LayoutTests/js/script-tests/Object-getOwnPropertyNames.js >index 7e1ab5a7329438ae0bc3932c785728a071f2a638..32a38c3c51cfd8a54aeef2bd8f4f0786912fe6e0 100644 >--- a/LayoutTests/js/script-tests/Object-getOwnPropertyNames.js >+++ b/LayoutTests/js/script-tests/Object-getOwnPropertyNames.js >@@ -51,7 +51,7 @@ > "encodeURI": "['length', 'name']", > "encodeURIComponent": "['length', 'name']", > // Built-in ECMA objects >- "Object": "['assign', 'create', 'defineProperties', 'defineProperty', 'entries', 'freeze', 'getOwnPropertyDescriptor', 'getOwnPropertyDescriptors', 'getOwnPropertyNames', 'getOwnPropertySymbols', 'getPrototypeOf', 'is', 'isExtensible', 'isFrozen', 'isSealed', 'keys', 'length', 'name', 'preventExtensions', 'prototype', 'seal', 'setPrototypeOf', 'values']", >+ "Object": "['assign', 'create', 'defineProperties', 'defineProperty', 'entries', 'freeze', 'fromEntries', 'getOwnPropertyDescriptor', 'getOwnPropertyDescriptors', 'getOwnPropertyNames', 'getOwnPropertySymbols', 'getPrototypeOf', 'is', 'isExtensible', 'isFrozen', 'isSealed', 'keys', 'length', 'name', 'preventExtensions', 'prototype', 'seal', 'setPrototypeOf', 'values']", > "Object.prototype": "['__defineGetter__', '__defineSetter__', '__lookupGetter__', '__lookupSetter__', '__proto__', 'constructor', 'hasOwnProperty', 'isPrototypeOf', 'propertyIsEnumerable', 'toLocaleString', 'toString', 'valueOf']", > "Function": "['length', 'name', 'prototype']", > "Function.prototype": "['apply', 'arguments', 'bind', 'call', 'caller', 'constructor', 'length', 'name', 'toString']", >diff --git a/JSTests/ChangeLog b/JSTests/ChangeLog >index 88c2011669330db42664a1b8de050562634e2f6f..d893f1a0607809143073f84265d5bd601109cb54 100644 >--- a/JSTests/ChangeLog >+++ b/JSTests/ChangeLog >@@ -1,3 +1,16 @@ >+2018-08-11 Yusuke Suzuki <yusukesuzuki@slowstart.org> >+ >+ Implement Object.fromEntries >+ https://bugs.webkit.org/show_bug.cgi?id=188481 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ * stress/object-from-entries.js: Added. >+ (shouldBe): >+ (shouldThrow): >+ (shouldBe.JSON.stringify.Object.getOwnPropertyDescriptor): >+ (shouldBe.set get shouldThrow): >+ > 2018-08-10 Keith Miller <keith_miller@apple.com> > > Slicing an ArrayBuffer with a long number returns an ArrayBuffer with byteLength zero >diff --git a/JSTests/stress/object-from-entries.js b/JSTests/stress/object-from-entries.js >new file mode 100644 >index 0000000000000000000000000000000000000000..200fa5518183bc8e8d75450d57622381ca0ec3a5 >--- /dev/null >+++ b/JSTests/stress/object-from-entries.js >@@ -0,0 +1,76 @@ >+function shouldBe(actual, expected) { >+ if (actual !== expected) >+ throw new Error('bad value: ' + actual); >+} >+ >+function shouldThrow(func, errorMessage) { >+ var errorThrown = false; >+ var error = null; >+ try { >+ func(); >+ } catch (e) { >+ errorThrown = true; >+ error = e; >+ } >+ if (!errorThrown) >+ throw new Error('not thrown'); >+ if (String(error) !== errorMessage) >+ throw new Error(`bad error: ${String(error)}`); >+} >+ >+shouldBe(JSON.stringify(Object.getOwnPropertyDescriptor(Object, "fromEntries")), `{"writable":true,"enumerable":false,"configurable":true}`); >+shouldBe(Object.fromEntries.length, 1); >+ >+shouldThrow(() => Object.fromEntries(null), `TypeError: null is not an object`); >+shouldThrow(() => Object.fromEntries(undefined), `TypeError: undefined is not an object`); >+shouldThrow(() => Object.fromEntries(0), `TypeError: undefined is not a function`); >+shouldThrow(() => Object.fromEntries(true), `TypeError: undefined is not a function`); >+shouldThrow(() => Object.fromEntries(Symbol("Cocoa")), `TypeError: undefined is not a function`); >+shouldThrow(() => Object.fromEntries("Cocoa"), `TypeError: Object.fromEntries requires the first iterable parameter yields objects`); >+shouldThrow(() => Object.fromEntries([0]), `TypeError: Object.fromEntries requires the first iterable parameter yields objects`); >+shouldThrow(() => Object.fromEntries([["Cocoa", "Cappuccino"], 0]), `TypeError: Object.fromEntries requires the first iterable parameter yields objects`); >+ >+{ >+ let object = Object.fromEntries([]); >+ shouldBe(JSON.stringify(object), `{}`); >+} >+{ >+ let object = Object.fromEntries([["Cocoa", "Cappuccino"]]); >+ shouldBe(JSON.stringify(object), `{"Cocoa":"Cappuccino"}`); >+ shouldBe(JSON.stringify(Object.getOwnPropertyDescriptor(object, "Cocoa")), `{"value":"Cappuccino","writable":true,"enumerable":true,"configurable":true}`); >+} >+{ >+ let obj = { abc: 1, def: 2, ghij: 3 }; >+ let res = Object.fromEntries( >+ Object.entries(obj) >+ .filter(([ key, val ]) => key.length === 3) >+ .map(([ key, val ]) => [ key, val * 2 ]) >+ ); >+ shouldBe(JSON.stringify(res), `{"abc":2,"def":4}`); >+} >+{ >+ let map = new Map([ [ 'a', 1 ], [ 'b', 2 ], [ 'c', 3 ] ]); >+ let obj = Object.fromEntries(map); >+ shouldBe(JSON.stringify(obj), `{"a":1,"b":2,"c":3}`); >+} >+{ >+ let arr = [ { name: 'Alice', age: 40 }, { name: 'Bob', age: 36 } ]; >+ let obj = Object.fromEntries(arr.map(({ name, age }) => [ name, age ])); >+ shouldBe(JSON.stringify(obj), `{"Alice":40,"Bob":36}`); >+} >+{ >+ Object.defineProperty(Object.prototype, "bad", { >+ get() { throw new Error("out"); }, >+ set(v) { throw new Error("out"); } >+ }); >+ shouldThrow(() => { >+ let object = {}; >+ object.bad; >+ }, `Error: out`); >+ shouldThrow(() => { >+ let object = {}; >+ object.bad = 42; >+ }, `Error: out`); >+ let object = Object.fromEntries([["bad", "value"]]); >+ shouldBe(JSON.stringify(object), `{"bad":"value"}`); >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Flags:
darin
:
review+
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 188481
:
346964
|
346965
| 346967