Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(20)

Side by Side Diff: include/v8.h

Issue 12297012: Runtime version of declarative native accessors. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | src/api.cc » ('j') | src/api.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 1512 matching lines...) Expand 10 before | Expand all | Expand 10 after
1523 */ 1523 */
1524 typedef Handle<Value> (*AccessorGetter)(Local<String> property, 1524 typedef Handle<Value> (*AccessorGetter)(Local<String> property,
1525 const AccessorInfo& info); 1525 const AccessorInfo& info);
1526 1526
1527 1527
1528 typedef void (*AccessorSetter)(Local<String> property, 1528 typedef void (*AccessorSetter)(Local<String> property,
1529 Local<Value> value, 1529 Local<Value> value,
1530 const AccessorInfo& info); 1530 const AccessorInfo& info);
1531 1531
1532 1532
1533 enum AccessorDescriptorType {
1534 kDescriptorPointerCompare,
1535 kDescriptorBitmaskCompare,
1536 kDescriptorPrimitiveValue,
1537 kDescriptorPointerDereference,
1538 kDescriptorInternalFieldDereference
1539 };
1540
1541
1542 enum AccessorDescriptorDataType {
1543 kDescriptorBoolType,
1544 kDescriptorInt8Type, kDescriptorUint8Type,
1545 kDescriptorInt16Type, kDescriptorUint16Type,
1546 kDescriptorInt32Type, kDescriptorUint32Type,
1547 kDescriptorFloatType, kDescriptorDoubleType
1548 };
1549
1550
1551 struct BitmaskCompareDescriptor {
1552 uint32_t bitmask;
1553 uint32_t compare_value;
1554 uint8_t size; // Must be in {1,2,4}.
1555 };
1556
1557
1558 struct PointerCompareDescriptor {
1559 void* compare_value;
1560 };
1561
1562
1563 struct PrimitiveValueDescriptor {
1564 AccessorDescriptorDataType data_type;
1565 uint8_t bool_offset; // Must be in [0,7], used for kDescriptorBoolType.
1566 };
1567
1568
1569 struct AccessorDescriptor {
Sven Panne 2013/02/19 08:41:16 I'm not totally happy with the way this algebraic
1570 uint8_t internal_field; // Ignored for kDescriptorPointerDereference.
1571 int16_t byte_offset;
1572 AccessorDescriptorType type;
1573 union {
1574 AccessorDescriptor* derefence_descriptor;
1575 struct BitmaskCompareDescriptor bitmask_compare_descriptor;
1576 struct PointerCompareDescriptor pointer_compare_descriptor;
1577 struct PrimitiveValueDescriptor primitive_value_descriptor;
1578 };
1579 };
1580
1581
1533 /** 1582 /**
1534 * Access control specifications. 1583 * Access control specifications.
1535 * 1584 *
1536 * Some accessors should be accessible across contexts. These 1585 * Some accessors should be accessible across contexts. These
1537 * accessors have an explicit access control parameter which specifies 1586 * accessors have an explicit access control parameter which specifies
1538 * the kind of cross-context access that should be allowed. 1587 * the kind of cross-context access that should be allowed.
1539 * 1588 *
1540 * Additionally, for security, accessors can prohibit overwriting by 1589 * Additionally, for security, accessors can prohibit overwriting by
1541 * accessors defined in JavaScript. For objects that have such 1590 * accessors defined in JavaScript. For objects that have such
1542 * accessors either locally or in their prototype chain it is not 1591 * accessors either locally or in their prototype chain it is not
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
1599 1648
1600 bool Delete(uint32_t index); 1649 bool Delete(uint32_t index);
1601 1650
1602 bool SetAccessor(Handle<String> name, 1651 bool SetAccessor(Handle<String> name,
1603 AccessorGetter getter, 1652 AccessorGetter getter,
1604 AccessorSetter setter = 0, 1653 AccessorSetter setter = 0,
1605 Handle<Value> data = Handle<Value>(), 1654 Handle<Value> data = Handle<Value>(),
1606 AccessControl settings = DEFAULT, 1655 AccessControl settings = DEFAULT,
1607 PropertyAttribute attribute = None); 1656 PropertyAttribute attribute = None);
1608 1657
1658 bool SetAccessor(Handle<String> name,
1659 const AccessorDescriptor* descriptor,
1660 AccessControl settings = DEFAULT,
1661 PropertyAttribute attribute = None);
1662
1609 /** 1663 /**
1610 * Returns an array containing the names of the enumerable properties 1664 * Returns an array containing the names of the enumerable properties
1611 * of this object, including properties from prototype objects. The 1665 * of this object, including properties from prototype objects. The
1612 * array returned by this method contains the same values as would 1666 * array returned by this method contains the same values as would
1613 * be enumerated by a for-in statement over this object. 1667 * be enumerated by a for-in statement over this object.
1614 */ 1668 */
1615 Local<Array> GetPropertyNames(); 1669 Local<Array> GetPropertyNames();
1616 1670
1617 /** 1671 /**
1618 * This function has the same functionality as GetPropertyNames but 1672 * This function has the same functionality as GetPropertyNames but
(...skipping 751 matching lines...) Expand 10 before | Expand all | Expand 10 after
2370 void ReadOnlyPrototype(); 2424 void ReadOnlyPrototype();
2371 2425
2372 /** 2426 /**
2373 * Returns true if the given object is an instance of this function 2427 * Returns true if the given object is an instance of this function
2374 * template. 2428 * template.
2375 */ 2429 */
2376 bool HasInstance(Handle<Value> object); 2430 bool HasInstance(Handle<Value> object);
2377 2431
2378 private: 2432 private:
2379 FunctionTemplate(); 2433 FunctionTemplate();
2380 void AddInstancePropertyAccessor(Handle<String> name,
2381 AccessorGetter getter,
2382 AccessorSetter setter,
2383 Handle<Value> data,
2384 AccessControl settings,
2385 PropertyAttribute attributes,
2386 Handle<AccessorSignature> signature);
2387 void SetNamedInstancePropertyHandler(NamedPropertyGetter getter, 2434 void SetNamedInstancePropertyHandler(NamedPropertyGetter getter,
2388 NamedPropertySetter setter, 2435 NamedPropertySetter setter,
2389 NamedPropertyQuery query, 2436 NamedPropertyQuery query,
2390 NamedPropertyDeleter remover, 2437 NamedPropertyDeleter remover,
2391 NamedPropertyEnumerator enumerator, 2438 NamedPropertyEnumerator enumerator,
2392 Handle<Value> data); 2439 Handle<Value> data);
2393 void SetIndexedInstancePropertyHandler(IndexedPropertyGetter getter, 2440 void SetIndexedInstancePropertyHandler(IndexedPropertyGetter getter,
2394 IndexedPropertySetter setter, 2441 IndexedPropertySetter setter,
2395 IndexedPropertyQuery query, 2442 IndexedPropertyQuery query,
2396 IndexedPropertyDeleter remover, 2443 IndexedPropertyDeleter remover,
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
2449 */ 2496 */
2450 void SetAccessor(Handle<String> name, 2497 void SetAccessor(Handle<String> name,
2451 AccessorGetter getter, 2498 AccessorGetter getter,
2452 AccessorSetter setter = 0, 2499 AccessorSetter setter = 0,
2453 Handle<Value> data = Handle<Value>(), 2500 Handle<Value> data = Handle<Value>(),
2454 AccessControl settings = DEFAULT, 2501 AccessControl settings = DEFAULT,
2455 PropertyAttribute attribute = None, 2502 PropertyAttribute attribute = None,
2456 Handle<AccessorSignature> signature = 2503 Handle<AccessorSignature> signature =
2457 Handle<AccessorSignature>()); 2504 Handle<AccessorSignature>());
2458 2505
2506 bool SetAccessor(Handle<String> name,
2507 const AccessorDescriptor* descriptor,
2508 AccessControl settings = DEFAULT,
2509 PropertyAttribute attribute = None,
2510 Handle<AccessorSignature> signature =
2511 Handle<AccessorSignature>());
2512
2459 /** 2513 /**
2460 * Sets a named property handler on the object template. 2514 * Sets a named property handler on the object template.
2461 * 2515 *
2462 * Whenever a named property is accessed on objects created from 2516 * Whenever a named property is accessed on objects created from
2463 * this object template, the provided callback is invoked instead of 2517 * this object template, the provided callback is invoked instead of
2464 * accessing the property directly on the JavaScript object. 2518 * accessing the property directly on the JavaScript object.
2465 * 2519 *
2466 * \param getter The callback to invoke when getting a property. 2520 * \param getter The callback to invoke when getting a property.
2467 * \param setter The callback to invoke when setting a property. 2521 * \param setter The callback to invoke when setting a property.
2468 * \param query The callback to invoke to check if a property is present, 2522 * \param query The callback to invoke to check if a property is present,
(...skipping 2113 matching lines...) Expand 10 before | Expand all | Expand 10 after
4582 Handle<Boolean> Boolean::New(bool value) { 4636 Handle<Boolean> Boolean::New(bool value) {
4583 return value ? True() : False(); 4637 return value ? True() : False();
4584 } 4638 }
4585 4639
4586 4640
4587 void Template::Set(const char* name, v8::Handle<Data> value) { 4641 void Template::Set(const char* name, v8::Handle<Data> value) {
4588 Set(v8::String::New(name), value); 4642 Set(v8::String::New(name), value);
4589 } 4643 }
4590 4644
4591 4645
4646 struct DescriptorVisitorHelper {
Sven Panne 2013/02/19 08:41:16 Why do we need all this stuff here in the external
4647 template<typename Descriptor, typename Visitor>
4648 static inline void VisitDescriptor(Descriptor* descriptor, Visitor* visitor) {
4649 if (!visitor->ShouldVisit(descriptor)) return;
4650 VisitFields(descriptor, visitor);
4651 }
4652 template<typename Visitor>
4653 static inline void VisitFields(BitmaskCompareDescriptor* descriptor,
4654 Visitor* visitor);
4655 template<typename Visitor>
4656 static inline void VisitFields(PointerCompareDescriptor* descriptor,
4657 Visitor* visitor);
4658 template<typename Visitor>
4659 static inline void VisitFields(PrimitiveValueDescriptor* descriptor,
4660 Visitor* visitor);
4661 template<typename Visitor>
4662 static inline void VisitFields(AccessorDescriptor* descriptor,
4663 Visitor* visitor);
4664 };
4665
4666
4667 template<typename Visitor>
4668 inline void DescriptorVisitorHelper::VisitFields(
4669 BitmaskCompareDescriptor* descriptor,
4670 Visitor* visitor) {
4671 visitor->Visit(&descriptor->size);
4672 visitor->Visit(&descriptor->bitmask);
4673 visitor->Visit(&descriptor->compare_value);
4674 }
4675
4676
4677 template<typename Visitor>
4678 inline void DescriptorVisitorHelper::VisitFields(
4679 PointerCompareDescriptor* descriptor,
4680 Visitor* visitor) {
4681 visitor->Visit(&descriptor->compare_value);
4682 }
4683
4684
4685 template<typename Visitor>
4686 inline void DescriptorVisitorHelper::VisitFields(
4687 PrimitiveValueDescriptor* descriptor,
4688 Visitor* visitor) {
4689 visitor->Visit(&descriptor->data_type);
4690 }
4691
4692
4693 template<typename Visitor>
4694 inline void DescriptorVisitorHelper::VisitFields(
4695 AccessorDescriptor* descriptor,
4696 Visitor* visitor) {
4697 visitor->Visit(&descriptor->internal_field);
4698 visitor->Visit(&descriptor->byte_offset);
4699 visitor->Visit(&descriptor->type);
4700 switch (static_cast<AccessorDescriptorType>(descriptor->type)) {
4701 case kDescriptorBitmaskCompare:
4702 VisitDescriptor(&descriptor->bitmask_compare_descriptor, visitor);
4703 break;
4704 case kDescriptorPointerCompare:
4705 VisitDescriptor(&descriptor->pointer_compare_descriptor, visitor);
4706 break;
4707 case kDescriptorPrimitiveValue:
4708 VisitDescriptor(&descriptor->primitive_value_descriptor, visitor);
4709 break;
4710 case kDescriptorPointerDereference:
4711 case kDescriptorInternalFieldDereference:
4712 VisitDescriptor(descriptor->derefence_descriptor, visitor);
4713 break;
4714 default:
4715 visitor->VisitError();
4716 break;
4717 }
4718 }
4719
4720
4592 Local<Value> Object::GetInternalField(int index) { 4721 Local<Value> Object::GetInternalField(int index) {
4593 #ifndef V8_ENABLE_CHECKS 4722 #ifndef V8_ENABLE_CHECKS
4594 typedef internal::Object O; 4723 typedef internal::Object O;
4595 typedef internal::Internals I; 4724 typedef internal::Internals I;
4596 O* obj = *reinterpret_cast<O**>(this); 4725 O* obj = *reinterpret_cast<O**>(this);
4597 // Fast path: If the object is a plain JSObject, which is the common case, we 4726 // Fast path: If the object is a plain JSObject, which is the common case, we
4598 // know where to find the internal fields and can return the value directly. 4727 // know where to find the internal fields and can return the value directly.
4599 if (I::GetInstanceType(obj) == I::kJSObjectType) { 4728 if (I::GetInstanceType(obj) == I::kJSObjectType) {
4600 int offset = I::kJSObjectHeaderSize + (internal::kApiPointerSize * index); 4729 int offset = I::kJSObjectHeaderSize + (internal::kApiPointerSize * index);
4601 O* value = I::ReadField<O*>(obj, offset); 4730 O* value = I::ReadField<O*>(obj, offset);
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
4922 5051
4923 5052
4924 } // namespace v8 5053 } // namespace v8
4925 5054
4926 5055
4927 #undef V8EXPORT 5056 #undef V8EXPORT
4928 #undef TYPE_CHECK 5057 #undef TYPE_CHECK
4929 5058
4930 5059
4931 #endif // V8_H_ 5060 #endif // V8_H_
OLDNEW
« no previous file with comments | « no previous file | src/api.cc » ('j') | src/api.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698