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

Unified Diff: src/builtins/builtins-spread.cc

Issue 2465253011: Fastpath some spread-call desugaring. (Closed)
Patch Set: Don't install spread on global obj Created 4 years, 1 month 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/builtins/builtins-spread.cc
diff --git a/src/builtins/builtins-spread.cc b/src/builtins/builtins-spread.cc
new file mode 100644
index 0000000000000000000000000000000000000000..87a55ba1a40960d2a2d856299632242bc71f6f0a
--- /dev/null
+++ b/src/builtins/builtins-spread.cc
@@ -0,0 +1,49 @@
+// Copyright 2016 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.
+
+#include "src/builtins/builtins-utils.h"
+#include "src/builtins/builtins.h"
+
+namespace v8 {
+namespace internal {
+
+BUILTIN(SpreadIterablePrepare) {
+ HandleScope scope(isolate);
+ DCHECK_EQ(2, args.length());
+ Handle<Object> spread = args.at<Object>(1);
+
+ if (spread->IsJSArray()) {
+ // Check that the spread arg has fast elements
+ Handle<JSArray> spread_array = Handle<JSArray>::cast(spread);
+ ElementsKind array_kind = spread_array->GetElementsKind();
+
+ if (IsFastElementsKind(array_kind)) {
+ // Check that the iterator hasn't been touched
+ Handle<Object> iterator_func;
+ Handle<Name> it_name = isolate->factory()->iterator_symbol();
+
+ if (Object::GetProperty(spread, it_name).ToHandle(&iterator_func)) {
Yang 2016/11/08 14:08:41 Does this violate the spec? GetProperty may be obs
petermarshall 2016/11/10 12:19:20 Yeah it does violate the spec. I added a test case
+ JSObject* default_iterator =
+ isolate->native_context()->initial_array_iterator();
+
+ if (*iterator_func == default_iterator) {
+ return *spread;
+ }
+ }
+ }
+ }
+
+ Handle<JSFunction> spread_iterable_function = isolate->spread_iterable();
+
+ Handle<Object> spreaded;
+ ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
+ isolate, spreaded,
+ Execution::Call(isolate, spread_iterable_function,
+ isolate->factory()->undefined_value(), 1, &spread));
+
+ return *spreaded;
+}
+
+} // namespace internal
+} // namespace v8
« src/bootstrapper.cc ('K') | « src/builtins/builtins.h ('k') | src/contexts.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698