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 1518 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1529 InitializeTemplate(obj, Consts::OBJECT_TEMPLATE); | 1529 InitializeTemplate(obj, Consts::OBJECT_TEMPLATE); |
1530 if (!constructor.IsEmpty()) | 1530 if (!constructor.IsEmpty()) |
1531 obj->set_constructor(*Utils::OpenHandle(*constructor)); | 1531 obj->set_constructor(*Utils::OpenHandle(*constructor)); |
1532 obj->set_internal_field_count(i::Smi::FromInt(0)); | 1532 obj->set_internal_field_count(i::Smi::FromInt(0)); |
1533 return Utils::ToLocal(obj); | 1533 return Utils::ToLocal(obj); |
1534 } | 1534 } |
1535 | 1535 |
1536 | 1536 |
1537 // Ensure that the object template has a constructor. If no | 1537 // Ensure that the object template has a constructor. If no |
1538 // constructor is available we create one. | 1538 // constructor is available we create one. |
1539 static void EnsureConstructor(ObjectTemplate* object_template) { | 1539 static i::Handle<i::FunctionTemplateInfo> EnsureConstructor( |
1540 if (Utils::OpenHandle(object_template)->constructor()->IsUndefined()) { | 1540 ObjectTemplate* object_template) { |
1541 Local<FunctionTemplate> templ = FunctionTemplate::New(); | 1541 i::Object* obj = Utils::OpenHandle(object_template)->constructor(); |
1542 i::Handle<i::FunctionTemplateInfo> constructor = Utils::OpenHandle(*templ); | 1542 if (!obj ->IsUndefined()) { |
1543 constructor->set_instance_template(*Utils::OpenHandle(object_template)); | 1543 i::FunctionTemplateInfo* info = i::FunctionTemplateInfo::cast(obj); |
1544 Utils::OpenHandle(object_template)->set_constructor(*constructor); | 1544 return i::Handle<i::FunctionTemplateInfo>(info, info->GetIsolate()); |
1545 } | 1545 } |
| 1546 Local<FunctionTemplate> templ = FunctionTemplate::New(); |
| 1547 i::Handle<i::FunctionTemplateInfo> constructor = Utils::OpenHandle(*templ); |
| 1548 constructor->set_instance_template(*Utils::OpenHandle(object_template)); |
| 1549 Utils::OpenHandle(object_template)->set_constructor(*constructor); |
| 1550 return constructor; |
1546 } | 1551 } |
1547 | 1552 |
1548 | 1553 |
1549 static inline void AddPropertyToFunctionTemplate( | 1554 static inline void AddPropertyToTemplate( |
1550 i::Handle<i::FunctionTemplateInfo> cons, | 1555 i::Handle<i::TemplateInfo> info, |
1551 i::Handle<i::AccessorInfo> obj) { | 1556 i::Handle<i::AccessorInfo> obj) { |
1552 i::Handle<i::Object> list(cons->property_accessors(), cons->GetIsolate()); | 1557 i::Handle<i::Object> list(info->property_accessors(), info->GetIsolate()); |
1553 if (list->IsUndefined()) { | 1558 if (list->IsUndefined()) { |
1554 list = NeanderArray().value(); | 1559 list = NeanderArray().value(); |
1555 cons->set_property_accessors(*list); | 1560 info->set_property_accessors(*list); |
1556 } | 1561 } |
1557 NeanderArray array(list); | 1562 NeanderArray array(list); |
1558 array.add(obj); | 1563 array.add(obj); |
1559 } | 1564 } |
1560 | 1565 |
1561 | 1566 |
1562 template<typename Setter, typename Getter, typename Data> | 1567 static inline i::Handle<i::TemplateInfo> GetTemplateInfo( |
1563 static bool ObjectTemplateSetAccessor( | 1568 Template* template_obj) { |
1564 ObjectTemplate* object_template, | 1569 return Utils::OpenHandle(template_obj); |
1565 v8::Handle<String> name, | 1570 } |
| 1571 |
| 1572 |
| 1573 // TODO(dcarney): remove this with ObjectTemplate::SetAccessor |
| 1574 static inline i::Handle<i::TemplateInfo> GetTemplateInfo( |
| 1575 ObjectTemplate* object_template) { |
| 1576 EnsureConstructor(object_template); |
| 1577 return Utils::OpenHandle(object_template); |
| 1578 } |
| 1579 |
| 1580 |
| 1581 template<typename Setter, typename Getter, typename Data, typename Template> |
| 1582 static bool TemplateSetAccessor( |
| 1583 Template* template_obj, |
| 1584 v8::Local<String> name, |
1566 Getter getter, | 1585 Getter getter, |
1567 Setter setter, | 1586 Setter setter, |
1568 Data data, | 1587 Data data, |
1569 AccessControl settings, | 1588 AccessControl settings, |
1570 PropertyAttribute attribute, | 1589 PropertyAttribute attribute, |
1571 v8::Handle<AccessorSignature> signature) { | 1590 v8::Local<AccessorSignature> signature) { |
1572 i::Isolate* isolate = Utils::OpenHandle(object_template)->GetIsolate(); | 1591 i::Isolate* isolate = Utils::OpenHandle(template_obj)->GetIsolate(); |
1573 if (IsDeadCheck(isolate, "v8::ObjectTemplate::SetAccessor()")) return false; | 1592 if (IsDeadCheck(isolate, "v8::ObjectTemplate::SetAccessor()")) return false; |
1574 ENTER_V8(isolate); | 1593 ENTER_V8(isolate); |
1575 i::HandleScope scope(isolate); | 1594 i::HandleScope scope(isolate); |
1576 EnsureConstructor(object_template); | |
1577 i::FunctionTemplateInfo* constructor = i::FunctionTemplateInfo::cast( | |
1578 Utils::OpenHandle(object_template)->constructor()); | |
1579 i::Handle<i::FunctionTemplateInfo> cons(constructor); | |
1580 i::Handle<i::AccessorInfo> obj = MakeAccessorInfo( | 1595 i::Handle<i::AccessorInfo> obj = MakeAccessorInfo( |
1581 name, getter, setter, data, settings, attribute, signature); | 1596 name, getter, setter, data, settings, attribute, signature); |
1582 if (obj.is_null()) return false; | 1597 if (obj.is_null()) return false; |
1583 AddPropertyToFunctionTemplate(cons, obj); | 1598 i::Handle<i::TemplateInfo> info = GetTemplateInfo(template_obj); |
| 1599 AddPropertyToTemplate(info, obj); |
1584 return true; | 1600 return true; |
1585 } | 1601 } |
1586 | 1602 |
1587 | 1603 |
| 1604 bool Template::SetDeclaredAccessor( |
| 1605 Local<String> name, |
| 1606 Local<DeclaredAccessorDescriptor> descriptor, |
| 1607 AccessControl settings, |
| 1608 PropertyAttribute attribute, |
| 1609 Local<AccessorSignature> signature) { |
| 1610 void* null = NULL; |
| 1611 return TemplateSetAccessor( |
| 1612 this, name, descriptor, null, null, settings, attribute, signature); |
| 1613 } |
| 1614 |
| 1615 |
| 1616 void Template::SetNativeDataProperty(v8::Local<String> name, |
| 1617 AccessorGetterCallback getter, |
| 1618 AccessorSetterCallback setter, |
| 1619 v8::Handle<Value> data, |
| 1620 AccessControl settings, |
| 1621 PropertyAttribute attribute, |
| 1622 v8::Local<AccessorSignature> signature) { |
| 1623 TemplateSetAccessor( |
| 1624 this, name, getter, setter, data, settings, attribute, signature); |
| 1625 } |
| 1626 |
| 1627 |
1588 void ObjectTemplate::SetAccessor(v8::Handle<String> name, | 1628 void ObjectTemplate::SetAccessor(v8::Handle<String> name, |
1589 AccessorGetter getter, | 1629 AccessorGetter getter, |
1590 AccessorSetter setter, | 1630 AccessorSetter setter, |
1591 v8::Handle<Value> data, | 1631 v8::Handle<Value> data, |
1592 AccessControl settings, | 1632 AccessControl settings, |
1593 PropertyAttribute attribute, | 1633 PropertyAttribute attribute, |
1594 v8::Handle<AccessorSignature> signature) { | 1634 v8::Handle<AccessorSignature> signature) { |
1595 ObjectTemplateSetAccessor( | 1635 TemplateSetAccessor( |
1596 this, name, getter, setter, data, settings, attribute, signature); | 1636 this, name, getter, setter, data, settings, attribute, signature); |
1597 } | 1637 } |
1598 | 1638 |
1599 | 1639 |
1600 void ObjectTemplate::SetAccessor(v8::Handle<String> name, | 1640 void ObjectTemplate::SetAccessor(v8::Handle<String> name, |
1601 AccessorGetterCallback getter, | 1641 AccessorGetterCallback getter, |
1602 AccessorSetterCallback setter, | 1642 AccessorSetterCallback setter, |
1603 v8::Handle<Value> data, | 1643 v8::Handle<Value> data, |
1604 AccessControl settings, | 1644 AccessControl settings, |
1605 PropertyAttribute attribute, | 1645 PropertyAttribute attribute, |
1606 v8::Handle<AccessorSignature> signature) { | 1646 v8::Handle<AccessorSignature> signature) { |
1607 ObjectTemplateSetAccessor( | 1647 TemplateSetAccessor( |
1608 this, name, getter, setter, data, settings, attribute, signature); | 1648 this, name, getter, setter, data, settings, attribute, signature); |
1609 } | 1649 } |
1610 | 1650 |
1611 | 1651 |
1612 bool ObjectTemplate::SetAccessor(Handle<String> name, | |
1613 Handle<DeclaredAccessorDescriptor> descriptor, | |
1614 AccessControl settings, | |
1615 PropertyAttribute attribute, | |
1616 Handle<AccessorSignature> signature) { | |
1617 void* null = NULL; | |
1618 return ObjectTemplateSetAccessor( | |
1619 this, name, descriptor, null, null, settings, attribute, signature); | |
1620 } | |
1621 | |
1622 | |
1623 template< | 1652 template< |
1624 typename Getter, | 1653 typename Getter, |
1625 typename Setter, | 1654 typename Setter, |
1626 typename Query, | 1655 typename Query, |
1627 typename Deleter, | 1656 typename Deleter, |
1628 typename Enumerator> | 1657 typename Enumerator> |
1629 static void ObjectTemplateSetNamedPropertyHandler( | 1658 static void ObjectTemplateSetNamedPropertyHandler( |
1630 ObjectTemplate* object_template, | 1659 ObjectTemplate* object_template, |
1631 Getter getter, | 1660 Getter getter, |
1632 Setter setter, | 1661 Setter setter, |
(...skipping 2157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3790 AccessorGetterCallback getter, | 3819 AccessorGetterCallback getter, |
3791 AccessorSetterCallback setter, | 3820 AccessorSetterCallback setter, |
3792 v8::Handle<Value> data, | 3821 v8::Handle<Value> data, |
3793 AccessControl settings, | 3822 AccessControl settings, |
3794 PropertyAttribute attributes) { | 3823 PropertyAttribute attributes) { |
3795 return ObjectSetAccessor( | 3824 return ObjectSetAccessor( |
3796 this, name, getter, setter, data, settings, attributes); | 3825 this, name, getter, setter, data, settings, attributes); |
3797 } | 3826 } |
3798 | 3827 |
3799 | 3828 |
3800 bool Object::SetAccessor(Handle<String> name, | 3829 bool Object::SetDeclaredAccessor(Local<String> name, |
3801 Handle<DeclaredAccessorDescriptor> descriptor, | 3830 Local<DeclaredAccessorDescriptor> descriptor, |
3802 AccessControl settings, | 3831 AccessControl settings, |
3803 PropertyAttribute attributes) { | 3832 PropertyAttribute attributes) { |
3804 void* null = NULL; | 3833 void* null = NULL; |
3805 return ObjectSetAccessor( | 3834 return ObjectSetAccessor( |
3806 this, name, descriptor, null, null, settings, attributes); | 3835 this, name, descriptor, null, null, settings, attributes); |
3807 } | 3836 } |
3808 | 3837 |
3809 | 3838 |
3810 bool v8::Object::HasOwnProperty(Handle<String> key) { | 3839 bool v8::Object::HasOwnProperty(Handle<String> key) { |
3811 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | 3840 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
3812 ON_BAILOUT(isolate, "v8::Object::HasOwnProperty()", | 3841 ON_BAILOUT(isolate, "v8::Object::HasOwnProperty()", |
3813 return false); | 3842 return false); |
(...skipping 1652 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5466 bool v8::V8::InitializeICU() { | 5495 bool v8::V8::InitializeICU() { |
5467 return i::InitializeICU(); | 5496 return i::InitializeICU(); |
5468 } | 5497 } |
5469 | 5498 |
5470 | 5499 |
5471 const char* v8::V8::GetVersion() { | 5500 const char* v8::V8::GetVersion() { |
5472 return i::Version::GetVersion(); | 5501 return i::Version::GetVersion(); |
5473 } | 5502 } |
5474 | 5503 |
5475 | 5504 |
5476 static i::Handle<i::FunctionTemplateInfo> | |
5477 EnsureConstructor(i::Handle<i::ObjectTemplateInfo> templ) { | |
5478 if (templ->constructor()->IsUndefined()) { | |
5479 Local<FunctionTemplate> constructor = FunctionTemplate::New(); | |
5480 Utils::OpenHandle(*constructor)->set_instance_template(*templ); | |
5481 templ->set_constructor(*Utils::OpenHandle(*constructor)); | |
5482 } | |
5483 return i::Handle<i::FunctionTemplateInfo>( | |
5484 i::FunctionTemplateInfo::cast(templ->constructor())); | |
5485 } | |
5486 | |
5487 | |
5488 static i::Handle<i::Context> CreateEnvironment( | 5505 static i::Handle<i::Context> CreateEnvironment( |
5489 i::Isolate* isolate, | 5506 i::Isolate* isolate, |
5490 v8::ExtensionConfiguration* extensions, | 5507 v8::ExtensionConfiguration* extensions, |
5491 v8::Handle<ObjectTemplate> global_template, | 5508 v8::Handle<ObjectTemplate> global_template, |
5492 v8::Handle<Value> global_object) { | 5509 v8::Handle<Value> global_object) { |
5493 i::Handle<i::Context> env; | 5510 i::Handle<i::Context> env; |
5494 | 5511 |
5495 // Enter V8 via an ENTER_V8 scope. | 5512 // Enter V8 via an ENTER_V8 scope. |
5496 { | 5513 { |
5497 ENTER_V8(isolate); | 5514 ENTER_V8(isolate); |
5498 v8::Handle<ObjectTemplate> proxy_template = global_template; | 5515 v8::Handle<ObjectTemplate> proxy_template = global_template; |
5499 i::Handle<i::FunctionTemplateInfo> proxy_constructor; | 5516 i::Handle<i::FunctionTemplateInfo> proxy_constructor; |
5500 i::Handle<i::FunctionTemplateInfo> global_constructor; | 5517 i::Handle<i::FunctionTemplateInfo> global_constructor; |
5501 | 5518 |
5502 if (!global_template.IsEmpty()) { | 5519 if (!global_template.IsEmpty()) { |
5503 // Make sure that the global_template has a constructor. | 5520 // Make sure that the global_template has a constructor. |
5504 global_constructor = | 5521 global_constructor = EnsureConstructor(*global_template); |
5505 EnsureConstructor(Utils::OpenHandle(*global_template)); | |
5506 | 5522 |
5507 // Create a fresh template for the global proxy object. | 5523 // Create a fresh template for the global proxy object. |
5508 proxy_template = ObjectTemplate::New(); | 5524 proxy_template = ObjectTemplate::New(); |
5509 proxy_constructor = | 5525 proxy_constructor = EnsureConstructor(*proxy_template); |
5510 EnsureConstructor(Utils::OpenHandle(*proxy_template)); | |
5511 | 5526 |
5512 // Set the global template to be the prototype template of | 5527 // Set the global template to be the prototype template of |
5513 // global proxy template. | 5528 // global proxy template. |
5514 proxy_constructor->set_prototype_template( | 5529 proxy_constructor->set_prototype_template( |
5515 *Utils::OpenHandle(*global_template)); | 5530 *Utils::OpenHandle(*global_template)); |
5516 | 5531 |
5517 // Migrate security handlers from global_template to | 5532 // Migrate security handlers from global_template to |
5518 // proxy_template. Temporarily removing access check | 5533 // proxy_template. Temporarily removing access check |
5519 // information from the global template. | 5534 // information from the global template. |
5520 if (!global_constructor->access_check_info()->IsUndefined()) { | 5535 if (!global_constructor->access_check_info()->IsUndefined()) { |
(...skipping 2629 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8150 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); | 8165 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); |
8151 Address callback_address = | 8166 Address callback_address = |
8152 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 8167 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
8153 VMState<EXTERNAL> state(isolate); | 8168 VMState<EXTERNAL> state(isolate); |
8154 ExternalCallbackScope call_scope(isolate, callback_address); | 8169 ExternalCallbackScope call_scope(isolate, callback_address); |
8155 return callback(info); | 8170 return callback(info); |
8156 } | 8171 } |
8157 | 8172 |
8158 | 8173 |
8159 } } // namespace v8::internal | 8174 } } // namespace v8::internal |
OLD | NEW |