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

Side by Side Diff: src/api.cc

Issue 1477023002: Deprecate Promise::Chain from V8 APIs (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Alphabetize includes Created 5 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') | 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
11 #include <cmath> // For isnan. 11 #include <cmath> // For isnan.
12 #include <limits>
13 #include <string>
14 #include <vector>
12 #include "include/v8-debug.h" 15 #include "include/v8-debug.h"
13 #include "include/v8-profiler.h" 16 #include "include/v8-profiler.h"
14 #include "include/v8-testing.h" 17 #include "include/v8-testing.h"
15 #include "src/api-natives.h" 18 #include "src/api-natives.h"
16 #include "src/assert-scope.h" 19 #include "src/assert-scope.h"
17 #include "src/background-parsing-task.h" 20 #include "src/background-parsing-task.h"
18 #include "src/base/functional.h" 21 #include "src/base/functional.h"
19 #include "src/base/platform/platform.h" 22 #include "src/base/platform/platform.h"
20 #include "src/base/platform/time.h" 23 #include "src/base/platform/time.h"
21 #include "src/base/utils/random-number-generator.h" 24 #include "src/base/utils/random-number-generator.h"
(...skipping 853 matching lines...) Expand 10 before | Expand all | Expand 10 after
875 obj_.set(0, i::Smi::FromInt(0)); 878 obj_.set(0, i::Smi::FromInt(0));
876 } 879 }
877 880
878 881
879 int NeanderArray::length() { 882 int NeanderArray::length() {
880 return i::Smi::cast(obj_.get(0))->value(); 883 return i::Smi::cast(obj_.get(0))->value();
881 } 884 }
882 885
883 886
884 i::Object* NeanderArray::get(int offset) { 887 i::Object* NeanderArray::get(int offset) {
885 DCHECK(0 <= offset); 888 DCHECK_LE(0, offset);
886 DCHECK(offset < length()); 889 DCHECK_LT(offset, length());
jochen (gone - plz use gerrit) 2015/12/07 15:39:54 could you please move the unrelated refactoring to
Dan Ehrenberg 2015/12/07 18:57:54 It seems like the lint checking recently got more
887 return obj_.get(offset + 1); 890 return obj_.get(offset + 1);
888 } 891 }
889 892
890 893
891 // This method cannot easily return an error value, therefore it is necessary 894 // This method cannot easily return an error value, therefore it is necessary
892 // to check for a dead VM with ON_BAILOUT before calling it. To remind you 895 // to check for a dead VM with ON_BAILOUT before calling it. To remind you
893 // about this there is no HandleScope in this method. When you add one to the 896 // about this there is no HandleScope in this method. When you add one to the
894 // site calling this method you should check that you ensured the VM was not 897 // site calling this method you should check that you ensured the VM was not
895 // dead first. 898 // dead first.
896 void NeanderArray::add(i::Isolate* isolate, i::Handle<i::Object> value) { 899 void NeanderArray::add(i::Isolate* isolate, i::Handle<i::Object> value) {
(...skipping 3929 matching lines...) Expand 10 before | Expand all | Expand 10 after
4826 (state & kRightmostEdgeIsCalculated)); 4829 (state & kRightmostEdgeIsCalculated));
4827 if (EndsWithSurrogate(state) && StartsWithSurrogate(state)) { 4830 if (EndsWithSurrogate(state) && StartsWithSurrogate(state)) {
4828 *length -= unibrow::Utf8::kBytesSavedByCombiningSurrogates; 4831 *length -= unibrow::Utf8::kBytesSavedByCombiningSurrogates;
4829 } 4832 }
4830 *state_out = kInitialState | 4833 *state_out = kInitialState |
4831 (state & kLeftmostEdgeIsSurrogate ? kStartsWithTrailingSurrogate : 0) | 4834 (state & kLeftmostEdgeIsSurrogate ? kStartsWithTrailingSurrogate : 0) |
4832 (state & kRightmostEdgeIsSurrogate ? kEndsWithLeadingSurrogate : 0); 4835 (state & kRightmostEdgeIsSurrogate ? kEndsWithLeadingSurrogate : 0);
4833 } 4836 }
4834 4837
4835 static int Calculate(i::ConsString* current, uint8_t* state_out) { 4838 static int Calculate(i::ConsString* current, uint8_t* state_out) {
4836 using namespace internal; 4839 using internal::ConsString;
4837 int total_length = 0; 4840 int total_length = 0;
4838 uint8_t state = kInitialState; 4841 uint8_t state = kInitialState;
4839 while (true) { 4842 while (true) {
4840 i::String* left = current->first(); 4843 i::String* left = current->first();
4841 i::String* right = current->second(); 4844 i::String* right = current->second();
4842 uint8_t right_leaf_state; 4845 uint8_t right_leaf_state;
4843 uint8_t left_leaf_state; 4846 uint8_t left_leaf_state;
4844 int leaf_length; 4847 int leaf_length;
4845 ConsString* left_as_cons = 4848 ConsString* left_as_cons =
4846 Visitor::VisitFlat(left, &leaf_length, &left_leaf_state); 4849 Visitor::VisitFlat(left, &leaf_length, &left_leaf_state);
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
4926 skip_capacity_check_(capacity == -1 || skip_capacity_check), 4929 skip_capacity_check_(capacity == -1 || skip_capacity_check),
4927 replace_invalid_utf8_(replace_invalid_utf8), 4930 replace_invalid_utf8_(replace_invalid_utf8),
4928 utf16_chars_read_(0) { 4931 utf16_chars_read_(0) {
4929 } 4932 }
4930 4933
4931 static int WriteEndCharacter(uint16_t character, 4934 static int WriteEndCharacter(uint16_t character,
4932 int last_character, 4935 int last_character,
4933 int remaining, 4936 int remaining,
4934 char* const buffer, 4937 char* const buffer,
4935 bool replace_invalid_utf8) { 4938 bool replace_invalid_utf8) {
4936 using namespace unibrow; 4939 DCHECK_GT(remaining, 0);
4937 DCHECK(remaining > 0);
4938 // We can't use a local buffer here because Encode needs to modify 4940 // We can't use a local buffer here because Encode needs to modify
4939 // previous characters in the stream. We know, however, that 4941 // previous characters in the stream. We know, however, that
4940 // exactly one character will be advanced. 4942 // exactly one character will be advanced.
4941 if (Utf16::IsSurrogatePair(last_character, character)) { 4943 if (unibrow::Utf16::IsSurrogatePair(last_character, character)) {
4942 int written = Utf8::Encode(buffer, 4944 int written = unibrow::Utf8::Encode(buffer, character, last_character,
4943 character, 4945 replace_invalid_utf8);
4944 last_character, 4946 DCHECK_EQ(written, 1);
4945 replace_invalid_utf8);
4946 DCHECK(written == 1);
4947 return written; 4947 return written;
4948 } 4948 }
4949 // Use a scratch buffer to check the required characters. 4949 // Use a scratch buffer to check the required characters.
4950 char temp_buffer[Utf8::kMaxEncodedSize]; 4950 char temp_buffer[unibrow::Utf8::kMaxEncodedSize];
4951 // Can't encode using last_character as gcc has array bounds issues. 4951 // Can't encode using last_character as gcc has array bounds issues.
4952 int written = Utf8::Encode(temp_buffer, 4952 int written = unibrow::Utf8::Encode(temp_buffer, character,
4953 character, 4953 unibrow::Utf16::kNoPreviousCharacter,
4954 Utf16::kNoPreviousCharacter, 4954 replace_invalid_utf8);
4955 replace_invalid_utf8);
4956 // Won't fit. 4955 // Won't fit.
4957 if (written > remaining) return 0; 4956 if (written > remaining) return 0;
4958 // Copy over the character from temp_buffer. 4957 // Copy over the character from temp_buffer.
4959 for (int j = 0; j < written; j++) { 4958 for (int j = 0; j < written; j++) {
4960 buffer[j] = temp_buffer[j]; 4959 buffer[j] = temp_buffer[j];
4961 } 4960 }
4962 return written; 4961 return written;
4963 } 4962 }
4964 4963
4965 // Visit writes out a group of code units (chars) of a v8::String to the 4964 // Visit writes out a group of code units (chars) of a v8::String to the
4966 // internal buffer_. This is done in two phases. The first phase calculates a 4965 // internal buffer_. This is done in two phases. The first phase calculates a
4967 // pesimistic estimate (writable_length) on how many code units can be safely 4966 // pesimistic estimate (writable_length) on how many code units can be safely
4968 // written without exceeding the buffer capacity and without writing the last 4967 // written without exceeding the buffer capacity and without writing the last
4969 // code unit (it could be a lead surrogate). The estimated number of code 4968 // code unit (it could be a lead surrogate). The estimated number of code
4970 // units is then written out in one go, and the reported byte usage is used 4969 // units is then written out in one go, and the reported byte usage is used
4971 // to correct the estimate. This is repeated until the estimate becomes <= 0 4970 // to correct the estimate. This is repeated until the estimate becomes <= 0
4972 // or all code units have been written out. The second phase writes out code 4971 // or all code units have been written out. The second phase writes out code
4973 // units until the buffer capacity is reached, would be exceeded by the next 4972 // units until the buffer capacity is reached, would be exceeded by the next
4974 // unit, or all units have been written out. 4973 // unit, or all units have been written out.
4975 template<typename Char> 4974 template<typename Char>
4976 void Visit(const Char* chars, const int length) { 4975 void Visit(const Char* chars, const int length) {
4977 using namespace unibrow;
4978 DCHECK(!early_termination_); 4976 DCHECK(!early_termination_);
4979 if (length == 0) return; 4977 if (length == 0) return;
4980 // Copy state to stack. 4978 // Copy state to stack.
4981 char* buffer = buffer_; 4979 char* buffer = buffer_;
4982 int last_character = 4980 int last_character = sizeof(Char) == 1
4983 sizeof(Char) == 1 ? Utf16::kNoPreviousCharacter : last_character_; 4981 ? unibrow::Utf16::kNoPreviousCharacter
4982 : last_character_;
4984 int i = 0; 4983 int i = 0;
4985 // Do a fast loop where there is no exit capacity check. 4984 // Do a fast loop where there is no exit capacity check.
4986 while (true) { 4985 while (true) {
4987 int fast_length; 4986 int fast_length;
4988 if (skip_capacity_check_) { 4987 if (skip_capacity_check_) {
4989 fast_length = length; 4988 fast_length = length;
4990 } else { 4989 } else {
4991 int remaining_capacity = capacity_ - static_cast<int>(buffer - start_); 4990 int remaining_capacity = capacity_ - static_cast<int>(buffer - start_);
4992 // Need enough space to write everything but one character. 4991 // Need enough space to write everything but one character.
4993 STATIC_ASSERT(Utf16::kMaxExtraUtf8BytesForOneUtf16CodeUnit == 3); 4992 STATIC_ASSERT(unibrow::Utf16::kMaxExtraUtf8BytesForOneUtf16CodeUnit ==
4993 3);
4994 int max_size_per_char = sizeof(Char) == 1 ? 2 : 3; 4994 int max_size_per_char = sizeof(Char) == 1 ? 2 : 3;
4995 int writable_length = 4995 int writable_length =
4996 (remaining_capacity - max_size_per_char)/max_size_per_char; 4996 (remaining_capacity - max_size_per_char)/max_size_per_char;
4997 // Need to drop into slow loop. 4997 // Need to drop into slow loop.
4998 if (writable_length <= 0) break; 4998 if (writable_length <= 0) break;
4999 fast_length = i + writable_length; 4999 fast_length = i + writable_length;
5000 if (fast_length > length) fast_length = length; 5000 if (fast_length > length) fast_length = length;
5001 } 5001 }
5002 // Write the characters to the stream. 5002 // Write the characters to the stream.
5003 if (sizeof(Char) == 1) { 5003 if (sizeof(Char) == 1) {
5004 for (; i < fast_length; i++) { 5004 for (; i < fast_length; i++) {
5005 buffer += 5005 buffer += unibrow::Utf8::EncodeOneByte(
5006 Utf8::EncodeOneByte(buffer, static_cast<uint8_t>(*chars++)); 5006 buffer, static_cast<uint8_t>(*chars++));
5007 DCHECK(capacity_ == -1 || (buffer - start_) <= capacity_); 5007 DCHECK(capacity_ == -1 || (buffer - start_) <= capacity_);
5008 } 5008 }
5009 } else { 5009 } else {
5010 for (; i < fast_length; i++) { 5010 for (; i < fast_length; i++) {
5011 uint16_t character = *chars++; 5011 uint16_t character = *chars++;
5012 buffer += Utf8::Encode(buffer, 5012 buffer += unibrow::Utf8::Encode(buffer, character, last_character,
5013 character, 5013 replace_invalid_utf8_);
5014 last_character,
5015 replace_invalid_utf8_);
5016 last_character = character; 5014 last_character = character;
5017 DCHECK(capacity_ == -1 || (buffer - start_) <= capacity_); 5015 DCHECK(capacity_ == -1 || (buffer - start_) <= capacity_);
5018 } 5016 }
5019 } 5017 }
5020 // Array is fully written. Exit. 5018 // Array is fully written. Exit.
5021 if (fast_length == length) { 5019 if (fast_length == length) {
5022 // Write state back out to object. 5020 // Write state back out to object.
5023 last_character_ = last_character; 5021 last_character_ = last_character;
5024 buffer_ = buffer; 5022 buffer_ = buffer;
5025 utf16_chars_read_ += length; 5023 utf16_chars_read_ += length;
5026 return; 5024 return;
5027 } 5025 }
5028 } 5026 }
5029 DCHECK(!skip_capacity_check_); 5027 DCHECK(!skip_capacity_check_);
5030 // Slow loop. Must check capacity on each iteration. 5028 // Slow loop. Must check capacity on each iteration.
5031 int remaining_capacity = capacity_ - static_cast<int>(buffer - start_); 5029 int remaining_capacity = capacity_ - static_cast<int>(buffer - start_);
5032 DCHECK(remaining_capacity >= 0); 5030 DCHECK_GE(remaining_capacity, 0);
5033 for (; i < length && remaining_capacity > 0; i++) { 5031 for (; i < length && remaining_capacity > 0; i++) {
5034 uint16_t character = *chars++; 5032 uint16_t character = *chars++;
5035 // remaining_capacity is <= 3 bytes at this point, so we do not write out 5033 // remaining_capacity is <= 3 bytes at this point, so we do not write out
5036 // an umatched lead surrogate. 5034 // an umatched lead surrogate.
5037 if (replace_invalid_utf8_ && Utf16::IsLeadSurrogate(character)) { 5035 if (replace_invalid_utf8_ && unibrow::Utf16::IsLeadSurrogate(character)) {
5038 early_termination_ = true; 5036 early_termination_ = true;
5039 break; 5037 break;
5040 } 5038 }
5041 int written = WriteEndCharacter(character, 5039 int written = WriteEndCharacter(character,
5042 last_character, 5040 last_character,
5043 remaining_capacity, 5041 remaining_capacity,
5044 buffer, 5042 buffer,
5045 replace_invalid_utf8_); 5043 replace_invalid_utf8_);
5046 if (written == 0) { 5044 if (written == 0) {
5047 early_termination_ = true; 5045 early_termination_ = true;
(...skipping 1408 matching lines...) Expand 10 before | Expand all | Expand 10 after
6456 return Just(true); 6454 return Just(true);
6457 } 6455 }
6458 6456
6459 6457
6460 void Promise::Resolver::Reject(Local<Value> value) { 6458 void Promise::Resolver::Reject(Local<Value> value) {
6461 auto context = ContextFromHeapObject(Utils::OpenHandle(this)); 6459 auto context = ContextFromHeapObject(Utils::OpenHandle(this));
6462 USE(Reject(context, value)); 6460 USE(Reject(context, value));
6463 } 6461 }
6464 6462
6465 6463
6466 MaybeLocal<Promise> Promise::Chain(Local<Context> context, 6464 namespace {
6467 Local<Function> handler) { 6465
6466 MaybeLocal<Promise> DoChain(Value* value, Local<Context> context,
6467 Local<Function> handler) {
6468 PREPARE_FOR_EXECUTION(context, "Promise::Chain", Promise); 6468 PREPARE_FOR_EXECUTION(context, "Promise::Chain", Promise);
6469 auto self = Utils::OpenHandle(this); 6469 auto self = Utils::OpenHandle(value);
6470 i::Handle<i::Object> argv[] = {Utils::OpenHandle(*handler)}; 6470 i::Handle<i::Object> argv[] = {Utils::OpenHandle(*handler)};
6471 i::Handle<i::Object> result; 6471 i::Handle<i::Object> result;
6472 has_pending_exception = !i::Execution::Call(isolate, isolate->promise_chain(), 6472 has_pending_exception = !i::Execution::Call(isolate, isolate->promise_chain(),
6473 self, arraysize(argv), argv) 6473 self, arraysize(argv), argv)
6474 .ToHandle(&result); 6474 .ToHandle(&result);
6475 RETURN_ON_FAILED_EXECUTION(Promise); 6475 RETURN_ON_FAILED_EXECUTION(Promise);
6476 RETURN_ESCAPED(Local<Promise>::Cast(Utils::ToLocal(result))); 6476 RETURN_ESCAPED(Local<Promise>::Cast(Utils::ToLocal(result)));
6477 } 6477 }
6478 6478
6479 } // namespace
6480
6481
6482 MaybeLocal<Promise> Promise::Chain(Local<Context> context,
6483 Local<Function> handler) {
6484 return DoChain(this, context, handler);
6485 }
6486
6479 6487
6480 Local<Promise> Promise::Chain(Local<Function> handler) { 6488 Local<Promise> Promise::Chain(Local<Function> handler) {
6481 auto context = ContextFromHeapObject(Utils::OpenHandle(this)); 6489 auto context = ContextFromHeapObject(Utils::OpenHandle(this));
6482 RETURN_TO_LOCAL_UNCHECKED(Chain(context, handler), Promise); 6490 RETURN_TO_LOCAL_UNCHECKED(DoChain(this, context, handler), Promise);
6483 } 6491 }
6484 6492
6485 6493
6486 MaybeLocal<Promise> Promise::Catch(Local<Context> context, 6494 MaybeLocal<Promise> Promise::Catch(Local<Context> context,
6487 Local<Function> handler) { 6495 Local<Function> handler) {
6488 PREPARE_FOR_EXECUTION(context, "Promise::Catch", Promise); 6496 PREPARE_FOR_EXECUTION(context, "Promise::Catch", Promise);
6489 auto self = Utils::OpenHandle(this); 6497 auto self = Utils::OpenHandle(this);
6490 i::Handle<i::Object> argv[] = { Utils::OpenHandle(*handler) }; 6498 i::Handle<i::Object> argv[] = { Utils::OpenHandle(*handler) };
6491 i::Handle<i::Object> result; 6499 i::Handle<i::Object> result;
6492 has_pending_exception = !i::Execution::Call(isolate, isolate->promise_catch(), 6500 has_pending_exception = !i::Execution::Call(isolate, isolate->promise_catch(),
(...skipping 1532 matching lines...) Expand 10 before | Expand all | Expand 10 after
8025 return (profile->end_time() - base::TimeTicks()).InMicroseconds(); 8033 return (profile->end_time() - base::TimeTicks()).InMicroseconds();
8026 } 8034 }
8027 8035
8028 8036
8029 int CpuProfile::GetSamplesCount() const { 8037 int CpuProfile::GetSamplesCount() const {
8030 return reinterpret_cast<const i::CpuProfile*>(this)->samples_count(); 8038 return reinterpret_cast<const i::CpuProfile*>(this)->samples_count();
8031 } 8039 }
8032 8040
8033 8041
8034 void CpuProfiler::SetSamplingInterval(int us) { 8042 void CpuProfiler::SetSamplingInterval(int us) {
8035 DCHECK(us >= 0); 8043 DCHECK_GE(us, 0);
8036 return reinterpret_cast<i::CpuProfiler*>(this)->set_sampling_interval( 8044 return reinterpret_cast<i::CpuProfiler*>(this)->set_sampling_interval(
8037 base::TimeDelta::FromMicroseconds(us)); 8045 base::TimeDelta::FromMicroseconds(us));
8038 } 8046 }
8039 8047
8040 8048
8041 void CpuProfiler::StartProfiling(Local<String> title, bool record_samples) { 8049 void CpuProfiler::StartProfiling(Local<String> title, bool record_samples) {
8042 reinterpret_cast<i::CpuProfiler*>(this)->StartProfiling( 8050 reinterpret_cast<i::CpuProfiler*>(this)->StartProfiling(
8043 *Utils::OpenHandle(*title), record_samples); 8051 *Utils::OpenHandle(*title), record_samples);
8044 } 8052 }
8045 8053
(...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after
8521 Address callback_address = 8529 Address callback_address =
8522 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); 8530 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback));
8523 VMState<EXTERNAL> state(isolate); 8531 VMState<EXTERNAL> state(isolate);
8524 ExternalCallbackScope call_scope(isolate, callback_address); 8532 ExternalCallbackScope call_scope(isolate, callback_address);
8525 callback(info); 8533 callback(info);
8526 } 8534 }
8527 8535
8528 8536
8529 } // namespace internal 8537 } // namespace internal
8530 } // namespace v8 8538 } // namespace v8
OLDNEW
« no previous file with comments | « include/v8.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698