OLD | NEW |
---|---|
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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/arguments.h" | 7 #include "src/arguments.h" |
8 #include "src/bootstrapper.h" | 8 #include "src/bootstrapper.h" |
9 #include "src/debug.h" | 9 #include "src/debug.h" |
10 #include "src/messages.h" | 10 #include "src/messages.h" |
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
411 // %ObjectSeal is a fast path and these cases are handled elsewhere. | 411 // %ObjectSeal is a fast path and these cases are handled elsewhere. |
412 RUNTIME_ASSERT(!object->HasSloppyArgumentsElements() && | 412 RUNTIME_ASSERT(!object->HasSloppyArgumentsElements() && |
413 !object->map()->is_observed() && !object->IsJSProxy()); | 413 !object->map()->is_observed() && !object->IsJSProxy()); |
414 | 414 |
415 Handle<Object> result; | 415 Handle<Object> result; |
416 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, result, JSObject::Seal(object)); | 416 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, result, JSObject::Seal(object)); |
417 return *result; | 417 return *result; |
418 } | 418 } |
419 | 419 |
420 | 420 |
421 RUNTIME_FUNCTION(Runtime_LoadGlobalViaContext) { | 421 namespace { |
422 HandleScope scope(isolate); | |
423 DCHECK_EQ(2, args.length()); | |
424 CONVERT_SMI_ARG_CHECKED(slot, 0); | |
425 CONVERT_ARG_HANDLE_CHECKED(Name, name, 1); | |
426 | 422 |
423 Object* StoreGlobalViaContext(Isolate* isolate, int slot, Handle<Object> value, | |
424 LanguageMode language_mode) { | |
427 // Go up context chain to the script context. | 425 // Go up context chain to the script context. |
428 Handle<Context> script_context(isolate->context()->script_context(), isolate); | 426 Handle<Context> script_context(isolate->context()->script_context(), isolate); |
429 DCHECK(script_context->IsScriptContext()); | 427 DCHECK(script_context->IsScriptContext()); |
430 DCHECK(script_context->get(slot)->IsPropertyCell()); | 428 DCHECK(script_context->get(slot)->IsPropertyCell()); |
431 | 429 |
432 // Lookup the named property on the global object. | 430 // Lookup the named property on the global object. |
431 Handle<ScopeInfo> scope_info(ScopeInfo::cast(script_context->extension()), | |
432 isolate); | |
433 Handle<Name> name(scope_info->ContextSlotName(slot), isolate); | |
433 Handle<GlobalObject> global_object(script_context->global_object(), isolate); | 434 Handle<GlobalObject> global_object(script_context->global_object(), isolate); |
434 LookupIterator it(global_object, name, LookupIterator::HIDDEN); | 435 LookupIterator it(global_object, name, LookupIterator::HIDDEN); |
435 | |
436 // Switch to fast mode only if there is a data property and it's not on | 436 // Switch to fast mode only if there is a data property and it's not on |
437 // a hidden prototype. | 437 // a hidden prototype. |
438 if (it.state() == LookupIterator::DATA && | 438 if (LookupIterator::DATA == it.state() && !it.IsReadOnly() && |
439 it.GetHolder<Object>()->IsJSGlobalObject()) { | 439 it.GetHolder<Object>()->IsJSGlobalObject()) { |
440 // Now update the cell in the script context. | 440 // Now update cell in the script context. |
441 Handle<PropertyCell> cell = it.GetPropertyCell(); | 441 Handle<PropertyCell> cell = it.GetPropertyCell(); |
442 script_context->set(slot, *cell); | 442 script_context->set(slot, *cell); |
443 } else { | 443 } else { |
444 // This is not a fast case, so keep this access in a slow mode. | 444 // This is not a fast case, so keep this access in a slow mode. |
445 // Store empty_property_cell here to release the outdated property cell. | 445 // Store empty_property_cell here to release the outdated property cell. |
446 script_context->set(slot, isolate->heap()->empty_property_cell()); | 446 script_context->set(slot, isolate->heap()->empty_property_cell()); |
447 } | 447 } |
448 | 448 |
449 Handle<Object> result; | 449 Handle<Object> result; |
450 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, result, Object::GetProperty(&it)); | 450 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
451 isolate, result, | |
452 Object::SetProperty(&it, value, language_mode, | |
453 Object::CERTAINLY_NOT_STORE_FROM_KEYED)); | |
451 return *result; | 454 return *result; |
452 } | 455 } |
453 | 456 |
457 } // namespace | |
454 | 458 |
455 namespace { | |
456 | 459 |
457 Object* StoreGlobalViaContext(Isolate* isolate, int slot, Handle<Name> name, | 460 RUNTIME_FUNCTION(Runtime_LoadGlobalViaContext) { |
Igor Sheludko
2015/07/27 18:54:49
Why did you change the order of functions?
Benedikt Meurer
2015/07/28 05:14:12
Leftover from unrelated change.
| |
458 Handle<Object> value, | 461 HandleScope scope(isolate); |
459 LanguageMode language_mode) { | 462 DCHECK_EQ(1, args.length()); |
463 CONVERT_SMI_ARG_CHECKED(slot, 0); | |
464 | |
460 // Go up context chain to the script context. | 465 // Go up context chain to the script context. |
461 Handle<Context> script_context(isolate->context()->script_context(), isolate); | 466 Handle<Context> script_context(isolate->context()->script_context(), isolate); |
462 DCHECK(script_context->IsScriptContext()); | 467 DCHECK(script_context->IsScriptContext()); |
463 DCHECK(script_context->get(slot)->IsPropertyCell()); | 468 DCHECK(script_context->get(slot)->IsPropertyCell()); |
464 | 469 |
465 // Lookup the named property on the global object. | 470 // Lookup the named property on the global object. |
471 Handle<ScopeInfo> scope_info(ScopeInfo::cast(script_context->extension()), | |
472 isolate); | |
473 Handle<Name> name(scope_info->ContextSlotName(slot), isolate); | |
466 Handle<GlobalObject> global_object(script_context->global_object(), isolate); | 474 Handle<GlobalObject> global_object(script_context->global_object(), isolate); |
467 LookupIterator it(global_object, name, LookupIterator::HIDDEN); | 475 LookupIterator it(global_object, name, LookupIterator::HIDDEN); |
476 | |
468 // Switch to fast mode only if there is a data property and it's not on | 477 // Switch to fast mode only if there is a data property and it's not on |
469 // a hidden prototype. | 478 // a hidden prototype. |
470 if (LookupIterator::DATA == it.state() && !it.IsReadOnly() && | 479 if (LookupIterator::DATA == it.state() && !it.IsReadOnly() && |
471 it.GetHolder<Object>()->IsJSGlobalObject()) { | 480 it.GetHolder<Object>()->IsJSGlobalObject()) { |
472 // Now update cell in the script context. | 481 // Now update the cell in the script context. |
473 Handle<PropertyCell> cell = it.GetPropertyCell(); | 482 Handle<PropertyCell> cell = it.GetPropertyCell(); |
474 script_context->set(slot, *cell); | 483 script_context->set(slot, *cell); |
475 } else { | 484 } else { |
476 // This is not a fast case, so keep this access in a slow mode. | 485 // This is not a fast case, so keep this access in a slow mode. |
477 // Store empty_property_cell here to release the outdated property cell. | 486 // Store empty_property_cell here to release the outdated property cell. |
478 script_context->set(slot, isolate->heap()->empty_property_cell()); | 487 script_context->set(slot, isolate->heap()->empty_property_cell()); |
479 } | 488 } |
480 | 489 |
481 Handle<Object> result; | 490 Handle<Object> result; |
482 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 491 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, result, Object::GetProperty(&it)); |
483 isolate, result, | |
484 Object::SetProperty(&it, value, language_mode, | |
485 Object::CERTAINLY_NOT_STORE_FROM_KEYED)); | |
486 return *result; | 492 return *result; |
487 } | 493 } |
488 | 494 |
489 } // namespace | |
490 | |
491 | 495 |
492 RUNTIME_FUNCTION(Runtime_StoreGlobalViaContext_Sloppy) { | 496 RUNTIME_FUNCTION(Runtime_StoreGlobalViaContext_Sloppy) { |
493 HandleScope scope(isolate); | 497 HandleScope scope(isolate); |
494 DCHECK_EQ(3, args.length()); | 498 DCHECK_EQ(2, args.length()); |
495 CONVERT_SMI_ARG_CHECKED(slot, 0); | 499 CONVERT_SMI_ARG_CHECKED(slot, 0); |
496 CONVERT_ARG_HANDLE_CHECKED(Name, name, 1); | 500 CONVERT_ARG_HANDLE_CHECKED(Object, value, 1); |
497 CONVERT_ARG_HANDLE_CHECKED(Object, value, 2); | |
498 | 501 |
499 return StoreGlobalViaContext(isolate, slot, name, value, SLOPPY); | 502 return StoreGlobalViaContext(isolate, slot, value, SLOPPY); |
500 } | 503 } |
501 | 504 |
502 | 505 |
503 RUNTIME_FUNCTION(Runtime_StoreGlobalViaContext_Strict) { | 506 RUNTIME_FUNCTION(Runtime_StoreGlobalViaContext_Strict) { |
504 HandleScope scope(isolate); | 507 HandleScope scope(isolate); |
505 DCHECK_EQ(3, args.length()); | 508 DCHECK_EQ(2, args.length()); |
506 CONVERT_SMI_ARG_CHECKED(slot, 0); | 509 CONVERT_SMI_ARG_CHECKED(slot, 0); |
507 CONVERT_ARG_HANDLE_CHECKED(Name, name, 1); | 510 CONVERT_ARG_HANDLE_CHECKED(Object, value, 1); |
508 CONVERT_ARG_HANDLE_CHECKED(Object, value, 2); | |
509 | 511 |
510 return StoreGlobalViaContext(isolate, slot, name, value, STRICT); | 512 return StoreGlobalViaContext(isolate, slot, value, STRICT); |
511 } | 513 } |
512 | 514 |
513 | 515 |
514 RUNTIME_FUNCTION(Runtime_GetProperty) { | 516 RUNTIME_FUNCTION(Runtime_GetProperty) { |
515 HandleScope scope(isolate); | 517 HandleScope scope(isolate); |
516 DCHECK(args.length() == 2); | 518 DCHECK(args.length() == 2); |
517 | 519 |
518 CONVERT_ARG_HANDLE_CHECKED(Object, object, 0); | 520 CONVERT_ARG_HANDLE_CHECKED(Object, object, 0); |
519 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1); | 521 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1); |
520 | 522 |
(...skipping 932 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1453 CONVERT_PROPERTY_ATTRIBUTES_CHECKED(attrs, 3); | 1455 CONVERT_PROPERTY_ATTRIBUTES_CHECKED(attrs, 3); |
1454 | 1456 |
1455 RETURN_FAILURE_ON_EXCEPTION( | 1457 RETURN_FAILURE_ON_EXCEPTION( |
1456 isolate, | 1458 isolate, |
1457 JSObject::DefineAccessor(object, name, isolate->factory()->null_value(), | 1459 JSObject::DefineAccessor(object, name, isolate->factory()->null_value(), |
1458 setter, attrs)); | 1460 setter, attrs)); |
1459 return isolate->heap()->undefined_value(); | 1461 return isolate->heap()->undefined_value(); |
1460 } | 1462 } |
1461 } // namespace internal | 1463 } // namespace internal |
1462 } // namespace v8 | 1464 } // namespace v8 |
OLD | NEW |