Chromium Code Reviews| 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 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 416 !object->map()->is_observed() && !object->IsJSProxy()); | 416 !object->map()->is_observed() && !object->IsJSProxy()); |
| 417 | 417 |
| 418 Handle<Object> result; | 418 Handle<Object> result; |
| 419 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, result, JSObject::Seal(object)); | 419 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, result, JSObject::Seal(object)); |
| 420 return *result; | 420 return *result; |
| 421 } | 421 } |
| 422 | 422 |
| 423 | 423 |
| 424 RUNTIME_FUNCTION(Runtime_LoadGlobalViaContext) { | 424 RUNTIME_FUNCTION(Runtime_LoadGlobalViaContext) { |
| 425 HandleScope scope(isolate); | 425 HandleScope scope(isolate); |
| 426 DCHECK(args.length() == 3); | 426 DCHECK_EQ(2, args.length()); |
| 427 CONVERT_ARG_HANDLE_CHECKED(Context, script_context, 0); | 427 CONVERT_SMI_ARG_CHECKED(slot, 0); |
| 428 CONVERT_SMI_ARG_CHECKED(index, 1); | 428 CONVERT_ARG_HANDLE_CHECKED(Name, name, 1); |
| 429 CONVERT_ARG_HANDLE_CHECKED(Name, name, 2); | 429 |
| 430 // Go up context chain to the script context. | |
| 431 Handle<Context> script_context(isolate->context()->script_context(), isolate); | |
| 430 DCHECK(script_context->IsScriptContext()); | 432 DCHECK(script_context->IsScriptContext()); |
| 431 DCHECK(script_context->get(index)->IsPropertyCell()); | 433 DCHECK(script_context->get(slot)->IsPropertyCell()); |
| 432 | 434 |
| 433 Handle<GlobalObject> global(script_context->global_object()); | 435 // Lookup the named property on the global object. |
| 436 Handle<GlobalObject> global_object(script_context->global_object(), isolate); | |
| 437 LookupIterator it(global_object, name, LookupIterator::HIDDEN); | |
| 434 | 438 |
| 435 LookupIterator it(global, name, LookupIterator::HIDDEN); | 439 // Switch to fast mode only if there is a data property and it's not on |
| 440 // a hidden prototype. | |
| 441 if (it.state() == LookupIterator::DATA && | |
| 442 it.GetHolder<Object>()->IsJSGlobalObject()) { | |
| 443 // Now update the cell in the script context. | |
| 444 script_context->set(slot, *it.GetPropertyCell()); | |
|
Igor Sheludko
2015/07/18 20:52:44
GC mole will complain about this change.
Benedikt Meurer
2015/07/24 05:18:29
Done.
| |
| 445 } else { | |
| 446 // This is not a fast case, so keep this access in a slow mode. | |
| 447 // Store empty_property_cell here to release the outdated property cell. | |
| 448 script_context->set(slot, isolate->heap()->empty_property_cell()); | |
| 449 } | |
| 450 | |
| 451 Handle<Object> result; | |
| 452 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, result, Object::GetProperty(&it)); | |
| 453 return *result; | |
| 454 } | |
| 455 | |
| 456 | |
| 457 namespace { | |
| 458 | |
| 459 Object* StoreGlobalViaContext(Isolate* isolate, int slot, Handle<Name> name, | |
| 460 Handle<Object> value, | |
| 461 LanguageMode language_mode) { | |
| 462 // Go up context chain to the script context. | |
| 463 Handle<Context> script_context(isolate->context()->script_context(), isolate); | |
| 464 DCHECK(script_context->IsScriptContext()); | |
| 465 DCHECK(script_context->get(slot)->IsPropertyCell()); | |
| 466 | |
| 467 // Lookup the named property on the global object. | |
| 468 Handle<GlobalObject> global_object(script_context->global_object(), isolate); | |
| 469 LookupIterator it(global_object, name, LookupIterator::HIDDEN); | |
| 436 // Switch to fast mode only if there is a data property and it's not on | 470 // Switch to fast mode only if there is a data property and it's not on |
| 437 // a hidden prototype. | 471 // a hidden prototype. |
| 438 if (LookupIterator::DATA == it.state() && | 472 if (LookupIterator::DATA == it.state() && |
| 439 it.GetHolder<Object>()->IsJSGlobalObject()) { | 473 it.GetHolder<Object>()->IsJSGlobalObject()) { |
| 440 // Now update cell in the script context. | 474 // Now update cell in the script context. |
| 441 Handle<PropertyCell> cell = it.GetPropertyCell(); | 475 script_context->set(slot, *it.GetPropertyCell()); |
|
Igor Sheludko
2015/07/18 20:52:44
GC mole will complain about this change.
Benedikt Meurer
2015/07/24 05:18:29
Done.
| |
| 442 script_context->set(index, *cell); | |
| 443 } else { | 476 } else { |
| 444 // This is not a fast case, so keep this access in a slow mode. | 477 // 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. | 478 // Store empty_property_cell here to release the outdated property cell. |
| 446 script_context->set(index, isolate->heap()->empty_property_cell()); | 479 script_context->set(slot, isolate->heap()->empty_property_cell()); |
| 447 } | 480 } |
| 448 | 481 |
| 449 Handle<Object> result; | 482 Handle<Object> result; |
| 450 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, result, Object::GetProperty(&it)); | |
| 451 | |
| 452 return *result; | |
| 453 } | |
| 454 | |
| 455 | |
| 456 RUNTIME_FUNCTION(Runtime_StoreGlobalViaContext) { | |
| 457 HandleScope scope(isolate); | |
| 458 DCHECK(args.length() == 5); | |
| 459 CONVERT_ARG_HANDLE_CHECKED(Context, script_context, 0); | |
| 460 CONVERT_SMI_ARG_CHECKED(index, 1); | |
| 461 CONVERT_ARG_HANDLE_CHECKED(Name, name, 2); | |
| 462 CONVERT_ARG_HANDLE_CHECKED(Object, value, 3); | |
| 463 CONVERT_LANGUAGE_MODE_ARG_CHECKED(language_mode_arg, 4); | |
| 464 DCHECK(script_context->IsScriptContext()); | |
| 465 DCHECK(script_context->get(index)->IsPropertyCell()); | |
| 466 LanguageMode language_mode = language_mode_arg; | |
| 467 | |
| 468 Handle<GlobalObject> global(script_context->global_object()); | |
| 469 | |
| 470 LookupIterator it(global, name, LookupIterator::HIDDEN); | |
| 471 // Switch to fast mode only if there is a data property and it's not on | |
| 472 // a hidden prototype. | |
| 473 if (LookupIterator::DATA == it.state() && | |
| 474 it.GetHolder<Object>()->IsJSGlobalObject()) { | |
| 475 // Now update cell in the script context. | |
| 476 Handle<PropertyCell> cell = it.GetPropertyCell(); | |
| 477 script_context->set(index, *cell); | |
| 478 } else { | |
| 479 // This is not a fast case, so keep this access in a slow mode. | |
| 480 // Store empty_property_cell here to release the outdated property cell. | |
| 481 script_context->set(index, isolate->heap()->empty_property_cell()); | |
| 482 } | |
| 483 | |
| 484 Handle<Object> result; | |
| 485 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 483 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 486 isolate, result, | 484 isolate, result, |
| 487 Object::SetProperty(&it, value, language_mode, | 485 Object::SetProperty(&it, value, language_mode, |
| 488 Object::CERTAINLY_NOT_STORE_FROM_KEYED)); | 486 Object::CERTAINLY_NOT_STORE_FROM_KEYED)); |
| 487 return *result; | |
| 488 } | |
| 489 | 489 |
| 490 return *result; | 490 } // namespace |
| 491 | |
| 492 | |
| 493 RUNTIME_FUNCTION(Runtime_StoreGlobalViaContext_Sloppy) { | |
| 494 HandleScope scope(isolate); | |
| 495 DCHECK_EQ(3, args.length()); | |
| 496 CONVERT_SMI_ARG_CHECKED(slot, 0); | |
| 497 CONVERT_ARG_HANDLE_CHECKED(Name, name, 1); | |
| 498 CONVERT_ARG_HANDLE_CHECKED(Object, value, 2); | |
| 499 | |
| 500 return StoreGlobalViaContext(isolate, slot, name, value, SLOPPY); | |
| 501 } | |
| 502 | |
| 503 | |
| 504 RUNTIME_FUNCTION(Runtime_StoreGlobalViaContext_Strict) { | |
| 505 HandleScope scope(isolate); | |
| 506 DCHECK_EQ(3, args.length()); | |
| 507 CONVERT_SMI_ARG_CHECKED(slot, 0); | |
| 508 CONVERT_ARG_HANDLE_CHECKED(Name, name, 1); | |
| 509 CONVERT_ARG_HANDLE_CHECKED(Object, value, 2); | |
| 510 | |
| 511 return StoreGlobalViaContext(isolate, slot, name, value, STRICT); | |
| 491 } | 512 } |
| 492 | 513 |
| 493 | 514 |
| 494 RUNTIME_FUNCTION(Runtime_GetProperty) { | 515 RUNTIME_FUNCTION(Runtime_GetProperty) { |
| 495 HandleScope scope(isolate); | 516 HandleScope scope(isolate); |
| 496 DCHECK(args.length() == 2); | 517 DCHECK(args.length() == 2); |
| 497 | 518 |
| 498 CONVERT_ARG_HANDLE_CHECKED(Object, object, 0); | 519 CONVERT_ARG_HANDLE_CHECKED(Object, object, 0); |
| 499 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1); | 520 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1); |
| 500 | 521 |
| (...skipping 972 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1473 CONVERT_PROPERTY_ATTRIBUTES_CHECKED(attrs, 3); | 1494 CONVERT_PROPERTY_ATTRIBUTES_CHECKED(attrs, 3); |
| 1474 | 1495 |
| 1475 RETURN_FAILURE_ON_EXCEPTION( | 1496 RETURN_FAILURE_ON_EXCEPTION( |
| 1476 isolate, | 1497 isolate, |
| 1477 JSObject::DefineAccessor(object, name, isolate->factory()->null_value(), | 1498 JSObject::DefineAccessor(object, name, isolate->factory()->null_value(), |
| 1478 setter, attrs)); | 1499 setter, attrs)); |
| 1479 return isolate->heap()->undefined_value(); | 1500 return isolate->heap()->undefined_value(); |
| 1480 } | 1501 } |
| 1481 } // namespace internal | 1502 } // namespace internal |
| 1482 } // namespace v8 | 1503 } // namespace v8 |
| OLD | NEW |