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 4771 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4782 return result; | 4782 return result; |
4783 } | 4783 } |
4784 | 4784 |
4785 | 4785 |
4786 Local<String> v8::String::NewExternal( | 4786 Local<String> v8::String::NewExternal( |
4787 v8::String::ExternalStringResource* resource) { | 4787 v8::String::ExternalStringResource* resource) { |
4788 i::Isolate* isolate = i::Isolate::Current(); | 4788 i::Isolate* isolate = i::Isolate::Current(); |
4789 EnsureInitializedForIsolate(isolate, "v8::String::NewExternal()"); | 4789 EnsureInitializedForIsolate(isolate, "v8::String::NewExternal()"); |
4790 LOG_API(isolate, "String::NewExternal"); | 4790 LOG_API(isolate, "String::NewExternal"); |
4791 ENTER_V8(isolate); | 4791 ENTER_V8(isolate); |
| 4792 CHECK(resource && resource->data()); |
4792 i::Handle<i::String> result = NewExternalStringHandle(isolate, resource); | 4793 i::Handle<i::String> result = NewExternalStringHandle(isolate, resource); |
4793 isolate->heap()->external_string_table()->AddString(*result); | 4794 isolate->heap()->external_string_table()->AddString(*result); |
4794 return Utils::ToLocal(result); | 4795 return Utils::ToLocal(result); |
4795 } | 4796 } |
4796 | 4797 |
4797 | 4798 |
4798 bool v8::String::MakeExternal(v8::String::ExternalStringResource* resource) { | 4799 bool v8::String::MakeExternal(v8::String::ExternalStringResource* resource) { |
4799 i::Handle<i::String> obj = Utils::OpenHandle(this); | 4800 i::Handle<i::String> obj = Utils::OpenHandle(this); |
4800 i::Isolate* isolate = obj->GetIsolate(); | 4801 i::Isolate* isolate = obj->GetIsolate(); |
4801 if (IsDeadCheck(isolate, "v8::String::MakeExternal()")) return false; | 4802 if (IsDeadCheck(isolate, "v8::String::MakeExternal()")) return false; |
4802 if (i::StringShape(*obj).IsExternalTwoByte()) { | 4803 if (i::StringShape(*obj).IsExternalTwoByte()) { |
4803 return false; // Already an external string. | 4804 return false; // Already an external string. |
4804 } | 4805 } |
4805 ENTER_V8(isolate); | 4806 ENTER_V8(isolate); |
4806 if (isolate->string_tracker()->IsFreshUnusedString(obj)) { | 4807 if (isolate->string_tracker()->IsFreshUnusedString(obj)) { |
4807 return false; | 4808 return false; |
4808 } | 4809 } |
4809 if (isolate->heap()->IsInGCPostProcessing()) { | 4810 if (isolate->heap()->IsInGCPostProcessing()) { |
4810 return false; | 4811 return false; |
4811 } | 4812 } |
| 4813 CHECK(resource && resource->data()); |
4812 bool result = obj->MakeExternal(resource); | 4814 bool result = obj->MakeExternal(resource); |
4813 if (result && !obj->IsSymbol()) { | 4815 if (result && !obj->IsSymbol()) { |
4814 isolate->heap()->external_string_table()->AddString(*obj); | 4816 isolate->heap()->external_string_table()->AddString(*obj); |
4815 } | 4817 } |
4816 return result; | 4818 return result; |
4817 } | 4819 } |
4818 | 4820 |
4819 | 4821 |
4820 Local<String> v8::String::NewExternal( | 4822 Local<String> v8::String::NewExternal( |
4821 v8::String::ExternalAsciiStringResource* resource) { | 4823 v8::String::ExternalAsciiStringResource* resource) { |
4822 i::Isolate* isolate = i::Isolate::Current(); | 4824 i::Isolate* isolate = i::Isolate::Current(); |
4823 EnsureInitializedForIsolate(isolate, "v8::String::NewExternal()"); | 4825 EnsureInitializedForIsolate(isolate, "v8::String::NewExternal()"); |
4824 LOG_API(isolate, "String::NewExternal"); | 4826 LOG_API(isolate, "String::NewExternal"); |
4825 ENTER_V8(isolate); | 4827 ENTER_V8(isolate); |
| 4828 CHECK(resource && resource->data()); |
4826 i::Handle<i::String> result = NewExternalAsciiStringHandle(isolate, resource); | 4829 i::Handle<i::String> result = NewExternalAsciiStringHandle(isolate, resource); |
4827 isolate->heap()->external_string_table()->AddString(*result); | 4830 isolate->heap()->external_string_table()->AddString(*result); |
4828 return Utils::ToLocal(result); | 4831 return Utils::ToLocal(result); |
4829 } | 4832 } |
4830 | 4833 |
4831 | 4834 |
4832 bool v8::String::MakeExternal( | 4835 bool v8::String::MakeExternal( |
4833 v8::String::ExternalAsciiStringResource* resource) { | 4836 v8::String::ExternalAsciiStringResource* resource) { |
4834 i::Handle<i::String> obj = Utils::OpenHandle(this); | 4837 i::Handle<i::String> obj = Utils::OpenHandle(this); |
4835 i::Isolate* isolate = obj->GetIsolate(); | 4838 i::Isolate* isolate = obj->GetIsolate(); |
4836 if (IsDeadCheck(isolate, "v8::String::MakeExternal()")) return false; | 4839 if (IsDeadCheck(isolate, "v8::String::MakeExternal()")) return false; |
4837 if (i::StringShape(*obj).IsExternalTwoByte()) { | 4840 if (i::StringShape(*obj).IsExternalTwoByte()) { |
4838 return false; // Already an external string. | 4841 return false; // Already an external string. |
4839 } | 4842 } |
4840 ENTER_V8(isolate); | 4843 ENTER_V8(isolate); |
4841 if (isolate->string_tracker()->IsFreshUnusedString(obj)) { | 4844 if (isolate->string_tracker()->IsFreshUnusedString(obj)) { |
4842 return false; | 4845 return false; |
4843 } | 4846 } |
4844 if (isolate->heap()->IsInGCPostProcessing()) { | 4847 if (isolate->heap()->IsInGCPostProcessing()) { |
4845 return false; | 4848 return false; |
4846 } | 4849 } |
| 4850 CHECK(resource && resource->data()); |
4847 bool result = obj->MakeExternal(resource); | 4851 bool result = obj->MakeExternal(resource); |
4848 if (result && !obj->IsSymbol()) { | 4852 if (result && !obj->IsSymbol()) { |
4849 isolate->heap()->external_string_table()->AddString(*obj); | 4853 isolate->heap()->external_string_table()->AddString(*obj); |
4850 } | 4854 } |
4851 return result; | 4855 return result; |
4852 } | 4856 } |
4853 | 4857 |
4854 | 4858 |
4855 bool v8::String::CanMakeExternal() { | 4859 bool v8::String::CanMakeExternal() { |
4856 if (!internal::FLAG_clever_optimizations) return false; | 4860 if (!internal::FLAG_clever_optimizations) return false; |
(...skipping 1663 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6520 | 6524 |
6521 v->VisitPointers(blocks_.first(), first_block_limit_); | 6525 v->VisitPointers(blocks_.first(), first_block_limit_); |
6522 | 6526 |
6523 for (int i = 1; i < blocks_.length(); i++) { | 6527 for (int i = 1; i < blocks_.length(); i++) { |
6524 v->VisitPointers(blocks_[i], &blocks_[i][kHandleBlockSize]); | 6528 v->VisitPointers(blocks_[i], &blocks_[i][kHandleBlockSize]); |
6525 } | 6529 } |
6526 } | 6530 } |
6527 | 6531 |
6528 | 6532 |
6529 } } // namespace v8::internal | 6533 } } // namespace v8::internal |
OLD | NEW |