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 5310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5321 | 5321 |
5322 | 5322 |
5323 inline int StringLength(const uint16_t* string) { | 5323 inline int StringLength(const uint16_t* string) { |
5324 int length = 0; | 5324 int length = 0; |
5325 while (string[length] != '\0') | 5325 while (string[length] != '\0') |
5326 length++; | 5326 length++; |
5327 return length; | 5327 return length; |
5328 } | 5328 } |
5329 | 5329 |
5330 | 5330 |
5331 inline i::Handle<i::String> NewString(i::Factory* factory, | 5331 MUST_USE_RESULT |
5332 String::NewStringType type, | 5332 inline i::MaybeHandle<i::String> NewString(i::Factory* factory, |
5333 i::Vector<const char> string) { | 5333 String::NewStringType type, |
| 5334 i::Vector<const char> string) { |
5334 if (type ==String::kInternalizedString) { | 5335 if (type ==String::kInternalizedString) { |
5335 return factory->InternalizeUtf8String(string); | 5336 return factory->InternalizeUtf8String(string); |
5336 } | 5337 } |
5337 return factory->NewStringFromUtf8(string); | 5338 return factory->NewStringFromUtf8(string); |
5338 } | 5339 } |
5339 | 5340 |
5340 | 5341 |
5341 inline i::Handle<i::String> NewString(i::Factory* factory, | 5342 MUST_USE_RESULT |
5342 String::NewStringType type, | 5343 inline i::MaybeHandle<i::String> NewString(i::Factory* factory, |
5343 i::Vector<const uint8_t> string) { | 5344 String::NewStringType type, |
| 5345 i::Vector<const uint8_t> string) { |
5344 if (type == String::kInternalizedString) { | 5346 if (type == String::kInternalizedString) { |
5345 return factory->InternalizeOneByteString(string); | 5347 return factory->InternalizeOneByteString(string); |
5346 } | 5348 } |
5347 return factory->NewStringFromOneByte(string); | 5349 return factory->NewStringFromOneByte(string); |
5348 } | 5350 } |
5349 | 5351 |
5350 | 5352 |
5351 inline i::Handle<i::String> NewString(i::Factory* factory, | 5353 MUST_USE_RESULT |
5352 String::NewStringType type, | 5354 inline i::MaybeHandle<i::String> NewString(i::Factory* factory, |
5353 i::Vector<const uint16_t> string) { | 5355 String::NewStringType type, |
| 5356 i::Vector<const uint16_t> string) { |
5354 if (type == String::kInternalizedString) { | 5357 if (type == String::kInternalizedString) { |
5355 return factory->InternalizeTwoByteString(string); | 5358 return factory->InternalizeTwoByteString(string); |
5356 } | 5359 } |
5357 return factory->NewStringFromTwoByte(string); | 5360 return factory->NewStringFromTwoByte(string); |
5358 } | 5361 } |
5359 | 5362 |
5360 | 5363 |
5361 template<typename Char> | 5364 template<typename Char> |
5362 inline Local<String> NewString(Isolate* v8_isolate, | 5365 inline Local<String> NewString(Isolate* v8_isolate, |
5363 const char* location, | 5366 const char* location, |
5364 const char* env, | 5367 const char* env, |
5365 const Char* data, | 5368 const Char* data, |
5366 String::NewStringType type, | 5369 String::NewStringType type, |
5367 int length) { | 5370 int length) { |
5368 i::Isolate* isolate = reinterpret_cast<internal::Isolate*>(v8_isolate); | 5371 i::Isolate* isolate = reinterpret_cast<internal::Isolate*>(v8_isolate); |
5369 EnsureInitializedForIsolate(isolate, location); | 5372 EnsureInitializedForIsolate(isolate, location); |
5370 LOG_API(isolate, env); | 5373 LOG_API(isolate, env); |
5371 if (length == 0 && type != String::kUndetectableString) { | 5374 if (length == 0 && type != String::kUndetectableString) { |
5372 return String::Empty(v8_isolate); | 5375 return String::Empty(v8_isolate); |
5373 } | 5376 } |
5374 ENTER_V8(isolate); | 5377 ENTER_V8(isolate); |
5375 if (length == -1) length = StringLength(data); | 5378 if (length == -1) length = StringLength(data); |
| 5379 // We do not expect this to fail. Change this if it does. |
5376 i::Handle<i::String> result = NewString( | 5380 i::Handle<i::String> result = NewString( |
5377 isolate->factory(), type, i::Vector<const Char>(data, length)); | 5381 isolate->factory(), |
5378 // We do not expect this to fail. Change this if it does. | 5382 type, |
5379 CHECK(!result.is_null()); | 5383 i::Vector<const Char>(data, length)).ToHandleChecked(); |
5380 if (type == String::kUndetectableString) { | 5384 if (type == String::kUndetectableString) { |
5381 result->MarkAsUndetectable(); | 5385 result->MarkAsUndetectable(); |
5382 } | 5386 } |
5383 return Utils::ToLocal(result); | 5387 return Utils::ToLocal(result); |
5384 } | 5388 } |
5385 | 5389 |
5386 } // anonymous namespace | 5390 } // anonymous namespace |
5387 | 5391 |
5388 | 5392 |
5389 Local<String> String::NewFromUtf8(Isolate* isolate, | 5393 Local<String> String::NewFromUtf8(Isolate* isolate, |
(...skipping 2222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7612 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); | 7616 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); |
7613 Address callback_address = | 7617 Address callback_address = |
7614 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 7618 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
7615 VMState<EXTERNAL> state(isolate); | 7619 VMState<EXTERNAL> state(isolate); |
7616 ExternalCallbackScope call_scope(isolate, callback_address); | 7620 ExternalCallbackScope call_scope(isolate, callback_address); |
7617 callback(info); | 7621 callback(info); |
7618 } | 7622 } |
7619 | 7623 |
7620 | 7624 |
7621 } } // namespace v8::internal | 7625 } } // namespace v8::internal |
OLD | NEW |