| OLD | NEW |
| 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/builtins.h" | 5 #include "src/builtins.h" |
| 6 | 6 |
| 7 #include "src/api.h" | 7 #include "src/api.h" |
| 8 #include "src/api-natives.h" | 8 #include "src/api-natives.h" |
| 9 #include "src/arguments.h" | 9 #include "src/arguments.h" |
| 10 #include "src/base/once.h" | 10 #include "src/base/once.h" |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 PrototypeIterator iter(isolate, receiver); | 244 PrototypeIterator iter(isolate, receiver); |
| 245 return PrototypeHasNoElements(&iter); | 245 return PrototypeHasNoElements(&iter); |
| 246 } | 246 } |
| 247 | 247 |
| 248 | 248 |
| 249 // Returns empty handle if not applicable. | 249 // Returns empty handle if not applicable. |
| 250 MUST_USE_RESULT | 250 MUST_USE_RESULT |
| 251 inline MaybeHandle<FixedArrayBase> EnsureJSArrayWithWritableFastElements( | 251 inline MaybeHandle<FixedArrayBase> EnsureJSArrayWithWritableFastElements( |
| 252 Isolate* isolate, Handle<Object> receiver, Arguments* args, | 252 Isolate* isolate, Handle<Object> receiver, Arguments* args, |
| 253 int first_added_arg) { | 253 int first_added_arg) { |
| 254 // We explicitly add a HandleScope to avoid creating several copies of the |
| 255 // same handle which would otherwise cause issue when left-trimming later-on. |
| 256 HandleScope scope(isolate); |
| 254 if (!receiver->IsJSArray()) return MaybeHandle<FixedArrayBase>(); | 257 if (!receiver->IsJSArray()) return MaybeHandle<FixedArrayBase>(); |
| 255 Handle<JSArray> array = Handle<JSArray>::cast(receiver); | 258 Handle<JSArray> array = Handle<JSArray>::cast(receiver); |
| 256 // If there may be elements accessors in the prototype chain, the fast path | 259 // If there may be elements accessors in the prototype chain, the fast path |
| 257 // cannot be used if there arguments to add to the array. | 260 // cannot be used if there arguments to add to the array. |
| 258 Heap* heap = isolate->heap(); | 261 Heap* heap = isolate->heap(); |
| 259 if (args != NULL && !IsJSArrayFastElementMovingAllowed(isolate, *array)) { | 262 if (args != NULL && !IsJSArrayFastElementMovingAllowed(isolate, *array)) { |
| 260 return MaybeHandle<FixedArrayBase>(); | 263 return MaybeHandle<FixedArrayBase>(); |
| 261 } | 264 } |
| 262 if (array->map()->is_observed()) return MaybeHandle<FixedArrayBase>(); | 265 if (array->map()->is_observed()) return MaybeHandle<FixedArrayBase>(); |
| 263 if (!array->map()->is_extensible()) return MaybeHandle<FixedArrayBase>(); | 266 if (!array->map()->is_extensible()) return MaybeHandle<FixedArrayBase>(); |
| 264 Handle<FixedArrayBase> elms(array->elements(), isolate); | 267 Handle<FixedArrayBase> elms(array->elements(), isolate); |
| 265 Map* map = elms->map(); | 268 Map* map = elms->map(); |
| 266 if (map == heap->fixed_array_map()) { | 269 if (map == heap->fixed_array_map()) { |
| 267 if (args == NULL || array->HasFastObjectElements()) return elms; | 270 if (args == NULL || array->HasFastObjectElements()) { |
| 271 return scope.CloseAndEscape(elms); |
| 272 } |
| 268 } else if (map == heap->fixed_cow_array_map()) { | 273 } else if (map == heap->fixed_cow_array_map()) { |
| 269 elms = JSObject::EnsureWritableFastElements(array); | 274 elms = JSObject::EnsureWritableFastElements(array); |
| 270 if (args == NULL || array->HasFastObjectElements()) return elms; | 275 if (args == NULL || array->HasFastObjectElements()) { |
| 276 return scope.CloseAndEscape(elms); |
| 277 } |
| 271 } else if (map == heap->fixed_double_array_map()) { | 278 } else if (map == heap->fixed_double_array_map()) { |
| 272 if (args == NULL) return elms; | 279 if (args == NULL) { |
| 280 return scope.CloseAndEscape(elms); |
| 281 } |
| 273 } else { | 282 } else { |
| 274 return MaybeHandle<FixedArrayBase>(); | 283 return MaybeHandle<FixedArrayBase>(); |
| 275 } | 284 } |
| 276 | 285 |
| 277 // Adding elements to the array prototype would break code that makes sure | 286 // Adding elements to the array prototype would break code that makes sure |
| 278 // it has no elements. Handle that elsewhere. | 287 // it has no elements. Handle that elsewhere. |
| 279 if (isolate->IsAnyInitialArrayPrototype(array)) { | 288 if (isolate->IsAnyInitialArrayPrototype(array)) { |
| 280 return MaybeHandle<FixedArrayBase>(); | 289 return MaybeHandle<FixedArrayBase>(); |
| 281 } | 290 } |
| 282 | 291 |
| 283 // Need to ensure that the arguments passed in args can be contained in | 292 // Need to ensure that the arguments passed in args can be contained in |
| 284 // the array. | 293 // the array. |
| 285 int args_length = args->length(); | 294 int args_length = args->length(); |
| 286 if (first_added_arg >= args_length) return handle(array->elements(), isolate); | 295 if (first_added_arg >= args_length) { |
| 296 return scope.CloseAndEscape(elms); |
| 297 } |
| 287 | 298 |
| 288 ElementsKind origin_kind = array->map()->elements_kind(); | 299 ElementsKind origin_kind = array->map()->elements_kind(); |
| 289 DCHECK(!IsFastObjectElementsKind(origin_kind)); | 300 DCHECK(!IsFastObjectElementsKind(origin_kind)); |
| 290 ElementsKind target_kind = origin_kind; | 301 ElementsKind target_kind = origin_kind; |
| 291 { | 302 { |
| 292 DisallowHeapAllocation no_gc; | 303 DisallowHeapAllocation no_gc; |
| 293 int arg_count = args_length - first_added_arg; | 304 int arg_count = args_length - first_added_arg; |
| 294 Object** arguments = args->arguments() - first_added_arg - (arg_count - 1); | 305 Object** arguments = args->arguments() - first_added_arg - (arg_count - 1); |
| 295 for (int i = 0; i < arg_count; i++) { | 306 for (int i = 0; i < arg_count; i++) { |
| 296 Object* arg = arguments[i]; | 307 Object* arg = arguments[i]; |
| 297 if (arg->IsHeapObject()) { | 308 if (arg->IsHeapObject()) { |
| 298 if (arg->IsHeapNumber()) { | 309 if (arg->IsHeapNumber()) { |
| 299 target_kind = FAST_DOUBLE_ELEMENTS; | 310 target_kind = FAST_DOUBLE_ELEMENTS; |
| 300 } else { | 311 } else { |
| 301 target_kind = FAST_ELEMENTS; | 312 target_kind = FAST_ELEMENTS; |
| 302 break; | 313 break; |
| 303 } | 314 } |
| 304 } | 315 } |
| 305 } | 316 } |
| 306 } | 317 } |
| 307 if (target_kind != origin_kind) { | 318 if (target_kind != origin_kind) { |
| 308 JSObject::TransitionElementsKind(array, target_kind); | 319 JSObject::TransitionElementsKind(array, target_kind); |
| 309 return handle(array->elements(), isolate); | 320 elms = handle(array->elements(), isolate); |
| 310 } | 321 } |
| 311 return elms; | 322 return scope.CloseAndEscape(elms); |
| 312 } | 323 } |
| 313 | 324 |
| 314 | 325 |
| 315 MUST_USE_RESULT static Object* CallJsIntrinsic( | 326 MUST_USE_RESULT static Object* CallJsIntrinsic( |
| 316 Isolate* isolate, Handle<JSFunction> function, | 327 Isolate* isolate, Handle<JSFunction> function, |
| 317 BuiltinArguments<BuiltinExtraArguments::kNone> args) { | 328 BuiltinArguments<BuiltinExtraArguments::kNone> args) { |
| 318 HandleScope handleScope(isolate); | 329 HandleScope handleScope(isolate); |
| 319 int argc = args.length() - 1; | 330 int argc = args.length() - 1; |
| 320 ScopedVector<Handle<Object> > argv(argc); | 331 ScopedVector<Handle<Object> > argv(argc); |
| 321 for (int i = 0; i < argc; ++i) { | 332 for (int i = 0; i < argc; ++i) { |
| (...skipping 4055 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4377 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) | 4388 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) |
| 4378 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) | 4389 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) |
| 4379 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) | 4390 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) |
| 4380 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) | 4391 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) |
| 4381 #undef DEFINE_BUILTIN_ACCESSOR_C | 4392 #undef DEFINE_BUILTIN_ACCESSOR_C |
| 4382 #undef DEFINE_BUILTIN_ACCESSOR_A | 4393 #undef DEFINE_BUILTIN_ACCESSOR_A |
| 4383 | 4394 |
| 4384 | 4395 |
| 4385 } // namespace internal | 4396 } // namespace internal |
| 4386 } // namespace v8 | 4397 } // namespace v8 |
| OLD | NEW |