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

Side by Side Diff: src/runtime/runtime-forin.cc

Issue 1576093004: [Interpreter] Add ForInPrepare runtime function which returns a ObjectTriple. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Add MIPS port Created 4 years, 11 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 unified diff | Download patch
« no previous file with comments | « src/runtime/runtime.cc ('k') | src/runtime/runtime-interpreter.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/runtime/runtime-utils.h" 5 #include "src/runtime/runtime-utils.h"
6 6
7 #include "src/arguments.h" 7 #include "src/arguments.h"
8 #include "src/factory.h"
9 #include "src/isolate-inl.h"
8 #include "src/objects-inl.h" 10 #include "src/objects-inl.h"
9 11
10 namespace v8 { 12 namespace v8 {
11 namespace internal { 13 namespace internal {
12 14
15 RUNTIME_FUNCTION_RETURN_TRIPLE(Runtime_ForInPrepare) {
16 HandleScope scope(isolate);
17 DCHECK_EQ(1, args.length());
18
19 if (!args[0]->IsJSReceiver()) {
20 return MakeTriple(isolate->ThrowIllegalOperation(), nullptr, nullptr);
21 }
22 Handle<JSReceiver> receiver = args.at<JSReceiver>(0);
23
24 Object* property_names = Runtime_GetPropertyNamesFast(
25 1, Handle<Object>::cast(receiver).location(), isolate);
26 if (isolate->has_pending_exception()) {
27 return MakeTriple(property_names, nullptr, nullptr);
28 }
29
30 Handle<Object> cache_type(property_names, isolate);
31 Handle<FixedArray> cache_array;
32 int cache_length;
33
34 Handle<Map> receiver_map = handle(receiver->map(), isolate);
35 if (cache_type->IsMap()) {
36 Handle<Map> cache_type_map =
37 handle(Handle<Map>::cast(cache_type)->map(), isolate);
38 DCHECK(cache_type_map.is_identical_to(isolate->factory()->meta_map()));
39 int enum_length = cache_type_map->EnumLength();
40 DescriptorArray* descriptors = receiver_map->instance_descriptors();
41 if (enum_length > 0 && descriptors->HasEnumCache()) {
42 cache_array = handle(descriptors->GetEnumCache(), isolate);
43 cache_length = cache_array->length();
44 } else {
45 cache_array = isolate->factory()->empty_fixed_array();
46 cache_length = 0;
47 }
48 } else {
49 cache_array = Handle<FixedArray>::cast(cache_type);
50 cache_length = cache_array->length();
51 // Cache type of SMI one entails slow check.
52 cache_type = Handle<Object>(Smi::FromInt(1), isolate);
53 }
54
55 return MakeTriple(*cache_type, *cache_array, Smi::FromInt(cache_length));
56 }
57
58
13 RUNTIME_FUNCTION(Runtime_ForInDone) { 59 RUNTIME_FUNCTION(Runtime_ForInDone) {
14 SealHandleScope scope(isolate); 60 SealHandleScope scope(isolate);
15 DCHECK_EQ(2, args.length()); 61 DCHECK_EQ(2, args.length());
16 CONVERT_SMI_ARG_CHECKED(index, 0); 62 CONVERT_SMI_ARG_CHECKED(index, 0);
17 CONVERT_SMI_ARG_CHECKED(length, 1); 63 CONVERT_SMI_ARG_CHECKED(length, 1);
18 DCHECK_LE(0, index); 64 DCHECK_LE(0, index);
19 DCHECK_LE(index, length); 65 DCHECK_LE(index, length);
20 return isolate->heap()->ToBoolean(index == length); 66 return isolate->heap()->ToBoolean(index == length);
21 } 67 }
22 68
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 SealHandleScope scope(isolate); 113 SealHandleScope scope(isolate);
68 DCHECK_EQ(1, args.length()); 114 DCHECK_EQ(1, args.length());
69 CONVERT_SMI_ARG_CHECKED(index, 0); 115 CONVERT_SMI_ARG_CHECKED(index, 0);
70 DCHECK_LE(0, index); 116 DCHECK_LE(0, index);
71 DCHECK_LT(index, Smi::kMaxValue); 117 DCHECK_LT(index, Smi::kMaxValue);
72 return Smi::FromInt(index + 1); 118 return Smi::FromInt(index + 1);
73 } 119 }
74 120
75 } // namespace internal 121 } // namespace internal
76 } // namespace v8 122 } // namespace v8
OLDNEW
« no previous file with comments | « src/runtime/runtime.cc ('k') | src/runtime/runtime-interpreter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698