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

Side by Side Diff: src/api.cc

Issue 11469014: Add a safe API for creating ASCII-only strings
Patch Set: Created 8 years 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
« no previous file with comments | « include/v8.h ('k') | src/factory.h » ('j') | src/heap.cc » ('J')
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 4831 matching lines...) Expand 10 before | Expand all | Expand 10 after
4842 if (length == 0) return Empty(); 4842 if (length == 0) return Empty();
4843 ENTER_V8(isolate); 4843 ENTER_V8(isolate);
4844 if (length == -1) length = i::StrLength(data); 4844 if (length == -1) length = i::StrLength(data);
4845 i::Handle<i::String> result = 4845 i::Handle<i::String> result =
4846 isolate->factory()->NewStringFromUtf8( 4846 isolate->factory()->NewStringFromUtf8(
4847 i::Vector<const char>(data, length)); 4847 i::Vector<const char>(data, length));
4848 return Utils::ToLocal(result); 4848 return Utils::ToLocal(result);
4849 } 4849 }
4850 4850
4851 4851
4852 Local<String> v8::String::NewFromAscii(const char* data, int length) {
4853 i::Isolate* isolate = i::Isolate::Current();
4854 EnsureInitializedForIsolate(isolate, "v8::String::NewFromAscii()");
4855 LOG_API(isolate, "String::NewFromAscii(char)");
4856 if (length == 0) return Empty();
4857 ENTER_V8(isolate);
4858 if (length == -1) length = i::StrLength(data);
4859 i::Handle<i::String> result =
4860 isolate->factory()->NewStringFromAsciiSafe(
4861 i::Vector<const char>(data, length));
4862 return Utils::ToLocal(result);
4863 }
4864
4865
4852 Local<String> v8::String::Concat(Handle<String> left, Handle<String> right) { 4866 Local<String> v8::String::Concat(Handle<String> left, Handle<String> right) {
4853 i::Handle<i::String> left_string = Utils::OpenHandle(*left); 4867 i::Handle<i::String> left_string = Utils::OpenHandle(*left);
4854 i::Isolate* isolate = left_string->GetIsolate(); 4868 i::Isolate* isolate = left_string->GetIsolate();
4855 EnsureInitializedForIsolate(isolate, "v8::String::New()"); 4869 EnsureInitializedForIsolate(isolate, "v8::String::New()");
4856 LOG_API(isolate, "String::New(char)"); 4870 LOG_API(isolate, "String::New(char)");
4857 ENTER_V8(isolate); 4871 ENTER_V8(isolate);
4858 i::Handle<i::String> right_string = Utils::OpenHandle(*right); 4872 i::Handle<i::String> right_string = Utils::OpenHandle(*right);
4859 i::Handle<i::String> result = isolate->factory()->NewConsString(left_string, 4873 i::Handle<i::String> result = isolate->factory()->NewConsString(left_string,
4860 right_string); 4874 right_string);
4861 return Utils::ToLocal(result); 4875 return Utils::ToLocal(result);
(...skipping 1849 matching lines...) Expand 10 before | Expand all | Expand 10 after
6711 6725
6712 v->VisitPointers(blocks_.first(), first_block_limit_); 6726 v->VisitPointers(blocks_.first(), first_block_limit_);
6713 6727
6714 for (int i = 1; i < blocks_.length(); i++) { 6728 for (int i = 1; i < blocks_.length(); i++) {
6715 v->VisitPointers(blocks_[i], &blocks_[i][kHandleBlockSize]); 6729 v->VisitPointers(blocks_[i], &blocks_[i][kHandleBlockSize]);
6716 } 6730 }
6717 } 6731 }
6718 6732
6719 6733
6720 } } // namespace v8::internal 6734 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « include/v8.h ('k') | src/factory.h » ('j') | src/heap.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698