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

Side by Side Diff: src/api.cc

Issue 2149763004: Minor cleanup: remove an unused declaration, reuse some others. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 5 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
« 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 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/api.h" 5 #include "src/api.h"
6 6
7 #include <string.h> // For memcpy, strlen. 7 #include <string.h> // For memcpy, strlen.
8 #ifdef V8_USE_ADDRESS_SANITIZER 8 #ifdef V8_USE_ADDRESS_SANITIZER
9 #include <sanitizer/asan_interface.h> 9 #include <sanitizer/asan_interface.h>
10 #endif // V8_USE_ADDRESS_SANITIZER 10 #endif // V8_USE_ADDRESS_SANITIZER
(...skipping 1769 matching lines...) Expand 10 before | Expand all | Expand 10 after
1780 1780
1781 const ScriptCompiler::CachedData* 1781 const ScriptCompiler::CachedData*
1782 ScriptCompiler::StreamedSource::GetCachedData() const { 1782 ScriptCompiler::StreamedSource::GetCachedData() const {
1783 return impl_->cached_data.get(); 1783 return impl_->cached_data.get();
1784 } 1784 }
1785 1785
1786 1786
1787 Local<Script> UnboundScript::BindToCurrentContext() { 1787 Local<Script> UnboundScript::BindToCurrentContext() {
1788 i::Handle<i::HeapObject> obj = 1788 i::Handle<i::HeapObject> obj =
1789 i::Handle<i::HeapObject>::cast(Utils::OpenHandle(this)); 1789 i::Handle<i::HeapObject>::cast(Utils::OpenHandle(this));
1790 i::Handle<i::SharedFunctionInfo>
1791 function_info(i::SharedFunctionInfo::cast(*obj), obj->GetIsolate());
1792 i::Isolate* isolate = obj->GetIsolate(); 1790 i::Isolate* isolate = obj->GetIsolate();
1793 1791 i::Handle<i::SharedFunctionInfo> function_info(
1794 i::Handle<i::JSReceiver> global(isolate->native_context()->global_object()); 1792 i::SharedFunctionInfo::cast(*obj), isolate);
1795 i::Handle<i::JSFunction> function = 1793 i::Handle<i::JSFunction> function =
1796 obj->GetIsolate()->factory()->NewFunctionFromSharedFunctionInfo( 1794 isolate->factory()->NewFunctionFromSharedFunctionInfo(
1797 function_info, isolate->native_context()); 1795 function_info, isolate->native_context());
1798 return ToApiHandle<Script>(function); 1796 return ToApiHandle<Script>(function);
1799 } 1797 }
1800 1798
1801 1799
1802 int UnboundScript::GetId() { 1800 int UnboundScript::GetId() {
1803 i::Handle<i::HeapObject> obj = 1801 i::Handle<i::HeapObject> obj =
1804 i::Handle<i::HeapObject>::cast(Utils::OpenHandle(this)); 1802 i::Handle<i::HeapObject>::cast(Utils::OpenHandle(this));
1805 i::Isolate* isolate = obj->GetIsolate(); 1803 i::Isolate* isolate = obj->GetIsolate();
1806 LOG_API(isolate, UnboundScript, GetId); 1804 LOG_API(isolate, UnboundScript, GetId);
(...skipping 3453 matching lines...) Expand 10 before | Expand all | Expand 10 after
5260 current = cons_string->second(); 5258 current = cons_string->second();
5261 } 5259 }
5262 return true; 5260 return true;
5263 } 5261 }
5264 5262
5265 5263
5266 int String::WriteUtf8(char* buffer, 5264 int String::WriteUtf8(char* buffer,
5267 int capacity, 5265 int capacity,
5268 int* nchars_ref, 5266 int* nchars_ref,
5269 int options) const { 5267 int options) const {
5270 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); 5268 i::Handle<i::String> str = Utils::OpenHandle(this);
5269 i::Isolate* isolate = str->GetIsolate();
5271 LOG_API(isolate, String, WriteUtf8); 5270 LOG_API(isolate, String, WriteUtf8);
5272 ENTER_V8(isolate); 5271 ENTER_V8(isolate);
5273 i::Handle<i::String> str = Utils::OpenHandle(this);
5274 if (options & HINT_MANY_WRITES_EXPECTED) { 5272 if (options & HINT_MANY_WRITES_EXPECTED) {
5275 str = i::String::Flatten(str); // Flatten the string for efficiency. 5273 str = i::String::Flatten(str); // Flatten the string for efficiency.
5276 } 5274 }
5277 const int string_length = str->length(); 5275 const int string_length = str->length();
5278 bool write_null = !(options & NO_NULL_TERMINATION); 5276 bool write_null = !(options & NO_NULL_TERMINATION);
5279 bool replace_invalid_utf8 = (options & REPLACE_INVALID_UTF8); 5277 bool replace_invalid_utf8 = (options & REPLACE_INVALID_UTF8);
5280 int max16BitCodeUnitSize = unibrow::Utf8::kMax16BitCodeUnitSize; 5278 int max16BitCodeUnitSize = unibrow::Utf8::kMax16BitCodeUnitSize;
5281 // First check if we can just write the string without checking capacity. 5279 // First check if we can just write the string without checking capacity.
5282 if (capacity == -1 || capacity / max16BitCodeUnitSize >= string_length) { 5280 if (capacity == -1 || capacity / max16BitCodeUnitSize >= string_length) {
5283 Utf8WriterVisitor writer(buffer, capacity, true, replace_invalid_utf8); 5281 Utf8WriterVisitor writer(buffer, capacity, true, replace_invalid_utf8);
5284 const int kMaxRecursion = 100; 5282 const int kMaxRecursion = 100;
5285 bool success = RecursivelySerializeToUtf8(*str, &writer, kMaxRecursion); 5283 bool success = RecursivelySerializeToUtf8(*str, &writer, kMaxRecursion);
5286 if (success) return writer.CompleteWrite(write_null, nchars_ref); 5284 if (success) return writer.CompleteWrite(write_null, nchars_ref);
5287 } else if (capacity >= string_length) { 5285 } else if (capacity >= string_length) {
5288 // First check that the buffer is large enough. 5286 // First check that the buffer is large enough.
5289 int utf8_bytes = v8::Utf8Length(*str, str->GetIsolate()); 5287 int utf8_bytes = v8::Utf8Length(*str, isolate);
5290 if (utf8_bytes <= capacity) { 5288 if (utf8_bytes <= capacity) {
5291 // one-byte fast path. 5289 // one-byte fast path.
5292 if (utf8_bytes == string_length) { 5290 if (utf8_bytes == string_length) {
5293 WriteOneByte(reinterpret_cast<uint8_t*>(buffer), 0, capacity, options); 5291 WriteOneByte(reinterpret_cast<uint8_t*>(buffer), 0, capacity, options);
5294 if (nchars_ref != NULL) *nchars_ref = string_length; 5292 if (nchars_ref != NULL) *nchars_ref = string_length;
5295 if (write_null && (utf8_bytes+1 <= capacity)) { 5293 if (write_null && (utf8_bytes+1 <= capacity)) {
5296 return string_length + 1; 5294 return string_length + 1;
5297 } 5295 }
5298 return string_length; 5296 return string_length;
5299 } 5297 }
(...skipping 1564 matching lines...) Expand 10 before | Expand all | Expand 10 after
6864 6862
6865 6863
6866 void v8::ArrayBuffer::Neuter() { 6864 void v8::ArrayBuffer::Neuter() {
6867 i::Handle<i::JSArrayBuffer> obj = Utils::OpenHandle(this); 6865 i::Handle<i::JSArrayBuffer> obj = Utils::OpenHandle(this);
6868 i::Isolate* isolate = obj->GetIsolate(); 6866 i::Isolate* isolate = obj->GetIsolate();
6869 Utils::ApiCheck(obj->is_external(), 6867 Utils::ApiCheck(obj->is_external(),
6870 "v8::ArrayBuffer::Neuter", 6868 "v8::ArrayBuffer::Neuter",
6871 "Only externalized ArrayBuffers can be neutered"); 6869 "Only externalized ArrayBuffers can be neutered");
6872 Utils::ApiCheck(obj->is_neuterable(), "v8::ArrayBuffer::Neuter", 6870 Utils::ApiCheck(obj->is_neuterable(), "v8::ArrayBuffer::Neuter",
6873 "Only neuterable ArrayBuffers can be neutered"); 6871 "Only neuterable ArrayBuffers can be neutered");
6874 LOG_API(obj->GetIsolate(), ArrayBuffer, Neuter); 6872 LOG_API(isolate, ArrayBuffer, Neuter);
6875 ENTER_V8(isolate); 6873 ENTER_V8(isolate);
6876 obj->Neuter(); 6874 obj->Neuter();
6877 } 6875 }
6878 6876
6879 6877
6880 size_t v8::ArrayBuffer::ByteLength() const { 6878 size_t v8::ArrayBuffer::ByteLength() const {
6881 i::Handle<i::JSArrayBuffer> obj = Utils::OpenHandle(this); 6879 i::Handle<i::JSArrayBuffer> obj = Utils::OpenHandle(this);
6882 return static_cast<size_t>(obj->byte_length()->Number()); 6880 return static_cast<size_t>(obj->byte_length()->Number());
6883 } 6881 }
6884 6882
(...skipping 2124 matching lines...) Expand 10 before | Expand all | Expand 10 after
9009 Address callback_address = 9007 Address callback_address =
9010 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); 9008 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback));
9011 VMState<EXTERNAL> state(isolate); 9009 VMState<EXTERNAL> state(isolate);
9012 ExternalCallbackScope call_scope(isolate, callback_address); 9010 ExternalCallbackScope call_scope(isolate, callback_address);
9013 callback(info); 9011 callback(info);
9014 } 9012 }
9015 9013
9016 9014
9017 } // namespace internal 9015 } // namespace internal
9018 } // namespace v8 9016 } // namespace v8
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