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

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

Issue 1162833006: [for-in] Make ForInNext and ForInFilter deal properly with exceptions. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 6 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 | « no previous file | no next file » | 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/arguments.h" 5 #include "src/arguments.h"
6 #include "src/runtime/runtime-utils.h" 6 #include "src/runtime/runtime-utils.h"
7 #include "src/v8.h" 7 #include "src/v8.h"
8 8
9 namespace v8 { 9 namespace v8 {
10 namespace internal { 10 namespace internal {
11 11
12 RUNTIME_FUNCTION(Runtime_ForInDone) { 12 RUNTIME_FUNCTION(Runtime_ForInDone) {
13 SealHandleScope scope(isolate); 13 SealHandleScope scope(isolate);
14 DCHECK_EQ(2, args.length()); 14 DCHECK_EQ(2, args.length());
15 CONVERT_SMI_ARG_CHECKED(index, 0); 15 CONVERT_SMI_ARG_CHECKED(index, 0);
16 CONVERT_SMI_ARG_CHECKED(length, 1); 16 CONVERT_SMI_ARG_CHECKED(length, 1);
17 DCHECK_LE(0, index); 17 DCHECK_LE(0, index);
18 DCHECK_LE(index, length); 18 DCHECK_LE(index, length);
19 return isolate->heap()->ToBoolean(index == length); 19 return isolate->heap()->ToBoolean(index == length);
20 } 20 }
21 21
22 22
23 RUNTIME_FUNCTION(Runtime_ForInFilter) { 23 RUNTIME_FUNCTION(Runtime_ForInFilter) {
24 HandleScope scope(isolate); 24 HandleScope scope(isolate);
25 DCHECK_EQ(2, args.length()); 25 DCHECK_EQ(2, args.length());
26 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, receiver, 0); 26 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, receiver, 0);
27 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1); 27 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1);
28 // TODO(turbofan): Fast case for array indices. 28 // TODO(turbofan): Fast case for array indices.
29 Handle<Name> name = Runtime::ToName(isolate, key).ToHandleChecked(); 29 Handle<Name> name;
30 if (!Runtime::ToName(isolate, key).ToHandle(&name)) {
31 return isolate->heap()->exception();
32 }
30 Maybe<bool> result = JSReceiver::HasProperty(receiver, name); 33 Maybe<bool> result = JSReceiver::HasProperty(receiver, name);
31 if (result.IsJust() && result.FromJust()) return *name; 34 if (!result.IsJust()) return isolate->heap()->exception();
35 if (result.FromJust()) return *name;
32 return isolate->heap()->undefined_value(); 36 return isolate->heap()->undefined_value();
33 } 37 }
34 38
35 39
36 RUNTIME_FUNCTION(Runtime_ForInNext) { 40 RUNTIME_FUNCTION(Runtime_ForInNext) {
37 HandleScope scope(isolate); 41 HandleScope scope(isolate);
38 DCHECK_EQ(4, args.length()); 42 DCHECK_EQ(4, args.length());
39 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, receiver, 0); 43 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, receiver, 0);
40 CONVERT_ARG_HANDLE_CHECKED(FixedArray, cache_array, 1); 44 CONVERT_ARG_HANDLE_CHECKED(FixedArray, cache_array, 1);
41 CONVERT_ARG_HANDLE_CHECKED(Object, cache_type, 2); 45 CONVERT_ARG_HANDLE_CHECKED(Object, cache_type, 2);
42 CONVERT_SMI_ARG_CHECKED(index, 3); 46 CONVERT_SMI_ARG_CHECKED(index, 3);
43 Handle<Object> key = handle(cache_array->get(index), isolate); 47 Handle<Object> key = handle(cache_array->get(index), isolate);
44 // Don't need filtering if expected map still matches that of the receiver, 48 // Don't need filtering if expected map still matches that of the receiver,
45 // and neither for proxies. 49 // and neither for proxies.
46 if (receiver->map() == *cache_type || *cache_type == Smi::FromInt(0)) { 50 if (receiver->map() == *cache_type || *cache_type == Smi::FromInt(0)) {
47 return *key; 51 return *key;
48 } 52 }
49 // TODO(turbofan): Fast case for array indices. 53 // TODO(turbofan): Fast case for array indices.
50 Handle<Name> name = Runtime::ToName(isolate, key).ToHandleChecked(); 54 Handle<Name> name;
55 if (!Runtime::ToName(isolate, key).ToHandle(&name)) {
56 return isolate->heap()->exception();
57 }
51 Maybe<bool> result = JSReceiver::HasProperty(receiver, name); 58 Maybe<bool> result = JSReceiver::HasProperty(receiver, name);
52 if (result.IsJust() && result.FromJust()) return *name; 59 if (!result.IsJust()) return isolate->heap()->exception();
60 if (result.FromJust()) return *name;
53 return isolate->heap()->undefined_value(); 61 return isolate->heap()->undefined_value();
54 } 62 }
55 63
56 64
57 RUNTIME_FUNCTION(Runtime_ForInStep) { 65 RUNTIME_FUNCTION(Runtime_ForInStep) {
58 SealHandleScope scope(isolate); 66 SealHandleScope scope(isolate);
59 DCHECK_EQ(1, args.length()); 67 DCHECK_EQ(1, args.length());
60 CONVERT_SMI_ARG_CHECKED(index, 0); 68 CONVERT_SMI_ARG_CHECKED(index, 0);
61 DCHECK_LE(0, index); 69 DCHECK_LE(0, index);
62 DCHECK_LT(index, Smi::kMaxValue); 70 DCHECK_LT(index, Smi::kMaxValue);
63 return Smi::FromInt(index + 1); 71 return Smi::FromInt(index + 1);
64 } 72 }
65 73
66 } // namespace internal 74 } // namespace internal
67 } // namespace v8 75 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698