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

Side by Side Diff: src/api.cc

Issue 10836236: Do checks when receiving external string resources through the API. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years, 4 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 | no next file » | 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 4772 matching lines...) Expand 10 before | Expand all | Expand 10 after
4783 return result; 4783 return result;
4784 } 4784 }
4785 4785
4786 4786
4787 Local<String> v8::String::NewExternal( 4787 Local<String> v8::String::NewExternal(
4788 v8::String::ExternalStringResource* resource) { 4788 v8::String::ExternalStringResource* resource) {
4789 i::Isolate* isolate = i::Isolate::Current(); 4789 i::Isolate* isolate = i::Isolate::Current();
4790 EnsureInitializedForIsolate(isolate, "v8::String::NewExternal()"); 4790 EnsureInitializedForIsolate(isolate, "v8::String::NewExternal()");
4791 LOG_API(isolate, "String::NewExternal"); 4791 LOG_API(isolate, "String::NewExternal");
4792 ENTER_V8(isolate); 4792 ENTER_V8(isolate);
4793 CHECK(resource && resource->data());
4793 i::Handle<i::String> result = NewExternalStringHandle(isolate, resource); 4794 i::Handle<i::String> result = NewExternalStringHandle(isolate, resource);
4794 isolate->heap()->external_string_table()->AddString(*result); 4795 isolate->heap()->external_string_table()->AddString(*result);
4795 return Utils::ToLocal(result); 4796 return Utils::ToLocal(result);
4796 } 4797 }
4797 4798
4798 4799
4799 bool v8::String::MakeExternal(v8::String::ExternalStringResource* resource) { 4800 bool v8::String::MakeExternal(v8::String::ExternalStringResource* resource) {
4800 i::Handle<i::String> obj = Utils::OpenHandle(this); 4801 i::Handle<i::String> obj = Utils::OpenHandle(this);
4801 i::Isolate* isolate = obj->GetIsolate(); 4802 i::Isolate* isolate = obj->GetIsolate();
4802 if (IsDeadCheck(isolate, "v8::String::MakeExternal()")) return false; 4803 if (IsDeadCheck(isolate, "v8::String::MakeExternal()")) return false;
4803 if (i::StringShape(*obj).IsExternalTwoByte()) { 4804 if (i::StringShape(*obj).IsExternalTwoByte()) {
4804 return false; // Already an external string. 4805 return false; // Already an external string.
4805 } 4806 }
4806 ENTER_V8(isolate); 4807 ENTER_V8(isolate);
4807 if (isolate->string_tracker()->IsFreshUnusedString(obj)) { 4808 if (isolate->string_tracker()->IsFreshUnusedString(obj)) {
4808 return false; 4809 return false;
4809 } 4810 }
4810 if (isolate->heap()->IsInGCPostProcessing()) { 4811 if (isolate->heap()->IsInGCPostProcessing()) {
4811 return false; 4812 return false;
4812 } 4813 }
4814 CHECK(resource && resource->data());
4813 bool result = obj->MakeExternal(resource); 4815 bool result = obj->MakeExternal(resource);
4814 if (result && !obj->IsSymbol()) { 4816 if (result && !obj->IsSymbol()) {
4815 isolate->heap()->external_string_table()->AddString(*obj); 4817 isolate->heap()->external_string_table()->AddString(*obj);
4816 } 4818 }
4817 return result; 4819 return result;
4818 } 4820 }
4819 4821
4820 4822
4821 Local<String> v8::String::NewExternal( 4823 Local<String> v8::String::NewExternal(
4822 v8::String::ExternalAsciiStringResource* resource) { 4824 v8::String::ExternalAsciiStringResource* resource) {
4823 i::Isolate* isolate = i::Isolate::Current(); 4825 i::Isolate* isolate = i::Isolate::Current();
4824 EnsureInitializedForIsolate(isolate, "v8::String::NewExternal()"); 4826 EnsureInitializedForIsolate(isolate, "v8::String::NewExternal()");
4825 LOG_API(isolate, "String::NewExternal"); 4827 LOG_API(isolate, "String::NewExternal");
4826 ENTER_V8(isolate); 4828 ENTER_V8(isolate);
4829 CHECK(resource && resource->data());
4827 i::Handle<i::String> result = NewExternalAsciiStringHandle(isolate, resource); 4830 i::Handle<i::String> result = NewExternalAsciiStringHandle(isolate, resource);
4828 isolate->heap()->external_string_table()->AddString(*result); 4831 isolate->heap()->external_string_table()->AddString(*result);
4829 return Utils::ToLocal(result); 4832 return Utils::ToLocal(result);
4830 } 4833 }
4831 4834
4832 4835
4833 bool v8::String::MakeExternal( 4836 bool v8::String::MakeExternal(
4834 v8::String::ExternalAsciiStringResource* resource) { 4837 v8::String::ExternalAsciiStringResource* resource) {
4835 i::Handle<i::String> obj = Utils::OpenHandle(this); 4838 i::Handle<i::String> obj = Utils::OpenHandle(this);
4836 i::Isolate* isolate = obj->GetIsolate(); 4839 i::Isolate* isolate = obj->GetIsolate();
4837 if (IsDeadCheck(isolate, "v8::String::MakeExternal()")) return false; 4840 if (IsDeadCheck(isolate, "v8::String::MakeExternal()")) return false;
4838 if (i::StringShape(*obj).IsExternalTwoByte()) { 4841 if (i::StringShape(*obj).IsExternalTwoByte()) {
4839 return false; // Already an external string. 4842 return false; // Already an external string.
4840 } 4843 }
4841 ENTER_V8(isolate); 4844 ENTER_V8(isolate);
4842 if (isolate->string_tracker()->IsFreshUnusedString(obj)) { 4845 if (isolate->string_tracker()->IsFreshUnusedString(obj)) {
4843 return false; 4846 return false;
4844 } 4847 }
4845 if (isolate->heap()->IsInGCPostProcessing()) { 4848 if (isolate->heap()->IsInGCPostProcessing()) {
4846 return false; 4849 return false;
4847 } 4850 }
4851 CHECK(resource && resource->data());
4848 bool result = obj->MakeExternal(resource); 4852 bool result = obj->MakeExternal(resource);
4849 if (result && !obj->IsSymbol()) { 4853 if (result && !obj->IsSymbol()) {
4850 isolate->heap()->external_string_table()->AddString(*obj); 4854 isolate->heap()->external_string_table()->AddString(*obj);
4851 } 4855 }
4852 return result; 4856 return result;
4853 } 4857 }
4854 4858
4855 4859
4856 bool v8::String::CanMakeExternal() { 4860 bool v8::String::CanMakeExternal() {
4857 if (!internal::FLAG_clever_optimizations) return false; 4861 if (!internal::FLAG_clever_optimizations) return false;
(...skipping 1664 matching lines...) Expand 10 before | Expand all | Expand 10 after
6522 6526
6523 v->VisitPointers(blocks_.first(), first_block_limit_); 6527 v->VisitPointers(blocks_.first(), first_block_limit_);
6524 6528
6525 for (int i = 1; i < blocks_.length(); i++) { 6529 for (int i = 1; i < blocks_.length(); i++) {
6526 v->VisitPointers(blocks_[i], &blocks_[i][kHandleBlockSize]); 6530 v->VisitPointers(blocks_[i], &blocks_[i][kHandleBlockSize]);
6527 } 6531 }
6528 } 6532 }
6529 6533
6530 6534
6531 } } // namespace v8::internal 6535 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698