| 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 1541 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1552 InitializeTemplate(obj, Consts::OBJECT_TEMPLATE); | 1552 InitializeTemplate(obj, Consts::OBJECT_TEMPLATE); |
| 1553 if (!constructor.IsEmpty()) | 1553 if (!constructor.IsEmpty()) |
| 1554 obj->set_constructor(*Utils::OpenHandle(*constructor)); | 1554 obj->set_constructor(*Utils::OpenHandle(*constructor)); |
| 1555 obj->set_internal_field_count(i::Smi::FromInt(0)); | 1555 obj->set_internal_field_count(i::Smi::FromInt(0)); |
| 1556 return Utils::ToLocal(obj); | 1556 return Utils::ToLocal(obj); |
| 1557 } | 1557 } |
| 1558 | 1558 |
| 1559 | 1559 |
| 1560 // Ensure that the object template has a constructor. If no | 1560 // Ensure that the object template has a constructor. If no |
| 1561 // constructor is available we create one. | 1561 // constructor is available we create one. |
| 1562 static void EnsureConstructor(ObjectTemplate* object_template) { | 1562 static i::Handle<i::FunctionTemplateInfo> EnsureConstructor( |
| 1563 if (Utils::OpenHandle(object_template)->constructor()->IsUndefined()) { | 1563 ObjectTemplate* object_template) { |
| 1564 Local<FunctionTemplate> templ = FunctionTemplate::New(); | 1564 i::Object* obj = Utils::OpenHandle(object_template)->constructor(); |
| 1565 i::Handle<i::FunctionTemplateInfo> constructor = Utils::OpenHandle(*templ); | 1565 if (!obj ->IsUndefined()) { |
| 1566 constructor->set_instance_template(*Utils::OpenHandle(object_template)); | 1566 i::FunctionTemplateInfo* info = i::FunctionTemplateInfo::cast(obj); |
| 1567 Utils::OpenHandle(object_template)->set_constructor(*constructor); | 1567 return i::Handle<i::FunctionTemplateInfo>(info, info->GetIsolate()); |
| 1568 } | 1568 } |
| 1569 Local<FunctionTemplate> templ = FunctionTemplate::New(); |
| 1570 i::Handle<i::FunctionTemplateInfo> constructor = Utils::OpenHandle(*templ); |
| 1571 constructor->set_instance_template(*Utils::OpenHandle(object_template)); |
| 1572 Utils::OpenHandle(object_template)->set_constructor(*constructor); |
| 1573 return constructor; |
| 1569 } | 1574 } |
| 1570 | 1575 |
| 1571 | 1576 |
| 1572 static inline void AddPropertyToFunctionTemplate( | 1577 static inline void AddPropertyToTemplate( |
| 1573 i::Handle<i::FunctionTemplateInfo> cons, | 1578 i::Handle<i::TemplateInfo> info, |
| 1574 i::Handle<i::AccessorInfo> obj) { | 1579 i::Handle<i::AccessorInfo> obj) { |
| 1575 i::Handle<i::Object> list(cons->property_accessors(), cons->GetIsolate()); | 1580 i::Handle<i::Object> list(info->property_accessors(), info->GetIsolate()); |
| 1576 if (list->IsUndefined()) { | 1581 if (list->IsUndefined()) { |
| 1577 list = NeanderArray().value(); | 1582 list = NeanderArray().value(); |
| 1578 cons->set_property_accessors(*list); | 1583 info->set_property_accessors(*list); |
| 1579 } | 1584 } |
| 1580 NeanderArray array(list); | 1585 NeanderArray array(list); |
| 1581 array.add(obj); | 1586 array.add(obj); |
| 1582 } | 1587 } |
| 1583 | 1588 |
| 1584 | 1589 |
| 1585 template<typename Setter, typename Getter, typename Data> | 1590 static inline i::Handle<i::TemplateInfo> GetTemplateInfo( |
| 1586 static bool ObjectTemplateSetAccessor( | 1591 Template* template_obj) { |
| 1587 ObjectTemplate* object_template, | 1592 return Utils::OpenHandle(template_obj); |
| 1593 } |
| 1594 |
| 1595 |
| 1596 // TODO(dcarney): remove this with ObjectTemplate::SetAccessor |
| 1597 static inline i::Handle<i::TemplateInfo> GetTemplateInfo( |
| 1598 ObjectTemplate* object_template) { |
| 1599 EnsureConstructor(object_template); |
| 1600 return Utils::OpenHandle(object_template); |
| 1601 } |
| 1602 |
| 1603 |
| 1604 template<typename Setter, typename Getter, typename Data, typename Template> |
| 1605 static bool TemplateSetAccessor( |
| 1606 Template* template_obj, |
| 1588 v8::Handle<String> name, | 1607 v8::Handle<String> name, |
| 1589 Getter getter, | 1608 Getter getter, |
| 1590 Setter setter, | 1609 Setter setter, |
| 1591 Data data, | 1610 Data data, |
| 1592 AccessControl settings, | 1611 AccessControl settings, |
| 1593 PropertyAttribute attribute, | 1612 PropertyAttribute attribute, |
| 1594 v8::Handle<AccessorSignature> signature) { | 1613 v8::Handle<AccessorSignature> signature) { |
| 1595 i::Isolate* isolate = Utils::OpenHandle(object_template)->GetIsolate(); | 1614 i::Isolate* isolate = Utils::OpenHandle(template_obj)->GetIsolate(); |
| 1596 if (IsDeadCheck(isolate, "v8::ObjectTemplate::SetAccessor()")) return false; | 1615 if (IsDeadCheck(isolate, "v8::ObjectTemplate::SetAccessor()")) return false; |
| 1597 ENTER_V8(isolate); | 1616 ENTER_V8(isolate); |
| 1598 i::HandleScope scope(isolate); | 1617 i::HandleScope scope(isolate); |
| 1599 EnsureConstructor(object_template); | |
| 1600 i::FunctionTemplateInfo* constructor = i::FunctionTemplateInfo::cast( | |
| 1601 Utils::OpenHandle(object_template)->constructor()); | |
| 1602 i::Handle<i::FunctionTemplateInfo> cons(constructor); | |
| 1603 i::Handle<i::AccessorInfo> obj = MakeAccessorInfo( | 1618 i::Handle<i::AccessorInfo> obj = MakeAccessorInfo( |
| 1604 name, getter, setter, data, settings, attribute, signature); | 1619 name, getter, setter, data, settings, attribute, signature); |
| 1605 if (obj.is_null()) return false; | 1620 if (obj.is_null()) return false; |
| 1606 AddPropertyToFunctionTemplate(cons, obj); | 1621 i::Handle<i::TemplateInfo> info = GetTemplateInfo(template_obj); |
| 1622 AddPropertyToTemplate(info, obj); |
| 1607 return true; | 1623 return true; |
| 1608 } | 1624 } |
| 1609 | 1625 |
| 1610 | 1626 |
| 1627 bool Template::SetDeclaredAccessor( |
| 1628 Handle<String> name, |
| 1629 Handle<DeclaredAccessorDescriptor> descriptor, |
| 1630 AccessControl settings, |
| 1631 PropertyAttribute attribute, |
| 1632 Handle<AccessorSignature> signature) { |
| 1633 void* null = NULL; |
| 1634 return TemplateSetAccessor( |
| 1635 this, name, descriptor, null, null, settings, attribute, signature); |
| 1636 } |
| 1637 |
| 1638 |
| 1639 void Template::SetNativeAccessor(v8::Handle<String> name, |
| 1640 AccessorGetterCallback getter, |
| 1641 AccessorSetterCallback setter, |
| 1642 v8::Handle<Value> data, |
| 1643 AccessControl settings, |
| 1644 PropertyAttribute attribute, |
| 1645 v8::Handle<AccessorSignature> signature) { |
| 1646 TemplateSetAccessor( |
| 1647 this, name, getter, setter, data, settings, attribute, signature); |
| 1648 } |
| 1649 |
| 1650 |
| 1611 void ObjectTemplate::SetAccessor(v8::Handle<String> name, | 1651 void ObjectTemplate::SetAccessor(v8::Handle<String> name, |
| 1612 AccessorGetter getter, | 1652 AccessorGetter getter, |
| 1613 AccessorSetter setter, | 1653 AccessorSetter setter, |
| 1614 v8::Handle<Value> data, | 1654 v8::Handle<Value> data, |
| 1615 AccessControl settings, | 1655 AccessControl settings, |
| 1616 PropertyAttribute attribute, | 1656 PropertyAttribute attribute, |
| 1617 v8::Handle<AccessorSignature> signature) { | 1657 v8::Handle<AccessorSignature> signature) { |
| 1618 ObjectTemplateSetAccessor( | 1658 TemplateSetAccessor( |
| 1619 this, name, getter, setter, data, settings, attribute, signature); | 1659 this, name, getter, setter, data, settings, attribute, signature); |
| 1620 } | 1660 } |
| 1621 | 1661 |
| 1622 | 1662 |
| 1623 void ObjectTemplate::SetAccessor(v8::Handle<String> name, | 1663 void ObjectTemplate::SetAccessor(v8::Handle<String> name, |
| 1624 AccessorGetterCallback getter, | 1664 AccessorGetterCallback getter, |
| 1625 AccessorSetterCallback setter, | 1665 AccessorSetterCallback setter, |
| 1626 v8::Handle<Value> data, | 1666 v8::Handle<Value> data, |
| 1627 AccessControl settings, | 1667 AccessControl settings, |
| 1628 PropertyAttribute attribute, | 1668 PropertyAttribute attribute, |
| 1629 v8::Handle<AccessorSignature> signature) { | 1669 v8::Handle<AccessorSignature> signature) { |
| 1630 ObjectTemplateSetAccessor( | 1670 TemplateSetAccessor( |
| 1631 this, name, getter, setter, data, settings, attribute, signature); | 1671 this, name, getter, setter, data, settings, attribute, signature); |
| 1632 } | 1672 } |
| 1633 | 1673 |
| 1634 | 1674 |
| 1635 bool ObjectTemplate::SetAccessor(Handle<String> name, | |
| 1636 Handle<DeclaredAccessorDescriptor> descriptor, | |
| 1637 AccessControl settings, | |
| 1638 PropertyAttribute attribute, | |
| 1639 Handle<AccessorSignature> signature) { | |
| 1640 void* null = NULL; | |
| 1641 return ObjectTemplateSetAccessor( | |
| 1642 this, name, descriptor, null, null, settings, attribute, signature); | |
| 1643 } | |
| 1644 | |
| 1645 | |
| 1646 template< | 1675 template< |
| 1647 typename Getter, | 1676 typename Getter, |
| 1648 typename Setter, | 1677 typename Setter, |
| 1649 typename Query, | 1678 typename Query, |
| 1650 typename Deleter, | 1679 typename Deleter, |
| 1651 typename Enumerator> | 1680 typename Enumerator> |
| 1652 static void ObjectTemplateSetNamedPropertyHandler( | 1681 static void ObjectTemplateSetNamedPropertyHandler( |
| 1653 ObjectTemplate* object_template, | 1682 ObjectTemplate* object_template, |
| 1654 Getter getter, | 1683 Getter getter, |
| 1655 Setter setter, | 1684 Setter setter, |
| (...skipping 2157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3813 AccessorGetterCallback getter, | 3842 AccessorGetterCallback getter, |
| 3814 AccessorSetterCallback setter, | 3843 AccessorSetterCallback setter, |
| 3815 v8::Handle<Value> data, | 3844 v8::Handle<Value> data, |
| 3816 AccessControl settings, | 3845 AccessControl settings, |
| 3817 PropertyAttribute attributes) { | 3846 PropertyAttribute attributes) { |
| 3818 return ObjectSetAccessor( | 3847 return ObjectSetAccessor( |
| 3819 this, name, getter, setter, data, settings, attributes); | 3848 this, name, getter, setter, data, settings, attributes); |
| 3820 } | 3849 } |
| 3821 | 3850 |
| 3822 | 3851 |
| 3823 bool Object::SetAccessor(Handle<String> name, | 3852 bool Object::SetDeclaredAccessor(Handle<String> name, |
| 3824 Handle<DeclaredAccessorDescriptor> descriptor, | 3853 Handle<DeclaredAccessorDescriptor> descriptor, |
| 3825 AccessControl settings, | 3854 AccessControl settings, |
| 3826 PropertyAttribute attributes) { | 3855 PropertyAttribute attributes) { |
| 3827 void* null = NULL; | 3856 void* null = NULL; |
| 3828 return ObjectSetAccessor( | 3857 return ObjectSetAccessor( |
| 3829 this, name, descriptor, null, null, settings, attributes); | 3858 this, name, descriptor, null, null, settings, attributes); |
| 3830 } | 3859 } |
| 3831 | 3860 |
| 3832 | 3861 |
| 3833 bool v8::Object::HasOwnProperty(Handle<String> key) { | 3862 bool v8::Object::HasOwnProperty(Handle<String> key) { |
| 3834 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | 3863 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3835 ON_BAILOUT(isolate, "v8::Object::HasOwnProperty()", | 3864 ON_BAILOUT(isolate, "v8::Object::HasOwnProperty()", |
| 3836 return false); | 3865 return false); |
| (...skipping 1652 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5489 bool v8::V8::InitializeICU() { | 5518 bool v8::V8::InitializeICU() { |
| 5490 return i::InitializeICU(); | 5519 return i::InitializeICU(); |
| 5491 } | 5520 } |
| 5492 | 5521 |
| 5493 | 5522 |
| 5494 const char* v8::V8::GetVersion() { | 5523 const char* v8::V8::GetVersion() { |
| 5495 return i::Version::GetVersion(); | 5524 return i::Version::GetVersion(); |
| 5496 } | 5525 } |
| 5497 | 5526 |
| 5498 | 5527 |
| 5499 static i::Handle<i::FunctionTemplateInfo> | |
| 5500 EnsureConstructor(i::Handle<i::ObjectTemplateInfo> templ) { | |
| 5501 if (templ->constructor()->IsUndefined()) { | |
| 5502 Local<FunctionTemplate> constructor = FunctionTemplate::New(); | |
| 5503 Utils::OpenHandle(*constructor)->set_instance_template(*templ); | |
| 5504 templ->set_constructor(*Utils::OpenHandle(*constructor)); | |
| 5505 } | |
| 5506 return i::Handle<i::FunctionTemplateInfo>( | |
| 5507 i::FunctionTemplateInfo::cast(templ->constructor())); | |
| 5508 } | |
| 5509 | |
| 5510 | |
| 5511 static i::Handle<i::Context> CreateEnvironment( | 5528 static i::Handle<i::Context> CreateEnvironment( |
| 5512 i::Isolate* isolate, | 5529 i::Isolate* isolate, |
| 5513 v8::ExtensionConfiguration* extensions, | 5530 v8::ExtensionConfiguration* extensions, |
| 5514 v8::Handle<ObjectTemplate> global_template, | 5531 v8::Handle<ObjectTemplate> global_template, |
| 5515 v8::Handle<Value> global_object) { | 5532 v8::Handle<Value> global_object) { |
| 5516 i::Handle<i::Context> env; | 5533 i::Handle<i::Context> env; |
| 5517 | 5534 |
| 5518 // Enter V8 via an ENTER_V8 scope. | 5535 // Enter V8 via an ENTER_V8 scope. |
| 5519 { | 5536 { |
| 5520 ENTER_V8(isolate); | 5537 ENTER_V8(isolate); |
| 5521 v8::Handle<ObjectTemplate> proxy_template = global_template; | 5538 v8::Handle<ObjectTemplate> proxy_template = global_template; |
| 5522 i::Handle<i::FunctionTemplateInfo> proxy_constructor; | 5539 i::Handle<i::FunctionTemplateInfo> proxy_constructor; |
| 5523 i::Handle<i::FunctionTemplateInfo> global_constructor; | 5540 i::Handle<i::FunctionTemplateInfo> global_constructor; |
| 5524 | 5541 |
| 5525 if (!global_template.IsEmpty()) { | 5542 if (!global_template.IsEmpty()) { |
| 5526 // Make sure that the global_template has a constructor. | 5543 // Make sure that the global_template has a constructor. |
| 5527 global_constructor = | 5544 global_constructor = EnsureConstructor(*global_template); |
| 5528 EnsureConstructor(Utils::OpenHandle(*global_template)); | |
| 5529 | 5545 |
| 5530 // Create a fresh template for the global proxy object. | 5546 // Create a fresh template for the global proxy object. |
| 5531 proxy_template = ObjectTemplate::New(); | 5547 proxy_template = ObjectTemplate::New(); |
| 5532 proxy_constructor = | 5548 proxy_constructor = EnsureConstructor(*proxy_template); |
| 5533 EnsureConstructor(Utils::OpenHandle(*proxy_template)); | |
| 5534 | 5549 |
| 5535 // Set the global template to be the prototype template of | 5550 // Set the global template to be the prototype template of |
| 5536 // global proxy template. | 5551 // global proxy template. |
| 5537 proxy_constructor->set_prototype_template( | 5552 proxy_constructor->set_prototype_template( |
| 5538 *Utils::OpenHandle(*global_template)); | 5553 *Utils::OpenHandle(*global_template)); |
| 5539 | 5554 |
| 5540 // Migrate security handlers from global_template to | 5555 // Migrate security handlers from global_template to |
| 5541 // proxy_template. Temporarily removing access check | 5556 // proxy_template. Temporarily removing access check |
| 5542 // information from the global template. | 5557 // information from the global template. |
| 5543 if (!global_constructor->access_check_info()->IsUndefined()) { | 5558 if (!global_constructor->access_check_info()->IsUndefined()) { |
| (...skipping 2629 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8173 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); | 8188 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); |
| 8174 Address callback_address = | 8189 Address callback_address = |
| 8175 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 8190 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
| 8176 VMState<EXTERNAL> state(isolate); | 8191 VMState<EXTERNAL> state(isolate); |
| 8177 ExternalCallbackScope call_scope(isolate, callback_address); | 8192 ExternalCallbackScope call_scope(isolate, callback_address); |
| 8178 return callback(info); | 8193 return callback(info); |
| 8179 } | 8194 } |
| 8180 | 8195 |
| 8181 | 8196 |
| 8182 } } // namespace v8::internal | 8197 } } // namespace v8::internal |
| OLD | NEW |