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 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 RUNTIME_FUNCTION(Runtime_LoadGlobalViaContext) { |
422 HandleScope scope(isolate); | 422 HandleScope scope(isolate); |
423 DCHECK(args.length() == 3); | 423 DCHECK_EQ(2, args.length()); |
424 CONVERT_ARG_HANDLE_CHECKED(Context, script_context, 0); | 424 CONVERT_SMI_ARG_CHECKED(slot, 0); |
425 CONVERT_SMI_ARG_CHECKED(index, 1); | 425 CONVERT_ARG_HANDLE_CHECKED(Name, name, 1); |
426 CONVERT_ARG_HANDLE_CHECKED(Name, name, 2); | 426 |
| 427 // Go up context chain to the script context. |
| 428 Handle<Context> script_context(isolate->context()->script_context(), isolate); |
427 DCHECK(script_context->IsScriptContext()); | 429 DCHECK(script_context->IsScriptContext()); |
428 DCHECK(script_context->get(index)->IsPropertyCell()); | 430 DCHECK(script_context->get(slot)->IsPropertyCell()); |
429 | 431 |
430 Handle<GlobalObject> global(script_context->global_object()); | 432 // Lookup the named property on the global object. |
| 433 Handle<GlobalObject> global_object(script_context->global_object(), isolate); |
| 434 LookupIterator it(global_object, name, LookupIterator::HIDDEN); |
431 | 435 |
432 LookupIterator it(global, name, LookupIterator::HIDDEN); | 436 // Switch to fast mode only if there is a data property and it's not on |
| 437 // a hidden prototype. |
| 438 if (it.state() == LookupIterator::DATA && |
| 439 it.GetHolder<Object>()->IsJSGlobalObject()) { |
| 440 // Now update the cell in the script context. |
| 441 Handle<PropertyCell> cell = it.GetPropertyCell(); |
| 442 script_context->set(slot, *cell); |
| 443 } else { |
| 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. |
| 446 script_context->set(slot, isolate->heap()->empty_property_cell()); |
| 447 } |
| 448 |
| 449 Handle<Object> result; |
| 450 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, result, Object::GetProperty(&it)); |
| 451 return *result; |
| 452 } |
| 453 |
| 454 |
| 455 namespace { |
| 456 |
| 457 Object* StoreGlobalViaContext(Isolate* isolate, int slot, Handle<Name> name, |
| 458 Handle<Object> value, |
| 459 LanguageMode language_mode) { |
| 460 // Go up context chain to the script context. |
| 461 Handle<Context> script_context(isolate->context()->script_context(), isolate); |
| 462 DCHECK(script_context->IsScriptContext()); |
| 463 DCHECK(script_context->get(slot)->IsPropertyCell()); |
| 464 |
| 465 // Lookup the named property on the global object. |
| 466 Handle<GlobalObject> global_object(script_context->global_object(), isolate); |
| 467 LookupIterator it(global_object, name, LookupIterator::HIDDEN); |
433 // Switch to fast mode only if there is a data property and it's not on | 468 // Switch to fast mode only if there is a data property and it's not on |
434 // a hidden prototype. | 469 // a hidden prototype. |
435 if (LookupIterator::DATA == it.state() && | 470 if (LookupIterator::DATA == it.state() && |
436 it.GetHolder<Object>()->IsJSGlobalObject()) { | 471 it.GetHolder<Object>()->IsJSGlobalObject()) { |
437 // Now update cell in the script context. | 472 // Now update cell in the script context. |
438 Handle<PropertyCell> cell = it.GetPropertyCell(); | 473 Handle<PropertyCell> cell = it.GetPropertyCell(); |
439 script_context->set(index, *cell); | 474 script_context->set(slot, *cell); |
440 } else { | 475 } else { |
441 // This is not a fast case, so keep this access in a slow mode. | 476 // This is not a fast case, so keep this access in a slow mode. |
442 // Store empty_property_cell here to release the outdated property cell. | 477 // Store empty_property_cell here to release the outdated property cell. |
443 script_context->set(index, isolate->heap()->empty_property_cell()); | 478 script_context->set(slot, isolate->heap()->empty_property_cell()); |
444 } | 479 } |
445 | 480 |
446 Handle<Object> result; | 481 Handle<Object> result; |
447 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, result, Object::GetProperty(&it)); | |
448 | |
449 return *result; | |
450 } | |
451 | |
452 | |
453 RUNTIME_FUNCTION(Runtime_StoreGlobalViaContext) { | |
454 HandleScope scope(isolate); | |
455 DCHECK(args.length() == 5); | |
456 CONVERT_ARG_HANDLE_CHECKED(Context, script_context, 0); | |
457 CONVERT_SMI_ARG_CHECKED(index, 1); | |
458 CONVERT_ARG_HANDLE_CHECKED(Name, name, 2); | |
459 CONVERT_ARG_HANDLE_CHECKED(Object, value, 3); | |
460 CONVERT_LANGUAGE_MODE_ARG_CHECKED(language_mode_arg, 4); | |
461 DCHECK(script_context->IsScriptContext()); | |
462 DCHECK(script_context->get(index)->IsPropertyCell()); | |
463 LanguageMode language_mode = language_mode_arg; | |
464 | |
465 Handle<GlobalObject> global(script_context->global_object()); | |
466 | |
467 LookupIterator it(global, name, LookupIterator::HIDDEN); | |
468 // Switch to fast mode only if there is a data property and it's not on | |
469 // a hidden prototype. | |
470 if (LookupIterator::DATA == it.state() && | |
471 it.GetHolder<Object>()->IsJSGlobalObject()) { | |
472 // Now update cell in the script context. | |
473 Handle<PropertyCell> cell = it.GetPropertyCell(); | |
474 script_context->set(index, *cell); | |
475 } else { | |
476 // 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. | |
478 script_context->set(index, isolate->heap()->empty_property_cell()); | |
479 } | |
480 | |
481 Handle<Object> result; | |
482 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 482 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
483 isolate, result, | 483 isolate, result, |
484 Object::SetProperty(&it, value, language_mode, | 484 Object::SetProperty(&it, value, language_mode, |
485 Object::CERTAINLY_NOT_STORE_FROM_KEYED)); | 485 Object::CERTAINLY_NOT_STORE_FROM_KEYED)); |
| 486 return *result; |
| 487 } |
486 | 488 |
487 return *result; | 489 } // namespace |
| 490 |
| 491 |
| 492 RUNTIME_FUNCTION(Runtime_StoreGlobalViaContext_Sloppy) { |
| 493 HandleScope scope(isolate); |
| 494 DCHECK_EQ(3, args.length()); |
| 495 CONVERT_SMI_ARG_CHECKED(slot, 0); |
| 496 CONVERT_ARG_HANDLE_CHECKED(Name, name, 1); |
| 497 CONVERT_ARG_HANDLE_CHECKED(Object, value, 2); |
| 498 |
| 499 return StoreGlobalViaContext(isolate, slot, name, value, SLOPPY); |
| 500 } |
| 501 |
| 502 |
| 503 RUNTIME_FUNCTION(Runtime_StoreGlobalViaContext_Strict) { |
| 504 HandleScope scope(isolate); |
| 505 DCHECK_EQ(3, args.length()); |
| 506 CONVERT_SMI_ARG_CHECKED(slot, 0); |
| 507 CONVERT_ARG_HANDLE_CHECKED(Name, name, 1); |
| 508 CONVERT_ARG_HANDLE_CHECKED(Object, value, 2); |
| 509 |
| 510 return StoreGlobalViaContext(isolate, slot, name, value, STRICT); |
488 } | 511 } |
489 | 512 |
490 | 513 |
491 RUNTIME_FUNCTION(Runtime_GetProperty) { | 514 RUNTIME_FUNCTION(Runtime_GetProperty) { |
492 HandleScope scope(isolate); | 515 HandleScope scope(isolate); |
493 DCHECK(args.length() == 2); | 516 DCHECK(args.length() == 2); |
494 | 517 |
495 CONVERT_ARG_HANDLE_CHECKED(Object, object, 0); | 518 CONVERT_ARG_HANDLE_CHECKED(Object, object, 0); |
496 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1); | 519 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1); |
497 | 520 |
(...skipping 932 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1430 CONVERT_PROPERTY_ATTRIBUTES_CHECKED(attrs, 3); | 1453 CONVERT_PROPERTY_ATTRIBUTES_CHECKED(attrs, 3); |
1431 | 1454 |
1432 RETURN_FAILURE_ON_EXCEPTION( | 1455 RETURN_FAILURE_ON_EXCEPTION( |
1433 isolate, | 1456 isolate, |
1434 JSObject::DefineAccessor(object, name, isolate->factory()->null_value(), | 1457 JSObject::DefineAccessor(object, name, isolate->factory()->null_value(), |
1435 setter, attrs)); | 1458 setter, attrs)); |
1436 return isolate->heap()->undefined_value(); | 1459 return isolate->heap()->undefined_value(); |
1437 } | 1460 } |
1438 } // namespace internal | 1461 } // namespace internal |
1439 } // namespace v8 | 1462 } // namespace v8 |
OLD | NEW |