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 1000 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1011 V8EXPORT bool Value() const; | 1011 V8EXPORT bool Value() const; |
1012 static inline Handle<Boolean> New(bool value); | 1012 static inline Handle<Boolean> New(bool value); |
1013 }; | 1013 }; |
1014 | 1014 |
1015 | 1015 |
1016 /** | 1016 /** |
1017 * A JavaScript string value (ECMA-262, 4.3.17). | 1017 * A JavaScript string value (ECMA-262, 4.3.17). |
1018 */ | 1018 */ |
1019 class String : public Primitive { | 1019 class String : public Primitive { |
1020 public: | 1020 public: |
1021 enum Encoding { | |
1022 UNKNOWN_ENCODING = 0x1, | |
1023 TWO_BYTE_ENCODING = 0x0, | |
1024 ASCII_ENCODING = 0x4 | |
1025 }; | |
1026 /** | 1021 /** |
1027 * Returns the number of characters in this string. | 1022 * Returns the number of characters in this string. |
1028 */ | 1023 */ |
1029 V8EXPORT int Length() const; | 1024 V8EXPORT int Length() const; |
1030 | 1025 |
1031 /** | 1026 /** |
1032 * Returns the number of bytes in the UTF-8 encoded | 1027 * Returns the number of bytes in the UTF-8 encoded |
1033 * representation of this string. | 1028 * representation of this string. |
1034 */ | 1029 */ |
1035 V8EXPORT int Utf8Length() const; | 1030 V8EXPORT int Utf8Length() const; |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1179 virtual ~ExternalAsciiStringResource() {} | 1174 virtual ~ExternalAsciiStringResource() {} |
1180 /** The string data from the underlying buffer.*/ | 1175 /** The string data from the underlying buffer.*/ |
1181 virtual const char* data() const = 0; | 1176 virtual const char* data() const = 0; |
1182 /** The number of ASCII characters in the string.*/ | 1177 /** The number of ASCII characters in the string.*/ |
1183 virtual size_t length() const = 0; | 1178 virtual size_t length() const = 0; |
1184 protected: | 1179 protected: |
1185 ExternalAsciiStringResource() {} | 1180 ExternalAsciiStringResource() {} |
1186 }; | 1181 }; |
1187 | 1182 |
1188 /** | 1183 /** |
1189 * If the string is an external string, return the ExternalStringResourceBase | |
1190 * regardless of the encoding, otherwise return NULL. The encoding of the | |
1191 * string is returned in encoding_out. | |
1192 */ | |
1193 inline ExternalStringResourceBase* GetExternalStringResourceBase( | |
1194 Encoding* encoding_out) const; | |
1195 | |
1196 /** | |
1197 * Get the ExternalStringResource for an external string. Returns | 1184 * Get the ExternalStringResource for an external string. Returns |
1198 * NULL if IsExternal() doesn't return true. | 1185 * NULL if IsExternal() doesn't return true. |
1199 */ | 1186 */ |
1200 inline ExternalStringResource* GetExternalStringResource() const; | 1187 inline ExternalStringResource* GetExternalStringResource() const; |
1201 | 1188 |
1202 /** | 1189 /** |
1203 * Get the ExternalAsciiStringResource for an external ASCII string. | 1190 * Get the ExternalAsciiStringResource for an external ASCII string. |
1204 * Returns NULL if IsExternalAscii() doesn't return true. | 1191 * Returns NULL if IsExternalAscii() doesn't return true. |
1205 */ | 1192 */ |
1206 V8EXPORT const ExternalAsciiStringResource* GetExternalAsciiStringResource() | 1193 V8EXPORT const ExternalAsciiStringResource* GetExternalAsciiStringResource() |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1349 private: | 1336 private: |
1350 uint16_t* str_; | 1337 uint16_t* str_; |
1351 int length_; | 1338 int length_; |
1352 | 1339 |
1353 // Disallow copying and assigning. | 1340 // Disallow copying and assigning. |
1354 Value(const Value&); | 1341 Value(const Value&); |
1355 void operator=(const Value&); | 1342 void operator=(const Value&); |
1356 }; | 1343 }; |
1357 | 1344 |
1358 private: | 1345 private: |
1359 V8EXPORT void VerifyExternalStringResourceBase(ExternalStringResourceBase* v, | |
1360 Encoding encoding) const; | |
1361 V8EXPORT void VerifyExternalStringResource(ExternalStringResource* val) const; | 1346 V8EXPORT void VerifyExternalStringResource(ExternalStringResource* val) const; |
1362 V8EXPORT static void CheckCast(v8::Value* obj); | 1347 V8EXPORT static void CheckCast(v8::Value* obj); |
1363 }; | 1348 }; |
1364 | 1349 |
1365 | 1350 |
1366 /** | 1351 /** |
1367 * A JavaScript number value (ECMA-262, 4.3.20) | 1352 * A JavaScript number value (ECMA-262, 4.3.20) |
1368 */ | 1353 */ |
1369 class Number : public Primitive { | 1354 class Number : public Primitive { |
1370 public: | 1355 public: |
(...skipping 2340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3711 bool HasOutOfMemoryException(); | 3696 bool HasOutOfMemoryException(); |
3712 | 3697 |
3713 /** Returns true if V8 has a current context. */ | 3698 /** Returns true if V8 has a current context. */ |
3714 static bool InContext(); | 3699 static bool InContext(); |
3715 | 3700 |
3716 /** | 3701 /** |
3717 * Associate an additional data object with the context. This is mainly used | 3702 * Associate an additional data object with the context. This is mainly used |
3718 * with the debugger to provide additional information on the context through | 3703 * with the debugger to provide additional information on the context through |
3719 * the debugger API. | 3704 * the debugger API. |
3720 */ | 3705 */ |
3721 void SetData(Handle<Value> data); | 3706 void SetData(Handle<String> data); |
3722 Local<Value> GetData(); | 3707 Local<Value> GetData(); |
3723 | 3708 |
3724 /** | 3709 /** |
3725 * Control whether code generation from strings is allowed. Calling | 3710 * Control whether code generation from strings is allowed. Calling |
3726 * this method with false will disable 'eval' and the 'Function' | 3711 * this method with false will disable 'eval' and the 'Function' |
3727 * constructor for code running in this context. If 'eval' or the | 3712 * constructor for code running in this context. If 'eval' or the |
3728 * 'Function' constructor are used an exception will be thrown. | 3713 * 'Function' constructor are used an exception will be thrown. |
3729 * | 3714 * |
3730 * If code generation from strings is not allowed the | 3715 * If code generation from strings is not allowed the |
3731 * V8::AllowCodeGenerationFromStrings callback will be invoked if | 3716 * V8::AllowCodeGenerationFromStrings callback will be invoked if |
3732 * set before blocking the call to 'eval' or the 'Function' | 3717 * set before blocking the call to 'eval' or the 'Function' |
3733 * constructor. If that callback returns true, the call will be | 3718 * constructor. If that callback returns true, the call will be |
3734 * allowed, otherwise an exception will be thrown. If no callback is | 3719 * allowed, otherwise an exception will be thrown. If no callback is |
3735 * set an exception will be thrown. | 3720 * set an exception will be thrown. |
3736 */ | 3721 */ |
3737 void AllowCodeGenerationFromStrings(bool allow); | 3722 void AllowCodeGenerationFromStrings(bool allow); |
3738 | 3723 |
3739 /** | 3724 /** |
3740 * Returns true if code generation from strings is allowed for the context. | 3725 * Returns true if code generation from strings is allowed for the context. |
3741 * For more details see AllowCodeGenerationFromStrings(bool) documentation. | 3726 * For more details see AllowCodeGenerationFromStrings(bool) documentation. |
3742 */ | 3727 */ |
3743 bool IsCodeGenerationFromStringsAllowed(); | 3728 bool IsCodeGenerationFromStringsAllowed(); |
3744 | 3729 |
3745 /** | 3730 /** |
3746 * Sets the error description for the exception that is thrown when | |
3747 * code generation from strings is not allowed and 'eval' or the 'Function' | |
3748 * constructor are called. | |
3749 */ | |
3750 void SetErrorMessageForCodeGenerationFromStrings(Handle<String> message); | |
3751 | |
3752 /** | |
3753 * Stack-allocated class which sets the execution context for all | 3731 * Stack-allocated class which sets the execution context for all |
3754 * operations executed within a local scope. | 3732 * operations executed within a local scope. |
3755 */ | 3733 */ |
3756 class Scope { | 3734 class Scope { |
3757 public: | 3735 public: |
3758 explicit inline Scope(Handle<Context> context) : context_(context) { | 3736 explicit inline Scope(Handle<Context> context) : context_(context) { |
3759 context_->Enter(); | 3737 context_->Enter(); |
3760 } | 3738 } |
3761 inline ~Scope() { context_->Exit(); } | 3739 inline ~Scope() { context_->Exit(); } |
3762 private: | 3740 private: |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4048 // These values match non-compiler-dependent values defined within | 4026 // These values match non-compiler-dependent values defined within |
4049 // the implementation of v8. | 4027 // the implementation of v8. |
4050 static const int kHeapObjectMapOffset = 0; | 4028 static const int kHeapObjectMapOffset = 0; |
4051 static const int kMapInstanceTypeOffset = 1 * kApiPointerSize + kApiIntSize; | 4029 static const int kMapInstanceTypeOffset = 1 * kApiPointerSize + kApiIntSize; |
4052 static const int kStringResourceOffset = 3 * kApiPointerSize; | 4030 static const int kStringResourceOffset = 3 * kApiPointerSize; |
4053 | 4031 |
4054 static const int kOddballKindOffset = 3 * kApiPointerSize; | 4032 static const int kOddballKindOffset = 3 * kApiPointerSize; |
4055 static const int kForeignAddressOffset = kApiPointerSize; | 4033 static const int kForeignAddressOffset = kApiPointerSize; |
4056 static const int kJSObjectHeaderSize = 3 * kApiPointerSize; | 4034 static const int kJSObjectHeaderSize = 3 * kApiPointerSize; |
4057 static const int kFullStringRepresentationMask = 0x07; | 4035 static const int kFullStringRepresentationMask = 0x07; |
4058 static const int kStringEncodingMask = 0x4; | |
4059 static const int kExternalTwoByteRepresentationTag = 0x02; | 4036 static const int kExternalTwoByteRepresentationTag = 0x02; |
4060 static const int kExternalAsciiRepresentationTag = 0x06; | |
4061 | 4037 |
4062 static const int kIsolateStateOffset = 0; | 4038 static const int kIsolateStateOffset = 0; |
4063 static const int kIsolateEmbedderDataOffset = 1 * kApiPointerSize; | 4039 static const int kIsolateEmbedderDataOffset = 1 * kApiPointerSize; |
4064 static const int kIsolateRootsOffset = 3 * kApiPointerSize; | 4040 static const int kIsolateRootsOffset = 3 * kApiPointerSize; |
4065 static const int kUndefinedValueRootIndex = 5; | 4041 static const int kUndefinedValueRootIndex = 5; |
4066 static const int kNullValueRootIndex = 7; | 4042 static const int kNullValueRootIndex = 7; |
4067 static const int kTrueValueRootIndex = 8; | 4043 static const int kTrueValueRootIndex = 8; |
4068 static const int kFalseValueRootIndex = 9; | 4044 static const int kFalseValueRootIndex = 9; |
4069 static const int kEmptySymbolRootIndex = 116; | 4045 static const int kEmptySymbolRootIndex = 116; |
4070 | 4046 |
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4405 } else { | 4381 } else { |
4406 result = NULL; | 4382 result = NULL; |
4407 } | 4383 } |
4408 #ifdef V8_ENABLE_CHECKS | 4384 #ifdef V8_ENABLE_CHECKS |
4409 VerifyExternalStringResource(result); | 4385 VerifyExternalStringResource(result); |
4410 #endif | 4386 #endif |
4411 return result; | 4387 return result; |
4412 } | 4388 } |
4413 | 4389 |
4414 | 4390 |
4415 String::ExternalStringResourceBase* String::GetExternalStringResourceBase( | |
4416 String::Encoding* encoding_out) const { | |
4417 typedef internal::Object O; | |
4418 typedef internal::Internals I; | |
4419 O* obj = *reinterpret_cast<O**>(const_cast<String*>(this)); | |
4420 int type = I::GetInstanceType(obj) & I::kFullStringRepresentationMask; | |
4421 *encoding_out = static_cast<Encoding>(type & I::kStringEncodingMask); | |
4422 ExternalStringResourceBase* resource = NULL; | |
4423 if (type == I::kExternalAsciiRepresentationTag || | |
4424 type == I::kExternalTwoByteRepresentationTag) { | |
4425 void* value = I::ReadField<void*>(obj, I::kStringResourceOffset); | |
4426 resource = static_cast<ExternalStringResourceBase*>(value); | |
4427 } | |
4428 #ifdef V8_ENABLE_CHECKS | |
4429 VerifyExternalStringResourceBase(resource, *encoding_out); | |
4430 #endif | |
4431 return resource; | |
4432 } | |
4433 | |
4434 | |
4435 bool Value::IsUndefined() const { | 4391 bool Value::IsUndefined() const { |
4436 #ifdef V8_ENABLE_CHECKS | 4392 #ifdef V8_ENABLE_CHECKS |
4437 return FullIsUndefined(); | 4393 return FullIsUndefined(); |
4438 #else | 4394 #else |
4439 return QuickIsUndefined(); | 4395 return QuickIsUndefined(); |
4440 #endif | 4396 #endif |
4441 } | 4397 } |
4442 | 4398 |
4443 bool Value::QuickIsUndefined() const { | 4399 bool Value::QuickIsUndefined() const { |
4444 typedef internal::Object O; | 4400 typedef internal::Object O; |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4654 | 4610 |
4655 | 4611 |
4656 } // namespace v8 | 4612 } // namespace v8 |
4657 | 4613 |
4658 | 4614 |
4659 #undef V8EXPORT | 4615 #undef V8EXPORT |
4660 #undef TYPE_CHECK | 4616 #undef TYPE_CHECK |
4661 | 4617 |
4662 | 4618 |
4663 #endif // V8_H_ | 4619 #endif // V8_H_ |
OLD | NEW |