Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(335)

Unified Diff: src/harmony-object.js

Issue 548833002: [es6] implement Object.assign (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Rebased again Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/harmony-object.js
diff --git a/src/harmony-object.js b/src/harmony-object.js
new file mode 100644
index 0000000000000000000000000000000000000000..74a7e2c81eb68028daa90870567e3d23e6e4b305
--- /dev/null
+++ b/src/harmony-object.js
@@ -0,0 +1,45 @@
+// Copyright 2014 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.
+//
+
+'use strict';
+
+// ES6, draft 10-14-14, section 19.1.2.1
+function ObjectAssign(target, sources) {
+ var to = ToObject(target);
+ var argsLen = %_ArgumentsLength();
+ if (argsLen < 2) return to;
+
+ for (var i = 1; i < argsLen; ++i) {
+ var nextSource = %_Arguments(i);
+ if (IS_NULL_OR_UNDEFINED(nextSource)) {
+ continue;
+ }
+
+ var from = ToObject(nextSource);
+ var keys = ObjectGetOwnPropertyKeys(from);
arv (Not doing code reviews) 2015/04/03 21:15:09 ObjectGetOwnPropertyKeys takes 2 params
arv (Not doing code reviews) 2015/04/03 21:15:09 This will not include proxies. Maybe call a higher
caitp (gmail) 2015/04/03 21:28:41 The filter is optional-ish, but will do On 2015/0
arv (Not doing code reviews) 2015/04/03 21:43:02 Yes, but it adds an adapter frame for no good reas
+ var len = keys.length;
+
+ for (var j = 0; j < len; ++j) {
+ var key = keys[j];
+ if (%_CallFunction(from, key, ObjectPropertyIsEnumerable)) {
+ var propValue = from[key];
+ to[key] = propValue;
+ }
+ }
+ }
+ return to;
+}
+
+
+function HarmonyObjectExtendObjectPrototype() {
+ %CheckIsBootstrapping();
+
+ // Set up non-enumerable functions on the Object object.
+ InstallFunctions($Object, DONT_ENUM, $Array(
+ "assign", ObjectAssign
+ ));
+}
+
+HarmonyObjectExtendObjectPrototype();

Powered by Google App Engine
This is Rietveld 408576698