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 1420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1431 InitializeTemplate(obj, Consts::OBJECT_TEMPLATE); | 1431 InitializeTemplate(obj, Consts::OBJECT_TEMPLATE); |
1432 if (!constructor.IsEmpty()) | 1432 if (!constructor.IsEmpty()) |
1433 obj->set_constructor(*Utils::OpenHandle(*constructor)); | 1433 obj->set_constructor(*Utils::OpenHandle(*constructor)); |
1434 obj->set_internal_field_count(i::Smi::FromInt(0)); | 1434 obj->set_internal_field_count(i::Smi::FromInt(0)); |
1435 return Utils::ToLocal(obj); | 1435 return Utils::ToLocal(obj); |
1436 } | 1436 } |
1437 | 1437 |
1438 | 1438 |
1439 // Ensure that the object template has a constructor. If no | 1439 // Ensure that the object template has a constructor. If no |
1440 // constructor is available we create one. | 1440 // constructor is available we create one. |
1441 static void EnsureConstructor(ObjectTemplate* object_template) { | 1441 static i::Handle<i::FunctionTemplateInfo> EnsureConstructor( |
1442 if (Utils::OpenHandle(object_template)->constructor()->IsUndefined()) { | 1442 ObjectTemplate* object_template) { |
1443 Local<FunctionTemplate> templ = FunctionTemplate::New(); | 1443 i::Object* obj = Utils::OpenHandle(object_template)->constructor(); |
1444 i::Handle<i::FunctionTemplateInfo> constructor = Utils::OpenHandle(*templ); | 1444 if (!obj ->IsUndefined()) { |
1445 constructor->set_instance_template(*Utils::OpenHandle(object_template)); | 1445 i::FunctionTemplateInfo* info = i::FunctionTemplateInfo::cast(obj); |
1446 Utils::OpenHandle(object_template)->set_constructor(*constructor); | 1446 return i::Handle<i::FunctionTemplateInfo>(info, info->GetIsolate()); |
1447 } | 1447 } |
| 1448 Local<FunctionTemplate> templ = FunctionTemplate::New(); |
| 1449 i::Handle<i::FunctionTemplateInfo> constructor = Utils::OpenHandle(*templ); |
| 1450 constructor->set_instance_template(*Utils::OpenHandle(object_template)); |
| 1451 Utils::OpenHandle(object_template)->set_constructor(*constructor); |
| 1452 return constructor; |
1448 } | 1453 } |
1449 | 1454 |
1450 | 1455 |
1451 static inline void AddPropertyToFunctionTemplate( | 1456 static inline void AddPropertyToTemplate( |
1452 i::Handle<i::FunctionTemplateInfo> cons, | 1457 i::Handle<i::TemplateInfo> info, |
1453 i::Handle<i::AccessorInfo> obj) { | 1458 i::Handle<i::AccessorInfo> obj) { |
1454 i::Handle<i::Object> list(cons->property_accessors(), cons->GetIsolate()); | 1459 i::Handle<i::Object> list(info->property_accessors(), info->GetIsolate()); |
1455 if (list->IsUndefined()) { | 1460 if (list->IsUndefined()) { |
1456 list = NeanderArray().value(); | 1461 list = NeanderArray().value(); |
1457 cons->set_property_accessors(*list); | 1462 info->set_property_accessors(*list); |
1458 } | 1463 } |
1459 NeanderArray array(list); | 1464 NeanderArray array(list); |
1460 array.add(obj); | 1465 array.add(obj); |
1461 } | 1466 } |
1462 | 1467 |
1463 | 1468 |
1464 template<typename Setter, typename Getter, typename Data> | 1469 static inline i::Handle<i::TemplateInfo> GetTemplateInfo( |
1465 static bool ObjectTemplateSetAccessor( | 1470 Template* template_obj) { |
1466 ObjectTemplate* object_template, | 1471 return Utils::OpenHandle(template_obj); |
1467 v8::Handle<String> name, | 1472 } |
| 1473 |
| 1474 |
| 1475 // TODO(dcarney): remove this with ObjectTemplate::SetAccessor |
| 1476 static inline i::Handle<i::TemplateInfo> GetTemplateInfo( |
| 1477 ObjectTemplate* object_template) { |
| 1478 EnsureConstructor(object_template); |
| 1479 return Utils::OpenHandle(object_template); |
| 1480 } |
| 1481 |
| 1482 |
| 1483 template<typename Setter, typename Getter, typename Data, typename Template> |
| 1484 static bool TemplateSetAccessor( |
| 1485 Template* template_obj, |
| 1486 v8::Local<String> name, |
1468 Getter getter, | 1487 Getter getter, |
1469 Setter setter, | 1488 Setter setter, |
1470 Data data, | 1489 Data data, |
1471 AccessControl settings, | 1490 AccessControl settings, |
1472 PropertyAttribute attribute, | 1491 PropertyAttribute attribute, |
1473 v8::Handle<AccessorSignature> signature) { | 1492 v8::Local<AccessorSignature> signature) { |
1474 i::Isolate* isolate = Utils::OpenHandle(object_template)->GetIsolate(); | 1493 i::Isolate* isolate = Utils::OpenHandle(template_obj)->GetIsolate(); |
1475 if (IsDeadCheck(isolate, "v8::ObjectTemplate::SetAccessor()")) return false; | 1494 if (IsDeadCheck(isolate, "v8::ObjectTemplate::SetAccessor()")) return false; |
1476 ENTER_V8(isolate); | 1495 ENTER_V8(isolate); |
1477 i::HandleScope scope(isolate); | 1496 i::HandleScope scope(isolate); |
1478 EnsureConstructor(object_template); | |
1479 i::FunctionTemplateInfo* constructor = i::FunctionTemplateInfo::cast( | |
1480 Utils::OpenHandle(object_template)->constructor()); | |
1481 i::Handle<i::FunctionTemplateInfo> cons(constructor); | |
1482 i::Handle<i::AccessorInfo> obj = MakeAccessorInfo( | 1497 i::Handle<i::AccessorInfo> obj = MakeAccessorInfo( |
1483 name, getter, setter, data, settings, attribute, signature); | 1498 name, getter, setter, data, settings, attribute, signature); |
1484 if (obj.is_null()) return false; | 1499 if (obj.is_null()) return false; |
1485 AddPropertyToFunctionTemplate(cons, obj); | 1500 i::Handle<i::TemplateInfo> info = GetTemplateInfo(template_obj); |
| 1501 AddPropertyToTemplate(info, obj); |
1486 return true; | 1502 return true; |
1487 } | 1503 } |
1488 | 1504 |
1489 | 1505 |
| 1506 bool Template::SetDeclaredAccessor( |
| 1507 Local<String> name, |
| 1508 Local<DeclaredAccessorDescriptor> descriptor, |
| 1509 PropertyAttribute attribute, |
| 1510 Local<AccessorSignature> signature, |
| 1511 AccessControl settings) { |
| 1512 void* null = NULL; |
| 1513 return TemplateSetAccessor( |
| 1514 this, name, descriptor, null, null, settings, attribute, signature); |
| 1515 } |
| 1516 |
| 1517 |
| 1518 void Template::SetNativeDataProperty(v8::Local<String> name, |
| 1519 AccessorGetterCallback getter, |
| 1520 AccessorSetterCallback setter, |
| 1521 v8::Handle<Value> data, |
| 1522 PropertyAttribute attribute, |
| 1523 v8::Local<AccessorSignature> signature, |
| 1524 AccessControl settings) { |
| 1525 TemplateSetAccessor( |
| 1526 this, name, getter, setter, data, settings, attribute, signature); |
| 1527 } |
| 1528 |
| 1529 |
1490 void ObjectTemplate::SetAccessor(v8::Handle<String> name, | 1530 void ObjectTemplate::SetAccessor(v8::Handle<String> name, |
1491 AccessorGetterCallback getter, | 1531 AccessorGetterCallback getter, |
1492 AccessorSetterCallback setter, | 1532 AccessorSetterCallback setter, |
1493 v8::Handle<Value> data, | 1533 v8::Handle<Value> data, |
1494 AccessControl settings, | 1534 AccessControl settings, |
1495 PropertyAttribute attribute, | 1535 PropertyAttribute attribute, |
1496 v8::Handle<AccessorSignature> signature) { | 1536 v8::Handle<AccessorSignature> signature) { |
1497 ObjectTemplateSetAccessor( | 1537 TemplateSetAccessor( |
1498 this, name, getter, setter, data, settings, attribute, signature); | 1538 this, name, getter, setter, data, settings, attribute, signature); |
1499 } | 1539 } |
1500 | 1540 |
1501 | 1541 |
1502 bool ObjectTemplate::SetAccessor(Handle<String> name, | |
1503 Handle<DeclaredAccessorDescriptor> descriptor, | |
1504 AccessControl settings, | |
1505 PropertyAttribute attribute, | |
1506 Handle<AccessorSignature> signature) { | |
1507 void* null = NULL; | |
1508 return ObjectTemplateSetAccessor( | |
1509 this, name, descriptor, null, null, settings, attribute, signature); | |
1510 } | |
1511 | |
1512 | |
1513 void ObjectTemplate::SetNamedPropertyHandler( | 1542 void ObjectTemplate::SetNamedPropertyHandler( |
1514 NamedPropertyGetterCallback getter, | 1543 NamedPropertyGetterCallback getter, |
1515 NamedPropertySetterCallback setter, | 1544 NamedPropertySetterCallback setter, |
1516 NamedPropertyQueryCallback query, | 1545 NamedPropertyQueryCallback query, |
1517 NamedPropertyDeleterCallback remover, | 1546 NamedPropertyDeleterCallback remover, |
1518 NamedPropertyEnumeratorCallback enumerator, | 1547 NamedPropertyEnumeratorCallback enumerator, |
1519 Handle<Value> data) { | 1548 Handle<Value> data) { |
1520 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | 1549 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
1521 if (IsDeadCheck(isolate, "v8::ObjectTemplate::SetNamedPropertyHandler()")) { | 1550 if (IsDeadCheck(isolate, "v8::ObjectTemplate::SetNamedPropertyHandler()")) { |
1522 return; | 1551 return; |
(...skipping 2108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3631 AccessorGetterCallback getter, | 3660 AccessorGetterCallback getter, |
3632 AccessorSetterCallback setter, | 3661 AccessorSetterCallback setter, |
3633 v8::Handle<Value> data, | 3662 v8::Handle<Value> data, |
3634 AccessControl settings, | 3663 AccessControl settings, |
3635 PropertyAttribute attributes) { | 3664 PropertyAttribute attributes) { |
3636 return ObjectSetAccessor( | 3665 return ObjectSetAccessor( |
3637 this, name, getter, setter, data, settings, attributes); | 3666 this, name, getter, setter, data, settings, attributes); |
3638 } | 3667 } |
3639 | 3668 |
3640 | 3669 |
3641 bool Object::SetAccessor(Handle<String> name, | 3670 bool Object::SetDeclaredAccessor(Local<String> name, |
3642 Handle<DeclaredAccessorDescriptor> descriptor, | 3671 Local<DeclaredAccessorDescriptor> descriptor, |
3643 AccessControl settings, | 3672 PropertyAttribute attributes, |
3644 PropertyAttribute attributes) { | 3673 AccessControl settings) { |
3645 void* null = NULL; | 3674 void* null = NULL; |
3646 return ObjectSetAccessor( | 3675 return ObjectSetAccessor( |
3647 this, name, descriptor, null, null, settings, attributes); | 3676 this, name, descriptor, null, null, settings, attributes); |
3648 } | 3677 } |
3649 | 3678 |
3650 | 3679 |
3651 bool v8::Object::HasOwnProperty(Handle<String> key) { | 3680 bool v8::Object::HasOwnProperty(Handle<String> key) { |
3652 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | 3681 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
3653 ON_BAILOUT(isolate, "v8::Object::HasOwnProperty()", | 3682 ON_BAILOUT(isolate, "v8::Object::HasOwnProperty()", |
3654 return false); | 3683 return false); |
(...skipping 1652 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5307 bool v8::V8::InitializeICU() { | 5336 bool v8::V8::InitializeICU() { |
5308 return i::InitializeICU(); | 5337 return i::InitializeICU(); |
5309 } | 5338 } |
5310 | 5339 |
5311 | 5340 |
5312 const char* v8::V8::GetVersion() { | 5341 const char* v8::V8::GetVersion() { |
5313 return i::Version::GetVersion(); | 5342 return i::Version::GetVersion(); |
5314 } | 5343 } |
5315 | 5344 |
5316 | 5345 |
5317 static i::Handle<i::FunctionTemplateInfo> | |
5318 EnsureConstructor(i::Handle<i::ObjectTemplateInfo> templ) { | |
5319 if (templ->constructor()->IsUndefined()) { | |
5320 Local<FunctionTemplate> constructor = FunctionTemplate::New(); | |
5321 Utils::OpenHandle(*constructor)->set_instance_template(*templ); | |
5322 templ->set_constructor(*Utils::OpenHandle(*constructor)); | |
5323 } | |
5324 return i::Handle<i::FunctionTemplateInfo>( | |
5325 i::FunctionTemplateInfo::cast(templ->constructor())); | |
5326 } | |
5327 | |
5328 | |
5329 static i::Handle<i::Context> CreateEnvironment( | 5346 static i::Handle<i::Context> CreateEnvironment( |
5330 i::Isolate* isolate, | 5347 i::Isolate* isolate, |
5331 v8::ExtensionConfiguration* extensions, | 5348 v8::ExtensionConfiguration* extensions, |
5332 v8::Handle<ObjectTemplate> global_template, | 5349 v8::Handle<ObjectTemplate> global_template, |
5333 v8::Handle<Value> global_object) { | 5350 v8::Handle<Value> global_object) { |
5334 i::Handle<i::Context> env; | 5351 i::Handle<i::Context> env; |
5335 | 5352 |
5336 // Enter V8 via an ENTER_V8 scope. | 5353 // Enter V8 via an ENTER_V8 scope. |
5337 { | 5354 { |
5338 ENTER_V8(isolate); | 5355 ENTER_V8(isolate); |
5339 v8::Handle<ObjectTemplate> proxy_template = global_template; | 5356 v8::Handle<ObjectTemplate> proxy_template = global_template; |
5340 i::Handle<i::FunctionTemplateInfo> proxy_constructor; | 5357 i::Handle<i::FunctionTemplateInfo> proxy_constructor; |
5341 i::Handle<i::FunctionTemplateInfo> global_constructor; | 5358 i::Handle<i::FunctionTemplateInfo> global_constructor; |
5342 | 5359 |
5343 if (!global_template.IsEmpty()) { | 5360 if (!global_template.IsEmpty()) { |
5344 // Make sure that the global_template has a constructor. | 5361 // Make sure that the global_template has a constructor. |
5345 global_constructor = | 5362 global_constructor = EnsureConstructor(*global_template); |
5346 EnsureConstructor(Utils::OpenHandle(*global_template)); | |
5347 | 5363 |
5348 // Create a fresh template for the global proxy object. | 5364 // Create a fresh template for the global proxy object. |
5349 proxy_template = ObjectTemplate::New(); | 5365 proxy_template = ObjectTemplate::New(); |
5350 proxy_constructor = | 5366 proxy_constructor = EnsureConstructor(*proxy_template); |
5351 EnsureConstructor(Utils::OpenHandle(*proxy_template)); | |
5352 | 5367 |
5353 // Set the global template to be the prototype template of | 5368 // Set the global template to be the prototype template of |
5354 // global proxy template. | 5369 // global proxy template. |
5355 proxy_constructor->set_prototype_template( | 5370 proxy_constructor->set_prototype_template( |
5356 *Utils::OpenHandle(*global_template)); | 5371 *Utils::OpenHandle(*global_template)); |
5357 | 5372 |
5358 // Migrate security handlers from global_template to | 5373 // Migrate security handlers from global_template to |
5359 // proxy_template. Temporarily removing access check | 5374 // proxy_template. Temporarily removing access check |
5360 // information from the global template. | 5375 // information from the global template. |
5361 if (!global_constructor->access_check_info()->IsUndefined()) { | 5376 if (!global_constructor->access_check_info()->IsUndefined()) { |
(...skipping 2505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7867 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); | 7882 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); |
7868 Address callback_address = | 7883 Address callback_address = |
7869 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 7884 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
7870 VMState<EXTERNAL> state(isolate); | 7885 VMState<EXTERNAL> state(isolate); |
7871 ExternalCallbackScope call_scope(isolate, callback_address); | 7886 ExternalCallbackScope call_scope(isolate, callback_address); |
7872 return callback(info); | 7887 return callback(info); |
7873 } | 7888 } |
7874 | 7889 |
7875 | 7890 |
7876 } } // namespace v8::internal | 7891 } } // namespace v8::internal |
OLD | NEW |