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

Side by Side Diff: src/builtins.cc

Issue 348313002: Introduce a PrototypeIterator template and use it all over the place (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: rebase Created 6 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « src/api.cc ('k') | src/deoptimizer.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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/api.h" 7 #include "src/api.h"
8 #include "src/arguments.h" 8 #include "src/arguments.h"
9 #include "src/base/once.h" 9 #include "src/base/once.h"
10 #include "src/bootstrapper.h" 10 #include "src/bootstrapper.h"
11 #include "src/builtins.h" 11 #include "src/builtins.h"
12 #include "src/cpu-profiler.h" 12 #include "src/cpu-profiler.h"
13 #include "src/gdb-jit.h" 13 #include "src/gdb-jit.h"
14 #include "src/heap-profiler.h" 14 #include "src/heap-profiler.h"
15 #include "src/ic-inl.h" 15 #include "src/ic-inl.h"
16 #include "src/mark-compact.h" 16 #include "src/mark-compact.h"
17 #include "src/prototype-iterator.h"
17 #include "src/stub-cache.h" 18 #include "src/stub-cache.h"
18 #include "src/vm-state-inl.h" 19 #include "src/vm-state-inl.h"
19 20
20 namespace v8 { 21 namespace v8 {
21 namespace internal { 22 namespace internal {
22 23
23 namespace { 24 namespace {
24 25
25 // Arguments object passed to C++ builtins. 26 // Arguments object passed to C++ builtins.
26 template <BuiltinExtraArguments extra_args> 27 template <BuiltinExtraArguments extra_args>
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 247
247 248
248 static bool ArrayPrototypeHasNoElements(Heap* heap, 249 static bool ArrayPrototypeHasNoElements(Heap* heap,
249 Context* native_context, 250 Context* native_context,
250 JSObject* array_proto) { 251 JSObject* array_proto) {
251 DisallowHeapAllocation no_gc; 252 DisallowHeapAllocation no_gc;
252 // This method depends on non writability of Object and Array prototype 253 // This method depends on non writability of Object and Array prototype
253 // fields. 254 // fields.
254 if (array_proto->elements() != heap->empty_fixed_array()) return false; 255 if (array_proto->elements() != heap->empty_fixed_array()) return false;
255 // Object.prototype 256 // Object.prototype
256 Object* proto = array_proto->GetPrototype(); 257 Object* proto = SAFE_GET_PROTOTYPE_FAST(array_proto);
257 if (proto == heap->null_value()) return false; 258 if (proto == heap->null_value()) return false;
258 array_proto = JSObject::cast(proto); 259 array_proto = JSObject::cast(proto);
259 if (array_proto != native_context->initial_object_prototype()) return false; 260 if (array_proto != native_context->initial_object_prototype()) return false;
260 if (array_proto->elements() != heap->empty_fixed_array()) return false; 261 if (array_proto->elements() != heap->empty_fixed_array()) return false;
261 return array_proto->GetPrototype()->IsNull(); 262 return SAFE_GET_PROTOTYPE_FAST(array_proto)->IsNull();
262 } 263 }
263 264
264 265
265 // Returns empty handle if not applicable. 266 // Returns empty handle if not applicable.
266 MUST_USE_RESULT 267 MUST_USE_RESULT
267 static inline MaybeHandle<FixedArrayBase> EnsureJSArrayWithWritableFastElements( 268 static inline MaybeHandle<FixedArrayBase> EnsureJSArrayWithWritableFastElements(
268 Isolate* isolate, 269 Isolate* isolate,
269 Handle<Object> receiver, 270 Handle<Object> receiver,
270 Arguments* args, 271 Arguments* args,
271 int first_added_arg) { 272 int first_added_arg) {
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 } 325 }
325 326
326 327
327 static inline bool IsJSArrayFastElementMovingAllowed(Heap* heap, 328 static inline bool IsJSArrayFastElementMovingAllowed(Heap* heap,
328 JSArray* receiver) { 329 JSArray* receiver) {
329 if (!FLAG_clever_optimizations) return false; 330 if (!FLAG_clever_optimizations) return false;
330 DisallowHeapAllocation no_gc; 331 DisallowHeapAllocation no_gc;
331 Context* native_context = heap->isolate()->context()->native_context(); 332 Context* native_context = heap->isolate()->context()->native_context();
332 JSObject* array_proto = 333 JSObject* array_proto =
333 JSObject::cast(native_context->array_function()->prototype()); 334 JSObject::cast(native_context->array_function()->prototype());
334 return receiver->GetPrototype() == array_proto && 335 return SAFE_GET_PROTOTYPE_FAST(receiver) == array_proto &&
335 ArrayPrototypeHasNoElements(heap, native_context, array_proto); 336 ArrayPrototypeHasNoElements(heap, native_context, array_proto);
336 } 337 }
337 338
338 339
339 MUST_USE_RESULT static Object* CallJsBuiltin( 340 MUST_USE_RESULT static Object* CallJsBuiltin(
340 Isolate* isolate, 341 Isolate* isolate,
341 const char* name, 342 const char* name,
342 BuiltinArguments<NO_EXTRA_ARGUMENTS> args) { 343 BuiltinArguments<NO_EXTRA_ARGUMENTS> args) {
343 HandleScope handleScope(isolate); 344 HandleScope handleScope(isolate);
344 345
(...skipping 649 matching lines...) Expand 10 before | Expand all | Expand 10 after
994 return CallJsBuiltin(isolate, "ArrayConcatJS", args); 995 return CallJsBuiltin(isolate, "ArrayConcatJS", args);
995 } 996 }
996 997
997 // Iterate through all the arguments performing checks 998 // Iterate through all the arguments performing checks
998 // and calculating total length. 999 // and calculating total length.
999 bool is_holey = false; 1000 bool is_holey = false;
1000 for (int i = 0; i < n_arguments; i++) { 1001 for (int i = 0; i < n_arguments; i++) {
1001 Object* arg = args[i]; 1002 Object* arg = args[i];
1002 if (!arg->IsJSArray() || 1003 if (!arg->IsJSArray() ||
1003 !JSArray::cast(arg)->HasFastElements() || 1004 !JSArray::cast(arg)->HasFastElements() ||
1004 JSArray::cast(arg)->GetPrototype() != array_proto) { 1005 SAFE_GET_PROTOTYPE_FAST(JSArray::cast(arg)) != array_proto) {
1005 AllowHeapAllocation allow_allocation; 1006 AllowHeapAllocation allow_allocation;
1006 return CallJsBuiltin(isolate, "ArrayConcatJS", args); 1007 return CallJsBuiltin(isolate, "ArrayConcatJS", args);
1007 } 1008 }
1008 int len = Smi::cast(JSArray::cast(arg)->length())->value(); 1009 int len = Smi::cast(JSArray::cast(arg)->length())->value();
1009 1010
1010 // We shouldn't overflow when adding another len. 1011 // We shouldn't overflow when adding another len.
1011 const int kHalfOfMaxInt = 1 << (kBitsPerInt - 2); 1012 const int kHalfOfMaxInt = 1 << (kBitsPerInt - 2);
1012 STATIC_ASSERT(FixedArray::kMaxLength < kHalfOfMaxInt); 1013 STATIC_ASSERT(FixedArray::kMaxLength < kHalfOfMaxInt);
1013 USE(kHalfOfMaxInt); 1014 USE(kHalfOfMaxInt);
1014 result_len += len; 1015 result_len += len;
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
1084 // ----------------------------------------------------------------------------- 1085 // -----------------------------------------------------------------------------
1085 // 1086 //
1086 1087
1087 1088
1088 // Searches the hidden prototype chain of the given object for the first 1089 // Searches the hidden prototype chain of the given object for the first
1089 // object that is an instance of the given type. If no such object can 1090 // object that is an instance of the given type. If no such object can
1090 // be found then Heap::null_value() is returned. 1091 // be found then Heap::null_value() is returned.
1091 static inline Object* FindHidden(Heap* heap, 1092 static inline Object* FindHidden(Heap* heap,
1092 Object* object, 1093 Object* object,
1093 FunctionTemplateInfo* type) { 1094 FunctionTemplateInfo* type) {
1094 if (type->IsTemplateFor(object)) return object; 1095 for (PrototypeIterator<STORE_AS_POINTER, TYPE_BASED_WALK, END_AT_NON_HIDDEN>
1095 Object* proto = object->GetPrototype(heap->isolate()); 1096 iter(heap->isolate(), object); !iter.IsAtEnd(); iter.Advance()) {
1096 if (proto->IsJSObject() && 1097 if (type->IsTemplateFor(iter.GetCurrent())) return iter.GetCurrent();
1097 JSObject::cast(proto)->map()->is_hidden_prototype()) {
1098 return FindHidden(heap, proto, type);
1099 } 1098 }
1100 return heap->null_value(); 1099 return heap->null_value();
1101 } 1100 }
1102 1101
1103 1102
1104 // Returns the holder JSObject if the function can legally be called 1103 // Returns the holder JSObject if the function can legally be called
1105 // with this receiver. Returns Heap::null_value() if the call is 1104 // with this receiver. Returns Heap::null_value() if the call is
1106 // illegal. Any arguments that don't fit the expected type is 1105 // illegal. Any arguments that don't fit the expected type is
1107 // overwritten with undefined. Note that holder and the arguments are 1106 // overwritten with undefined. Note that holder and the arguments are
1108 // implicitly rewritten with the first object in the hidden prototype 1107 // implicitly rewritten with the first object in the hidden prototype
(...skipping 604 matching lines...) Expand 10 before | Expand all | Expand 10 after
1713 } 1712 }
1714 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) 1713 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C)
1715 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) 1714 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A)
1716 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) 1715 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H)
1717 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) 1716 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A)
1718 #undef DEFINE_BUILTIN_ACCESSOR_C 1717 #undef DEFINE_BUILTIN_ACCESSOR_C
1719 #undef DEFINE_BUILTIN_ACCESSOR_A 1718 #undef DEFINE_BUILTIN_ACCESSOR_A
1720 1719
1721 1720
1722 } } // namespace v8::internal 1721 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/api.cc ('k') | src/deoptimizer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698