From: bmeurer@chromium.org Date: Tue, 26 Aug 2014 09:19:24 +0000 (+0000) Subject: Replace our homegrown ARRAY_SIZE() with Chrome's arraysize(). X-Git-Tag: upstream/4.7.83~7385 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=90c893259647b359d2ab1cab6fa55c7745c81c8d;p=platform%2Fupstream%2Fv8.git Replace our homegrown ARRAY_SIZE() with Chrome's arraysize(). Our own ARRAY_SIZE() was pretty bad at error checking. If you use arrasize() in a wrong way, the compiler will issue an error instead of silently doing the wrong thing. The previous ARRAY_SIZE() macro is still available as ARRAYSIZE_UNSAFE() similar to Chrome. R=yangguo@chromium.org Review URL: https://codereview.chromium.org/501323002 git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@23389 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- diff --git a/src/api.cc b/src/api.cc index 45efd68..041d86b 100644 --- a/src/api.cc +++ b/src/api.cc @@ -2065,7 +2065,7 @@ MUST_USE_RESULT static i::MaybeHandle CallV8HeapFunction( i::Handle argv[] = { data }; return CallV8HeapFunction(name, i::Isolate::Current()->js_builtins_object(), - ARRAY_SIZE(argv), + arraysize(argv), argv); } @@ -2967,7 +2967,7 @@ bool Value::Equals(Handle that) const { EXCEPTION_PREAMBLE(isolate); i::Handle result; has_pending_exception = !CallV8HeapFunction( - "EQUALS", obj, ARRAY_SIZE(args), args).ToHandle(&result); + "EQUALS", obj, arraysize(args), args).ToHandle(&result); EXCEPTION_BAILOUT_CHECK(isolate, false); return *result == i::Smi::FromInt(i::EQUAL); } @@ -3196,7 +3196,7 @@ Local v8::Object::GetOwnPropertyDescriptor(Local key) { has_pending_exception = !CallV8HeapFunction( "ObjectGetOwnPropertyDescriptor", isolate->factory()->undefined_value(), - ARRAY_SIZE(args), + arraysize(args), args).ToHandle(&result); EXCEPTION_BAILOUT_CHECK(isolate, Local()); return Utils::ToLocal(result); @@ -5735,7 +5735,7 @@ static i::Handle RegExpFlagsToString(RegExp::Flags flags) { if ((flags & RegExp::kGlobal) != 0) flags_buf[num_flags++] = 'g'; if ((flags & RegExp::kMultiline) != 0) flags_buf[num_flags++] = 'm'; if ((flags & RegExp::kIgnoreCase) != 0) flags_buf[num_flags++] = 'i'; - DCHECK(num_flags <= static_cast(ARRAY_SIZE(flags_buf))); + DCHECK(num_flags <= static_cast(arraysize(flags_buf))); return isolate->factory()->InternalizeOneByteString( i::Vector(flags_buf, num_flags)); } @@ -5841,7 +5841,7 @@ bool Value::IsPromise() const { isolate, isolate->is_promise(), isolate->factory()->undefined_value(), - ARRAY_SIZE(argv), argv, + arraysize(argv), argv, false).ToHandle(&b); EXCEPTION_BAILOUT_CHECK(isolate, false); return b->BooleanValue(); @@ -5882,7 +5882,7 @@ void Promise::Resolver::Resolve(Handle value) { isolate, isolate->promise_resolve(), isolate->factory()->undefined_value(), - ARRAY_SIZE(argv), argv, + arraysize(argv), argv, false).is_null(); EXCEPTION_BAILOUT_CHECK(isolate, /* void */ ;); } @@ -5899,7 +5899,7 @@ void Promise::Resolver::Reject(Handle value) { isolate, isolate->promise_reject(), isolate->factory()->undefined_value(), - ARRAY_SIZE(argv), argv, + arraysize(argv), argv, false).is_null(); EXCEPTION_BAILOUT_CHECK(isolate, /* void */ ;); } @@ -5917,7 +5917,7 @@ Local Promise::Chain(Handle handler) { isolate, isolate->promise_chain(), promise, - ARRAY_SIZE(argv), argv, + arraysize(argv), argv, false).ToHandle(&result); EXCEPTION_BAILOUT_CHECK(isolate, Local()); return Local::Cast(Utils::ToLocal(result)); @@ -5936,7 +5936,7 @@ Local Promise::Catch(Handle handler) { isolate, isolate->promise_catch(), promise, - ARRAY_SIZE(argv), argv, + arraysize(argv), argv, false).ToHandle(&result); EXCEPTION_BAILOUT_CHECK(isolate, Local()); return Local::Cast(Utils::ToLocal(result)); @@ -5955,7 +5955,7 @@ Local Promise::Then(Handle handler) { isolate, isolate->promise_then(), promise, - ARRAY_SIZE(argv), argv, + arraysize(argv), argv, false).ToHandle(&result); EXCEPTION_BAILOUT_CHECK(isolate, Local()); return Local::Cast(Utils::ToLocal(result)); @@ -7575,7 +7575,7 @@ void HandleScopeImplementer::IterateThis(ObjectVisitor* v) { } List* context_lists[2] = { &saved_contexts_, &entered_contexts_}; - for (unsigned i = 0; i < ARRAY_SIZE(context_lists); i++) { + for (unsigned i = 0; i < arraysize(context_lists); i++) { if (context_lists[i]->is_empty()) continue; Object** start = reinterpret_cast(&context_lists[i]->first()); v->VisitPointers(start, start + context_lists[i]->length()); diff --git a/src/arm/code-stubs-arm.cc b/src/arm/code-stubs-arm.cc index d96560f..0d6ec18 100644 --- a/src/arm/code-stubs-arm.cc +++ b/src/arm/code-stubs-arm.cc @@ -23,7 +23,7 @@ void FastNewClosureStub::InitializeInterfaceDescriptor( CodeStubInterfaceDescriptor* descriptor) { Register registers[] = { cp, r2 }; descriptor->Initialize( - MajorKey(), ARRAY_SIZE(registers), registers, + MajorKey(), arraysize(registers), registers, Runtime::FunctionForId(Runtime::kNewClosureFromStubFailure)->entry); } @@ -31,14 +31,14 @@ void FastNewClosureStub::InitializeInterfaceDescriptor( void FastNewContextStub::InitializeInterfaceDescriptor( CodeStubInterfaceDescriptor* descriptor) { Register registers[] = { cp, r1 }; - descriptor->Initialize(MajorKey(), ARRAY_SIZE(registers), registers); + descriptor->Initialize(MajorKey(), arraysize(registers), registers); } void ToNumberStub::InitializeInterfaceDescriptor( CodeStubInterfaceDescriptor* descriptor) { Register registers[] = { cp, r0 }; - descriptor->Initialize(MajorKey(), ARRAY_SIZE(registers), registers); + descriptor->Initialize(MajorKey(), arraysize(registers), registers); } @@ -46,7 +46,7 @@ void NumberToStringStub::InitializeInterfaceDescriptor( CodeStubInterfaceDescriptor* descriptor) { Register registers[] = { cp, r0 }; descriptor->Initialize( - MajorKey(), ARRAY_SIZE(registers), registers, + MajorKey(), arraysize(registers), registers, Runtime::FunctionForId(Runtime::kNumberToStringRT)->entry); } @@ -60,7 +60,7 @@ void FastCloneShallowArrayStub::InitializeInterfaceDescriptor( Representation::Smi(), Representation::Tagged() }; descriptor->Initialize( - MajorKey(), ARRAY_SIZE(registers), registers, + MajorKey(), arraysize(registers), registers, Runtime::FunctionForId(Runtime::kCreateArrayLiteralStubBailout)->entry, representations); } @@ -70,7 +70,7 @@ void FastCloneShallowObjectStub::InitializeInterfaceDescriptor( CodeStubInterfaceDescriptor* descriptor) { Register registers[] = { cp, r3, r2, r1, r0 }; descriptor->Initialize( - MajorKey(), ARRAY_SIZE(registers), registers, + MajorKey(), arraysize(registers), registers, Runtime::FunctionForId(Runtime::kCreateObjectLiteral)->entry); } @@ -78,7 +78,7 @@ void FastCloneShallowObjectStub::InitializeInterfaceDescriptor( void CreateAllocationSiteStub::InitializeInterfaceDescriptor( CodeStubInterfaceDescriptor* descriptor) { Register registers[] = { cp, r2, r3 }; - descriptor->Initialize(MajorKey(), ARRAY_SIZE(registers), registers); + descriptor->Initialize(MajorKey(), arraysize(registers), registers); } @@ -86,7 +86,7 @@ void CallFunctionStub::InitializeInterfaceDescriptor( CodeStubInterfaceDescriptor* descriptor) { // r1 function the function to call Register registers[] = {cp, r1}; - descriptor->Initialize(MajorKey(), ARRAY_SIZE(registers), registers); + descriptor->Initialize(MajorKey(), arraysize(registers), registers); } @@ -100,7 +100,7 @@ void CallConstructStub::InitializeInterfaceDescriptor( // TODO(turbofan): So far we don't gather type feedback and hence skip the // slot parameter, but ArrayConstructStub needs the vector to be undefined. Register registers[] = {cp, r0, r1, r2}; - descriptor->Initialize(MajorKey(), ARRAY_SIZE(registers), registers); + descriptor->Initialize(MajorKey(), arraysize(registers), registers); } @@ -108,7 +108,7 @@ void RegExpConstructResultStub::InitializeInterfaceDescriptor( CodeStubInterfaceDescriptor* descriptor) { Register registers[] = { cp, r2, r1, r0 }; descriptor->Initialize( - MajorKey(), ARRAY_SIZE(registers), registers, + MajorKey(), arraysize(registers), registers, Runtime::FunctionForId(Runtime::kRegExpConstructResult)->entry); } @@ -118,7 +118,7 @@ void TransitionElementsKindStub::InitializeInterfaceDescriptor( Register registers[] = { cp, r0, r1 }; Address entry = Runtime::FunctionForId(Runtime::kTransitionElementsKind)->entry; - descriptor->Initialize(MajorKey(), ARRAY_SIZE(registers), registers, + descriptor->Initialize(MajorKey(), arraysize(registers), registers, FUNCTION_ADDR(entry)); } @@ -126,7 +126,7 @@ void TransitionElementsKindStub::InitializeInterfaceDescriptor( void CompareNilICStub::InitializeInterfaceDescriptor( CodeStubInterfaceDescriptor* descriptor) { Register registers[] = { cp, r0 }; - descriptor->Initialize(MajorKey(), ARRAY_SIZE(registers), registers, + descriptor->Initialize(MajorKey(), arraysize(registers), registers, FUNCTION_ADDR(CompareNilIC_Miss)); descriptor->SetMissHandler( ExternalReference(IC_Utility(IC::kCompareNilIC_Miss), isolate())); @@ -149,7 +149,7 @@ static void InitializeArrayConstructorDescriptor( if (constant_stack_parameter_count == 0) { Register registers[] = { cp, r1, r2 }; - descriptor->Initialize(major, ARRAY_SIZE(registers), registers, + descriptor->Initialize(major, arraysize(registers), registers, deopt_handler, NULL, constant_stack_parameter_count, JS_FUNCTION_STUB_MODE); } else { @@ -160,7 +160,7 @@ static void InitializeArrayConstructorDescriptor( Representation::Tagged(), Representation::Tagged(), Representation::Integer32() }; - descriptor->Initialize(major, ARRAY_SIZE(registers), registers, r0, + descriptor->Initialize(major, arraysize(registers), registers, r0, deopt_handler, representations, constant_stack_parameter_count, JS_FUNCTION_STUB_MODE, PASS_ARGUMENTS); @@ -180,7 +180,7 @@ static void InitializeInternalArrayConstructorDescriptor( if (constant_stack_parameter_count == 0) { Register registers[] = { cp, r1 }; - descriptor->Initialize(major, ARRAY_SIZE(registers), registers, + descriptor->Initialize(major, arraysize(registers), registers, deopt_handler, NULL, constant_stack_parameter_count, JS_FUNCTION_STUB_MODE); } else { @@ -190,7 +190,7 @@ static void InitializeInternalArrayConstructorDescriptor( Representation::Tagged(), Representation::Tagged(), Representation::Integer32() }; - descriptor->Initialize(major, ARRAY_SIZE(registers), registers, r0, + descriptor->Initialize(major, arraysize(registers), registers, r0, deopt_handler, representations, constant_stack_parameter_count, JS_FUNCTION_STUB_MODE, PASS_ARGUMENTS); @@ -219,7 +219,7 @@ void ArrayNArgumentsConstructorStub::InitializeInterfaceDescriptor( void ToBooleanStub::InitializeInterfaceDescriptor( CodeStubInterfaceDescriptor* descriptor) { Register registers[] = { cp, r0 }; - descriptor->Initialize(MajorKey(), ARRAY_SIZE(registers), registers, + descriptor->Initialize(MajorKey(), arraysize(registers), registers, FUNCTION_ADDR(ToBooleanIC_Miss)); descriptor->SetMissHandler( ExternalReference(IC_Utility(IC::kToBooleanIC_Miss), isolate())); @@ -247,7 +247,7 @@ void InternalArrayNArgumentsConstructorStub::InitializeInterfaceDescriptor( void BinaryOpICStub::InitializeInterfaceDescriptor( CodeStubInterfaceDescriptor* descriptor) { Register registers[] = { cp, r1, r0 }; - descriptor->Initialize(MajorKey(), ARRAY_SIZE(registers), registers, + descriptor->Initialize(MajorKey(), arraysize(registers), registers, FUNCTION_ADDR(BinaryOpIC_Miss)); descriptor->SetMissHandler( ExternalReference(IC_Utility(IC::kBinaryOpIC_Miss), isolate())); @@ -257,7 +257,7 @@ void BinaryOpICStub::InitializeInterfaceDescriptor( void BinaryOpWithAllocationSiteStub::InitializeInterfaceDescriptor( CodeStubInterfaceDescriptor* descriptor) { Register registers[] = { cp, r2, r1, r0 }; - descriptor->Initialize(MajorKey(), ARRAY_SIZE(registers), registers, + descriptor->Initialize(MajorKey(), arraysize(registers), registers, FUNCTION_ADDR(BinaryOpIC_MissWithAllocationSite)); } @@ -265,7 +265,7 @@ void BinaryOpWithAllocationSiteStub::InitializeInterfaceDescriptor( void StringAddStub::InitializeInterfaceDescriptor( CodeStubInterfaceDescriptor* descriptor) { Register registers[] = { cp, r1, r0 }; - descriptor->Initialize(MajorKey(), ARRAY_SIZE(registers), registers, + descriptor->Initialize(MajorKey(), arraysize(registers), registers, Runtime::FunctionForId(Runtime::kStringAdd)->entry); } @@ -291,7 +291,7 @@ void CallDescriptors::InitializeForIsolate(Isolate* isolate) { Representation::Integer32(), // actual number of arguments Representation::Integer32(), // expected number of arguments }; - descriptor->Initialize(ARRAY_SIZE(registers), registers, + descriptor->Initialize(arraysize(registers), registers, representations, &default_descriptor); } { @@ -304,7 +304,7 @@ void CallDescriptors::InitializeForIsolate(Isolate* isolate) { Representation::Tagged(), // context Representation::Tagged(), // key }; - descriptor->Initialize(ARRAY_SIZE(registers), registers, + descriptor->Initialize(arraysize(registers), registers, representations, &noInlineDescriptor); } { @@ -317,7 +317,7 @@ void CallDescriptors::InitializeForIsolate(Isolate* isolate) { Representation::Tagged(), // context Representation::Tagged(), // name }; - descriptor->Initialize(ARRAY_SIZE(registers), registers, + descriptor->Initialize(arraysize(registers), registers, representations, &noInlineDescriptor); } { @@ -330,7 +330,7 @@ void CallDescriptors::InitializeForIsolate(Isolate* isolate) { Representation::Tagged(), // context Representation::Tagged(), // receiver }; - descriptor->Initialize(ARRAY_SIZE(registers), registers, + descriptor->Initialize(arraysize(registers), registers, representations, &default_descriptor); } { @@ -349,7 +349,7 @@ void CallDescriptors::InitializeForIsolate(Isolate* isolate) { Representation::Tagged(), // holder Representation::External(), // api_function_address }; - descriptor->Initialize(ARRAY_SIZE(registers), registers, + descriptor->Initialize(arraysize(registers), registers, representations, &default_descriptor); } } diff --git a/src/arm64/assembler-arm64.cc b/src/arm64/assembler-arm64.cc index 7f86e14..9d804db 100644 --- a/src/arm64/assembler-arm64.cc +++ b/src/arm64/assembler-arm64.cc @@ -227,7 +227,7 @@ bool AreAliased(const CPURegister& reg1, const CPURegister& reg2, const CPURegister regs[] = {reg1, reg2, reg3, reg4, reg5, reg6, reg7, reg8}; - for (unsigned i = 0; i < ARRAY_SIZE(regs); i++) { + for (unsigned i = 0; i < arraysize(regs); i++) { if (regs[i].IsRegister()) { number_of_valid_regs++; unique_regs |= regs[i].Bit(); @@ -2664,7 +2664,7 @@ bool Assembler::IsImmLogical(uint64_t value, int multiplier_idx = CountLeadingZeros(d, kXRegSizeInBits) - 57; // Ensure that the index to the multipliers array is within bounds. DCHECK((multiplier_idx >= 0) && - (static_cast(multiplier_idx) < ARRAY_SIZE(multipliers))); + (static_cast(multiplier_idx) < arraysize(multipliers))); uint64_t multiplier = multipliers[multiplier_idx]; uint64_t candidate = (b - a) * multiplier; diff --git a/src/arm64/code-stubs-arm64.cc b/src/arm64/code-stubs-arm64.cc index c00b572..b57748a 100644 --- a/src/arm64/code-stubs-arm64.cc +++ b/src/arm64/code-stubs-arm64.cc @@ -24,7 +24,7 @@ void FastNewClosureStub::InitializeInterfaceDescriptor( // x2: function info Register registers[] = { cp, x2 }; descriptor->Initialize( - MajorKey(), ARRAY_SIZE(registers), registers, + MajorKey(), arraysize(registers), registers, Runtime::FunctionForId(Runtime::kNewClosureFromStubFailure)->entry); } @@ -34,7 +34,7 @@ void FastNewContextStub::InitializeInterfaceDescriptor( // cp: context // x1: function Register registers[] = { cp, x1 }; - descriptor->Initialize(MajorKey(), ARRAY_SIZE(registers), registers); + descriptor->Initialize(MajorKey(), arraysize(registers), registers); } @@ -43,7 +43,7 @@ void ToNumberStub::InitializeInterfaceDescriptor( // cp: context // x0: value Register registers[] = { cp, x0 }; - descriptor->Initialize(MajorKey(), ARRAY_SIZE(registers), registers); + descriptor->Initialize(MajorKey(), arraysize(registers), registers); } @@ -53,7 +53,7 @@ void NumberToStringStub::InitializeInterfaceDescriptor( // x0: value Register registers[] = { cp, x0 }; descriptor->Initialize( - MajorKey(), ARRAY_SIZE(registers), registers, + MajorKey(), arraysize(registers), registers, Runtime::FunctionForId(Runtime::kNumberToStringRT)->entry); } @@ -71,7 +71,7 @@ void FastCloneShallowArrayStub::InitializeInterfaceDescriptor( Representation::Smi(), Representation::Tagged() }; descriptor->Initialize( - MajorKey(), ARRAY_SIZE(registers), registers, + MajorKey(), arraysize(registers), registers, Runtime::FunctionForId(Runtime::kCreateArrayLiteralStubBailout)->entry, representations); } @@ -86,7 +86,7 @@ void FastCloneShallowObjectStub::InitializeInterfaceDescriptor( // x0: object literal flags Register registers[] = { cp, x3, x2, x1, x0 }; descriptor->Initialize( - MajorKey(), ARRAY_SIZE(registers), registers, + MajorKey(), arraysize(registers), registers, Runtime::FunctionForId(Runtime::kCreateObjectLiteral)->entry); } @@ -97,7 +97,7 @@ void CreateAllocationSiteStub::InitializeInterfaceDescriptor( // x2: feedback vector // x3: call feedback slot Register registers[] = { cp, x2, x3 }; - descriptor->Initialize(MajorKey(), ARRAY_SIZE(registers), registers); + descriptor->Initialize(MajorKey(), arraysize(registers), registers); } @@ -105,7 +105,7 @@ void CallFunctionStub::InitializeInterfaceDescriptor( CodeStubInterfaceDescriptor* descriptor) { // x1 function the function to call Register registers[] = {cp, x1}; - descriptor->Initialize(MajorKey(), ARRAY_SIZE(registers), registers); + descriptor->Initialize(MajorKey(), arraysize(registers), registers); } @@ -118,7 +118,7 @@ void CallConstructStub::InitializeInterfaceDescriptor( // TODO(turbofan): So far we don't gather type feedback and hence skip the // slot parameter, but ArrayConstructStub needs the vector to be undefined. Register registers[] = {cp, x0, x1, x2}; - descriptor->Initialize(MajorKey(), ARRAY_SIZE(registers), registers); + descriptor->Initialize(MajorKey(), arraysize(registers), registers); } @@ -130,7 +130,7 @@ void RegExpConstructResultStub::InitializeInterfaceDescriptor( // x0: string Register registers[] = { cp, x2, x1, x0 }; descriptor->Initialize( - MajorKey(), ARRAY_SIZE(registers), registers, + MajorKey(), arraysize(registers), registers, Runtime::FunctionForId(Runtime::kRegExpConstructResult)->entry); } @@ -143,7 +143,7 @@ void TransitionElementsKindStub::InitializeInterfaceDescriptor( Register registers[] = { cp, x0, x1 }; Address entry = Runtime::FunctionForId(Runtime::kTransitionElementsKind)->entry; - descriptor->Initialize(MajorKey(), ARRAY_SIZE(registers), registers, + descriptor->Initialize(MajorKey(), arraysize(registers), registers, FUNCTION_ADDR(entry)); } @@ -153,7 +153,7 @@ void CompareNilICStub::InitializeInterfaceDescriptor( // cp: context // x0: value to compare Register registers[] = { cp, x0 }; - descriptor->Initialize(MajorKey(), ARRAY_SIZE(registers), registers, + descriptor->Initialize(MajorKey(), arraysize(registers), registers, FUNCTION_ADDR(CompareNilIC_Miss)); descriptor->SetMissHandler( ExternalReference(IC_Utility(IC::kCompareNilIC_Miss), isolate())); @@ -175,7 +175,7 @@ static void InitializeArrayConstructorDescriptor( if (constant_stack_parameter_count == 0) { Register registers[] = { cp, x1, x2 }; - descriptor->Initialize(major, ARRAY_SIZE(registers), registers, + descriptor->Initialize(major, arraysize(registers), registers, deopt_handler, NULL, constant_stack_parameter_count, JS_FUNCTION_STUB_MODE); } else { @@ -186,7 +186,7 @@ static void InitializeArrayConstructorDescriptor( Representation::Tagged(), Representation::Tagged(), Representation::Integer32() }; - descriptor->Initialize(major, ARRAY_SIZE(registers), registers, x0, + descriptor->Initialize(major, arraysize(registers), registers, x0, deopt_handler, representations, constant_stack_parameter_count, JS_FUNCTION_STUB_MODE, PASS_ARGUMENTS); @@ -223,7 +223,7 @@ static void InitializeInternalArrayConstructorDescriptor( if (constant_stack_parameter_count == 0) { Register registers[] = { cp, x1 }; - descriptor->Initialize(major, ARRAY_SIZE(registers), registers, + descriptor->Initialize(major, arraysize(registers), registers, deopt_handler, NULL, constant_stack_parameter_count, JS_FUNCTION_STUB_MODE); } else { @@ -233,7 +233,7 @@ static void InitializeInternalArrayConstructorDescriptor( Representation::Tagged(), Representation::Tagged(), Representation::Integer32() }; - descriptor->Initialize(major, ARRAY_SIZE(registers), registers, x0, + descriptor->Initialize(major, arraysize(registers), registers, x0, deopt_handler, representations, constant_stack_parameter_count, JS_FUNCTION_STUB_MODE, PASS_ARGUMENTS); @@ -264,7 +264,7 @@ void ToBooleanStub::InitializeInterfaceDescriptor( // cp: context // x0: value Register registers[] = { cp, x0 }; - descriptor->Initialize(MajorKey(), ARRAY_SIZE(registers), registers, + descriptor->Initialize(MajorKey(), arraysize(registers), registers, FUNCTION_ADDR(ToBooleanIC_Miss)); descriptor->SetMissHandler( ExternalReference(IC_Utility(IC::kToBooleanIC_Miss), isolate())); @@ -277,7 +277,7 @@ void BinaryOpICStub::InitializeInterfaceDescriptor( // x1: left operand // x0: right operand Register registers[] = { cp, x1, x0 }; - descriptor->Initialize(MajorKey(), ARRAY_SIZE(registers), registers, + descriptor->Initialize(MajorKey(), arraysize(registers), registers, FUNCTION_ADDR(BinaryOpIC_Miss)); descriptor->SetMissHandler( ExternalReference(IC_Utility(IC::kBinaryOpIC_Miss), isolate())); @@ -291,7 +291,7 @@ void BinaryOpWithAllocationSiteStub::InitializeInterfaceDescriptor( // x1: left operand // x0: right operand Register registers[] = { cp, x2, x1, x0 }; - descriptor->Initialize(MajorKey(), ARRAY_SIZE(registers), registers, + descriptor->Initialize(MajorKey(), arraysize(registers), registers, FUNCTION_ADDR(BinaryOpIC_MissWithAllocationSite)); } @@ -302,7 +302,7 @@ void StringAddStub::InitializeInterfaceDescriptor( // x1: left operand // x0: right operand Register registers[] = { cp, x1, x0 }; - descriptor->Initialize(MajorKey(), ARRAY_SIZE(registers), registers, + descriptor->Initialize(MajorKey(), arraysize(registers), registers, Runtime::FunctionForId(Runtime::kStringAdd)->entry); } @@ -328,7 +328,7 @@ void CallDescriptors::InitializeForIsolate(Isolate* isolate) { Representation::Integer32(), // actual number of arguments Representation::Integer32(), // expected number of arguments }; - descriptor->Initialize(ARRAY_SIZE(registers), registers, + descriptor->Initialize(arraysize(registers), registers, representations, &default_descriptor); } { @@ -341,7 +341,7 @@ void CallDescriptors::InitializeForIsolate(Isolate* isolate) { Representation::Tagged(), // context Representation::Tagged(), // key }; - descriptor->Initialize(ARRAY_SIZE(registers), registers, + descriptor->Initialize(arraysize(registers), registers, representations, &noInlineDescriptor); } { @@ -354,7 +354,7 @@ void CallDescriptors::InitializeForIsolate(Isolate* isolate) { Representation::Tagged(), // context Representation::Tagged(), // name }; - descriptor->Initialize(ARRAY_SIZE(registers), registers, + descriptor->Initialize(arraysize(registers), registers, representations, &noInlineDescriptor); } { @@ -367,7 +367,7 @@ void CallDescriptors::InitializeForIsolate(Isolate* isolate) { Representation::Tagged(), // context Representation::Tagged(), // receiver }; - descriptor->Initialize(ARRAY_SIZE(registers), registers, + descriptor->Initialize(arraysize(registers), registers, representations, &default_descriptor); } { @@ -386,7 +386,7 @@ void CallDescriptors::InitializeForIsolate(Isolate* isolate) { Representation::Tagged(), // holder Representation::External(), // api_function_address }; - descriptor->Initialize(ARRAY_SIZE(registers), registers, + descriptor->Initialize(arraysize(registers), registers, representations, &default_descriptor); } } diff --git a/src/arm64/instrument-arm64.cc b/src/arm64/instrument-arm64.cc index 59982d9..da505ff 100644 --- a/src/arm64/instrument-arm64.cc +++ b/src/arm64/instrument-arm64.cc @@ -107,7 +107,7 @@ Instrument::Instrument(const char* datafile, uint64_t sample_period) } } - static const int num_counters = ARRAY_SIZE(kCounterList); + static const int num_counters = arraysize(kCounterList); // Dump an instrumentation description comment at the top of the file. fprintf(output_stream_, "# counters=%d\n", num_counters); diff --git a/src/arm64/simulator-arm64.cc b/src/arm64/simulator-arm64.cc index 9d4f781..de911bf 100644 --- a/src/arm64/simulator-arm64.cc +++ b/src/arm64/simulator-arm64.cc @@ -1065,7 +1065,7 @@ void Simulator::PrintSystemRegisters(bool print_all) { "0b10 (Round towards Minus Infinity)", "0b11 (Round towards Zero)" }; - DCHECK(fpcr().RMode() < ARRAY_SIZE(rmode)); + DCHECK(fpcr().RMode() < arraysize(rmode)); fprintf(stream_, "# %sFPCR: %sAHP:%d DN:%d FZ:%d RMode:%s%s\n", clr_flag_name, clr_flag_value, diff --git a/src/ast.cc b/src/ast.cc index 02ca2c7..e683bf2 100644 --- a/src/ast.cc +++ b/src/ast.cc @@ -1119,7 +1119,7 @@ Handle Literal::ToString() { if (value_->IsString()) return value_->AsString()->string(); DCHECK(value_->IsNumber()); char arr[100]; - Vector buffer(arr, ARRAY_SIZE(arr)); + Vector buffer(arr, arraysize(arr)); const char* str; if (value()->IsSmi()) { // Optimization only, the heap number case would subsume this. diff --git a/src/base/logging.cc b/src/base/logging.cc index 4f62ac4..c3f609f 100644 --- a/src/base/logging.cc +++ b/src/base/logging.cc @@ -22,7 +22,7 @@ namespace base { void DumpBacktrace() { #if V8_LIBC_GLIBC || V8_OS_BSD void* trace[100]; - int size = backtrace(trace, ARRAY_SIZE(trace)); + int size = backtrace(trace, arraysize(trace)); char** symbols = backtrace_symbols(trace, size); OS::PrintError("\n==== C stack trace ===============================\n\n"); if (size == 0) { @@ -54,7 +54,7 @@ void DumpBacktrace() { bt_sprn_memmap(&memmap, out, sizeof(out)); OS::PrintError(out); bt_addr_t trace[100]; - int size = bt_get_backtrace(&acc, trace, ARRAY_SIZE(trace)); + int size = bt_get_backtrace(&acc, trace, arraysize(trace)); OS::PrintError("\n==== C stack trace ===============================\n\n"); if (size == 0) { OS::PrintError("(empty)\n"); diff --git a/src/base/macros.h b/src/base/macros.h index 50828db..c8a1408 100644 --- a/src/base/macros.h +++ b/src/base/macros.h @@ -20,13 +20,74 @@ (reinterpret_cast(&(reinterpret_cast(4)->field)) - 4) -// The expression ARRAY_SIZE(a) is a compile-time constant of type -// size_t which represents the number of elements of the given -// array. You should only use ARRAY_SIZE on statically allocated -// arrays. -#define ARRAY_SIZE(a) \ - ((sizeof(a) / sizeof(*(a))) / \ - static_cast(!(sizeof(a) % sizeof(*(a))))) +// The arraysize(arr) macro returns the # of elements in an array arr. +// The expression is a compile-time constant, and therefore can be +// used in defining new arrays, for example. If you use arraysize on +// a pointer by mistake, you will get a compile-time error. +// +// One caveat is that arraysize() doesn't accept any array of an +// anonymous type or a type defined inside a function. In these rare +// cases, you have to use the unsafe ARRAYSIZE_UNSAFE() macro below. This is +// due to a limitation in C++'s template system. The limitation might +// eventually be removed, but it hasn't happened yet. +#define arraysize(array) (sizeof(ArraySizeHelper(array))) + + +// This template function declaration is used in defining arraysize. +// Note that the function doesn't need an implementation, as we only +// use its type. +template +char (&ArraySizeHelper(T (&array)[N]))[N]; + + +#if V8_CC_GNU +// That gcc wants both of these prototypes seems mysterious. VC, for +// its part, can't decide which to use (another mystery). Matching of +// template overloads: the final frontier. +template +char (&ArraySizeHelper(const T (&array)[N]))[N]; +#endif + + +// ARRAYSIZE_UNSAFE performs essentially the same calculation as arraysize, +// but can be used on anonymous types or types defined inside +// functions. It's less safe than arraysize as it accepts some +// (although not all) pointers. Therefore, you should use arraysize +// whenever possible. +// +// The expression ARRAYSIZE_UNSAFE(a) is a compile-time constant of type +// size_t. +// +// ARRAYSIZE_UNSAFE catches a few type errors. If you see a compiler error +// +// "warning: division by zero in ..." +// +// when using ARRAYSIZE_UNSAFE, you are (wrongfully) giving it a pointer. +// You should only use ARRAYSIZE_UNSAFE on statically allocated arrays. +// +// The following comments are on the implementation details, and can +// be ignored by the users. +// +// ARRAYSIZE_UNSAFE(arr) works by inspecting sizeof(arr) (the # of bytes in +// the array) and sizeof(*(arr)) (the # of bytes in one array +// element). If the former is divisible by the latter, perhaps arr is +// indeed an array, in which case the division result is the # of +// elements in the array. Otherwise, arr cannot possibly be an array, +// and we generate a compiler error to prevent the code from +// compiling. +// +// Since the size of bool is implementation-defined, we need to cast +// !(sizeof(a) & sizeof(*(a))) to size_t in order to ensure the final +// result has type size_t. +// +// This macro is not perfect as it wrongfully accepts certain +// pointers, namely where the pointer size is divisible by the pointee +// size. Since all our code has to go through a 32-bit compiler, +// where a pointer is 4 bytes, this means all pointers to a type whose +// size is 3 or greater than 4 will be (righteously) rejected. +#define ARRAYSIZE_UNSAFE(a) \ + ((sizeof(a) / sizeof(*(a))) / \ + static_cast(!(sizeof(a) % sizeof(*(a))))) // NOLINT // A macro to disallow the evil copy constructor and operator= functions diff --git a/src/bootstrapper.cc b/src/bootstrapper.cc index e0e90b3..09e56d9 100644 --- a/src/bootstrapper.cc +++ b/src/bootstrapper.cc @@ -2682,7 +2682,7 @@ Genesis::Genesis(Isolate* isolate, NONE).Assert(); // Initialize trigonometric lookup tables and constants. - const int constants_size = ARRAY_SIZE(fdlibm::MathConstants::constants); + const int constants_size = arraysize(fdlibm::MathConstants::constants); const int table_num_bytes = constants_size * kDoubleSize; v8::Local trig_buffer = v8::ArrayBuffer::New( reinterpret_cast(isolate), diff --git a/src/cached-powers.cc b/src/cached-powers.cc index 5726c49..dd9e3b4 100644 --- a/src/cached-powers.cc +++ b/src/cached-powers.cc @@ -111,7 +111,7 @@ static const CachedPower kCachedPowers[] = { }; #ifdef DEBUG -static const int kCachedPowersLength = ARRAY_SIZE(kCachedPowers); +static const int kCachedPowersLength = arraysize(kCachedPowers); #endif static const int kCachedPowersOffset = 348; // -1 * the first decimal_exponent. diff --git a/src/code-stubs.cc b/src/code-stubs.cc index 9b84122..7506608 100644 --- a/src/code-stubs.cc +++ b/src/code-stubs.cc @@ -585,7 +585,7 @@ void LoadFastElementStub::InitializeInterfaceDescriptor( LoadIC::ReceiverRegister(), LoadIC::NameRegister() }; STATIC_ASSERT(LoadIC::kParameterCount == 2); - descriptor->Initialize(MajorKey(), ARRAY_SIZE(registers), registers, + descriptor->Initialize(MajorKey(), arraysize(registers), registers, FUNCTION_ADDR(KeyedLoadIC_MissFromStubFailure)); } @@ -596,7 +596,7 @@ void LoadDictionaryElementStub::InitializeInterfaceDescriptor( LoadIC::ReceiverRegister(), LoadIC::NameRegister() }; STATIC_ASSERT(LoadIC::kParameterCount == 2); - descriptor->Initialize(MajorKey(), ARRAY_SIZE(registers), registers, + descriptor->Initialize(MajorKey(), arraysize(registers), registers, FUNCTION_ADDR(KeyedLoadIC_MissFromStubFailure)); } @@ -608,7 +608,7 @@ void KeyedLoadGenericStub::InitializeInterfaceDescriptor( LoadIC::NameRegister() }; STATIC_ASSERT(LoadIC::kParameterCount == 2); descriptor->Initialize( - MajorKey(), ARRAY_SIZE(registers), registers, + MajorKey(), arraysize(registers), registers, Runtime::FunctionForId(Runtime::kKeyedGetProperty)->entry); } @@ -618,13 +618,13 @@ void HandlerStub::InitializeInterfaceDescriptor( if (kind() == Code::LOAD_IC) { Register registers[] = {InterfaceDescriptor::ContextRegister(), LoadIC::ReceiverRegister(), LoadIC::NameRegister()}; - descriptor->Initialize(MajorKey(), ARRAY_SIZE(registers), registers); + descriptor->Initialize(MajorKey(), arraysize(registers), registers); } else { DCHECK_EQ(Code::STORE_IC, kind()); Register registers[] = {InterfaceDescriptor::ContextRegister(), StoreIC::ReceiverRegister(), StoreIC::NameRegister(), StoreIC::ValueRegister()}; - descriptor->Initialize(MajorKey(), ARRAY_SIZE(registers), registers, + descriptor->Initialize(MajorKey(), arraysize(registers), registers, FUNCTION_ADDR(StoreIC_MissFromStubFailure)); } } @@ -636,7 +636,7 @@ void StoreFastElementStub::InitializeInterfaceDescriptor( KeyedStoreIC::ReceiverRegister(), KeyedStoreIC::NameRegister(), KeyedStoreIC::ValueRegister() }; - descriptor->Initialize(MajorKey(), ARRAY_SIZE(registers), registers, + descriptor->Initialize(MajorKey(), arraysize(registers), registers, FUNCTION_ADDR(KeyedStoreIC_MissFromStubFailure)); } @@ -648,7 +648,7 @@ void ElementsTransitionAndStoreStub::InitializeInterfaceDescriptor( MapRegister(), KeyRegister(), ObjectRegister() }; - descriptor->Initialize(MajorKey(), ARRAY_SIZE(registers), registers, + descriptor->Initialize(MajorKey(), arraysize(registers), registers, FUNCTION_ADDR(ElementsTransitionAndStoreIC_Miss)); } @@ -658,7 +658,7 @@ void InstanceofStub::InitializeInterfaceDescriptor( Register registers[] = { InterfaceDescriptor::ContextRegister(), InstanceofStub::left(), InstanceofStub::right() }; - descriptor->Initialize(MajorKey(), ARRAY_SIZE(registers), registers); + descriptor->Initialize(MajorKey(), arraysize(registers), registers); } diff --git a/src/compiler/arm/instruction-selector-arm.cc b/src/compiler/arm/instruction-selector-arm.cc index a234e5a..96f95e9 100644 --- a/src/compiler/arm/instruction-selector-arm.cc +++ b/src/compiler/arm/instruction-selector-arm.cc @@ -272,8 +272,8 @@ static void VisitBinop(InstructionSelector* selector, Node* node, DCHECK_NE(0, input_count); DCHECK_NE(0, output_count); - DCHECK_GE(ARRAY_SIZE(inputs), input_count); - DCHECK_GE(ARRAY_SIZE(outputs), output_count); + DCHECK_GE(arraysize(inputs), input_count); + DCHECK_GE(arraysize(outputs), output_count); DCHECK_NE(kMode_None, AddressingModeField::decode(opcode)); Instruction* instr = selector->Emit(cont->Encode(opcode), output_count, @@ -345,7 +345,7 @@ void InstructionSelector::VisitStore(Node* node) { // TODO(dcarney): handle immediate indices. InstructionOperand* temps[] = {g.TempRegister(r5), g.TempRegister(r6)}; Emit(kArmStoreWriteBarrier, NULL, g.UseFixed(base, r4), - g.UseFixed(index, r5), g.UseFixed(value, r6), ARRAY_SIZE(temps), + g.UseFixed(index, r5), g.UseFixed(value, r6), arraysize(temps), temps); return; } @@ -502,8 +502,8 @@ static inline void VisitShift(InstructionSelector* selector, Node* node, DCHECK_NE(0, input_count); DCHECK_NE(0, output_count); - DCHECK_GE(ARRAY_SIZE(inputs), input_count); - DCHECK_GE(ARRAY_SIZE(outputs), output_count); + DCHECK_GE(arraysize(inputs), input_count); + DCHECK_GE(arraysize(outputs), output_count); DCHECK_NE(kMode_None, AddressingModeField::decode(opcode)); Instruction* instr = selector->Emit(cont->Encode(opcode), output_count, @@ -890,8 +890,8 @@ static void VisitWordCompare(InstructionSelector* selector, Node* node, } DCHECK_NE(0, input_count); - DCHECK_GE(ARRAY_SIZE(inputs), input_count); - DCHECK_GE(ARRAY_SIZE(outputs), output_count); + DCHECK_GE(arraysize(inputs), input_count); + DCHECK_GE(arraysize(outputs), output_count); Instruction* instr = selector->Emit(cont->Encode(opcode), output_count, outputs, input_count, inputs); diff --git a/src/compiler/arm64/instruction-selector-arm64.cc b/src/compiler/arm64/instruction-selector-arm64.cc index e7381b5..8445e9f 100644 --- a/src/compiler/arm64/instruction-selector-arm64.cc +++ b/src/compiler/arm64/instruction-selector-arm64.cc @@ -124,8 +124,8 @@ static void VisitBinop(InstructionSelector* selector, Node* node, DCHECK_NE(0, input_count); DCHECK_NE(0, output_count); - DCHECK_GE(ARRAY_SIZE(inputs), input_count); - DCHECK_GE(ARRAY_SIZE(outputs), output_count); + DCHECK_GE(arraysize(inputs), input_count); + DCHECK_GE(arraysize(outputs), output_count); Instruction* instr = selector->Emit(cont->Encode(opcode), output_count, outputs, input_count, inputs); @@ -198,7 +198,7 @@ void InstructionSelector::VisitStore(Node* node) { // TODO(dcarney): handle immediate indices. InstructionOperand* temps[] = {g.TempRegister(x11), g.TempRegister(x12)}; Emit(kArm64StoreWriteBarrier, NULL, g.UseFixed(base, x10), - g.UseFixed(index, x11), g.UseFixed(value, x12), ARRAY_SIZE(temps), + g.UseFixed(index, x11), g.UseFixed(value, x12), arraysize(temps), temps); return; } diff --git a/src/compiler/graph-builder.h b/src/compiler/graph-builder.h index fc90008..dfa79b8 100644 --- a/src/compiler/graph-builder.h +++ b/src/compiler/graph-builder.h @@ -32,29 +32,29 @@ class GraphBuilder { Node* NewNode(Operator* op, Node* n1, Node* n2) { Node* buffer[] = {n1, n2}; - return MakeNode(op, ARRAY_SIZE(buffer), buffer); + return MakeNode(op, arraysize(buffer), buffer); } Node* NewNode(Operator* op, Node* n1, Node* n2, Node* n3) { Node* buffer[] = {n1, n2, n3}; - return MakeNode(op, ARRAY_SIZE(buffer), buffer); + return MakeNode(op, arraysize(buffer), buffer); } Node* NewNode(Operator* op, Node* n1, Node* n2, Node* n3, Node* n4) { Node* buffer[] = {n1, n2, n3, n4}; - return MakeNode(op, ARRAY_SIZE(buffer), buffer); + return MakeNode(op, arraysize(buffer), buffer); } Node* NewNode(Operator* op, Node* n1, Node* n2, Node* n3, Node* n4, Node* n5) { Node* buffer[] = {n1, n2, n3, n4, n5}; - return MakeNode(op, ARRAY_SIZE(buffer), buffer); + return MakeNode(op, arraysize(buffer), buffer); } Node* NewNode(Operator* op, Node* n1, Node* n2, Node* n3, Node* n4, Node* n5, Node* n6) { Node* nodes[] = {n1, n2, n3, n4, n5, n6}; - return MakeNode(op, ARRAY_SIZE(nodes), nodes); + return MakeNode(op, arraysize(nodes), nodes); } Node* NewNode(Operator* op, int value_input_count, Node** value_inputs) { diff --git a/src/compiler/graph.h b/src/compiler/graph.h index 65ea3b3..64d297f 100644 --- a/src/compiler/graph.h +++ b/src/compiler/graph.h @@ -34,25 +34,25 @@ class Graph : public GenericGraph { Node* NewNode(Operator* op, Node* n1) { return NewNode(op, 1, &n1); } Node* NewNode(Operator* op, Node* n1, Node* n2) { Node* nodes[] = {n1, n2}; - return NewNode(op, ARRAY_SIZE(nodes), nodes); + return NewNode(op, arraysize(nodes), nodes); } Node* NewNode(Operator* op, Node* n1, Node* n2, Node* n3) { Node* nodes[] = {n1, n2, n3}; - return NewNode(op, ARRAY_SIZE(nodes), nodes); + return NewNode(op, arraysize(nodes), nodes); } Node* NewNode(Operator* op, Node* n1, Node* n2, Node* n3, Node* n4) { Node* nodes[] = {n1, n2, n3, n4}; - return NewNode(op, ARRAY_SIZE(nodes), nodes); + return NewNode(op, arraysize(nodes), nodes); } Node* NewNode(Operator* op, Node* n1, Node* n2, Node* n3, Node* n4, Node* n5) { Node* nodes[] = {n1, n2, n3, n4, n5}; - return NewNode(op, ARRAY_SIZE(nodes), nodes); + return NewNode(op, arraysize(nodes), nodes); } Node* NewNode(Operator* op, Node* n1, Node* n2, Node* n3, Node* n4, Node* n5, Node* n6) { Node* nodes[] = {n1, n2, n3, n4, n5, n6}; - return NewNode(op, ARRAY_SIZE(nodes), nodes); + return NewNode(op, arraysize(nodes), nodes); } void ChangeOperator(Node* node, Operator* op); diff --git a/src/compiler/ia32/instruction-selector-ia32.cc b/src/compiler/ia32/instruction-selector-ia32.cc index 4184bbd..0b20903 100644 --- a/src/compiler/ia32/instruction-selector-ia32.cc +++ b/src/compiler/ia32/instruction-selector-ia32.cc @@ -106,7 +106,7 @@ void InstructionSelector::VisitStore(Node* node) { // TODO(dcarney): handle immediate indices. InstructionOperand* temps[] = {g.TempRegister(ecx), g.TempRegister(edx)}; Emit(kIA32StoreWriteBarrier, NULL, g.UseFixed(base, ebx), - g.UseFixed(index, ecx), g.UseFixed(value, edx), ARRAY_SIZE(temps), + g.UseFixed(index, ecx), g.UseFixed(value, edx), arraysize(temps), temps); return; } @@ -195,8 +195,8 @@ static void VisitBinop(InstructionSelector* selector, Node* node, DCHECK_NE(0, input_count); DCHECK_NE(0, output_count); - DCHECK_GE(ARRAY_SIZE(inputs), input_count); - DCHECK_GE(ARRAY_SIZE(outputs), output_count); + DCHECK_GE(arraysize(inputs), input_count); + DCHECK_GE(arraysize(outputs), output_count); Instruction* instr = selector->Emit(cont->Encode(opcode), output_count, outputs, input_count, inputs); @@ -316,7 +316,7 @@ static inline void VisitDiv(InstructionSelector* selector, Node* node, ArchOpcode opcode) { IA32OperandGenerator g(selector); InstructionOperand* temps[] = {g.TempRegister(edx)}; - size_t temp_count = ARRAY_SIZE(temps); + size_t temp_count = arraysize(temps); selector->Emit(opcode, g.DefineAsFixed(node, eax), g.UseFixed(node->InputAt(0), eax), g.UseUnique(node->InputAt(1)), temp_count, temps); @@ -337,7 +337,7 @@ static inline void VisitMod(InstructionSelector* selector, Node* node, ArchOpcode opcode) { IA32OperandGenerator g(selector); InstructionOperand* temps[] = {g.TempRegister(eax), g.TempRegister(edx)}; - size_t temp_count = ARRAY_SIZE(temps); + size_t temp_count = arraysize(temps); selector->Emit(opcode, g.DefineAsFixed(node, edx), g.UseFixed(node->InputAt(0), eax), g.UseUnique(node->InputAt(1)), temp_count, temps); diff --git a/src/compiler/instruction-selector.cc b/src/compiler/instruction-selector.cc index 6db5542..e65b85b 100644 --- a/src/compiler/instruction-selector.cc +++ b/src/compiler/instruction-selector.cc @@ -91,7 +91,7 @@ Instruction* InstructionSelector::Emit(InstructionCode opcode, InstructionOperand** temps) { size_t output_count = output == NULL ? 0 : 1; InstructionOperand* inputs[] = {a, b}; - size_t input_count = ARRAY_SIZE(inputs); + size_t input_count = arraysize(inputs); return Emit(opcode, output_count, &output, input_count, inputs, temp_count, temps); } @@ -105,7 +105,7 @@ Instruction* InstructionSelector::Emit(InstructionCode opcode, InstructionOperand** temps) { size_t output_count = output == NULL ? 0 : 1; InstructionOperand* inputs[] = {a, b, c}; - size_t input_count = ARRAY_SIZE(inputs); + size_t input_count = arraysize(inputs); return Emit(opcode, output_count, &output, input_count, inputs, temp_count, temps); } @@ -117,7 +117,7 @@ Instruction* InstructionSelector::Emit( size_t temp_count, InstructionOperand** temps) { size_t output_count = output == NULL ? 0 : 1; InstructionOperand* inputs[] = {a, b, c, d}; - size_t input_count = ARRAY_SIZE(inputs); + size_t input_count = arraysize(inputs); return Emit(opcode, output_count, &output, input_count, inputs, temp_count, temps); } diff --git a/src/compiler/js-generic-lowering.cc b/src/compiler/js-generic-lowering.cc index 77cb929..16dcbf8 100644 --- a/src/compiler/js-generic-lowering.cc +++ b/src/compiler/js-generic-lowering.cc @@ -49,7 +49,7 @@ class LoadICStubShim : public HydrogenCodeStub { Register registers[] = { InterfaceDescriptor::ContextRegister(), LoadIC::ReceiverRegister(), LoadIC::NameRegister() }; - descriptor->Initialize(MajorKey(), ARRAY_SIZE(registers), registers); + descriptor->Initialize(MajorKey(), arraysize(registers), registers); } private: @@ -79,7 +79,7 @@ class KeyedLoadICStubShim : public HydrogenCodeStub { Register registers[] = { InterfaceDescriptor::ContextRegister(), KeyedLoadIC::ReceiverRegister(), KeyedLoadIC::NameRegister() }; - descriptor->Initialize(MajorKey(), ARRAY_SIZE(registers), registers); + descriptor->Initialize(MajorKey(), arraysize(registers), registers); } private: @@ -109,7 +109,7 @@ class StoreICStubShim : public HydrogenCodeStub { StoreIC::ReceiverRegister(), StoreIC::NameRegister(), StoreIC::ValueRegister() }; - descriptor->Initialize(MajorKey(), ARRAY_SIZE(registers), registers); + descriptor->Initialize(MajorKey(), arraysize(registers), registers); } private: @@ -143,7 +143,7 @@ class KeyedStoreICStubShim : public HydrogenCodeStub { KeyedStoreIC::ReceiverRegister(), KeyedStoreIC::NameRegister(), KeyedStoreIC::ValueRegister() }; - descriptor->Initialize(MajorKey(), ARRAY_SIZE(registers), registers); + descriptor->Initialize(MajorKey(), arraysize(registers), registers); } private: diff --git a/src/compiler/x64/instruction-selector-x64.cc b/src/compiler/x64/instruction-selector-x64.cc index e3ef747..3334922 100644 --- a/src/compiler/x64/instruction-selector-x64.cc +++ b/src/compiler/x64/instruction-selector-x64.cc @@ -119,7 +119,7 @@ void InstructionSelector::VisitStore(Node* node) { // TODO(dcarney): handle immediate indices. InstructionOperand* temps[] = {g.TempRegister(rcx), g.TempRegister(rdx)}; Emit(kX64StoreWriteBarrier, NULL, g.UseFixed(base, rbx), - g.UseFixed(index, rcx), g.UseFixed(value, rdx), ARRAY_SIZE(temps), + g.UseFixed(index, rcx), g.UseFixed(value, rdx), arraysize(temps), temps); return; } @@ -206,8 +206,8 @@ static void VisitBinop(InstructionSelector* selector, Node* node, DCHECK_NE(0, input_count); DCHECK_NE(0, output_count); - DCHECK_GE(ARRAY_SIZE(inputs), input_count); - DCHECK_GE(ARRAY_SIZE(outputs), output_count); + DCHECK_GE(arraysize(inputs), input_count); + DCHECK_GE(arraysize(outputs), output_count); Instruction* instr = selector->Emit(cont->Encode(opcode), output_count, outputs, input_count, inputs); @@ -428,7 +428,7 @@ static void VisitDiv(InstructionSelector* selector, Node* node, InstructionOperand* temps[] = {g.TempRegister(rdx)}; selector->Emit( opcode, g.DefineAsFixed(node, rax), g.UseFixed(node->InputAt(0), rax), - g.UseUniqueRegister(node->InputAt(1)), ARRAY_SIZE(temps), temps); + g.UseUniqueRegister(node->InputAt(1)), arraysize(temps), temps); } @@ -458,7 +458,7 @@ static void VisitMod(InstructionSelector* selector, Node* node, InstructionOperand* temps[] = {g.TempRegister(rax), g.TempRegister(rdx)}; selector->Emit( opcode, g.DefineAsFixed(node, rdx), g.UseFixed(node->InputAt(0), rax), - g.UseUniqueRegister(node->InputAt(1)), ARRAY_SIZE(temps), temps); + g.UseUniqueRegister(node->InputAt(1)), arraysize(temps), temps); } diff --git a/src/conversions.cc b/src/conversions.cc index 4b41d5e..69272b5 100644 --- a/src/conversions.cc +++ b/src/conversions.cc @@ -211,7 +211,7 @@ char* DoubleToFixedCString(double value, int f) { // use the non-fixed conversion routine. if (abs_value >= kFirstNonFixed) { char arr[100]; - Vector buffer(arr, ARRAY_SIZE(arr)); + Vector buffer(arr, arraysize(arr)); return StrDup(DoubleToCString(value, buffer)); } diff --git a/src/debug.cc b/src/debug.cc index 6b983ce..f4ab115 100644 --- a/src/debug.cc +++ b/src/debug.cc @@ -1051,7 +1051,7 @@ bool Debug::CheckBreakPoint(Handle break_point_object) { Handle result; if (!Execution::TryCall(check_break_point, isolate_->js_builtins_object(), - ARRAY_SIZE(argv), + arraysize(argv), argv).ToHandle(&result)) { return false; } @@ -2458,7 +2458,7 @@ MaybeHandle Debug::MakeJSObject(const char* constructor_name, MaybeHandle Debug::MakeExecutionState() { // Create the execution state object. Handle argv[] = { isolate_->factory()->NewNumberFromInt(break_id()) }; - return MakeJSObject("MakeExecutionState", ARRAY_SIZE(argv), argv); + return MakeJSObject("MakeExecutionState", arraysize(argv), argv); } @@ -2466,7 +2466,7 @@ MaybeHandle Debug::MakeBreakEvent(Handle break_points_hit) { // Create the new break event object. Handle argv[] = { isolate_->factory()->NewNumberFromInt(break_id()), break_points_hit }; - return MakeJSObject("MakeBreakEvent", ARRAY_SIZE(argv), argv); + return MakeJSObject("MakeBreakEvent", arraysize(argv), argv); } @@ -2478,7 +2478,7 @@ MaybeHandle Debug::MakeExceptionEvent(Handle exception, exception, isolate_->factory()->ToBoolean(uncaught), promise }; - return MakeJSObject("MakeExceptionEvent", ARRAY_SIZE(argv), argv); + return MakeJSObject("MakeExceptionEvent", arraysize(argv), argv); } @@ -2488,21 +2488,21 @@ MaybeHandle Debug::MakeCompileEvent(Handle