OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 4349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4360 } | 4360 } |
4361 result->NotFound(); | 4361 result->NotFound(); |
4362 } | 4362 } |
4363 | 4363 |
4364 | 4364 |
4365 // Try to update an accessor in an elements dictionary. Return true if the | 4365 // Try to update an accessor in an elements dictionary. Return true if the |
4366 // update succeeded, and false otherwise. | 4366 // update succeeded, and false otherwise. |
4367 static bool UpdateGetterSetterInDictionary( | 4367 static bool UpdateGetterSetterInDictionary( |
4368 SeededNumberDictionary* dictionary, | 4368 SeededNumberDictionary* dictionary, |
4369 uint32_t index, | 4369 uint32_t index, |
4370 bool is_getter, | 4370 AccessorComponent component, |
4371 Object* fun, | 4371 Object* fun, |
4372 PropertyAttributes attributes) { | 4372 PropertyAttributes attributes) { |
4373 int entry = dictionary->FindEntry(index); | 4373 int entry = dictionary->FindEntry(index); |
4374 if (entry != SeededNumberDictionary::kNotFound) { | 4374 if (entry != SeededNumberDictionary::kNotFound) { |
4375 Object* result = dictionary->ValueAt(entry); | 4375 Object* result = dictionary->ValueAt(entry); |
4376 PropertyDetails details = dictionary->DetailsAt(entry); | 4376 PropertyDetails details = dictionary->DetailsAt(entry); |
4377 // TODO(mstarzinger): We should check for details.IsDontDelete() here once | 4377 // TODO(mstarzinger): We should check for details.IsDontDelete() here once |
4378 // we only call into the runtime once to set both getter and setter. | 4378 // we only call into the runtime once to set both getter and setter. |
4379 if (details.type() == CALLBACKS && result->IsAccessorPair()) { | 4379 if (details.type() == CALLBACKS && result->IsAccessorPair()) { |
4380 if (details.attributes() != attributes) { | 4380 if (details.attributes() != attributes) { |
4381 dictionary->DetailsAtPut(entry, | 4381 dictionary->DetailsAtPut(entry, |
4382 PropertyDetails(attributes, CALLBACKS, index)); | 4382 PropertyDetails(attributes, CALLBACKS, index)); |
4383 } | 4383 } |
4384 AccessorPair::cast(result)->set(is_getter, fun); | 4384 AccessorPair::cast(result)->set(component, fun); |
4385 return true; | 4385 return true; |
4386 } | 4386 } |
4387 } | 4387 } |
4388 return false; | 4388 return false; |
4389 } | 4389 } |
4390 | 4390 |
4391 | 4391 |
4392 MaybeObject* JSObject::DefineElementAccessor(uint32_t index, | 4392 MaybeObject* JSObject::DefineElementAccessor(uint32_t index, |
4393 bool is_getter, | 4393 AccessorComponent component, |
4394 Object* fun, | 4394 Object* fun, |
4395 PropertyAttributes attributes) { | 4395 PropertyAttributes attributes) { |
4396 switch (GetElementsKind()) { | 4396 switch (GetElementsKind()) { |
4397 case FAST_SMI_ONLY_ELEMENTS: | 4397 case FAST_SMI_ONLY_ELEMENTS: |
4398 case FAST_ELEMENTS: | 4398 case FAST_ELEMENTS: |
4399 case FAST_DOUBLE_ELEMENTS: | 4399 case FAST_DOUBLE_ELEMENTS: |
4400 break; | 4400 break; |
4401 case EXTERNAL_PIXEL_ELEMENTS: | 4401 case EXTERNAL_PIXEL_ELEMENTS: |
4402 case EXTERNAL_BYTE_ELEMENTS: | 4402 case EXTERNAL_BYTE_ELEMENTS: |
4403 case EXTERNAL_UNSIGNED_BYTE_ELEMENTS: | 4403 case EXTERNAL_UNSIGNED_BYTE_ELEMENTS: |
4404 case EXTERNAL_SHORT_ELEMENTS: | 4404 case EXTERNAL_SHORT_ELEMENTS: |
4405 case EXTERNAL_UNSIGNED_SHORT_ELEMENTS: | 4405 case EXTERNAL_UNSIGNED_SHORT_ELEMENTS: |
4406 case EXTERNAL_INT_ELEMENTS: | 4406 case EXTERNAL_INT_ELEMENTS: |
4407 case EXTERNAL_UNSIGNED_INT_ELEMENTS: | 4407 case EXTERNAL_UNSIGNED_INT_ELEMENTS: |
4408 case EXTERNAL_FLOAT_ELEMENTS: | 4408 case EXTERNAL_FLOAT_ELEMENTS: |
4409 case EXTERNAL_DOUBLE_ELEMENTS: | 4409 case EXTERNAL_DOUBLE_ELEMENTS: |
4410 // Ignore getters and setters on pixel and external array elements. | 4410 // Ignore getters and setters on pixel and external array elements. |
4411 return GetHeap()->undefined_value(); | 4411 return GetHeap()->undefined_value(); |
4412 case DICTIONARY_ELEMENTS: | 4412 case DICTIONARY_ELEMENTS: |
4413 if (UpdateGetterSetterInDictionary(element_dictionary(), | 4413 if (UpdateGetterSetterInDictionary(element_dictionary(), |
4414 index, | 4414 index, |
4415 is_getter, | 4415 component, |
4416 fun, | 4416 fun, |
4417 attributes)) { | 4417 attributes)) { |
4418 return GetHeap()->undefined_value(); | 4418 return GetHeap()->undefined_value(); |
4419 } | 4419 } |
4420 break; | 4420 break; |
4421 case NON_STRICT_ARGUMENTS_ELEMENTS: { | 4421 case NON_STRICT_ARGUMENTS_ELEMENTS: { |
4422 // Ascertain whether we have read-only properties or an existing | 4422 // Ascertain whether we have read-only properties or an existing |
4423 // getter/setter pair in an arguments elements dictionary backing | 4423 // getter/setter pair in an arguments elements dictionary backing |
4424 // store. | 4424 // store. |
4425 FixedArray* parameter_map = FixedArray::cast(elements()); | 4425 FixedArray* parameter_map = FixedArray::cast(elements()); |
4426 uint32_t length = parameter_map->length(); | 4426 uint32_t length = parameter_map->length(); |
4427 Object* probe = | 4427 Object* probe = |
4428 index < (length - 2) ? parameter_map->get(index + 2) : NULL; | 4428 index < (length - 2) ? parameter_map->get(index + 2) : NULL; |
4429 if (probe == NULL || probe->IsTheHole()) { | 4429 if (probe == NULL || probe->IsTheHole()) { |
4430 FixedArray* arguments = FixedArray::cast(parameter_map->get(1)); | 4430 FixedArray* arguments = FixedArray::cast(parameter_map->get(1)); |
4431 if (arguments->IsDictionary()) { | 4431 if (arguments->IsDictionary()) { |
4432 SeededNumberDictionary* dictionary = | 4432 SeededNumberDictionary* dictionary = |
4433 SeededNumberDictionary::cast(arguments); | 4433 SeededNumberDictionary::cast(arguments); |
4434 if (UpdateGetterSetterInDictionary(dictionary, | 4434 if (UpdateGetterSetterInDictionary(dictionary, |
4435 index, | 4435 index, |
4436 is_getter, | 4436 component, |
4437 fun, | 4437 fun, |
4438 attributes)) { | 4438 attributes)) { |
4439 return GetHeap()->undefined_value(); | 4439 return GetHeap()->undefined_value(); |
4440 } | 4440 } |
4441 } | 4441 } |
4442 } | 4442 } |
4443 break; | 4443 break; |
4444 } | 4444 } |
4445 } | 4445 } |
4446 | 4446 |
4447 AccessorPair* accessors; | 4447 AccessorPair* accessors; |
4448 { MaybeObject* maybe_accessors = GetHeap()->AllocateAccessorPair(); | 4448 { MaybeObject* maybe_accessors = GetHeap()->AllocateAccessorPair(); |
4449 if (!maybe_accessors->To(&accessors)) return maybe_accessors; | 4449 if (!maybe_accessors->To(&accessors)) return maybe_accessors; |
4450 } | 4450 } |
4451 accessors->set(is_getter, fun); | 4451 accessors->set(component, fun); |
4452 | 4452 |
4453 return SetElementCallback(index, accessors, attributes); | 4453 return SetElementCallback(index, accessors, attributes); |
4454 } | 4454 } |
4455 | 4455 |
4456 | 4456 |
4457 MaybeObject* JSObject::DefinePropertyAccessor(String* name, | 4457 MaybeObject* JSObject::DefinePropertyAccessor(String* name, |
4458 bool is_getter, | 4458 AccessorComponent component, |
4459 Object* fun, | 4459 Object* fun, |
4460 PropertyAttributes attributes) { | 4460 PropertyAttributes attributes) { |
4461 // Lookup the name. | 4461 // Lookup the name. |
4462 LookupResult result(GetHeap()->isolate()); | 4462 LookupResult result(GetHeap()->isolate()); |
4463 LocalLookupRealNamedProperty(name, &result); | 4463 LocalLookupRealNamedProperty(name, &result); |
4464 if (result.IsFound()) { | 4464 if (result.IsFound()) { |
4465 // TODO(mstarzinger): We should check for result.IsDontDelete() here once | 4465 // TODO(mstarzinger): We should check for result.IsDontDelete() here once |
4466 // we only call into the runtime once to set both getter and setter. | 4466 // we only call into the runtime once to set both getter and setter. |
4467 if (result.type() == CALLBACKS) { | 4467 if (result.type() == CALLBACKS) { |
4468 Object* obj = result.GetCallbackObject(); | 4468 Object* obj = result.GetCallbackObject(); |
4469 // Need to preserve old getters/setters. | 4469 // Need to preserve old getters/setters. |
4470 if (obj->IsAccessorPair()) { | 4470 if (obj->IsAccessorPair()) { |
4471 AccessorPair* copy; | 4471 AccessorPair* copy; |
4472 { MaybeObject* maybe_copy = | 4472 { MaybeObject* maybe_copy = |
4473 AccessorPair::cast(obj)->CopyWithoutTransitions(); | 4473 AccessorPair::cast(obj)->CopyWithoutTransitions(); |
4474 if (!maybe_copy->To(©)) return maybe_copy; | 4474 if (!maybe_copy->To(©)) return maybe_copy; |
4475 } | 4475 } |
4476 copy->set(is_getter, fun); | 4476 copy->set(component, fun); |
4477 // Use set to update attributes. | 4477 // Use set to update attributes. |
4478 return SetPropertyCallback(name, copy, attributes); | 4478 return SetPropertyCallback(name, copy, attributes); |
4479 } | 4479 } |
4480 } | 4480 } |
4481 } | 4481 } |
4482 | 4482 |
4483 AccessorPair* accessors; | 4483 AccessorPair* accessors; |
4484 { MaybeObject* maybe_accessors = GetHeap()->AllocateAccessorPair(); | 4484 { MaybeObject* maybe_accessors = GetHeap()->AllocateAccessorPair(); |
4485 if (!maybe_accessors->To(&accessors)) return maybe_accessors; | 4485 if (!maybe_accessors->To(&accessors)) return maybe_accessors; |
4486 } | 4486 } |
4487 accessors->set(is_getter, fun); | 4487 accessors->set(component, fun); |
4488 | 4488 |
4489 return SetPropertyCallback(name, accessors, attributes); | 4489 return SetPropertyCallback(name, accessors, attributes); |
4490 } | 4490 } |
4491 | 4491 |
4492 | 4492 |
4493 bool JSObject::CanSetCallback(String* name) { | 4493 bool JSObject::CanSetCallback(String* name) { |
4494 ASSERT(!IsAccessCheckNeeded() || | 4494 ASSERT(!IsAccessCheckNeeded() || |
4495 GetIsolate()->MayNamedAccess(this, name, v8::ACCESS_SET)); | 4495 GetIsolate()->MayNamedAccess(this, name, v8::ACCESS_SET)); |
4496 | 4496 |
4497 // Check if there is an API defined callback object which prohibits | 4497 // Check if there is an API defined callback object which prohibits |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4586 } | 4586 } |
4587 | 4587 |
4588 if (convert_back_to_fast) { | 4588 if (convert_back_to_fast) { |
4589 MaybeObject* maybe_ok = TransformToFastProperties(0); | 4589 MaybeObject* maybe_ok = TransformToFastProperties(0); |
4590 if (maybe_ok->IsFailure()) return maybe_ok; | 4590 if (maybe_ok->IsFailure()) return maybe_ok; |
4591 } | 4591 } |
4592 return GetHeap()->undefined_value(); | 4592 return GetHeap()->undefined_value(); |
4593 } | 4593 } |
4594 | 4594 |
4595 MaybeObject* JSObject::DefineAccessor(String* name, | 4595 MaybeObject* JSObject::DefineAccessor(String* name, |
4596 bool is_getter, | 4596 AccessorComponent component, |
4597 Object* fun, | 4597 Object* fun, |
4598 PropertyAttributes attributes) { | 4598 PropertyAttributes attributes) { |
4599 ASSERT(fun->IsSpecFunction() || fun->IsUndefined()); | 4599 ASSERT(fun->IsSpecFunction() || fun->IsUndefined()); |
4600 Isolate* isolate = GetIsolate(); | 4600 Isolate* isolate = GetIsolate(); |
4601 // Check access rights if needed. | 4601 // Check access rights if needed. |
4602 if (IsAccessCheckNeeded() && | 4602 if (IsAccessCheckNeeded() && |
4603 !isolate->MayNamedAccess(this, name, v8::ACCESS_SET)) { | 4603 !isolate->MayNamedAccess(this, name, v8::ACCESS_SET)) { |
4604 isolate->ReportFailedAccessCheck(this, v8::ACCESS_SET); | 4604 isolate->ReportFailedAccessCheck(this, v8::ACCESS_SET); |
4605 return isolate->heap()->undefined_value(); | 4605 return isolate->heap()->undefined_value(); |
4606 } | 4606 } |
4607 | 4607 |
4608 if (IsJSGlobalProxy()) { | 4608 if (IsJSGlobalProxy()) { |
4609 Object* proto = GetPrototype(); | 4609 Object* proto = GetPrototype(); |
4610 if (proto->IsNull()) return this; | 4610 if (proto->IsNull()) return this; |
4611 ASSERT(proto->IsJSGlobalObject()); | 4611 ASSERT(proto->IsJSGlobalObject()); |
4612 return JSObject::cast(proto)->DefineAccessor(name, is_getter, | 4612 return JSObject::cast(proto)->DefineAccessor(name, component, |
4613 fun, attributes); | 4613 fun, attributes); |
4614 } | 4614 } |
4615 | 4615 |
4616 // Make sure that the top context does not change when doing callbacks or | 4616 // Make sure that the top context does not change when doing callbacks or |
4617 // interceptor calls. | 4617 // interceptor calls. |
4618 AssertNoContextChange ncc; | 4618 AssertNoContextChange ncc; |
4619 | 4619 |
4620 // Try to flatten before operating on the string. | 4620 // Try to flatten before operating on the string. |
4621 name->TryFlatten(); | 4621 name->TryFlatten(); |
4622 | 4622 |
4623 if (!CanSetCallback(name)) return isolate->heap()->undefined_value(); | 4623 if (!CanSetCallback(name)) return isolate->heap()->undefined_value(); |
4624 | 4624 |
4625 uint32_t index = 0; | 4625 uint32_t index = 0; |
4626 return name->AsArrayIndex(&index) ? | 4626 return name->AsArrayIndex(&index) ? |
4627 DefineElementAccessor(index, is_getter, fun, attributes) : | 4627 DefineElementAccessor(index, component, fun, attributes) : |
4628 DefinePropertyAccessor(name, is_getter, fun, attributes); | 4628 DefinePropertyAccessor(name, component, fun, attributes); |
4629 } | 4629 } |
4630 | 4630 |
4631 | 4631 |
4632 MaybeObject* JSObject::DefineAccessor(AccessorInfo* info) { | 4632 MaybeObject* JSObject::DefineAccessor(AccessorInfo* info) { |
4633 Isolate* isolate = GetIsolate(); | 4633 Isolate* isolate = GetIsolate(); |
4634 String* name = String::cast(info->name()); | 4634 String* name = String::cast(info->name()); |
4635 // Check access rights if needed. | 4635 // Check access rights if needed. |
4636 if (IsAccessCheckNeeded() && | 4636 if (IsAccessCheckNeeded() && |
4637 !isolate->MayNamedAccess(this, name, v8::ACCESS_SET)) { | 4637 !isolate->MayNamedAccess(this, name, v8::ACCESS_SET)) { |
4638 isolate->ReportFailedAccessCheck(this, v8::ACCESS_SET); | 4638 isolate->ReportFailedAccessCheck(this, v8::ACCESS_SET); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4704 { MaybeObject* maybe_ok = | 4704 { MaybeObject* maybe_ok = |
4705 SetPropertyCallback(name, info, info->property_attributes()); | 4705 SetPropertyCallback(name, info, info->property_attributes()); |
4706 if (maybe_ok->IsFailure()) return maybe_ok; | 4706 if (maybe_ok->IsFailure()) return maybe_ok; |
4707 } | 4707 } |
4708 } | 4708 } |
4709 | 4709 |
4710 return this; | 4710 return this; |
4711 } | 4711 } |
4712 | 4712 |
4713 | 4713 |
4714 Object* JSObject::LookupAccessor(String* name, bool is_getter) { | 4714 Object* JSObject::LookupAccessor(String* name, AccessorComponent component) { |
4715 Heap* heap = GetHeap(); | 4715 Heap* heap = GetHeap(); |
4716 | 4716 |
4717 // Make sure that the top context does not change when doing callbacks or | 4717 // Make sure that the top context does not change when doing callbacks or |
4718 // interceptor calls. | 4718 // interceptor calls. |
4719 AssertNoContextChange ncc; | 4719 AssertNoContextChange ncc; |
4720 | 4720 |
4721 // Check access rights if needed. | 4721 // Check access rights if needed. |
4722 if (IsAccessCheckNeeded() && | 4722 if (IsAccessCheckNeeded() && |
4723 !heap->isolate()->MayNamedAccess(this, name, v8::ACCESS_HAS)) { | 4723 !heap->isolate()->MayNamedAccess(this, name, v8::ACCESS_HAS)) { |
4724 heap->isolate()->ReportFailedAccessCheck(this, v8::ACCESS_HAS); | 4724 heap->isolate()->ReportFailedAccessCheck(this, v8::ACCESS_HAS); |
4725 return heap->undefined_value(); | 4725 return heap->undefined_value(); |
4726 } | 4726 } |
4727 | 4727 |
4728 // Make the lookup and include prototypes. | 4728 // Make the lookup and include prototypes. |
4729 uint32_t index = 0; | 4729 uint32_t index = 0; |
4730 if (name->AsArrayIndex(&index)) { | 4730 if (name->AsArrayIndex(&index)) { |
4731 for (Object* obj = this; | 4731 for (Object* obj = this; |
4732 obj != heap->null_value(); | 4732 obj != heap->null_value(); |
4733 obj = JSObject::cast(obj)->GetPrototype()) { | 4733 obj = JSObject::cast(obj)->GetPrototype()) { |
4734 JSObject* js_object = JSObject::cast(obj); | 4734 JSObject* js_object = JSObject::cast(obj); |
4735 if (js_object->HasDictionaryElements()) { | 4735 if (js_object->HasDictionaryElements()) { |
4736 SeededNumberDictionary* dictionary = js_object->element_dictionary(); | 4736 SeededNumberDictionary* dictionary = js_object->element_dictionary(); |
4737 int entry = dictionary->FindEntry(index); | 4737 int entry = dictionary->FindEntry(index); |
4738 if (entry != SeededNumberDictionary::kNotFound) { | 4738 if (entry != SeededNumberDictionary::kNotFound) { |
4739 Object* element = dictionary->ValueAt(entry); | 4739 Object* element = dictionary->ValueAt(entry); |
4740 PropertyDetails details = dictionary->DetailsAt(entry); | 4740 if (dictionary->DetailsAt(entry).type() == CALLBACKS && |
4741 if (details.type() == CALLBACKS) { | 4741 element->IsAccessorPair()) { |
4742 if (element->IsAccessorPair()) { | 4742 return AccessorPair::cast(element)->get(component); |
4743 AccessorPair* accessors = AccessorPair::cast(element); | |
4744 return is_getter ? accessors->getter() : accessors->setter(); | |
4745 } | |
4746 } | 4743 } |
4747 } | 4744 } |
4748 } | 4745 } |
4749 } | 4746 } |
4750 } else { | 4747 } else { |
4751 for (Object* obj = this; | 4748 for (Object* obj = this; |
4752 obj != heap->null_value(); | 4749 obj != heap->null_value(); |
4753 obj = JSObject::cast(obj)->GetPrototype()) { | 4750 obj = JSObject::cast(obj)->GetPrototype()) { |
4754 LookupResult result(heap->isolate()); | 4751 LookupResult result(heap->isolate()); |
4755 JSObject::cast(obj)->LocalLookup(name, &result); | 4752 JSObject::cast(obj)->LocalLookup(name, &result); |
4756 if (result.IsProperty()) { | 4753 if (result.IsProperty()) { |
4757 if (result.IsReadOnly()) return heap->undefined_value(); | 4754 if (result.IsReadOnly()) return heap->undefined_value(); |
4758 if (result.type() == CALLBACKS) { | 4755 if (result.type() == CALLBACKS) { |
4759 Object* obj = result.GetCallbackObject(); | 4756 Object* obj = result.GetCallbackObject(); |
4760 if (obj->IsAccessorPair()) { | 4757 if (obj->IsAccessorPair()) { |
4761 AccessorPair* accessors = AccessorPair::cast(obj); | 4758 return AccessorPair::cast(obj)->get(component); |
4762 return is_getter ? accessors->getter() : accessors->setter(); | |
4763 } | 4759 } |
4764 } | 4760 } |
4765 } | 4761 } |
4766 } | 4762 } |
4767 } | 4763 } |
4768 return heap->undefined_value(); | 4764 return heap->undefined_value(); |
4769 } | 4765 } |
4770 | 4766 |
4771 | 4767 |
4772 Object* JSObject::SlowReverseLookup(Object* value) { | 4768 Object* JSObject::SlowReverseLookup(Object* value) { |
(...skipping 8394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13167 if (break_point_objects()->IsUndefined()) return 0; | 13163 if (break_point_objects()->IsUndefined()) return 0; |
13168 // Single break point. | 13164 // Single break point. |
13169 if (!break_point_objects()->IsFixedArray()) return 1; | 13165 if (!break_point_objects()->IsFixedArray()) return 1; |
13170 // Multiple break points. | 13166 // Multiple break points. |
13171 return FixedArray::cast(break_point_objects())->length(); | 13167 return FixedArray::cast(break_point_objects())->length(); |
13172 } | 13168 } |
13173 #endif // ENABLE_DEBUGGER_SUPPORT | 13169 #endif // ENABLE_DEBUGGER_SUPPORT |
13174 | 13170 |
13175 | 13171 |
13176 } } // namespace v8::internal | 13172 } } // namespace v8::internal |
OLD | NEW |