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

Side by Side Diff: include/v8.h

Issue 13626002: ES6 symbols: extend V8 API to support symbols (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Added TODO Created 7 years, 8 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.h » ('j') | no next file with comments »
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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 class Object; 120 class Object;
121 class ObjectOperationDescriptor; 121 class ObjectOperationDescriptor;
122 class ObjectTemplate; 122 class ObjectTemplate;
123 class Primitive; 123 class Primitive;
124 class RawOperationDescriptor; 124 class RawOperationDescriptor;
125 class Signature; 125 class Signature;
126 class StackFrame; 126 class StackFrame;
127 class StackTrace; 127 class StackTrace;
128 class String; 128 class String;
129 class StringObject; 129 class StringObject;
130 class Symbol;
131 class SymbolObject;
130 class Uint32; 132 class Uint32;
131 class Utils; 133 class Utils;
132 class Value; 134 class Value;
133 template <class T> class Handle; 135 template <class T> class Handle;
134 template <class T> class Local; 136 template <class T> class Local;
135 template <class T> class Persistent; 137 template <class T> class Persistent;
136 138
137 namespace internal { 139 namespace internal {
138 class Arguments; 140 class Arguments;
139 class Heap; 141 class Heap;
(...skipping 826 matching lines...) Expand 10 before | Expand all | Expand 10 after
966 */ 968 */
967 bool IsFalse() const; 969 bool IsFalse() const;
968 970
969 /** 971 /**
970 * Returns true if this value is an instance of the String type. 972 * Returns true if this value is an instance of the String type.
971 * See ECMA-262 8.4. 973 * See ECMA-262 8.4.
972 */ 974 */
973 V8_INLINE(bool IsString() const); 975 V8_INLINE(bool IsString() const);
974 976
975 /** 977 /**
978 * Returns true if this value is a symbol.
979 * This is an experimental feature.
980 */
981 bool IsSymbol() const;
982
983 /**
976 * Returns true if this value is a function. 984 * Returns true if this value is a function.
977 */ 985 */
978 bool IsFunction() const; 986 bool IsFunction() const;
979 987
980 /** 988 /**
981 * Returns true if this value is an array. 989 * Returns true if this value is an array.
982 */ 990 */
983 bool IsArray() const; 991 bool IsArray() const;
984 992
985 /** 993 /**
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1026 * Returns true if this value is a Number object. 1034 * Returns true if this value is a Number object.
1027 */ 1035 */
1028 bool IsNumberObject() const; 1036 bool IsNumberObject() const;
1029 1037
1030 /** 1038 /**
1031 * Returns true if this value is a String object. 1039 * Returns true if this value is a String object.
1032 */ 1040 */
1033 bool IsStringObject() const; 1041 bool IsStringObject() const;
1034 1042
1035 /** 1043 /**
1044 * Returns true if this value is a Symbol object.
1045 * This is an experimental feature.
1046 */
1047 bool IsSymbolObject() const;
1048
1049 /**
1036 * Returns true if this value is a NativeError. 1050 * Returns true if this value is a NativeError.
1037 */ 1051 */
1038 bool IsNativeError() const; 1052 bool IsNativeError() const;
1039 1053
1040 /** 1054 /**
1041 * Returns true if this value is a RegExp. 1055 * Returns true if this value is a RegExp.
1042 */ 1056 */
1043 bool IsRegExp() const; 1057 bool IsRegExp() const;
1044 1058
1045 Local<Boolean> ToBoolean() const; 1059 Local<Boolean> ToBoolean() const;
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
1304 /** 1318 /**
1305 * Allocates a new string from either UTF-8 encoded or ASCII data. 1319 * Allocates a new string from either UTF-8 encoded or ASCII data.
1306 * The second parameter 'length' gives the buffer length. If omitted, 1320 * The second parameter 'length' gives the buffer length. If omitted,
1307 * the function calls 'strlen' to determine the buffer length. 1321 * the function calls 'strlen' to determine the buffer length.
1308 */ 1322 */
1309 static Local<String> New(const char* data, int length = -1); 1323 static Local<String> New(const char* data, int length = -1);
1310 1324
1311 /** Allocates a new string from 16-bit character codes.*/ 1325 /** Allocates a new string from 16-bit character codes.*/
1312 static Local<String> New(const uint16_t* data, int length = -1); 1326 static Local<String> New(const uint16_t* data, int length = -1);
1313 1327
1314 /** Creates a symbol. Returns one if it exists already.*/ 1328 /**
1329 * Creates an internalized string (historically called a "symbol",
1330 * not to be confused with ES6 symbols). Returns one if it exists already.
1331 * TODO(rossberg): Deprecate me when the new string API is here.
1332 */
1315 static Local<String> NewSymbol(const char* data, int length = -1); 1333 static Local<String> NewSymbol(const char* data, int length = -1);
1316 1334
1317 /** 1335 /**
1318 * Creates a new string by concatenating the left and the right strings 1336 * Creates a new string by concatenating the left and the right strings
1319 * passed in as parameters. 1337 * passed in as parameters.
1320 */ 1338 */
1321 static Local<String> Concat(Handle<String> left, Handle<String> right); 1339 static Local<String> Concat(Handle<String> left, Handle<String> right);
1322 1340
1323 /** 1341 /**
1324 * Creates a new external string using the data defined in the given 1342 * Creates a new external string using the data defined in the given
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
1443 1461
1444 private: 1462 private:
1445 void VerifyExternalStringResourceBase(ExternalStringResourceBase* v, 1463 void VerifyExternalStringResourceBase(ExternalStringResourceBase* v,
1446 Encoding encoding) const; 1464 Encoding encoding) const;
1447 void VerifyExternalStringResource(ExternalStringResource* val) const; 1465 void VerifyExternalStringResource(ExternalStringResource* val) const;
1448 static void CheckCast(v8::Value* obj); 1466 static void CheckCast(v8::Value* obj);
1449 }; 1467 };
1450 1468
1451 1469
1452 /** 1470 /**
1471 * A JavaScript symbol (ECMA-262 edition 6)
1472 *
1473 * This is an experimental feature. Use at your own risk.
1474 */
1475 class V8EXPORT Symbol : public Primitive {
1476 public:
1477 // Returns the print name string of the symbol, or undefined if none.
1478 Local<Value> Name() const;
1479
1480 // Create a symbol without a print name.
1481 static Local<Symbol> New(Isolate* isolate);
1482
1483 // Create a symbol with a print name.
1484 static Local<Symbol> New(Isolate *isolate, const char* data, int length = -1);
1485
1486 V8_INLINE(static Symbol* Cast(v8::Value* obj));
1487 private:
1488 Symbol();
1489 static void CheckCast(v8::Value* obj);
1490 };
1491
1492
1493 /**
1453 * A JavaScript number value (ECMA-262, 4.3.20) 1494 * A JavaScript number value (ECMA-262, 4.3.20)
1454 */ 1495 */
1455 class V8EXPORT Number : public Primitive { 1496 class V8EXPORT Number : public Primitive {
1456 public: 1497 public:
1457 double Value() const; 1498 double Value() const;
1458 static Local<Number> New(double value); 1499 static Local<Number> New(double value);
1459 V8_INLINE(static Number* Cast(v8::Value* obj)); 1500 V8_INLINE(static Number* Cast(v8::Value* obj));
1460 private: 1501 private:
1461 Number(); 1502 Number();
1462 static void CheckCast(v8::Value* obj); 1503 static void CheckCast(v8::Value* obj);
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
1583 1624
1584 Local<Value> Get(uint32_t index); 1625 Local<Value> Get(uint32_t index);
1585 1626
1586 /** 1627 /**
1587 * Gets the property attributes of a property which can be None or 1628 * Gets the property attributes of a property which can be None or
1588 * any combination of ReadOnly, DontEnum and DontDelete. Returns 1629 * any combination of ReadOnly, DontEnum and DontDelete. Returns
1589 * None when the property doesn't exist. 1630 * None when the property doesn't exist.
1590 */ 1631 */
1591 PropertyAttribute GetPropertyAttributes(Handle<Value> key); 1632 PropertyAttribute GetPropertyAttributes(Handle<Value> key);
1592 1633
1593 // TODO(1245389): Replace the type-specific versions of these 1634 bool Has(Handle<Value> key);
1594 // functions with generic ones that accept a Handle<Value> key.
1595 bool Has(Handle<String> key);
1596 1635
1597 bool Delete(Handle<String> key); 1636 bool Delete(Handle<Value> key);
1598 1637
1599 // Delete a property on this object bypassing interceptors and 1638 // Delete a property on this object bypassing interceptors and
1600 // ignoring dont-delete attributes. 1639 // ignoring dont-delete attributes.
1601 bool ForceDelete(Handle<Value> key); 1640 bool ForceDelete(Handle<Value> key);
1602 1641
1603 bool Has(uint32_t index); 1642 bool Has(uint32_t index);
1604 1643
1605 bool Delete(uint32_t index); 1644 bool Delete(uint32_t index);
1606 1645
1607 bool SetAccessor(Handle<String> name, 1646 bool SetAccessor(Handle<String> name,
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after
1975 Local<String> StringValue() const; 2014 Local<String> StringValue() const;
1976 2015
1977 V8_INLINE(static StringObject* Cast(v8::Value* obj)); 2016 V8_INLINE(static StringObject* Cast(v8::Value* obj));
1978 2017
1979 private: 2018 private:
1980 static void CheckCast(v8::Value* obj); 2019 static void CheckCast(v8::Value* obj);
1981 }; 2020 };
1982 2021
1983 2022
1984 /** 2023 /**
2024 * A Symbol object (ECMA-262 edition 6).
2025 *
2026 * This is an experimental feature. Use at your own risk.
2027 */
2028 class V8EXPORT SymbolObject : public Object {
2029 public:
2030 static Local<Value> New(Isolate* isolate, Handle<Symbol> value);
2031
2032 /**
2033 * Returns the Symbol held by the object.
2034 */
2035 Local<Symbol> SymbolValue() const;
2036
2037 V8_INLINE(static SymbolObject* Cast(v8::Value* obj));
2038
2039 private:
2040 static void CheckCast(v8::Value* obj);
2041 };
2042
2043
2044 /**
1985 * An instance of the built-in RegExp constructor (ECMA-262, 15.10). 2045 * An instance of the built-in RegExp constructor (ECMA-262, 15.10).
1986 */ 2046 */
1987 class V8EXPORT RegExp : public Object { 2047 class V8EXPORT RegExp : public Object {
1988 public: 2048 public:
1989 /** 2049 /**
1990 * Regular expression flag bits. They can be or'ed to enable a set 2050 * Regular expression flag bits. They can be or'ed to enable a set
1991 * of flags. 2051 * of flags.
1992 */ 2052 */
1993 enum Flags { 2053 enum Flags {
1994 kNone = 0, 2054 kNone = 0,
(...skipping 2845 matching lines...) Expand 10 before | Expand all | Expand 10 after
4840 4900
4841 bool Value::QuickIsString() const { 4901 bool Value::QuickIsString() const {
4842 typedef internal::Object O; 4902 typedef internal::Object O;
4843 typedef internal::Internals I; 4903 typedef internal::Internals I;
4844 O* obj = *reinterpret_cast<O**>(const_cast<Value*>(this)); 4904 O* obj = *reinterpret_cast<O**>(const_cast<Value*>(this));
4845 if (!I::HasHeapObjectTag(obj)) return false; 4905 if (!I::HasHeapObjectTag(obj)) return false;
4846 return (I::GetInstanceType(obj) < I::kFirstNonstringType); 4906 return (I::GetInstanceType(obj) < I::kFirstNonstringType);
4847 } 4907 }
4848 4908
4849 4909
4910 Symbol* Symbol::Cast(v8::Value* value) {
4911 #ifdef V8_ENABLE_CHECKS
4912 CheckCast(value);
4913 #endif
4914 return static_cast<Symbol*>(value);
4915 }
4916
4917
4850 Number* Number::Cast(v8::Value* value) { 4918 Number* Number::Cast(v8::Value* value) {
4851 #ifdef V8_ENABLE_CHECKS 4919 #ifdef V8_ENABLE_CHECKS
4852 CheckCast(value); 4920 CheckCast(value);
4853 #endif 4921 #endif
4854 return static_cast<Number*>(value); 4922 return static_cast<Number*>(value);
4855 } 4923 }
4856 4924
4857 4925
4858 Integer* Integer::Cast(v8::Value* value) { 4926 Integer* Integer::Cast(v8::Value* value) {
4859 #ifdef V8_ENABLE_CHECKS 4927 #ifdef V8_ENABLE_CHECKS
(...skipping 12 matching lines...) Expand all
4872 4940
4873 4941
4874 StringObject* StringObject::Cast(v8::Value* value) { 4942 StringObject* StringObject::Cast(v8::Value* value) {
4875 #ifdef V8_ENABLE_CHECKS 4943 #ifdef V8_ENABLE_CHECKS
4876 CheckCast(value); 4944 CheckCast(value);
4877 #endif 4945 #endif
4878 return static_cast<StringObject*>(value); 4946 return static_cast<StringObject*>(value);
4879 } 4947 }
4880 4948
4881 4949
4950 SymbolObject* SymbolObject::Cast(v8::Value* value) {
4951 #ifdef V8_ENABLE_CHECKS
4952 CheckCast(value);
4953 #endif
4954 return static_cast<SymbolObject*>(value);
4955 }
4956
4957
4882 NumberObject* NumberObject::Cast(v8::Value* value) { 4958 NumberObject* NumberObject::Cast(v8::Value* value) {
4883 #ifdef V8_ENABLE_CHECKS 4959 #ifdef V8_ENABLE_CHECKS
4884 CheckCast(value); 4960 CheckCast(value);
4885 #endif 4961 #endif
4886 return static_cast<NumberObject*>(value); 4962 return static_cast<NumberObject*>(value);
4887 } 4963 }
4888 4964
4889 4965
4890 BooleanObject* BooleanObject::Cast(v8::Value* value) { 4966 BooleanObject* BooleanObject::Cast(v8::Value* value) {
4891 #ifdef V8_ENABLE_CHECKS 4967 #ifdef V8_ENABLE_CHECKS
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
5038 5114
5039 5115
5040 } // namespace v8 5116 } // namespace v8
5041 5117
5042 5118
5043 #undef V8EXPORT 5119 #undef V8EXPORT
5044 #undef TYPE_CHECK 5120 #undef TYPE_CHECK
5045 5121
5046 5122
5047 #endif // V8_H_ 5123 #endif // V8_H_
OLDNEW
« no previous file with comments | « no previous file | src/api.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698