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 2294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2305 } | 2305 } |
2306 | 2306 |
2307 | 2307 |
2308 // --- J S O N --- | 2308 // --- J S O N --- |
2309 | 2309 |
2310 Local<Value> JSON::Parse(Local<String> json_string) { | 2310 Local<Value> JSON::Parse(Local<String> json_string) { |
2311 i::Isolate* isolate = i::Isolate::Current(); | 2311 i::Isolate* isolate = i::Isolate::Current(); |
2312 EnsureInitializedForIsolate(isolate, "v8::JSON::Parse"); | 2312 EnsureInitializedForIsolate(isolate, "v8::JSON::Parse"); |
2313 ENTER_V8(isolate); | 2313 ENTER_V8(isolate); |
2314 i::HandleScope scope(isolate); | 2314 i::HandleScope scope(isolate); |
2315 i::Handle<i::String> source = i::Handle<i::String>( | 2315 i::Handle<i::String> source = |
2316 FlattenGetString(Utils::OpenHandle(*json_string))); | 2316 i::String::Flatten(Utils::OpenHandle(*json_string)); |
2317 EXCEPTION_PREAMBLE(isolate); | 2317 EXCEPTION_PREAMBLE(isolate); |
2318 i::MaybeHandle<i::Object> maybe_result = | 2318 i::MaybeHandle<i::Object> maybe_result = |
2319 source->IsSeqOneByteString() ? i::JsonParser<true>::Parse(source) | 2319 source->IsSeqOneByteString() ? i::JsonParser<true>::Parse(source) |
2320 : i::JsonParser<false>::Parse(source); | 2320 : i::JsonParser<false>::Parse(source); |
2321 i::Handle<i::Object> result; | 2321 i::Handle<i::Object> result; |
2322 has_pending_exception = !maybe_result.ToHandle(&result); | 2322 has_pending_exception = !maybe_result.ToHandle(&result); |
2323 EXCEPTION_BAILOUT_CHECK(isolate, Local<Object>()); | 2323 EXCEPTION_BAILOUT_CHECK(isolate, Local<Object>()); |
2324 return Utils::ToLocal( | 2324 return Utils::ToLocal( |
2325 i::Handle<i::Object>::cast(scope.CloseAndEscape(result))); | 2325 i::Handle<i::Object>::cast(scope.CloseAndEscape(result))); |
2326 } | 2326 } |
(...skipping 2342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4669 | 4669 |
4670 int String::WriteUtf8(char* buffer, | 4670 int String::WriteUtf8(char* buffer, |
4671 int capacity, | 4671 int capacity, |
4672 int* nchars_ref, | 4672 int* nchars_ref, |
4673 int options) const { | 4673 int options) const { |
4674 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | 4674 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
4675 LOG_API(isolate, "String::WriteUtf8"); | 4675 LOG_API(isolate, "String::WriteUtf8"); |
4676 ENTER_V8(isolate); | 4676 ENTER_V8(isolate); |
4677 i::Handle<i::String> str = Utils::OpenHandle(this); | 4677 i::Handle<i::String> str = Utils::OpenHandle(this); |
4678 if (options & HINT_MANY_WRITES_EXPECTED) { | 4678 if (options & HINT_MANY_WRITES_EXPECTED) { |
4679 FlattenString(str); // Flatten the string for efficiency. | 4679 str = i::String::Flatten(str); // Flatten the string for efficiency. |
4680 } | 4680 } |
4681 const int string_length = str->length(); | 4681 const int string_length = str->length(); |
4682 bool write_null = !(options & NO_NULL_TERMINATION); | 4682 bool write_null = !(options & NO_NULL_TERMINATION); |
4683 bool replace_invalid_utf8 = (options & REPLACE_INVALID_UTF8); | 4683 bool replace_invalid_utf8 = (options & REPLACE_INVALID_UTF8); |
4684 int max16BitCodeUnitSize = unibrow::Utf8::kMax16BitCodeUnitSize; | 4684 int max16BitCodeUnitSize = unibrow::Utf8::kMax16BitCodeUnitSize; |
4685 // First check if we can just write the string without checking capacity. | 4685 // First check if we can just write the string without checking capacity. |
4686 if (capacity == -1 || capacity / max16BitCodeUnitSize >= string_length) { | 4686 if (capacity == -1 || capacity / max16BitCodeUnitSize >= string_length) { |
4687 Utf8WriterVisitor writer(buffer, capacity, true, replace_invalid_utf8); | 4687 Utf8WriterVisitor writer(buffer, capacity, true, replace_invalid_utf8); |
4688 const int kMaxRecursion = 100; | 4688 const int kMaxRecursion = 100; |
4689 bool success = RecursivelySerializeToUtf8(*str, &writer, kMaxRecursion); | 4689 bool success = RecursivelySerializeToUtf8(*str, &writer, kMaxRecursion); |
(...skipping 14 matching lines...) Expand all Loading... |
4704 if (write_null && (utf8_bytes+1 > capacity)) { | 4704 if (write_null && (utf8_bytes+1 > capacity)) { |
4705 options |= NO_NULL_TERMINATION; | 4705 options |= NO_NULL_TERMINATION; |
4706 } | 4706 } |
4707 // Recurse once without a capacity limit. | 4707 // Recurse once without a capacity limit. |
4708 // This will get into the first branch above. | 4708 // This will get into the first branch above. |
4709 // TODO(dcarney) Check max left rec. in Utf8Length and fall through. | 4709 // TODO(dcarney) Check max left rec. in Utf8Length and fall through. |
4710 return WriteUtf8(buffer, -1, nchars_ref, options); | 4710 return WriteUtf8(buffer, -1, nchars_ref, options); |
4711 } | 4711 } |
4712 } | 4712 } |
4713 // Recursive slow path can potentially be unreasonable slow. Flatten. | 4713 // Recursive slow path can potentially be unreasonable slow. Flatten. |
4714 str = FlattenGetString(str); | 4714 str = i::String::Flatten(str); |
4715 Utf8WriterVisitor writer(buffer, capacity, false, replace_invalid_utf8); | 4715 Utf8WriterVisitor writer(buffer, capacity, false, replace_invalid_utf8); |
4716 i::String::VisitFlat(&writer, *str); | 4716 i::String::VisitFlat(&writer, *str); |
4717 return writer.CompleteWrite(write_null, nchars_ref); | 4717 return writer.CompleteWrite(write_null, nchars_ref); |
4718 } | 4718 } |
4719 | 4719 |
4720 | 4720 |
4721 template<typename CharType> | 4721 template<typename CharType> |
4722 static inline int WriteHelper(const String* string, | 4722 static inline int WriteHelper(const String* string, |
4723 CharType* buffer, | 4723 CharType* buffer, |
4724 int start, | 4724 int start, |
4725 int length, | 4725 int length, |
4726 int options) { | 4726 int options) { |
4727 i::Isolate* isolate = Utils::OpenHandle(string)->GetIsolate(); | 4727 i::Isolate* isolate = Utils::OpenHandle(string)->GetIsolate(); |
4728 LOG_API(isolate, "String::Write"); | 4728 LOG_API(isolate, "String::Write"); |
4729 ENTER_V8(isolate); | 4729 ENTER_V8(isolate); |
4730 ASSERT(start >= 0 && length >= -1); | 4730 ASSERT(start >= 0 && length >= -1); |
4731 i::Handle<i::String> str = Utils::OpenHandle(string); | 4731 i::Handle<i::String> str = Utils::OpenHandle(string); |
4732 isolate->string_tracker()->RecordWrite(str); | 4732 isolate->string_tracker()->RecordWrite(str); |
4733 if (options & String::HINT_MANY_WRITES_EXPECTED) { | 4733 if (options & String::HINT_MANY_WRITES_EXPECTED) { |
4734 // Flatten the string for efficiency. This applies whether we are | 4734 // Flatten the string for efficiency. This applies whether we are |
4735 // using StringCharacterStream or Get(i) to access the characters. | 4735 // using StringCharacterStream or Get(i) to access the characters. |
4736 FlattenString(str); | 4736 str = i::String::Flatten(str); |
4737 } | 4737 } |
4738 int end = start + length; | 4738 int end = start + length; |
4739 if ((length == -1) || (length > str->length() - start) ) | 4739 if ((length == -1) || (length > str->length() - start) ) |
4740 end = str->length(); | 4740 end = str->length(); |
4741 if (end < 0) return 0; | 4741 if (end < 0) return 0; |
4742 i::String::WriteToFlat(*str, buffer, start, end); | 4742 i::String::WriteToFlat(*str, buffer, start, end); |
4743 if (!(options & String::NO_NULL_TERMINATION) && | 4743 if (!(options & String::NO_NULL_TERMINATION) && |
4744 (length == -1 || end - start < length)) { | 4744 (length == -1 || end - start < length)) { |
4745 buffer[end - start] = '\0'; | 4745 buffer[end - start] = '\0'; |
4746 } | 4746 } |
(...skipping 2925 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7672 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); | 7672 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); |
7673 Address callback_address = | 7673 Address callback_address = |
7674 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 7674 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
7675 VMState<EXTERNAL> state(isolate); | 7675 VMState<EXTERNAL> state(isolate); |
7676 ExternalCallbackScope call_scope(isolate, callback_address); | 7676 ExternalCallbackScope call_scope(isolate, callback_address); |
7677 callback(info); | 7677 callback(info); |
7678 } | 7678 } |
7679 | 7679 |
7680 | 7680 |
7681 } } // namespace v8::internal | 7681 } } // namespace v8::internal |
OLD | NEW |