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

Side by Side Diff: src/api.cc

Issue 501323002: Replace our homegrown ARRAY_SIZE() with Chrome's arraysize(). (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 3 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 | src/arm/code-stubs-arm.cc » ('j') | src/base/macros.h » ('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 // 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 2047 matching lines...) Expand 10 before | Expand all | Expand 10 after
2058 return i::Execution::Call(isolate, fun, recv, argc, argv); 2058 return i::Execution::Call(isolate, fun, recv, argc, argv);
2059 } 2059 }
2060 2060
2061 2061
2062 MUST_USE_RESULT static i::MaybeHandle<i::Object> CallV8HeapFunction( 2062 MUST_USE_RESULT static i::MaybeHandle<i::Object> CallV8HeapFunction(
2063 const char* name, 2063 const char* name,
2064 i::Handle<i::Object> data) { 2064 i::Handle<i::Object> data) {
2065 i::Handle<i::Object> argv[] = { data }; 2065 i::Handle<i::Object> argv[] = { data };
2066 return CallV8HeapFunction(name, 2066 return CallV8HeapFunction(name,
2067 i::Isolate::Current()->js_builtins_object(), 2067 i::Isolate::Current()->js_builtins_object(),
2068 ARRAY_SIZE(argv), 2068 arraysize(argv),
2069 argv); 2069 argv);
2070 } 2070 }
2071 2071
2072 2072
2073 int Message::GetLineNumber() const { 2073 int Message::GetLineNumber() const {
2074 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); 2074 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
2075 ON_BAILOUT(isolate, "v8::Message::GetLineNumber()", return kNoLineNumberInfo); 2075 ON_BAILOUT(isolate, "v8::Message::GetLineNumber()", return kNoLineNumberInfo);
2076 ENTER_V8(isolate); 2076 ENTER_V8(isolate);
2077 i::HandleScope scope(isolate); 2077 i::HandleScope scope(isolate);
2078 2078
(...skipping 881 matching lines...) Expand 10 before | Expand all | Expand 10 after
2960 // If both obj and other are JSObjects, we'd better compare by identity 2960 // If both obj and other are JSObjects, we'd better compare by identity
2961 // immediately when going into JS builtin. The reason is Invoke 2961 // immediately when going into JS builtin. The reason is Invoke
2962 // would overwrite global object receiver with global proxy. 2962 // would overwrite global object receiver with global proxy.
2963 if (obj->IsJSObject() && other->IsJSObject()) { 2963 if (obj->IsJSObject() && other->IsJSObject()) {
2964 return *obj == *other; 2964 return *obj == *other;
2965 } 2965 }
2966 i::Handle<i::Object> args[] = { other }; 2966 i::Handle<i::Object> args[] = { other };
2967 EXCEPTION_PREAMBLE(isolate); 2967 EXCEPTION_PREAMBLE(isolate);
2968 i::Handle<i::Object> result; 2968 i::Handle<i::Object> result;
2969 has_pending_exception = !CallV8HeapFunction( 2969 has_pending_exception = !CallV8HeapFunction(
2970 "EQUALS", obj, ARRAY_SIZE(args), args).ToHandle(&result); 2970 "EQUALS", obj, arraysize(args), args).ToHandle(&result);
2971 EXCEPTION_BAILOUT_CHECK(isolate, false); 2971 EXCEPTION_BAILOUT_CHECK(isolate, false);
2972 return *result == i::Smi::FromInt(i::EQUAL); 2972 return *result == i::Smi::FromInt(i::EQUAL);
2973 } 2973 }
2974 2974
2975 2975
2976 bool Value::StrictEquals(Handle<Value> that) const { 2976 bool Value::StrictEquals(Handle<Value> that) const {
2977 i::Isolate* isolate = i::Isolate::Current(); 2977 i::Isolate* isolate = i::Isolate::Current();
2978 i::Handle<i::Object> obj = Utils::OpenHandle(this, true); 2978 i::Handle<i::Object> obj = Utils::OpenHandle(this, true);
2979 if (!Utils::ApiCheck(!obj.is_null() && !that.IsEmpty(), 2979 if (!Utils::ApiCheck(!obj.is_null() && !that.IsEmpty(),
2980 "v8::Value::StrictEquals()", 2980 "v8::Value::StrictEquals()",
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
3189 return Local<Value>()); 3189 return Local<Value>());
3190 ENTER_V8(isolate); 3190 ENTER_V8(isolate);
3191 i::Handle<i::JSObject> obj = Utils::OpenHandle(this); 3191 i::Handle<i::JSObject> obj = Utils::OpenHandle(this);
3192 i::Handle<i::Name> key_name = Utils::OpenHandle(*key); 3192 i::Handle<i::Name> key_name = Utils::OpenHandle(*key);
3193 i::Handle<i::Object> args[] = { obj, key_name }; 3193 i::Handle<i::Object> args[] = { obj, key_name };
3194 EXCEPTION_PREAMBLE(isolate); 3194 EXCEPTION_PREAMBLE(isolate);
3195 i::Handle<i::Object> result; 3195 i::Handle<i::Object> result;
3196 has_pending_exception = !CallV8HeapFunction( 3196 has_pending_exception = !CallV8HeapFunction(
3197 "ObjectGetOwnPropertyDescriptor", 3197 "ObjectGetOwnPropertyDescriptor",
3198 isolate->factory()->undefined_value(), 3198 isolate->factory()->undefined_value(),
3199 ARRAY_SIZE(args), 3199 arraysize(args),
3200 args).ToHandle(&result); 3200 args).ToHandle(&result);
3201 EXCEPTION_BAILOUT_CHECK(isolate, Local<Value>()); 3201 EXCEPTION_BAILOUT_CHECK(isolate, Local<Value>());
3202 return Utils::ToLocal(result); 3202 return Utils::ToLocal(result);
3203 } 3203 }
3204 3204
3205 3205
3206 Local<Value> v8::Object::GetPrototype() { 3206 Local<Value> v8::Object::GetPrototype() {
3207 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); 3207 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
3208 ON_BAILOUT(isolate, "v8::Object::GetPrototype()", return Local<v8::Value>()); 3208 ON_BAILOUT(isolate, "v8::Object::GetPrototype()", return Local<v8::Value>());
3209 ENTER_V8(isolate); 3209 ENTER_V8(isolate);
(...skipping 2518 matching lines...) Expand 10 before | Expand all | Expand 10 after
5728 } 5728 }
5729 5729
5730 5730
5731 static i::Handle<i::String> RegExpFlagsToString(RegExp::Flags flags) { 5731 static i::Handle<i::String> RegExpFlagsToString(RegExp::Flags flags) {
5732 i::Isolate* isolate = i::Isolate::Current(); 5732 i::Isolate* isolate = i::Isolate::Current();
5733 uint8_t flags_buf[3]; 5733 uint8_t flags_buf[3];
5734 int num_flags = 0; 5734 int num_flags = 0;
5735 if ((flags & RegExp::kGlobal) != 0) flags_buf[num_flags++] = 'g'; 5735 if ((flags & RegExp::kGlobal) != 0) flags_buf[num_flags++] = 'g';
5736 if ((flags & RegExp::kMultiline) != 0) flags_buf[num_flags++] = 'm'; 5736 if ((flags & RegExp::kMultiline) != 0) flags_buf[num_flags++] = 'm';
5737 if ((flags & RegExp::kIgnoreCase) != 0) flags_buf[num_flags++] = 'i'; 5737 if ((flags & RegExp::kIgnoreCase) != 0) flags_buf[num_flags++] = 'i';
5738 DCHECK(num_flags <= static_cast<int>(ARRAY_SIZE(flags_buf))); 5738 DCHECK(num_flags <= static_cast<int>(arraysize(flags_buf)));
5739 return isolate->factory()->InternalizeOneByteString( 5739 return isolate->factory()->InternalizeOneByteString(
5740 i::Vector<const uint8_t>(flags_buf, num_flags)); 5740 i::Vector<const uint8_t>(flags_buf, num_flags));
5741 } 5741 }
5742 5742
5743 5743
5744 Local<v8::RegExp> v8::RegExp::New(Handle<String> pattern, 5744 Local<v8::RegExp> v8::RegExp::New(Handle<String> pattern,
5745 Flags flags) { 5745 Flags flags) {
5746 i::Isolate* isolate = Utils::OpenHandle(*pattern)->GetIsolate(); 5746 i::Isolate* isolate = Utils::OpenHandle(*pattern)->GetIsolate();
5747 EnsureInitializedForIsolate(isolate, "v8::RegExp::New()"); 5747 EnsureInitializedForIsolate(isolate, "v8::RegExp::New()");
5748 LOG_API(isolate, "RegExp::New"); 5748 LOG_API(isolate, "RegExp::New");
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
5834 i::Isolate* isolate = obj->GetIsolate(); 5834 i::Isolate* isolate = obj->GetIsolate();
5835 LOG_API(isolate, "IsPromise"); 5835 LOG_API(isolate, "IsPromise");
5836 ENTER_V8(isolate); 5836 ENTER_V8(isolate);
5837 EXCEPTION_PREAMBLE(isolate); 5837 EXCEPTION_PREAMBLE(isolate);
5838 i::Handle<i::Object> argv[] = { obj }; 5838 i::Handle<i::Object> argv[] = { obj };
5839 i::Handle<i::Object> b; 5839 i::Handle<i::Object> b;
5840 has_pending_exception = !i::Execution::Call( 5840 has_pending_exception = !i::Execution::Call(
5841 isolate, 5841 isolate,
5842 isolate->is_promise(), 5842 isolate->is_promise(),
5843 isolate->factory()->undefined_value(), 5843 isolate->factory()->undefined_value(),
5844 ARRAY_SIZE(argv), argv, 5844 arraysize(argv), argv,
5845 false).ToHandle(&b); 5845 false).ToHandle(&b);
5846 EXCEPTION_BAILOUT_CHECK(isolate, false); 5846 EXCEPTION_BAILOUT_CHECK(isolate, false);
5847 return b->BooleanValue(); 5847 return b->BooleanValue();
5848 } 5848 }
5849 5849
5850 5850
5851 Local<Promise::Resolver> Promise::Resolver::New(Isolate* v8_isolate) { 5851 Local<Promise::Resolver> Promise::Resolver::New(Isolate* v8_isolate) {
5852 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); 5852 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
5853 LOG_API(isolate, "Promise::Resolver::New"); 5853 LOG_API(isolate, "Promise::Resolver::New");
5854 ENTER_V8(isolate); 5854 ENTER_V8(isolate);
(...skipping 20 matching lines...) Expand all
5875 i::Handle<i::JSObject> promise = Utils::OpenHandle(this); 5875 i::Handle<i::JSObject> promise = Utils::OpenHandle(this);
5876 i::Isolate* isolate = promise->GetIsolate(); 5876 i::Isolate* isolate = promise->GetIsolate();
5877 LOG_API(isolate, "Promise::Resolver::Resolve"); 5877 LOG_API(isolate, "Promise::Resolver::Resolve");
5878 ENTER_V8(isolate); 5878 ENTER_V8(isolate);
5879 EXCEPTION_PREAMBLE(isolate); 5879 EXCEPTION_PREAMBLE(isolate);
5880 i::Handle<i::Object> argv[] = { promise, Utils::OpenHandle(*value) }; 5880 i::Handle<i::Object> argv[] = { promise, Utils::OpenHandle(*value) };
5881 has_pending_exception = i::Execution::Call( 5881 has_pending_exception = i::Execution::Call(
5882 isolate, 5882 isolate,
5883 isolate->promise_resolve(), 5883 isolate->promise_resolve(),
5884 isolate->factory()->undefined_value(), 5884 isolate->factory()->undefined_value(),
5885 ARRAY_SIZE(argv), argv, 5885 arraysize(argv), argv,
5886 false).is_null(); 5886 false).is_null();
5887 EXCEPTION_BAILOUT_CHECK(isolate, /* void */ ;); 5887 EXCEPTION_BAILOUT_CHECK(isolate, /* void */ ;);
5888 } 5888 }
5889 5889
5890 5890
5891 void Promise::Resolver::Reject(Handle<Value> value) { 5891 void Promise::Resolver::Reject(Handle<Value> value) {
5892 i::Handle<i::JSObject> promise = Utils::OpenHandle(this); 5892 i::Handle<i::JSObject> promise = Utils::OpenHandle(this);
5893 i::Isolate* isolate = promise->GetIsolate(); 5893 i::Isolate* isolate = promise->GetIsolate();
5894 LOG_API(isolate, "Promise::Resolver::Reject"); 5894 LOG_API(isolate, "Promise::Resolver::Reject");
5895 ENTER_V8(isolate); 5895 ENTER_V8(isolate);
5896 EXCEPTION_PREAMBLE(isolate); 5896 EXCEPTION_PREAMBLE(isolate);
5897 i::Handle<i::Object> argv[] = { promise, Utils::OpenHandle(*value) }; 5897 i::Handle<i::Object> argv[] = { promise, Utils::OpenHandle(*value) };
5898 has_pending_exception = i::Execution::Call( 5898 has_pending_exception = i::Execution::Call(
5899 isolate, 5899 isolate,
5900 isolate->promise_reject(), 5900 isolate->promise_reject(),
5901 isolate->factory()->undefined_value(), 5901 isolate->factory()->undefined_value(),
5902 ARRAY_SIZE(argv), argv, 5902 arraysize(argv), argv,
5903 false).is_null(); 5903 false).is_null();
5904 EXCEPTION_BAILOUT_CHECK(isolate, /* void */ ;); 5904 EXCEPTION_BAILOUT_CHECK(isolate, /* void */ ;);
5905 } 5905 }
5906 5906
5907 5907
5908 Local<Promise> Promise::Chain(Handle<Function> handler) { 5908 Local<Promise> Promise::Chain(Handle<Function> handler) {
5909 i::Handle<i::JSObject> promise = Utils::OpenHandle(this); 5909 i::Handle<i::JSObject> promise = Utils::OpenHandle(this);
5910 i::Isolate* isolate = promise->GetIsolate(); 5910 i::Isolate* isolate = promise->GetIsolate();
5911 LOG_API(isolate, "Promise::Chain"); 5911 LOG_API(isolate, "Promise::Chain");
5912 ENTER_V8(isolate); 5912 ENTER_V8(isolate);
5913 EXCEPTION_PREAMBLE(isolate); 5913 EXCEPTION_PREAMBLE(isolate);
5914 i::Handle<i::Object> argv[] = { Utils::OpenHandle(*handler) }; 5914 i::Handle<i::Object> argv[] = { Utils::OpenHandle(*handler) };
5915 i::Handle<i::Object> result; 5915 i::Handle<i::Object> result;
5916 has_pending_exception = !i::Execution::Call( 5916 has_pending_exception = !i::Execution::Call(
5917 isolate, 5917 isolate,
5918 isolate->promise_chain(), 5918 isolate->promise_chain(),
5919 promise, 5919 promise,
5920 ARRAY_SIZE(argv), argv, 5920 arraysize(argv), argv,
5921 false).ToHandle(&result); 5921 false).ToHandle(&result);
5922 EXCEPTION_BAILOUT_CHECK(isolate, Local<Promise>()); 5922 EXCEPTION_BAILOUT_CHECK(isolate, Local<Promise>());
5923 return Local<Promise>::Cast(Utils::ToLocal(result)); 5923 return Local<Promise>::Cast(Utils::ToLocal(result));
5924 } 5924 }
5925 5925
5926 5926
5927 Local<Promise> Promise::Catch(Handle<Function> handler) { 5927 Local<Promise> Promise::Catch(Handle<Function> handler) {
5928 i::Handle<i::JSObject> promise = Utils::OpenHandle(this); 5928 i::Handle<i::JSObject> promise = Utils::OpenHandle(this);
5929 i::Isolate* isolate = promise->GetIsolate(); 5929 i::Isolate* isolate = promise->GetIsolate();
5930 LOG_API(isolate, "Promise::Catch"); 5930 LOG_API(isolate, "Promise::Catch");
5931 ENTER_V8(isolate); 5931 ENTER_V8(isolate);
5932 EXCEPTION_PREAMBLE(isolate); 5932 EXCEPTION_PREAMBLE(isolate);
5933 i::Handle<i::Object> argv[] = { Utils::OpenHandle(*handler) }; 5933 i::Handle<i::Object> argv[] = { Utils::OpenHandle(*handler) };
5934 i::Handle<i::Object> result; 5934 i::Handle<i::Object> result;
5935 has_pending_exception = !i::Execution::Call( 5935 has_pending_exception = !i::Execution::Call(
5936 isolate, 5936 isolate,
5937 isolate->promise_catch(), 5937 isolate->promise_catch(),
5938 promise, 5938 promise,
5939 ARRAY_SIZE(argv), argv, 5939 arraysize(argv), argv,
5940 false).ToHandle(&result); 5940 false).ToHandle(&result);
5941 EXCEPTION_BAILOUT_CHECK(isolate, Local<Promise>()); 5941 EXCEPTION_BAILOUT_CHECK(isolate, Local<Promise>());
5942 return Local<Promise>::Cast(Utils::ToLocal(result)); 5942 return Local<Promise>::Cast(Utils::ToLocal(result));
5943 } 5943 }
5944 5944
5945 5945
5946 Local<Promise> Promise::Then(Handle<Function> handler) { 5946 Local<Promise> Promise::Then(Handle<Function> handler) {
5947 i::Handle<i::JSObject> promise = Utils::OpenHandle(this); 5947 i::Handle<i::JSObject> promise = Utils::OpenHandle(this);
5948 i::Isolate* isolate = promise->GetIsolate(); 5948 i::Isolate* isolate = promise->GetIsolate();
5949 LOG_API(isolate, "Promise::Then"); 5949 LOG_API(isolate, "Promise::Then");
5950 ENTER_V8(isolate); 5950 ENTER_V8(isolate);
5951 EXCEPTION_PREAMBLE(isolate); 5951 EXCEPTION_PREAMBLE(isolate);
5952 i::Handle<i::Object> argv[] = { Utils::OpenHandle(*handler) }; 5952 i::Handle<i::Object> argv[] = { Utils::OpenHandle(*handler) };
5953 i::Handle<i::Object> result; 5953 i::Handle<i::Object> result;
5954 has_pending_exception = !i::Execution::Call( 5954 has_pending_exception = !i::Execution::Call(
5955 isolate, 5955 isolate,
5956 isolate->promise_then(), 5956 isolate->promise_then(),
5957 promise, 5957 promise,
5958 ARRAY_SIZE(argv), argv, 5958 arraysize(argv), argv,
5959 false).ToHandle(&result); 5959 false).ToHandle(&result);
5960 EXCEPTION_BAILOUT_CHECK(isolate, Local<Promise>()); 5960 EXCEPTION_BAILOUT_CHECK(isolate, Local<Promise>());
5961 return Local<Promise>::Cast(Utils::ToLocal(result)); 5961 return Local<Promise>::Cast(Utils::ToLocal(result));
5962 } 5962 }
5963 5963
5964 5964
5965 bool v8::ArrayBuffer::IsExternal() const { 5965 bool v8::ArrayBuffer::IsExternal() const {
5966 return Utils::OpenHandle(this)->is_external(); 5966 return Utils::OpenHandle(this)->is_external();
5967 } 5967 }
5968 5968
(...skipping 1599 matching lines...) Expand 10 before | Expand all | Expand 10 after
7568 7568
7569 DCHECK(last_handle_before_deferred_block_ == NULL || 7569 DCHECK(last_handle_before_deferred_block_ == NULL ||
7570 found_block_before_deferred); 7570 found_block_before_deferred);
7571 7571
7572 // Iterate over live handles in the last block (if any). 7572 // Iterate over live handles in the last block (if any).
7573 if (!blocks()->is_empty()) { 7573 if (!blocks()->is_empty()) {
7574 v->VisitPointers(blocks()->last(), handle_scope_data_.next); 7574 v->VisitPointers(blocks()->last(), handle_scope_data_.next);
7575 } 7575 }
7576 7576
7577 List<Context*>* context_lists[2] = { &saved_contexts_, &entered_contexts_}; 7577 List<Context*>* context_lists[2] = { &saved_contexts_, &entered_contexts_};
7578 for (unsigned i = 0; i < ARRAY_SIZE(context_lists); i++) { 7578 for (unsigned i = 0; i < arraysize(context_lists); i++) {
7579 if (context_lists[i]->is_empty()) continue; 7579 if (context_lists[i]->is_empty()) continue;
7580 Object** start = reinterpret_cast<Object**>(&context_lists[i]->first()); 7580 Object** start = reinterpret_cast<Object**>(&context_lists[i]->first());
7581 v->VisitPointers(start, start + context_lists[i]->length()); 7581 v->VisitPointers(start, start + context_lists[i]->length());
7582 } 7582 }
7583 } 7583 }
7584 7584
7585 7585
7586 void HandleScopeImplementer::Iterate(ObjectVisitor* v) { 7586 void HandleScopeImplementer::Iterate(ObjectVisitor* v) {
7587 HandleScopeData* current = isolate_->handle_scope_data(); 7587 HandleScopeData* current = isolate_->handle_scope_data();
7588 handle_scope_data_ = *current; 7588 handle_scope_data_ = *current;
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
7677 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); 7677 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate());
7678 Address callback_address = 7678 Address callback_address =
7679 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); 7679 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback));
7680 VMState<EXTERNAL> state(isolate); 7680 VMState<EXTERNAL> state(isolate);
7681 ExternalCallbackScope call_scope(isolate, callback_address); 7681 ExternalCallbackScope call_scope(isolate, callback_address);
7682 callback(info); 7682 callback(info);
7683 } 7683 }
7684 7684
7685 7685
7686 } } // namespace v8::internal 7686 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | src/arm/code-stubs-arm.cc » ('j') | src/base/macros.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698