From 14e80e5c91465a0290333eb625f930ec2af7ba9b Mon Sep 17 00:00:00 2001 From: jgruber Date: Mon, 10 Jul 2017 14:58:27 +0200 Subject: [PATCH] Add Smi::ToInt helper method This adds a convenience method for the common Smi to int conversion pattern. Bug: Change-Id: I7d7b171c36cfec5f6d10c60f1d9c3e06e3aed0fa Reviewed-on: https://chromium-review.googlesource.com/563205 Commit-Queue: Jakob Gruber Reviewed-by: Benedikt Meurer Reviewed-by: Michael Lippautz Reviewed-by: Andreas Rossberg Cr-Commit-Position: refs/heads/master@{#46516} --- src/api-natives.cc | 6 +- src/api.cc | 36 +++--- src/arguments.h | 4 +- src/asmjs/asm-js.cc | 2 +- src/ast/compile-time-value.cc | 2 +- src/ast/prettyprinter.cc | 3 +- src/bootstrapper.cc | 8 +- src/builtins/builtins-array.cc | 24 ++-- src/builtins/builtins-callsite.cc | 2 +- src/builtins/builtins-error.cc | 4 +- src/builtins/builtins-string.cc | 2 +- src/builtins/builtins-typedarray.cc | 2 +- src/code-stub-assembler.cc | 4 +- src/contexts-inl.h | 6 +- src/conversions-inl.h | 10 +- src/debug/debug.cc | 5 +- src/debug/liveedit.cc | 7 +- src/deoptimizer.cc | 8 +- src/elements.cc | 36 +++--- src/feedback-vector-inl.h | 10 +- src/feedback-vector.cc | 16 +-- src/frames-inl.h | 2 +- src/frames.cc | 16 +-- src/full-codegen/arm/full-codegen-arm.cc | 2 +- src/full-codegen/arm64/full-codegen-arm64.cc | 2 +- src/full-codegen/ia32/full-codegen-ia32.cc | 2 +- src/full-codegen/mips/full-codegen-mips.cc | 2 +- .../mips64/full-codegen-mips64.cc | 2 +- src/full-codegen/ppc/full-codegen-ppc.cc | 2 +- src/full-codegen/s390/full-codegen-s390.cc | 2 +- src/full-codegen/x64/full-codegen-x64.cc | 2 +- src/full-codegen/x87/full-codegen-x87.cc | 2 +- src/heap/heap-inl.h | 2 +- src/heap/heap.cc | 2 +- src/heap/incremental-marking.cc | 2 +- src/ic/ic.cc | 4 +- src/interpreter/bytecode-array-accessor.cc | 2 +- src/isolate-inl.h | 2 +- src/isolate.cc | 11 +- src/json-stringifier.cc | 6 +- src/layout-descriptor-inl.h | 4 +- src/layout-descriptor.cc | 8 +- src/log.cc | 2 +- src/messages.cc | 2 +- src/objects-debug.cc | 28 ++--- src/objects-inl.h | 95 ++++++++-------- src/objects-printer.cc | 23 ++-- src/objects.cc | 103 +++++++++--------- src/objects.h | 3 + src/objects/compilation-cache-inl.h | 4 +- src/objects/debug-objects.cc | 6 +- src/objects/dictionary.h | 2 +- src/objects/frame-array-inl.h | 2 +- src/objects/hash-table.h | 22 ++-- src/objects/literal-objects.cc | 2 +- src/objects/object-macros.h | 6 +- src/objects/scope-info.cc | 23 ++-- src/objects/scope-info.h | 2 +- src/objects/shared-function-info-inl.h | 3 +- src/profiler/heap-snapshot-generator.cc | 6 +- src/regexp/jsregexp.cc | 6 +- src/regexp/regexp-utils.cc | 2 +- src/runtime/runtime-array.cc | 2 +- src/runtime/runtime-collections.cc | 4 +- src/runtime/runtime-debug.cc | 6 +- src/runtime/runtime-internal.cc | 2 +- src/runtime/runtime-liveedit.cc | 2 +- src/runtime/runtime-object.cc | 2 +- src/runtime/runtime-regexp.cc | 6 +- src/runtime/runtime-scopes.cc | 4 +- src/string-builder.h | 8 +- src/transitions.h | 4 +- src/wasm/module-compiler.cc | 5 +- src/wasm/wasm-code-specialization.cc | 2 +- src/wasm/wasm-interpreter.cc | 7 +- src/wasm/wasm-module.cc | 16 ++- src/wasm/wasm-objects.h | 12 +- test/cctest/compiler/test-code-assembler.cc | 4 +- test/cctest/compiler/test-run-stubs.cc | 2 +- test/cctest/heap/test-heap.cc | 2 +- test/cctest/interpreter/test-interpreter.cc | 6 +- test/cctest/test-api.cc | 4 +- test/cctest/test-array-list.cc | 14 +-- test/cctest/test-code-stub-assembler.cc | 4 +- test/cctest/test-debug.cc | 2 +- test/cctest/test-dictionary.cc | 2 +- test/cctest/test-elements-kind.cc | 40 +++---- test/cctest/test-field-type-tracking.cc | 2 +- test/cctest/test-identity-map.cc | 2 +- test/cctest/wasm/test-run-wasm-js.cc | 2 +- test/common/wasm/wasm-module-runner.cc | 2 +- 91 files changed, 375 insertions(+), 413 deletions(-) diff --git a/src/api-natives.cc b/src/api-natives.cc index a747363ba6..48389b44d8 100644 --- a/src/api-natives.cc +++ b/src/api-natives.cc @@ -250,7 +250,7 @@ MaybeHandle ConfigureInstance(Isolate* isolate, Handle obj, DCHECK_EQ(kData, details.kind()); v8::Intrinsic intrinsic = - static_cast(Smi::cast(properties->get(i++))->value()); + static_cast(Smi::ToInt(properties->get(i++))); auto prop_data = handle(GetIntrinsic(isolate, intrinsic), isolate); RETURN_ON_EXCEPTION(isolate, DefineDataProperty(isolate, obj, name, @@ -356,7 +356,7 @@ MaybeHandle InstantiateObject(Isolate* isolate, bool is_hidden_prototype, bool is_prototype) { Handle constructor; - int serial_number = Smi::cast(info->serial_number())->value(); + int serial_number = Smi::ToInt(info->serial_number()); if (!new_target.is_null()) { if (IsSimpleInstantiation(isolate, *info, *new_target)) { constructor = Handle::cast(new_target); @@ -446,7 +446,7 @@ MaybeHandle GetInstancePrototype(Isolate* isolate, MaybeHandle InstantiateFunction(Isolate* isolate, Handle data, Handle name) { - int serial_number = Smi::cast(data->serial_number())->value(); + int serial_number = Smi::ToInt(data->serial_number()); if (serial_number) { Handle result; if (ProbeInstantiationsCache(isolate, serial_number, diff --git a/src/api.cc b/src/api.cc index a3d37be68e..f7717fe60f 100644 --- a/src/api.cc +++ b/src/api.cc @@ -2138,7 +2138,7 @@ Location Module::GetModuleRequestLocation(int i) const { i::Handle module_request_positions( self->info()->module_request_positions(), isolate); CHECK_LT(i, module_request_positions->length()); - int position = i::Smi::cast(module_request_positions->get(i))->value(); + int position = i::Smi::ToInt(module_request_positions->get(i)); i::Handle script(self->script(), isolate); i::Script::PositionInfo info; i::Script::GetPositionInfo(script, position, &info, i::Script::WITH_OFFSET); @@ -3634,7 +3634,7 @@ bool Value::IsInt32() const { bool Value::IsUint32() const { i::Handle obj = Utils::OpenHandle(this); - if (obj->IsSmi()) return i::Smi::cast(*obj)->value() >= 0; + if (obj->IsSmi()) return i::Smi::ToInt(*obj) >= 0; if (obj->IsNumber()) { double value = obj->Number(); return !i::IsMinusZero(value) && @@ -4112,7 +4112,7 @@ int64_t Value::IntegerValue() const { auto obj = Utils::OpenHandle(this); if (obj->IsNumber()) { if (obj->IsSmi()) { - return i::Smi::cast(*obj)->value(); + return i::Smi::ToInt(*obj); } else { return static_cast(obj->Number()); } @@ -4130,7 +4130,7 @@ Maybe Value::Int32Value(Local context) const { i::Handle num; has_pending_exception = !i::Object::ToInt32(isolate, obj).ToHandle(&num); RETURN_ON_FAILED_EXECUTION_PRIMITIVE(int32_t); - return Just(num->IsSmi() ? i::Smi::cast(*num)->value() + return Just(num->IsSmi() ? i::Smi::ToInt(*num) : static_cast(num->Number())); } @@ -4151,7 +4151,7 @@ Maybe Value::Uint32Value(Local context) const { i::Handle num; has_pending_exception = !i::Object::ToUint32(isolate, obj).ToHandle(&num); RETURN_ON_FAILED_EXECUTION_PRIMITIVE(uint32_t); - return Just(num->IsSmi() ? static_cast(i::Smi::cast(*num)->value()) + return Just(num->IsSmi() ? static_cast(i::Smi::ToInt(*num)) : static_cast(num->Number())); } @@ -4166,7 +4166,7 @@ uint32_t Value::Uint32Value() const { MaybeLocal Value::ToArrayIndex(Local context) const { auto self = Utils::OpenHandle(this); if (self->IsSmi()) { - if (i::Smi::cast(*self)->value() >= 0) return Utils::Uint32ToLocal(self); + if (i::Smi::ToInt(*self) >= 0) return Utils::Uint32ToLocal(self); return Local(); } PREPARE_FOR_EXECUTION(context, Object, ToArrayIndex, Uint32); @@ -4192,7 +4192,7 @@ MaybeLocal Value::ToArrayIndex(Local context) const { Local Value::ToArrayIndex() const { auto self = Utils::OpenHandle(this); if (self->IsSmi()) { - if (i::Smi::cast(*self)->value() >= 0) return Utils::Uint32ToLocal(self); + if (i::Smi::ToInt(*self) >= 0) return Utils::Uint32ToLocal(self); return Local(); } auto context = ContextFromHeapObject(self); @@ -6198,7 +6198,7 @@ bool Boolean::Value() const { int64_t Integer::Value() const { i::Handle obj = Utils::OpenHandle(this); if (obj->IsSmi()) { - return i::Smi::cast(*obj)->value(); + return i::Smi::ToInt(*obj); } else { return static_cast(obj->Number()); } @@ -6208,7 +6208,7 @@ int64_t Integer::Value() const { int32_t Int32::Value() const { i::Handle obj = Utils::OpenHandle(this); if (obj->IsSmi()) { - return i::Smi::cast(*obj)->value(); + return i::Smi::ToInt(*obj); } else { return static_cast(obj->Number()); } @@ -6218,7 +6218,7 @@ int32_t Int32::Value() const { uint32_t Uint32::Value() const { i::Handle obj = Utils::OpenHandle(this); if (obj->IsSmi()) { - return i::Smi::cast(*obj)->value(); + return i::Smi::ToInt(*obj); } else { return static_cast(obj->Number()); } @@ -7202,8 +7202,7 @@ void v8::Date::DateTimeConfigurationChangeNotification(Isolate* isolate) { DCHECK_EQ(1, date_cache_version->length()); CHECK(date_cache_version->get(0)->IsSmi()); date_cache_version->set( - 0, - i::Smi::FromInt(i::Smi::cast(date_cache_version->get(0))->value() + 1)); + 0, i::Smi::FromInt(i::Smi::ToInt(date_cache_version->get(0)) + 1)); } @@ -7269,7 +7268,7 @@ uint32_t v8::Array::Length() const { i::Handle obj = Utils::OpenHandle(this); i::Object* length = obj->length(); if (length->IsSmi()) { - return i::Smi::cast(length)->value(); + return i::Smi::ToInt(length); } else { return static_cast(length->Number()); } @@ -9309,7 +9308,7 @@ void debug::SetContextId(Local context, int id) { int debug::GetContextId(Local context) { i::Object* value = Utils::OpenHandle(*context)->debug_context_id(); - return (value->IsSmi()) ? i::Smi::cast(value)->value() : 0; + return (value->IsSmi()) ? i::Smi::ToInt(value) : 0; } Local debug::GetDebugContext(Isolate* isolate) { @@ -9489,7 +9488,7 @@ Maybe debug::Script::ContextId() const { i::HandleScope handle_scope(isolate); i::Handle script = Utils::OpenHandle(this); i::Object* value = script->context_data(); - if (value->IsSmi()) return Just(i::Smi::cast(value)->value()); + if (value->IsSmi()) return Just(i::Smi::ToInt(value)); return Nothing(); } @@ -9513,7 +9512,7 @@ bool debug::Script::IsModule() const { namespace { int GetSmiValue(i::Handle array, int index) { - return i::Smi::cast(array->get(index))->value(); + return i::Smi::ToInt(array->get(index)); } bool CompareBreakLocation(const i::BreakLocation& loc1, @@ -9788,15 +9787,14 @@ v8::MaybeLocal debug::EntriesPreview(Isolate* v8_isolate, *is_key_value = kind == MapAsArrayKind::kEntries; if (!iterator->HasMore()) return v8::Array::New(v8_isolate); return Utils::ToLocal(MapAsArray(isolate, iterator->table(), - i::Smi::cast(iterator->index())->value(), - kind)); + i::Smi::ToInt(iterator->index()), kind)); } if (object->IsJSSetIterator()) { i::Handle it = i::Handle::cast(object); *is_key_value = false; if (!it->HasMore()) return v8::Array::New(v8_isolate); return Utils::ToLocal( - SetAsArray(isolate, it->table(), i::Smi::cast(it->index())->value())); + SetAsArray(isolate, it->table(), i::Smi::ToInt(it->index()))); } return v8::MaybeLocal(); } diff --git a/src/arguments.h b/src/arguments.h index 1d91b20b2b..f3fcb8edb0 100644 --- a/src/arguments.h +++ b/src/arguments.h @@ -50,9 +50,7 @@ class Arguments BASE_EMBEDDED { return Handle(reinterpret_cast(value)); } - int smi_at(int index) { - return Smi::cast((*this)[index])->value(); - } + int smi_at(int index) { return Smi::ToInt((*this)[index]); } double number_at(int index) { return (*this)[index]->Number(); diff --git a/src/asmjs/asm-js.cc b/src/asmjs/asm-js.cc index c6da965f19..fb257e316e 100644 --- a/src/asmjs/asm-js.cc +++ b/src/asmjs/asm-js.cc @@ -277,7 +277,7 @@ MaybeHandle AsmJs::InstantiateAsmWasm(Isolate* isolate, ReportInstantiationFailure(script, position, "Requires standard library"); return MaybeHandle(); } - int member_id = Smi::cast(stdlib_uses->get(i))->value(); + int member_id = Smi::ToInt(stdlib_uses->get(i)); wasm::AsmJsParser::StandardMember member = static_cast(member_id); if (!IsStdlibMemberValid(isolate, stdlib, member, diff --git a/src/ast/compile-time-value.cc b/src/ast/compile-time-value.cc index b86343d059..1e73aee474 100644 --- a/src/ast/compile-time-value.cc +++ b/src/ast/compile-time-value.cc @@ -41,7 +41,7 @@ Handle CompileTimeValue::GetValue(Isolate* isolate, } int CompileTimeValue::GetLiteralTypeFlags(Handle value) { - return Smi::cast(value->get(kLiteralTypeSlot))->value(); + return Smi::ToInt(value->get(kLiteralTypeSlot)); } Handle CompileTimeValue::GetElements(Handle value) { diff --git a/src/ast/prettyprinter.cc b/src/ast/prettyprinter.cc index cc7f247b19..80de4fbc49 100644 --- a/src/ast/prettyprinter.cc +++ b/src/ast/prettyprinter.cc @@ -550,8 +550,7 @@ void AstPrinter::PrintLiteral(MaybeHandle maybe_value, bool quote) { if (object->IsJSFunction()) { Print("JS-Function"); } else if (object->IsJSArray()) { - Print("JS-array[%u]", - Smi::cast(JSArray::cast(object)->length())->value()); + Print("JS-array[%u]", Smi::ToInt(JSArray::cast(object)->length())); } else if (object->IsJSObject()) { Print("JS-Object"); } else { diff --git a/src/bootstrapper.cc b/src/bootstrapper.cc index c63a1f2a86..3eb33036a9 100644 --- a/src/bootstrapper.cc +++ b/src/bootstrapper.cc @@ -4328,7 +4328,7 @@ bool Genesis::InstallNatives(GlobalContextType context_type) { // Verification of important array prototype properties. Object* length = proto->length(); CHECK(length->IsSmi()); - CHECK(Smi::cast(length)->value() == 0); + CHECK(Smi::ToInt(length) == 0); CHECK(proto->HasSmiOrObjectElements()); // This is necessary to enable fast checks for absence of elements // on Array.prototype and below. @@ -4892,7 +4892,7 @@ void Genesis::TransferNamedProperties(Handle from, Handle(from->global_dictionary()); Handle indices = GlobalDictionary::IterationIndices(properties); for (int i = 0; i < indices->length(); i++) { - int index = Smi::cast(indices->get(i))->value(); + int index = Smi::ToInt(indices->get(i)); // If the property is already there we skip it. Handle cell(properties->CellAt(index)); Handle key(cell->name(), isolate()); @@ -4913,7 +4913,7 @@ void Genesis::TransferNamedProperties(Handle from, Handle key_indices = NameDictionary::IterationIndices(properties); for (int i = 0; i < key_indices->length(); i++) { - int key_index = Smi::cast(key_indices->get(i))->value(); + int key_index = Smi::ToInt(key_indices->get(i)); Object* raw_key = properties->KeyAt(key_index); DCHECK(properties->IsKey(isolate(), raw_key)); DCHECK(raw_key->IsName()); @@ -5018,7 +5018,7 @@ Genesis::Genesis( // proxy of the correct size. Object* size = isolate->heap()->serialized_global_proxy_sizes()->get( static_cast(context_snapshot_index) - 1); - instance_size = Smi::cast(size)->value(); + instance_size = Smi::ToInt(size); } else { instance_size = JSGlobalProxy::SizeWithEmbedderFields( global_proxy_template.IsEmpty() diff --git a/src/builtins/builtins-array.cc b/src/builtins/builtins-array.cc index 1a6af44726..73c9c7ef89 100644 --- a/src/builtins/builtins-array.cc +++ b/src/builtins/builtins-array.cc @@ -24,7 +24,7 @@ inline bool ClampedToInteger(Isolate* isolate, Object* object, int* out) { // This is an extended version of ECMA-262 7.1.11 handling signed values // Try to convert object to a number and clamp values to [kMinInt, kMaxInt] if (object->IsSmi()) { - *out = Smi::cast(object)->value(); + *out = Smi::ToInt(object); return true; } else if (object->IsHeapNumber()) { double value = HeapNumber::cast(object)->value(); @@ -60,7 +60,7 @@ inline bool GetSloppyArgumentsLength(Isolate* isolate, Handle object, DCHECK(object->HasFastElements() || object->HasFastArgumentsElements()); Object* len_obj = object->InObjectPropertyAt(JSArgumentsObject::kLengthIndex); if (!len_obj->IsSmi()) return false; - *out = Max(0, Smi::cast(len_obj)->value()); + *out = Max(0, Smi::ToInt(len_obj)); FixedArray* parameters = FixedArray::cast(object->elements()); if (object->HasSloppyArgumentsElements()) { @@ -173,11 +173,11 @@ BUILTIN(ArrayPush) { // Fast Elements Path int to_add = args.length() - 1; Handle array = Handle::cast(receiver); - int len = Smi::cast(array->length())->value(); + int len = Smi::ToInt(array->length()); if (to_add == 0) return Smi::FromInt(len); // Currently fixed arrays cannot grow too big, so we should never hit this. - DCHECK_LE(to_add, Smi::kMaxValue - Smi::cast(array->length())->value()); + DCHECK_LE(to_add, Smi::kMaxValue - Smi::ToInt(array->length())); if (JSArray::HasReadOnlyLength(array)) { return CallJsIntrinsic(isolate, isolate->array_push(), args); @@ -197,7 +197,7 @@ BUILTIN(ArrayPop) { Handle array = Handle::cast(receiver); - uint32_t len = static_cast(Smi::cast(array->length())->value()); + uint32_t len = static_cast(Smi::ToInt(array->length())); if (len == 0) return isolate->heap()->undefined_value(); if (JSArray::HasReadOnlyLength(array)) { @@ -228,7 +228,7 @@ BUILTIN(ArrayShift) { } Handle array = Handle::cast(receiver); - int len = Smi::cast(array->length())->value(); + int len = Smi::ToInt(array->length()); if (len == 0) return heap->undefined_value(); if (JSArray::HasReadOnlyLength(array)) { @@ -250,7 +250,7 @@ BUILTIN(ArrayUnshift) { if (to_add == 0) return array->length(); // Currently fixed arrays cannot grow too big, so we should never hit this. - DCHECK_LE(to_add, Smi::kMaxValue - Smi::cast(array->length())->value()); + DCHECK_LE(to_add, Smi::kMaxValue - Smi::ToInt(array->length())); if (JSArray::HasReadOnlyLength(array)) { return CallJsIntrinsic(isolate, isolate->array_unshift(), args); @@ -279,7 +279,7 @@ BUILTIN(ArraySlice) { AllowHeapAllocation allow_allocation; return CallJsIntrinsic(isolate, isolate->array_slice(), args); } - len = Smi::cast(array->length())->value(); + len = Smi::ToInt(array->length()); } else if (receiver->IsJSObject() && GetSloppyArgumentsLength(isolate, Handle::cast(receiver), &len)) { @@ -352,7 +352,7 @@ BUILTIN(ArraySplice) { return CallJsIntrinsic(isolate, isolate->array_splice(), args); } } - int len = Smi::cast(array->length())->value(); + int len = Smi::ToInt(array->length()); // clip relative start to [0, len] int actual_start = (relative_start < 0) ? Max(len + relative_start, 0) : Min(relative_start, len); @@ -1019,7 +1019,7 @@ Object* Slow_ArrayConcat(BuiltinArguments* args, Handle species, for (int i = 0; i < argument_count; i++) { Handle obj((*args)[i], isolate); if (obj->IsSmi()) { - double_storage->set(j, Smi::cast(*obj)->value()); + double_storage->set(j, Smi::ToInt(*obj)); j++; } else if (obj->IsNumber()) { double_storage->set(j, obj->Number()); @@ -1061,7 +1061,7 @@ Object* Slow_ArrayConcat(BuiltinArguments* args, Handle species, failure = true; break; } - int32_t int_value = Smi::cast(element)->value(); + int32_t int_value = Smi::ToInt(element); double_storage->set(j, int_value); j++; } @@ -1180,7 +1180,7 @@ MaybeHandle Fast_ArrayConcat(Isolate* isolate, } // The Array length is guaranted to be <= kHalfOfMaxInt thus we won't // overflow. - result_len += Smi::cast(array->length())->value(); + result_len += Smi::ToInt(array->length()); DCHECK(result_len >= 0); // Throw an Error if we overflow the FixedArray limits if (FixedDoubleArray::kMaxLength < result_len || diff --git a/src/builtins/builtins-callsite.cc b/src/builtins/builtins-callsite.cc index ebf90990a0..24dc946a24 100644 --- a/src/builtins/builtins-callsite.cc +++ b/src/builtins/builtins-callsite.cc @@ -41,7 +41,7 @@ Handle GetFrameArray(Isolate* isolate, Handle object) { int GetFrameIndex(Isolate* isolate, Handle object) { Handle frame_index_obj = JSObject::GetDataProperty( object, isolate->factory()->call_site_frame_index_symbol()); - return Smi::cast(*frame_index_obj)->value(); + return Smi::ToInt(*frame_index_obj); } } // namespace diff --git a/src/builtins/builtins-error.cc b/src/builtins/builtins-error.cc index 5b28863364..b914f637f2 100644 --- a/src/builtins/builtins-error.cc +++ b/src/builtins/builtins-error.cc @@ -96,8 +96,8 @@ Object* MakeGenericError(Isolate* isolate, BuiltinArguments args, RETURN_RESULT_OR_FAILURE( isolate, ErrorUtils::MakeGenericError(isolate, constructor, - Smi::cast(*template_index)->value(), - arg0, arg1, arg2, SKIP_NONE)); + Smi::ToInt(*template_index), arg0, + arg1, arg2, SKIP_NONE)); } } // namespace diff --git a/src/builtins/builtins-string.cc b/src/builtins/builtins-string.cc index b45a8601df..ba87d755f6 100644 --- a/src/builtins/builtins-string.cc +++ b/src/builtins/builtins-string.cc @@ -519,7 +519,7 @@ MUST_USE_RESULT static Object* ConvertCase( if (answer->IsException(isolate) || answer->IsString()) return answer; DCHECK(answer->IsSmi()); - length = Smi::cast(answer)->value(); + length = Smi::ToInt(answer); if (s->IsOneByteRepresentation() && length > 0) { ASSIGN_RETURN_FAILURE_ON_EXCEPTION( isolate, result, isolate->factory()->NewRawOneByteString(length)); diff --git a/src/builtins/builtins-typedarray.cc b/src/builtins/builtins-typedarray.cc index 773e5480ac..176a79965b 100644 --- a/src/builtins/builtins-typedarray.cc +++ b/src/builtins/builtins-typedarray.cc @@ -27,7 +27,7 @@ namespace { int64_t CapRelativeIndex(Handle num, int64_t minimum, int64_t maximum) { int64_t relative; if (V8_LIKELY(num->IsSmi())) { - relative = Smi::cast(*num)->value(); + relative = Smi::ToInt(*num); } else { DCHECK(num->IsHeapNumber()); double fp = HeapNumber::cast(*num)->value(); diff --git a/src/code-stub-assembler.cc b/src/code-stub-assembler.cc index 4fbfb4a8a9..751f734d51 100644 --- a/src/code-stub-assembler.cc +++ b/src/code-stub-assembler.cc @@ -8186,7 +8186,7 @@ Node* CodeStubAssembler::StrictEqual(Node* lhs, Node* rhs, // if (!lhs->IsSmi()) { // if (lhs->IsHeapNumber()) { // if (rhs->IsSmi()) { - // return Smi::cast(rhs)->value() == HeapNumber::cast(lhs)->value(); + // return Smi::ToInt(rhs) == HeapNumber::cast(lhs)->value(); // } else if (rhs->IsHeapNumber()) { // return HeapNumber::cast(rhs)->value() == // HeapNumber::cast(lhs)->value(); @@ -8213,7 +8213,7 @@ Node* CodeStubAssembler::StrictEqual(Node* lhs, Node* rhs, // return false; // } else { // if (rhs->IsHeapNumber()) { - // return Smi::cast(lhs)->value() == HeapNumber::cast(rhs)->value(); + // return Smi::ToInt(lhs) == HeapNumber::cast(rhs)->value(); // } else { // return false; // } diff --git a/src/contexts-inl.h b/src/contexts-inl.h index a2ca70ae23..bbc3dea021 100644 --- a/src/contexts-inl.h +++ b/src/contexts-inl.h @@ -23,11 +23,7 @@ ScriptContextTable* ScriptContextTable::cast(Object* context) { return reinterpret_cast(context); } - -int ScriptContextTable::used() const { - return Smi::cast(get(kUsedSlot))->value(); -} - +int ScriptContextTable::used() const { return Smi::ToInt(get(kUsedSlot)); } void ScriptContextTable::set_used(int used) { set(kUsedSlot, Smi::FromInt(used)); diff --git a/src/conversions-inl.h b/src/conversions-inl.h index c4753ebc93..d96425179d 100644 --- a/src/conversions-inl.h +++ b/src/conversions-inl.h @@ -153,18 +153,18 @@ bool DoubleToUint32IfEqualToSelf(double value, uint32_t* uint32_value) { } int32_t NumberToInt32(Object* number) { - if (number->IsSmi()) return Smi::cast(number)->value(); + if (number->IsSmi()) return Smi::ToInt(number); return DoubleToInt32(number->Number()); } uint32_t NumberToUint32(Object* number) { - if (number->IsSmi()) return Smi::cast(number)->value(); + if (number->IsSmi()) return Smi::ToInt(number); return DoubleToUint32(number->Number()); } uint32_t PositiveNumberToUint32(Object* number) { if (number->IsSmi()) { - int value = Smi::cast(number)->value(); + int value = Smi::ToInt(number); if (value <= 0) return 0; return value; } @@ -178,7 +178,7 @@ uint32_t PositiveNumberToUint32(Object* number) { } int64_t NumberToInt64(Object* number) { - if (number->IsSmi()) return Smi::cast(number)->value(); + if (number->IsSmi()) return Smi::ToInt(number); return static_cast(number->Number()); } @@ -186,7 +186,7 @@ bool TryNumberToSize(Object* number, size_t* result) { // Do not create handles in this function! Don't use SealHandleScope because // the function can be used concurrently. if (number->IsSmi()) { - int value = Smi::cast(number)->value(); + int value = Smi::ToInt(number); DCHECK(static_cast(Smi::kMaxValue) <= std::numeric_limits::max()); if (value >= 0) { diff --git a/src/debug/debug.cc b/src/debug/debug.cc index e98db5c7c6..e18c09fd8c 100644 --- a/src/debug/debug.cc +++ b/src/debug/debug.cc @@ -2243,9 +2243,8 @@ void Debug::PrintBreakLocation() { int column = Script::GetColumnNumber(script, source_position) - (line == 0 ? script->column_offset() : 0); Handle line_ends(FixedArray::cast(script->line_ends())); - int line_start = - line == 0 ? 0 : Smi::cast(line_ends->get(line - 1))->value() + 1; - int line_end = Smi::cast(line_ends->get(line))->value(); + int line_start = line == 0 ? 0 : Smi::ToInt(line_ends->get(line - 1)) + 1; + int line_end = Smi::ToInt(line_ends->get(line)); DisallowHeapAllocation no_gc; String::FlatContent content = source->GetFlatContent(); if (content.IsOneByte()) { diff --git a/src/debug/liveedit.cc b/src/debug/liveedit.cc index 074538adcb..31d76d7bd0 100644 --- a/src/debug/liveedit.cc +++ b/src/debug/liveedit.cc @@ -437,7 +437,7 @@ class LineEndsWrapper { int string_len_; int GetPosAfterNewLine(int index) { - return Smi::cast(ends_array_->get(index))->value() + 1; + return Smi::ToInt(ends_array_->get(index)) + 1; } }; @@ -603,7 +603,7 @@ static Handle UnwrapSharedFunctionInfoFromJSValue( static int GetArrayLength(Handle array) { Object* length = array->length(); CHECK(length->IsSmi()); - return Smi::cast(length)->value(); + return Smi::ToInt(length); } void FunctionInfoWrapper::SetInitialProperties(Handle name, @@ -1243,8 +1243,7 @@ class MultipleFunctionTarget { Handle old_element = JSReceiver::GetElement(isolate, result_, i).ToHandleChecked(); if (!old_element->IsSmi() || - Smi::cast(*old_element)->value() == - LiveEdit::FUNCTION_AVAILABLE_FOR_PATCH) { + Smi::ToInt(*old_element) == LiveEdit::FUNCTION_AVAILABLE_FOR_PATCH) { SetElementSloppy(result_, i, Handle(Smi::FromInt(status), isolate)); } diff --git a/src/deoptimizer.cc b/src/deoptimizer.cc index 1330e62157..5ff442588c 100644 --- a/src/deoptimizer.cc +++ b/src/deoptimizer.cc @@ -3766,7 +3766,7 @@ Handle TranslatedState::MaterializeCapturedObjectAt( CHECK(iterated_string->IsString()); object->set_string(String::cast(*iterated_string)); CHECK(next_index->IsSmi()); - object->set_index(Smi::cast(*next_index)->value()); + object->set_index(Smi::ToInt(*next_index)); return object; } case JS_ASYNC_FROM_SYNC_ITERATOR_TYPE: { @@ -3830,8 +3830,8 @@ Handle TranslatedState::MaterializeCapturedObjectAt( object->set_context(Context::cast(*context)); object->set_receiver(*receiver); object->set_input_or_debug_pos(*input_or_debug_pos); - object->set_resume_mode(Smi::cast(*resume_mode)->value()); - object->set_continuation(Smi::cast(*continuation_offset)->value()); + object->set_resume_mode(Smi::ToInt(*resume_mode)); + object->set_continuation(Smi::ToInt(*continuation_offset)); object->set_register_file(FixedArray::cast(*register_file)); int in_object_properties = map->GetInObjectProperties(); for (int i = 0; i < in_object_properties; ++i) { @@ -3853,7 +3853,7 @@ Handle TranslatedState::MaterializeCapturedObjectAt( Handle first = materializer.FieldAt(value_index); Handle second = materializer.FieldAt(value_index); object->set_map(*map); - object->set_length(Smi::cast(*string_length)->value()); + object->set_length(Smi::ToInt(*string_length)); object->set_first(String::cast(*first)); object->set_second(String::cast(*second)); CHECK(hash->IsNumber()); // The {Name::kEmptyHashField} value. diff --git a/src/elements.cc b/src/elements.cc index 43c1c9a92a..8570fde87d 100644 --- a/src/elements.cc +++ b/src/elements.cc @@ -313,7 +313,7 @@ static void CopySmiToDoubleElements(FixedArrayBase* from_base, if (hole_or_smi == the_hole) { to->set_the_hole(to_start); } else { - to->set(to_start, Smi::cast(hole_or_smi)->value()); + to->set(to_start, Smi::ToInt(hole_or_smi)); } } } @@ -353,7 +353,7 @@ static void CopyPackedSmiToDoubleElements(FixedArrayBase* from_base, from_start < from_end; from_start++, to_start++) { Object* smi = from->get(from_start); DCHECK(!smi->IsTheHole(from->GetIsolate())); - to->set(to_start, Smi::cast(smi)->value()); + to->set(to_start, Smi::ToInt(smi)); } } @@ -555,7 +555,7 @@ class ElementsAccessorBase : public ElementsAccessor { if (holder->IsJSArray()) { Object* length_obj = JSArray::cast(holder)->length(); if (length_obj->IsSmi()) { - length = Smi::cast(length_obj)->value(); + length = Smi::ToInt(length_obj); } } else { length = fixed_array_base->length(); @@ -585,7 +585,7 @@ class ElementsAccessorBase : public ElementsAccessor { static void TryTransitionResultArrayToPacked(Handle array) { if (!IsHoleyOrDictionaryElementsKind(kind())) return; Handle backing_store(array->elements()); - int length = Smi::cast(array->length())->value(); + int length = Smi::ToInt(array->length()); if (!Subclass::IsPackedImpl(*array, *backing_store, 0, length)) { return; } @@ -806,7 +806,7 @@ class ElementsAccessorBase : public ElementsAccessor { if (receiver->IsJSArray()) { DCHECK(JSArray::cast(receiver)->length()->IsSmi()); return static_cast( - Smi::cast(JSArray::cast(receiver)->length())->value()); + Smi::ToInt(JSArray::cast(receiver)->length())); } return Subclass::GetCapacityImpl(receiver, elements); } @@ -845,7 +845,7 @@ class ElementsAccessorBase : public ElementsAccessor { int packed_size = kPackedSizeNotKnown; if (IsFastPackedElementsKind(from_kind) && object->IsJSArray()) { - packed_size = Smi::cast(JSArray::cast(*object)->length())->value(); + packed_size = Smi::ToInt(JSArray::cast(*object)->length()); } Subclass::CopyElementsImpl(*old_elements, src_index, *new_elements, @@ -981,8 +981,7 @@ class ElementsAccessorBase : public ElementsAccessor { bool is_packed = IsFastPackedElementsKind(from_kind) && from_holder->IsJSArray(); if (is_packed) { - packed_size = - Smi::cast(JSArray::cast(from_holder)->length())->value(); + packed_size = Smi::ToInt(JSArray::cast(from_holder)->length()); if (copy_size >= 0 && packed_size > copy_size) { packed_size = copy_size; } @@ -1812,7 +1811,7 @@ class DictionaryElementsAccessor if (k->Number() > SeededNumberDictionary::kRequiresSlowElementsLimit) { requires_slow_elements = true; } else { - max_key = Max(max_key, Smi::cast(k)->value()); + max_key = Max(max_key, Smi::ToInt(k)); } } if (requires_slow_elements) { @@ -2117,7 +2116,7 @@ class FastElementsAccessor : public ElementsAccessorBase { Arguments* args, uint32_t add_count) { Isolate* isolate = receiver->GetIsolate(); Heap* heap = isolate->heap(); - uint32_t length = Smi::cast(receiver->length())->value(); + uint32_t length = Smi::ToInt(receiver->length()); uint32_t new_length = length - delete_count + add_count; ElementsKind kind = KindTraits::Kind; @@ -2435,8 +2434,7 @@ class FastElementsAccessor : public ElementsAccessorBase { JSObject::EnsureWritableFastElements(receiver); } Handle backing_store(receiver->elements(), isolate); - uint32_t length = - static_cast(Smi::cast(receiver->length())->value()); + uint32_t length = static_cast(Smi::ToInt(receiver->length())); DCHECK(length > 0); int new_length = length - 1; int remove_index = remove_position == AT_START ? 0 : new_length; @@ -2458,7 +2456,7 @@ class FastElementsAccessor : public ElementsAccessorBase { Handle backing_store, Arguments* args, uint32_t add_size, Where add_position) { - uint32_t length = Smi::cast(receiver->length())->value(); + uint32_t length = Smi::ToInt(receiver->length()); DCHECK(0 < add_size); uint32_t elms_len = backing_store->length(); // Check we do not overflow the new_length. @@ -2910,7 +2908,7 @@ class TypedElementsAccessor ctype value; if (obj_value->IsSmi()) { - value = BackingStore::from(Smi::cast(*obj_value)->value()); + value = BackingStore::from(Smi::ToInt(*obj_value)); } else { DCHECK(obj_value->IsHeapNumber()); value = BackingStore::from(HeapNumber::cast(*obj_value)->value()); @@ -3252,7 +3250,7 @@ class TypedElementsAccessor for (uint32_t i = 0; i < length; i++) { Object* elem = source_store->get(i); DCHECK(elem->IsSmi()); - int int_value = Smi::cast(elem)->value(); + int int_value = Smi::ToInt(elem); dest->set(i, dest->from(int_value)); } return true; @@ -3264,7 +3262,7 @@ class TypedElementsAccessor } else { Object* elem = source_store->get(i); DCHECK(elem->IsSmi()); - int int_value = Smi::cast(elem)->value(); + int int_value = Smi::ToInt(elem); dest->set(i, dest->from(int_value)); } } @@ -3382,7 +3380,7 @@ class SloppyArgumentsElementsAccessor Object* probe = elements->get_mapped_entry(entry); DCHECK(!probe->IsTheHole(isolate)); Context* context = elements->context(); - int context_entry = Smi::cast(probe)->value(); + int context_entry = Smi::ToInt(probe); DCHECK(!context->get(context_entry)->IsTheHole(isolate)); return handle(context->get(context_entry), isolate); } else { @@ -3418,7 +3416,7 @@ class SloppyArgumentsElementsAccessor Object* probe = elements->get_mapped_entry(entry); DCHECK(!probe->IsTheHole(store->GetIsolate())); Context* context = elements->context(); - int context_entry = Smi::cast(probe)->value(); + int context_entry = Smi::ToInt(probe); DCHECK(!context->get(context_entry)->IsTheHole(store->GetIsolate())); context->set(context_entry, value); } else { @@ -3770,7 +3768,7 @@ class SlowSloppyArgumentsElementsAccessor Object* probe = elements->get_mapped_entry(entry); DCHECK(!probe->IsTheHole(isolate)); Context* context = elements->context(); - int context_entry = Smi::cast(probe)->value(); + int context_entry = Smi::ToInt(probe); DCHECK(!context->get(context_entry)->IsTheHole(isolate)); context->set(context_entry, *value); diff --git a/src/feedback-vector-inl.h b/src/feedback-vector-inl.h index 483613d984..e3245b8204 100644 --- a/src/feedback-vector-inl.h +++ b/src/feedback-vector-inl.h @@ -47,7 +47,7 @@ bool FeedbackMetadata::is_empty() const { int FeedbackMetadata::slot_count() const { if (length() == 0) return 0; DCHECK(length() > kReservedIndexCount); - return Smi::cast(get(kSlotsCountIndex))->value(); + return Smi::ToInt(get(kSlotsCountIndex)); } // static @@ -106,7 +106,7 @@ SharedFunctionInfo* FeedbackVector::shared_function_info() const { } int FeedbackVector::invocation_count() const { - return Smi::cast(get(kInvocationCountIndex))->value(); + return Smi::ToInt(get(kInvocationCountIndex)); } void FeedbackVector::clear_invocation_count() { @@ -140,7 +140,7 @@ bool FeedbackVector::has_optimization_marker() const { } int FeedbackVector::profiler_ticks() const { - return Smi::cast(get(kProfilerTicksIndex))->value(); + return Smi::ToInt(get(kProfilerTicksIndex)); } void FeedbackVector::set_profiler_ticks(int ticks) { @@ -254,7 +254,7 @@ void FeedbackVector::ComputeCounts(int* with_type_info, int* generic, // TODO(mvstanton): Remove code_is_interpreted when full code is retired // from service. if (code_is_interpreted) { - int const feedback = Smi::cast(obj)->value(); + int const feedback = Smi::ToInt(obj); BinaryOperationHint hint = BinaryOperationHintFromFeedback(feedback); if (hint == BinaryOperationHint::kAny) { gen++; @@ -271,7 +271,7 @@ void FeedbackVector::ComputeCounts(int* with_type_info, int* generic, // TODO(mvstanton): Remove code_is_interpreted when full code is retired // from service. if (code_is_interpreted) { - int const feedback = Smi::cast(obj)->value(); + int const feedback = Smi::ToInt(obj); CompareOperationHint hint = CompareOperationHintFromFeedback(feedback); if (hint == CompareOperationHint::kAny) { diff --git a/src/feedback-vector.cc b/src/feedback-vector.cc index d0cd0fc61e..3b1b059803 100644 --- a/src/feedback-vector.cc +++ b/src/feedback-vector.cc @@ -37,13 +37,13 @@ std::ostream& operator<<(std::ostream& os, FeedbackSlotKind kind) { FeedbackSlotKind FeedbackMetadata::GetKind(FeedbackSlot slot) const { int index = VectorICComputer::index(kReservedIndexCount, slot.ToInt()); - int data = Smi::cast(get(index))->value(); + int data = Smi::ToInt(get(index)); return VectorICComputer::decode(data, slot.ToInt()); } void FeedbackMetadata::SetKind(FeedbackSlot slot, FeedbackSlotKind kind) { int index = VectorICComputer::index(kReservedIndexCount, slot.ToInt()); - int data = Smi::cast(get(index))->value(); + int data = Smi::ToInt(get(index)); int new_data = VectorICComputer::encode(data, slot.ToInt(), kind); set(index, Smi::FromInt(new_data)); } @@ -631,7 +631,7 @@ InlineCacheState CallICNexus::StateFromFeedback() const { int CallICNexus::ExtractCallCount() { Object* call_count = GetFeedbackExtra(); CHECK(call_count->IsSmi()); - int value = Smi::cast(call_count)->value(); + int value = Smi::ToInt(call_count); return value; } @@ -874,7 +874,7 @@ KeyedAccessStoreMode KeyedStoreICNexus::GetKeyedAccessStoreMode() const { IcCheckType KeyedLoadICNexus::GetKeyType() const { Object* feedback = GetFeedback(); if (feedback == *FeedbackVector::MegamorphicSentinel(GetIsolate())) { - return static_cast(Smi::cast(GetFeedbackExtra())->value()); + return static_cast(Smi::ToInt(GetFeedbackExtra())); } return IsPropertyNameFeedback(feedback) ? PROPERTY : ELEMENT; } @@ -882,7 +882,7 @@ IcCheckType KeyedLoadICNexus::GetKeyType() const { IcCheckType KeyedStoreICNexus::GetKeyType() const { Object* feedback = GetFeedback(); if (feedback == *FeedbackVector::MegamorphicSentinel(GetIsolate())) { - return static_cast(Smi::cast(GetFeedbackExtra())->value()); + return static_cast(Smi::ToInt(GetFeedbackExtra())); } return IsPropertyNameFeedback(feedback) ? PROPERTY : ELEMENT; } @@ -910,12 +910,12 @@ InlineCacheState CompareICNexus::StateFromFeedback() const { } BinaryOperationHint BinaryOpICNexus::GetBinaryOperationFeedback() const { - int feedback = Smi::cast(GetFeedback())->value(); + int feedback = Smi::ToInt(GetFeedback()); return BinaryOperationHintFromFeedback(feedback); } CompareOperationHint CompareICNexus::GetCompareOperationFeedback() const { - int feedback = Smi::cast(GetFeedback())->value(); + int feedback = Smi::ToInt(GetFeedback()); return CompareOperationHintFromFeedback(feedback); } @@ -999,7 +999,7 @@ Handle ConvertToJSObject(Isolate* isolate, Handle position_specific_types( ArrayList::cast(feedback->get(value_index))); - int position = Smi::cast(key)->value(); + int position = Smi::ToInt(key); JSObject::AddDataElement(type_profile, position, isolate->factory()->NewJSArrayWithElements( position_specific_types->Elements()), diff --git a/src/frames-inl.h b/src/frames-inl.h index 4042a90592..7f409968c0 100644 --- a/src/frames-inl.h +++ b/src/frames-inl.h @@ -111,7 +111,7 @@ inline Object* BuiltinExitFrame::receiver_slot_object() const { // fp[2 + argc - 1]: receiver. Object* argc_slot = argc_slot_object(); DCHECK(argc_slot->IsSmi()); - int argc = Smi::cast(argc_slot)->value(); + int argc = Smi::ToInt(argc_slot); const int receiverOffset = BuiltinExitFrameConstants::kNewTargetOffset + (argc - 1) * kPointerSize; diff --git a/src/frames.cc b/src/frames.cc index 00c4500b3c..3b37c88c38 100644 --- a/src/frames.cc +++ b/src/frames.cc @@ -694,7 +694,7 @@ int BuiltinExitFrame::ComputeParametersCount() const { DCHECK(argc_slot->IsSmi()); // Argc also counts the receiver, target, new target, and argc itself as args, // therefore the real argument count is argc - 4. - int argc = Smi::cast(argc_slot)->value() - 4; + int argc = Smi::ToInt(argc_slot) - 4; DCHECK(argc >= 0); return argc; } @@ -1159,7 +1159,7 @@ int JavaScriptFrame::ComputeParametersCount() const { int JavaScriptBuiltinContinuationFrame::ComputeParametersCount() const { Object* argc_object = Memory::Object_at(fp() + BuiltinContinuationFrameConstants::kArgCOffset); - return Smi::cast(argc_object)->value(); + return Smi::ToInt(argc_object); } namespace { @@ -1275,7 +1275,7 @@ uint32_t FrameSummary::WasmCompiledFrameSummary::function_index() const { FixedArray* deopt_data = code()->deoptimization_data(); DCHECK_EQ(2, deopt_data->length()); DCHECK(deopt_data->get(1)->IsSmi()); - int val = Smi::cast(deopt_data->get(1))->value(); + int val = Smi::ToInt(deopt_data->get(1)); DCHECK_LE(0, val); return static_cast(val); } @@ -1598,7 +1598,7 @@ int InterpretedFrame::GetBytecodeOffset() const { DCHECK_EQ( InterpreterFrameConstants::kBytecodeOffsetFromFp, InterpreterFrameConstants::kExpressionsOffset - index * kPointerSize); - int raw_offset = Smi::cast(GetExpression(index))->value(); + int raw_offset = Smi::ToInt(GetExpression(index)); return raw_offset - BytecodeArray::kHeaderSize + kHeapObjectTag; } @@ -1609,7 +1609,7 @@ int InterpretedFrame::GetBytecodeOffset(Address fp) { InterpreterFrameConstants::kBytecodeOffsetFromFp, InterpreterFrameConstants::kExpressionsOffset - index * kPointerSize); Address expression_offset = fp + offset - index * kPointerSize; - int raw_offset = Smi::cast(Memory::Object_at(expression_offset))->value(); + int raw_offset = Smi::ToInt(Memory::Object_at(expression_offset)); return raw_offset - BytecodeArray::kHeaderSize + kHeapObjectTag; } @@ -1667,12 +1667,12 @@ void InterpretedFrame::Summarize(List* functions, } int ArgumentsAdaptorFrame::GetNumberOfIncomingArguments() const { - return Smi::cast(GetExpression(0))->value(); + return Smi::ToInt(GetExpression(0)); } int ArgumentsAdaptorFrame::GetLength(Address fp) { const int offset = ArgumentsAdaptorFrameConstants::kLengthOffset; - return Smi::cast(Memory::Object_at(fp + offset))->value(); + return Smi::ToInt(Memory::Object_at(fp + offset)); } Code* ArgumentsAdaptorFrame::unchecked_code() const { @@ -1681,7 +1681,7 @@ Code* ArgumentsAdaptorFrame::unchecked_code() const { } int BuiltinFrame::GetNumberOfIncomingArguments() const { - return Smi::cast(GetExpression(0))->value(); + return Smi::ToInt(GetExpression(0)); } void BuiltinFrame::PrintFrameKind(StringStream* accumulator) const { diff --git a/src/full-codegen/arm/full-codegen-arm.cc b/src/full-codegen/arm/full-codegen-arm.cc index 2f83844087..03c0efe554 100644 --- a/src/full-codegen/arm/full-codegen-arm.cc +++ b/src/full-codegen/arm/full-codegen-arm.cc @@ -535,7 +535,7 @@ void FullCodeGenerator::TestContext::Plug(Handle lit) const { if (true_label_ != fall_through_) __ b(true_label_); } } else if (lit->IsSmi()) { - if (Smi::cast(*lit)->value() == 0) { + if (Smi::ToInt(*lit) == 0) { if (false_label_ != fall_through_) __ b(false_label_); } else { if (true_label_ != fall_through_) __ b(true_label_); diff --git a/src/full-codegen/arm64/full-codegen-arm64.cc b/src/full-codegen/arm64/full-codegen-arm64.cc index 7027665270..bc8dee209b 100644 --- a/src/full-codegen/arm64/full-codegen-arm64.cc +++ b/src/full-codegen/arm64/full-codegen-arm64.cc @@ -525,7 +525,7 @@ void FullCodeGenerator::TestContext::Plug(Handle lit) const { if (true_label_ != fall_through_) __ B(true_label_); } } else if (lit->IsSmi()) { - if (Smi::cast(*lit)->value() == 0) { + if (Smi::ToInt(*lit) == 0) { if (false_label_ != fall_through_) __ B(false_label_); } else { if (true_label_ != fall_through_) __ B(true_label_); diff --git a/src/full-codegen/ia32/full-codegen-ia32.cc b/src/full-codegen/ia32/full-codegen-ia32.cc index fc39a28086..b27c8cf183 100644 --- a/src/full-codegen/ia32/full-codegen-ia32.cc +++ b/src/full-codegen/ia32/full-codegen-ia32.cc @@ -472,7 +472,7 @@ void FullCodeGenerator::TestContext::Plug(Handle lit) const { if (true_label_ != fall_through_) __ jmp(true_label_); } } else if (lit->IsSmi()) { - if (Smi::cast(*lit)->value() == 0) { + if (Smi::ToInt(*lit) == 0) { if (false_label_ != fall_through_) __ jmp(false_label_); } else { if (true_label_ != fall_through_) __ jmp(true_label_); diff --git a/src/full-codegen/mips/full-codegen-mips.cc b/src/full-codegen/mips/full-codegen-mips.cc index 7efcc68a7d..42bb3fbd40 100644 --- a/src/full-codegen/mips/full-codegen-mips.cc +++ b/src/full-codegen/mips/full-codegen-mips.cc @@ -512,7 +512,7 @@ void FullCodeGenerator::TestContext::Plug(Handle lit) const { if (true_label_ != fall_through_) __ Branch(true_label_); } } else if (lit->IsSmi()) { - if (Smi::cast(*lit)->value() == 0) { + if (Smi::ToInt(*lit) == 0) { if (false_label_ != fall_through_) __ Branch(false_label_); } else { if (true_label_ != fall_through_) __ Branch(true_label_); diff --git a/src/full-codegen/mips64/full-codegen-mips64.cc b/src/full-codegen/mips64/full-codegen-mips64.cc index 1d42f1a384..f8f3c0d1db 100644 --- a/src/full-codegen/mips64/full-codegen-mips64.cc +++ b/src/full-codegen/mips64/full-codegen-mips64.cc @@ -512,7 +512,7 @@ void FullCodeGenerator::TestContext::Plug(Handle lit) const { if (true_label_ != fall_through_) __ Branch(true_label_); } } else if (lit->IsSmi()) { - if (Smi::cast(*lit)->value() == 0) { + if (Smi::ToInt(*lit) == 0) { if (false_label_ != fall_through_) __ Branch(false_label_); } else { if (true_label_ != fall_through_) __ Branch(true_label_); diff --git a/src/full-codegen/ppc/full-codegen-ppc.cc b/src/full-codegen/ppc/full-codegen-ppc.cc index 2611c17733..a7c6e345fb 100644 --- a/src/full-codegen/ppc/full-codegen-ppc.cc +++ b/src/full-codegen/ppc/full-codegen-ppc.cc @@ -504,7 +504,7 @@ void FullCodeGenerator::TestContext::Plug(Handle lit) const { if (true_label_ != fall_through_) __ b(true_label_); } } else if (lit->IsSmi()) { - if (Smi::cast(*lit)->value() == 0) { + if (Smi::ToInt(*lit) == 0) { if (false_label_ != fall_through_) __ b(false_label_); } else { if (true_label_ != fall_through_) __ b(true_label_); diff --git a/src/full-codegen/s390/full-codegen-s390.cc b/src/full-codegen/s390/full-codegen-s390.cc index de0e9293bb..581b3b6387 100644 --- a/src/full-codegen/s390/full-codegen-s390.cc +++ b/src/full-codegen/s390/full-codegen-s390.cc @@ -495,7 +495,7 @@ void FullCodeGenerator::TestContext::Plug(Handle lit) const { if (true_label_ != fall_through_) __ b(true_label_); } } else if (lit->IsSmi()) { - if (Smi::cast(*lit)->value() == 0) { + if (Smi::ToInt(*lit) == 0) { if (false_label_ != fall_through_) __ b(false_label_); } else { if (true_label_ != fall_through_) __ b(true_label_); diff --git a/src/full-codegen/x64/full-codegen-x64.cc b/src/full-codegen/x64/full-codegen-x64.cc index 53c535d385..3338cd0bf0 100644 --- a/src/full-codegen/x64/full-codegen-x64.cc +++ b/src/full-codegen/x64/full-codegen-x64.cc @@ -485,7 +485,7 @@ void FullCodeGenerator::TestContext::Plug(Handle lit) const { if (true_label_ != fall_through_) __ jmp(true_label_); } } else if (lit->IsSmi()) { - if (Smi::cast(*lit)->value() == 0) { + if (Smi::ToInt(*lit) == 0) { if (false_label_ != fall_through_) __ jmp(false_label_); } else { if (true_label_ != fall_through_) __ jmp(true_label_); diff --git a/src/full-codegen/x87/full-codegen-x87.cc b/src/full-codegen/x87/full-codegen-x87.cc index 2b689f3c41..dd77308eb7 100644 --- a/src/full-codegen/x87/full-codegen-x87.cc +++ b/src/full-codegen/x87/full-codegen-x87.cc @@ -467,7 +467,7 @@ void FullCodeGenerator::TestContext::Plug(Handle lit) const { if (true_label_ != fall_through_) __ jmp(true_label_); } } else if (lit->IsSmi()) { - if (Smi::cast(*lit)->value() == 0) { + if (Smi::ToInt(*lit) == 0) { if (false_label_ != fall_through_) __ jmp(false_label_); } else { if (true_label_ != fall_through_) __ jmp(true_label_); diff --git a/src/heap/heap-inl.h b/src/heap/heap-inl.h index 070f961505..a1a09504dd 100644 --- a/src/heap/heap-inl.h +++ b/src/heap/heap-inl.h @@ -32,7 +32,7 @@ namespace internal { AllocationSpace AllocationResult::RetrySpace() { DCHECK(IsRetry()); - return static_cast(Smi::cast(object_)->value()); + return static_cast(Smi::ToInt(object_)); } HeapObject* AllocationResult::ToObjectChecked() { diff --git a/src/heap/heap.cc b/src/heap/heap.cc index f29df07a8c..ac19f39e3e 100644 --- a/src/heap/heap.cc +++ b/src/heap/heap.cc @@ -815,7 +815,7 @@ void Heap::PreprocessStackTraces() { // a stack trace that has already been preprocessed. Guard against this. if (!maybe_code->IsAbstractCode()) break; AbstractCode* abstract_code = AbstractCode::cast(maybe_code); - int offset = Smi::cast(elements->get(j + 3))->value(); + int offset = Smi::ToInt(elements->get(j + 3)); int pos = abstract_code->SourcePosition(offset); elements->set(j + 2, Smi::FromInt(pos)); } diff --git a/src/heap/incremental-marking.cc b/src/heap/incremental-marking.cc index e0c79ebaba..a7531a324d 100644 --- a/src/heap/incremental-marking.cc +++ b/src/heap/incremental-marking.cc @@ -727,7 +727,7 @@ void IncrementalMarking::RetainMaps() { DCHECK(retained_maps->Get(i)->IsWeakCell()); WeakCell* cell = WeakCell::cast(retained_maps->Get(i)); if (cell->cleared()) continue; - int age = Smi::cast(retained_maps->Get(i + 1))->value(); + int age = Smi::ToInt(retained_maps->Get(i + 1)); int new_age; Map* map = Map::cast(cell->value()); if (i >= number_of_disposed_maps && !map_retaining_is_disabled && diff --git a/src/ic/ic.cc b/src/ic/ic.cc index 91df19ad5c..b5e08be8ee 100644 --- a/src/ic/ic.cc +++ b/src/ic/ic.cc @@ -2290,9 +2290,9 @@ MaybeHandle KeyedStoreIC::Store(Handle object, old_receiver_map = handle(receiver->map(), isolate()); is_arguments = receiver->IsJSArgumentsObject(); if (!is_arguments) { - key_is_valid_index = key->IsSmi() && Smi::cast(*key)->value() >= 0; + key_is_valid_index = key->IsSmi() && Smi::ToInt(*key) >= 0; if (key_is_valid_index) { - uint32_t index = static_cast(Smi::cast(*key)->value()); + uint32_t index = static_cast(Smi::ToInt(*key)); store_mode = GetStoreMode(receiver, index, value); } } diff --git a/src/interpreter/bytecode-array-accessor.cc b/src/interpreter/bytecode-array-accessor.cc index ab7e9ada57..f597981514 100644 --- a/src/interpreter/bytecode-array-accessor.cc +++ b/src/interpreter/bytecode-array-accessor.cc @@ -260,7 +260,7 @@ JumpTableTargetOffsets::iterator::iterator( JumpTableTargetOffset JumpTableTargetOffsets::iterator::operator*() { DCHECK_LT(table_offset_, table_end_); DCHECK(current_->IsSmi()); - return {index_, accessor_->GetAbsoluteOffset(Smi::cast(*current_)->value())}; + return {index_, accessor_->GetAbsoluteOffset(Smi::ToInt(*current_))}; } JumpTableTargetOffsets::iterator& JumpTableTargetOffsets::iterator:: diff --git a/src/isolate-inl.h b/src/isolate-inl.h index e51abf207d..cea33db360 100644 --- a/src/isolate-inl.h +++ b/src/isolate-inl.h @@ -130,7 +130,7 @@ bool Isolate::IsArraySpeciesLookupChainIntact() { PropertyCell* species_cell = heap()->species_protector(); return species_cell->value()->IsSmi() && - Smi::cast(species_cell->value())->value() == kProtectorValid; + Smi::ToInt(species_cell->value()) == kProtectorValid; } bool Isolate::IsStringLengthOverflowIntact() { diff --git a/src/isolate.cc b/src/isolate.cc index 1cac9955e0..56b960a04f 100644 --- a/src/isolate.cc +++ b/src/isolate.cc @@ -1213,7 +1213,7 @@ Object* Isolate::UnwindAndFindHandler() { // Gather information from the handler. Code* code = frame->LookupCode(); return FoundHandler( - nullptr, code, Smi::cast(code->handler_table()->get(0))->value(), + nullptr, code, Smi::ToInt(code->handler_table()->get(0)), handler->address() + StackHandlerConstants::kSize, 0); } @@ -3050,7 +3050,7 @@ bool Isolate::IsFastArrayConstructorPrototypeChainIntact() { PropertyCell* no_elements_cell = heap()->array_protector(); bool cell_reports_intact = no_elements_cell->value()->IsSmi() && - Smi::cast(no_elements_cell->value())->value() == kProtectorValid; + Smi::ToInt(no_elements_cell->value()) == kProtectorValid; #ifdef DEBUG Map* root_array_map = @@ -3108,8 +3108,7 @@ bool Isolate::IsFastArrayConstructorPrototypeChainIntact() { bool Isolate::IsIsConcatSpreadableLookupChainIntact() { Cell* is_concat_spreadable_cell = heap()->is_concat_spreadable_protector(); bool is_is_concat_spreadable_set = - Smi::cast(is_concat_spreadable_cell->value())->value() == - kProtectorInvalid; + Smi::ToInt(is_concat_spreadable_cell->value()) == kProtectorInvalid; #ifdef DEBUG Map* root_array_map = get_initial_js_array_map(GetInitialFastElementsKind()); if (root_array_map == NULL) { @@ -3674,7 +3673,7 @@ void Isolate::CheckDetachedContextsAfterGC() { if (length == 0) return; int new_length = 0; for (int i = 0; i < length; i += 2) { - int mark_sweeps = Smi::cast(detached_contexts->get(i))->value(); + int mark_sweeps = Smi::ToInt(detached_contexts->get(i)); DCHECK(detached_contexts->get(i + 1)->IsWeakCell()); WeakCell* cell = WeakCell::cast(detached_contexts->get(i + 1)); if (!cell->cleared()) { @@ -3688,7 +3687,7 @@ void Isolate::CheckDetachedContextsAfterGC() { PrintF("%d detached contexts are collected out of %d\n", length - new_length, length); for (int i = 0; i < new_length; i += 2) { - int mark_sweeps = Smi::cast(detached_contexts->get(i))->value(); + int mark_sweeps = Smi::ToInt(detached_contexts->get(i)); DCHECK(detached_contexts->get(i + 1)->IsWeakCell()); WeakCell* cell = WeakCell::cast(detached_contexts->get(i + 1)); if (mark_sweeps > 3) { diff --git a/src/json-stringifier.cc b/src/json-stringifier.cc index 072ef4eeb5..5cbc419150 100644 --- a/src/json-stringifier.cc +++ b/src/json-stringifier.cc @@ -216,7 +216,7 @@ MaybeHandle JsonStringifier::ApplyReplacerFunction( Handle JsonStringifier::CurrentHolder( Handle value, Handle initial_holder) { - int length = Smi::cast(stack_->length())->value(); + int length = Smi::ToInt(stack_->length()); if (length == 0) { Handle holder = factory()->NewJSObject(isolate_->object_function()); @@ -237,7 +237,7 @@ JsonStringifier::Result JsonStringifier::StackPush(Handle object) { return EXCEPTION; } - int length = Smi::cast(stack_->length())->value(); + int length = Smi::ToInt(stack_->length()); { DisallowHeapAllocation no_allocation; FixedArray* elements = FixedArray::cast(stack_->elements()); @@ -257,7 +257,7 @@ JsonStringifier::Result JsonStringifier::StackPush(Handle object) { } void JsonStringifier::StackPop() { - int length = Smi::cast(stack_->length())->value(); + int length = Smi::ToInt(stack_->length()); stack_->set_length(Smi::FromInt(length - 1)); } diff --git a/src/layout-descriptor-inl.h b/src/layout-descriptor-inl.h index 2cc263728e..f49fd14a3f 100644 --- a/src/layout-descriptor-inl.h +++ b/src/layout-descriptor-inl.h @@ -83,7 +83,7 @@ LayoutDescriptor* LayoutDescriptor::SetTagged(int field_index, bool tagged) { set_layout_word(layout_word_index, value); return this; } else { - uint32_t value = static_cast(Smi::cast(this)->value()); + uint32_t value = static_cast(Smi::ToInt(this)); if (tagged) { value &= ~layout_mask; } else { @@ -110,7 +110,7 @@ bool LayoutDescriptor::IsTagged(int field_index) { uint32_t value = get_layout_word(layout_word_index); return (value & layout_mask) == 0; } else { - uint32_t value = static_cast(Smi::cast(this)->value()); + uint32_t value = static_cast(Smi::ToInt(this)); return (value & layout_mask) == 0; } } diff --git a/src/layout-descriptor.cc b/src/layout-descriptor.cc index c7b8afe2df..ed3f738735 100644 --- a/src/layout-descriptor.cc +++ b/src/layout-descriptor.cc @@ -113,8 +113,7 @@ Handle LayoutDescriptor::EnsureCapacity( return new_layout_descriptor; } else { // Fast layout. - uint32_t value = - static_cast(Smi::cast(*layout_descriptor)->value()); + uint32_t value = static_cast(Smi::ToInt(*layout_descriptor)); new_layout_descriptor->set_layout_word(0, value); return new_layout_descriptor; } @@ -139,9 +138,8 @@ bool LayoutDescriptor::IsTagged(int field_index, int max_sequence_length, } uint32_t layout_mask = static_cast(1) << layout_bit_index; - uint32_t value = IsSlowLayout() - ? get_layout_word(layout_word_index) - : static_cast(Smi::cast(this)->value()); + uint32_t value = IsSlowLayout() ? get_layout_word(layout_word_index) + : static_cast(Smi::ToInt(this)); bool is_tagged = (value & layout_mask) == 0; if (!is_tagged) value = ~value; // Count set bits instead of cleared bits. diff --git a/src/log.cc b/src/log.cc index 4eafe6461c..35e6e54d1a 100644 --- a/src/log.cc +++ b/src/log.cc @@ -1349,7 +1349,7 @@ void Logger::ICEvent(const char* type, bool keyed, const Address pc, int line, msg.AppendAddress(reinterpret_cast
(map)); msg.Append(","); if (key->IsSmi()) { - msg.Append("%d", Smi::cast(key)->value()); + msg.Append("%d", Smi::ToInt(key)); } else if (key->IsNumber()) { msg.Append("%lf", key->Number()); } else if (key->IsString()) { diff --git a/src/messages.cc b/src/messages.cc index 161925da36..3f29295bd8 100644 --- a/src/messages.cc +++ b/src/messages.cc @@ -148,7 +148,7 @@ void MessageHandler::ReportMessageNoExceptions( FixedArray* listener = FixedArray::cast(global_listeners->get(i)); Foreign* callback_obj = Foreign::cast(listener->get(0)); int32_t message_levels = - static_cast(Smi::cast(listener->get(2))->value()); + static_cast(Smi::ToInt(listener->get(2))); if (!(message_levels & error_level)) { continue; } diff --git a/src/objects-debug.cc b/src/objects-debug.cc index ca1774ebb1..7b37966363 100644 --- a/src/objects-debug.cc +++ b/src/objects-debug.cc @@ -547,7 +547,7 @@ void SloppyArgumentsElements::SloppyArgumentsElementsVerify( CHECK(accessor->HasElement(holder, i, arg_elements)); continue; } - int mappedIndex = Smi::cast(mapped)->value(); + int mappedIndex = Smi::ToInt(mapped); nofMappedParameters++; CHECK_LE(maxMappedIndex, mappedIndex); maxMappedIndex = mappedIndex; @@ -608,32 +608,32 @@ void JSDate::JSDateVerify() { cache_stamp()->IsNaN()); if (month()->IsSmi()) { - int month = Smi::cast(this->month())->value(); + int month = Smi::ToInt(this->month()); CHECK(0 <= month && month <= 11); } if (day()->IsSmi()) { - int day = Smi::cast(this->day())->value(); + int day = Smi::ToInt(this->day()); CHECK(1 <= day && day <= 31); } if (hour()->IsSmi()) { - int hour = Smi::cast(this->hour())->value(); + int hour = Smi::ToInt(this->hour()); CHECK(0 <= hour && hour <= 23); } if (min()->IsSmi()) { - int min = Smi::cast(this->min())->value(); + int min = Smi::ToInt(this->min()); CHECK(0 <= min && min <= 59); } if (sec()->IsSmi()) { - int sec = Smi::cast(this->sec())->value(); + int sec = Smi::ToInt(this->sec()); CHECK(0 <= sec && sec <= 59); } if (weekday()->IsSmi()) { - int weekday = Smi::cast(this->weekday())->value(); + int weekday = Smi::ToInt(this->weekday()); CHECK(0 <= weekday && weekday <= 6); } if (cache_stamp()->IsSmi()) { - CHECK(Smi::cast(cache_stamp())->value() <= - Smi::cast(isolate->date_cache()->stamp())->value()); + CHECK(Smi::ToInt(cache_stamp()) <= + Smi::ToInt(isolate->date_cache()->stamp())); } } @@ -784,7 +784,7 @@ void Oddball::OddballVerify() { number == heap->hole_nan_value()); } else { CHECK(number->IsSmi()); - int value = Smi::cast(number)->value(); + int value = Smi::ToInt(number); // Hidden oddballs have negative smis. const int kLeastHiddenOddballNumber = -7; CHECK_LE(value, 1); @@ -907,7 +907,7 @@ void JSArray::JSArrayVerify() { if (!length()->IsNumber()) return; // Verify that the length and the elements backing store are in sync. if (length()->IsSmi() && HasFastElements()) { - int size = Smi::cast(length())->value(); + int size = Smi::ToInt(length()); // Holey / Packed backing stores might have slack or might have not been // properly initialized yet. CHECK(size <= elements()->length() || @@ -1103,12 +1103,12 @@ void JSRegExp::JSRegExpVerify() { // Smi : Not compiled yet (-1). // Code/ByteArray: Compiled code. CHECK( - (one_byte_data->IsSmi() && Smi::cast(one_byte_data)->value() == - JSRegExp::kUninitializedValue) || + (one_byte_data->IsSmi() && + Smi::ToInt(one_byte_data) == JSRegExp::kUninitializedValue) || (is_native ? one_byte_data->IsCode() : one_byte_data->IsByteArray())); Object* uc16_data = arr->get(JSRegExp::kIrregexpUC16CodeIndex); CHECK((uc16_data->IsSmi() && - Smi::cast(uc16_data)->value() == JSRegExp::kUninitializedValue) || + Smi::ToInt(uc16_data) == JSRegExp::kUninitializedValue) || (is_native ? uc16_data->IsCode() : uc16_data->IsByteArray())); CHECK(arr->get(JSRegExp::kIrregexpCaptureCountIndex)->IsSmi()); diff --git a/src/objects-inl.h b/src/objects-inl.h index d6247831da..5aa47ba0b9 100644 --- a/src/objects-inl.h +++ b/src/objects-inl.h @@ -735,7 +735,7 @@ bool Object::FitsRepresentation(Representation representation) { bool Object::ToUint32(uint32_t* value) const { if (IsSmi()) { - int num = Smi::cast(this)->value(); + int num = Smi::ToInt(this); if (num < 0) return false; *value = static_cast(num); return true; @@ -809,7 +809,7 @@ MaybeHandle Object::ToString(Isolate* isolate, Handle input) { // static MaybeHandle Object::ToLength(Isolate* isolate, Handle input) { if (input->IsSmi()) { - int value = std::max(Smi::cast(*input)->value(), 0); + int value = std::max(Smi::ToInt(*input), 0); return handle(Smi::FromInt(value), isolate); } return ConvertToLength(isolate, input); @@ -818,7 +818,7 @@ MaybeHandle Object::ToLength(Isolate* isolate, Handle input) { // static MaybeHandle Object::ToIndex(Isolate* isolate, Handle input, MessageTemplate::Template error_index) { - if (input->IsSmi() && Smi::cast(*input)->value() >= 0) return input; + if (input->IsSmi() && Smi::ToInt(*input) >= 0) return input; return ConvertToIndex(isolate, input, error_index); } @@ -917,6 +917,7 @@ Object** HeapObject::RawField(HeapObject* obj, int byte_offset) { return reinterpret_cast(FIELD_ADDR(obj, byte_offset)); } +int Smi::ToInt(const Object* object) { return Smi::cast(object)->value(); } MapWord MapWord::FromMap(const Map* map) { return MapWord(reinterpret_cast(map)); @@ -1389,11 +1390,7 @@ ACCESSORS(Oddball, to_string, String, kToStringOffset) ACCESSORS(Oddball, to_number, Object, kToNumberOffset) ACCESSORS(Oddball, type_of, String, kTypeOfOffset) - -byte Oddball::kind() const { - return Smi::cast(READ_FIELD(this, kKindOffset))->value(); -} - +byte Oddball::kind() const { return Smi::ToInt(READ_FIELD(this, kKindOffset)); } void Oddball::set_kind(byte value) { WRITE_FIELD(this, kKindOffset, Smi::FromInt(value)); @@ -1603,7 +1600,7 @@ void JSObject::WriteToField(int descriptor, PropertyDetails details, // and stores to the stack silently clear the signalling bit). uint64_t bits; if (value->IsSmi()) { - bits = bit_cast(static_cast(Smi::cast(value)->value())); + bits = bit_cast(static_cast(Smi::ToInt(value))); } else { DCHECK(value->IsHeapNumber()); bits = HeapNumber::cast(value)->value_as_bits(); @@ -1848,7 +1845,7 @@ int WeakFixedArray::Length() const { int WeakFixedArray::last_used_index() const { - return Smi::cast(FixedArray::cast(this)->get(kLastUsedIndexIndex))->value(); + return Smi::ToInt(FixedArray::cast(this)->get(kLastUsedIndexIndex)); } @@ -1873,7 +1870,7 @@ T* WeakFixedArray::Iterator::Next() { int ArrayList::Length() const { if (FixedArray::cast(this)->length() == 0) return 0; - return Smi::cast(FixedArray::cast(this)->get(kLengthIndex))->value(); + return Smi::ToInt(FixedArray::cast(this)->get(kLengthIndex)); } @@ -1904,7 +1901,7 @@ void ArrayList::Clear(int index, Object* undefined) { int RegExpMatchInfo::NumberOfCaptureRegisters() { DCHECK_GE(length(), kLastMatchOverhead); Object* obj = get(kNumberOfCapturesIndex); - return Smi::cast(obj)->value(); + return Smi::ToInt(obj); } void RegExpMatchInfo::SetNumberOfCaptureRegisters(int value) { @@ -1936,7 +1933,7 @@ void RegExpMatchInfo::SetLastInput(Object* value) { int RegExpMatchInfo::Capture(int i) { DCHECK_LT(i, NumberOfCaptureRegisters()); Object* obj = get(kFirstCaptureIndex + i); - return Smi::cast(obj)->value(); + return Smi::ToInt(obj); } void RegExpMatchInfo::SetCapture(int i, int value) { @@ -2034,7 +2031,7 @@ bool DescriptorArray::IsEmpty() { int DescriptorArray::number_of_descriptors() { DCHECK(length() >= kFirstIndex || IsEmpty()); int len = length(); - return len == 0 ? 0 : Smi::cast(get(kDescriptorLengthIndex))->value(); + return len == 0 ? 0 : Smi::ToInt(get(kDescriptorLengthIndex)); } @@ -2392,17 +2389,14 @@ void DescriptorArray::SwapSortedKeys(int first, int second) { } int HashTableBase::NumberOfElements() const { - return Smi::cast(get(kNumberOfElementsIndex))->value(); + return Smi::ToInt(get(kNumberOfElementsIndex)); } int HashTableBase::NumberOfDeletedElements() const { - return Smi::cast(get(kNumberOfDeletedElementsIndex))->value(); -} - -int HashTableBase::Capacity() const { - return Smi::cast(get(kCapacityIndex))->value(); + return Smi::ToInt(get(kNumberOfDeletedElementsIndex)); } +int HashTableBase::Capacity() const { return Smi::ToInt(get(kCapacityIndex)); } void HashTableBase::ElementAdded() { SetNumberOfElements(NumberOfElements() + 1); @@ -2486,7 +2480,7 @@ bool ObjectHashSet::Has(Isolate* isolate, Handle key, int32_t hash) { bool ObjectHashSet::Has(Isolate* isolate, Handle key) { Object* hash = key->GetHash(); if (!hash->IsSmi()) return false; - return FindEntry(isolate, key, Smi::cast(hash)->value()) != kNotFound; + return FindEntry(isolate, key, Smi::ToInt(hash)) != kNotFound; } bool StringSetShape::IsMatch(String* key, Object* value) { @@ -2522,8 +2516,7 @@ uint32_t StringTableShape::HashForObject(Isolate* isolate, Object* object) { bool SeededNumberDictionary::requires_slow_elements() { Object* max_index_object = get(kMaxNumberKeyIndex); if (!max_index_object->IsSmi()) return false; - return 0 != - (Smi::cast(max_index_object)->value() & kRequiresSlowElementsMask); + return 0 != (Smi::ToInt(max_index_object) & kRequiresSlowElementsMask); } @@ -2531,7 +2524,7 @@ uint32_t SeededNumberDictionary::max_number_key() { DCHECK(!requires_slow_elements()); Object* max_index_object = get(kMaxNumberKeyIndex); if (!max_index_object->IsSmi()) return 0; - uint32_t value = static_cast(Smi::cast(max_index_object)->value()); + uint32_t value = static_cast(Smi::ToInt(max_index_object)); return value >> kRequiresSlowElementsTagSize; } @@ -2613,20 +2606,20 @@ int DeoptimizationInputData::DeoptCount() { int HandlerTable::GetRangeStart(int index) const { - return Smi::cast(get(index * kRangeEntrySize + kRangeStartIndex))->value(); + return Smi::ToInt(get(index * kRangeEntrySize + kRangeStartIndex)); } int HandlerTable::GetRangeEnd(int index) const { - return Smi::cast(get(index * kRangeEntrySize + kRangeEndIndex))->value(); + return Smi::ToInt(get(index * kRangeEntrySize + kRangeEndIndex)); } int HandlerTable::GetRangeHandler(int index) const { return HandlerOffsetField::decode( - Smi::cast(get(index * kRangeEntrySize + kRangeHandlerIndex))->value()); + Smi::ToInt(get(index * kRangeEntrySize + kRangeHandlerIndex))); } int HandlerTable::GetRangeData(int index) const { - return Smi::cast(get(index * kRangeEntrySize + kRangeDataIndex))->value(); + return Smi::ToInt(get(index * kRangeEntrySize + kRangeDataIndex)); } void HandlerTable::SetRangeStart(int index, int value) { @@ -3040,7 +3033,7 @@ template void FixedTypedArray::SetValue(uint32_t index, Object* value) { ElementType cast_value = Traits::defaultValue(); if (value->IsSmi()) { - int int_value = Smi::cast(value)->value(); + int int_value = Smi::ToInt(value); cast_value = from(int_value); } else if (value->IsHeapNumber()) { double double_value = HeapNumber::cast(value)->value(); @@ -3575,9 +3568,7 @@ void DependentCode::set_next_link(DependentCode* next) { set(kNextLinkIndex, next); } - -int DependentCode::flags() { return Smi::cast(get(kFlagsIndex))->value(); } - +int DependentCode::flags() { return Smi::ToInt(get(kFlagsIndex)); } void DependentCode::set_flags(int flags) { set(kFlagsIndex, Smi::FromInt(flags)); @@ -4487,27 +4478,27 @@ ACCESSORS(ObjectTemplateInfo, data, Object, kDataOffset) int ObjectTemplateInfo::embedder_field_count() const { Object* value = data(); DCHECK(value->IsSmi()); - return EmbedderFieldCount::decode(Smi::cast(value)->value()); + return EmbedderFieldCount::decode(Smi::ToInt(value)); } void ObjectTemplateInfo::set_embedder_field_count(int count) { - return set_data(Smi::FromInt( - EmbedderFieldCount::update(Smi::cast(data())->value(), count))); + return set_data( + Smi::FromInt(EmbedderFieldCount::update(Smi::ToInt(data()), count))); } bool ObjectTemplateInfo::immutable_proto() const { Object* value = data(); DCHECK(value->IsSmi()); - return IsImmutablePrototype::decode(Smi::cast(value)->value()); + return IsImmutablePrototype::decode(Smi::ToInt(value)); } void ObjectTemplateInfo::set_immutable_proto(bool immutable) { return set_data(Smi::FromInt( - IsImmutablePrototype::update(Smi::cast(data())->value(), immutable))); + IsImmutablePrototype::update(Smi::ToInt(data()), immutable))); } int TemplateList::length() const { - return Smi::cast(FixedArray::cast(this)->get(kLengthIndex))->value(); + return Smi::ToInt(FixedArray::cast(this)->get(kLengthIndex)); } Object* TemplateList::get(int index) const { @@ -5290,7 +5281,7 @@ int JSRegExp::CaptureCount() { case ATOM: return 0; case IRREGEXP: - return Smi::cast(DataAt(kIrregexpCaptureCountIndex))->value(); + return Smi::ToInt(DataAt(kIrregexpCaptureCountIndex)); default: UNREACHABLE(); } @@ -5952,11 +5943,11 @@ bool ObjectHashTableShape::IsMatch(Handle key, Object* other) { } uint32_t ObjectHashTableShape::Hash(Isolate* isolate, Handle key) { - return Smi::cast(key->GetHash())->value(); + return Smi::ToInt(key->GetHash()); } uint32_t ObjectHashTableShape::HashForObject(Isolate* isolate, Object* other) { - return Smi::cast(other->GetHash())->value(); + return Smi::ToInt(other->GetHash()); } @@ -6076,13 +6067,13 @@ bool JSArray::HasArrayPrototype(Isolate* isolate) { int TypeFeedbackInfo::ic_total_count() { - int current = Smi::cast(READ_FIELD(this, kStorage1Offset))->value(); + int current = Smi::ToInt(READ_FIELD(this, kStorage1Offset)); return ICTotalCountField::decode(current); } void TypeFeedbackInfo::set_ic_total_count(int count) { - int value = Smi::cast(READ_FIELD(this, kStorage1Offset))->value(); + int value = Smi::ToInt(READ_FIELD(this, kStorage1Offset)); value = ICTotalCountField::update(value, ICTotalCountField::decode(count)); WRITE_FIELD(this, kStorage1Offset, Smi::FromInt(value)); @@ -6090,14 +6081,14 @@ void TypeFeedbackInfo::set_ic_total_count(int count) { int TypeFeedbackInfo::ic_with_type_info_count() { - int current = Smi::cast(READ_FIELD(this, kStorage2Offset))->value(); + int current = Smi::ToInt(READ_FIELD(this, kStorage2Offset)); return ICsWithTypeInfoCountField::decode(current); } void TypeFeedbackInfo::change_ic_with_type_info_count(int delta) { if (delta == 0) return; - int value = Smi::cast(READ_FIELD(this, kStorage2Offset))->value(); + int value = Smi::ToInt(READ_FIELD(this, kStorage2Offset)); int new_count = ICsWithTypeInfoCountField::decode(value) + delta; // We can get negative count here when the type-feedback info is // shared between two code objects. The can only happen when @@ -6113,7 +6104,7 @@ void TypeFeedbackInfo::change_ic_with_type_info_count(int delta) { int TypeFeedbackInfo::ic_generic_count() { - return Smi::cast(READ_FIELD(this, kStorage3Offset))->value(); + return Smi::ToInt(READ_FIELD(this, kStorage3Offset)); } @@ -6135,7 +6126,7 @@ void TypeFeedbackInfo::initialize_storage() { void TypeFeedbackInfo::change_own_type_change_checksum() { - int value = Smi::cast(READ_FIELD(this, kStorage1Offset))->value(); + int value = Smi::ToInt(READ_FIELD(this, kStorage1Offset)); int checksum = OwnTypeChangeChecksum::decode(value); checksum = (checksum + 1) % (1 << kTypeChangeChecksumBits); value = OwnTypeChangeChecksum::update(value, checksum); @@ -6147,7 +6138,7 @@ void TypeFeedbackInfo::change_own_type_change_checksum() { void TypeFeedbackInfo::set_inlined_type_change_checksum(int checksum) { - int value = Smi::cast(READ_FIELD(this, kStorage2Offset))->value(); + int value = Smi::ToInt(READ_FIELD(this, kStorage2Offset)); int mask = (1 << kTypeChangeChecksumBits) - 1; value = InlinedTypeChangeChecksum::update(value, checksum & mask); // Ensure packed bit field is in Smi range. @@ -6158,13 +6149,13 @@ void TypeFeedbackInfo::set_inlined_type_change_checksum(int checksum) { int TypeFeedbackInfo::own_type_change_checksum() { - int value = Smi::cast(READ_FIELD(this, kStorage1Offset))->value(); + int value = Smi::ToInt(READ_FIELD(this, kStorage1Offset)); return OwnTypeChangeChecksum::decode(value); } bool TypeFeedbackInfo::matches_inlined_type_change_checksum(int checksum) { - int value = Smi::cast(READ_FIELD(this, kStorage2Offset))->value(); + int value = Smi::ToInt(READ_FIELD(this, kStorage2Offset)); int mask = (1 << kTypeChangeChecksumBits) - 1; return InlinedTypeChangeChecksum::decode(value) == (checksum & mask); } @@ -6185,7 +6176,7 @@ Relocatable::~Relocatable() { template Object* OrderedHashTableIterator::CurrentKey() { TableType* table(TableType::cast(this->table())); - int index = Smi::cast(this->index())->value(); + int index = Smi::ToInt(this->index()); Object* key = table->KeyAt(index); DCHECK(!key->IsTheHole(table->GetIsolate())); return key; @@ -6194,7 +6185,7 @@ Object* OrderedHashTableIterator::CurrentKey() { Object* JSMapIterator::CurrentValue() { OrderedHashMap* table(OrderedHashMap::cast(this->table())); - int index = Smi::cast(this->index())->value(); + int index = Smi::ToInt(this->index()); Object* value = table->ValueAt(index); DCHECK(!value->IsTheHole(table->GetIsolate())); return value; diff --git a/src/objects-printer.cc b/src/objects-printer.cc index 5e453692ba..7bc4dedfc4 100644 --- a/src/objects-printer.cc +++ b/src/objects-printer.cc @@ -30,8 +30,8 @@ void Object::Print() { void Object::Print(std::ostream& os) { // NOLINT if (IsSmi()) { - os << "Smi: " << std::hex << "0x" << Smi::cast(this)->value(); - os << std::dec << " (" << Smi::cast(this)->value() << ")\n"; + os << "Smi: " << std::hex << "0x" << Smi::ToInt(this); + os << std::dec << " (" << Smi::ToInt(this) << ")\n"; } else { HeapObject::cast(this)->HeapObjectPrint(os); } @@ -891,15 +891,14 @@ void JSDate::JSDatePrint(std::ostream& os) { // NOLINT } else { // TODO(svenpanne) Add some basic formatting to our streams. ScopedVector buf(100); - SNPrintF( - buf, "\n - time = %s %04d/%02d/%02d %02d:%02d:%02d\n", - weekdays[weekday()->IsSmi() ? Smi::cast(weekday())->value() + 1 : 0], - year()->IsSmi() ? Smi::cast(year())->value() : -1, - month()->IsSmi() ? Smi::cast(month())->value() : -1, - day()->IsSmi() ? Smi::cast(day())->value() : -1, - hour()->IsSmi() ? Smi::cast(hour())->value() : -1, - min()->IsSmi() ? Smi::cast(min())->value() : -1, - sec()->IsSmi() ? Smi::cast(sec())->value() : -1); + SNPrintF(buf, "\n - time = %s %04d/%02d/%02d %02d:%02d:%02d\n", + weekdays[weekday()->IsSmi() ? Smi::ToInt(weekday()) + 1 : 0], + year()->IsSmi() ? Smi::ToInt(year()) : -1, + month()->IsSmi() ? Smi::ToInt(month()) : -1, + day()->IsSmi() ? Smi::ToInt(day()) : -1, + hour()->IsSmi() ? Smi::ToInt(hour()) : -1, + min()->IsSmi() ? Smi::ToInt(min()) : -1, + sec()->IsSmi() ? Smi::ToInt(sec()) : -1); os << buf.start(); } JSObjectPrintBody(os, this); @@ -1551,7 +1550,7 @@ void LayoutDescriptor::Print(std::ostream& os) { // NOLINT os << ""; } else if (IsSmi()) { os << "fast"; - PrintBitMask(os, static_cast(Smi::cast(this)->value())); + PrintBitMask(os, static_cast(Smi::ToInt(this))); } else if (IsOddball() && IsUninitialized(HeapObject::cast(this)->GetIsolate())) { os << ""; diff --git a/src/objects.cc b/src/objects.cc index 90d66b8100..246bd09fd3 100644 --- a/src/objects.cc +++ b/src/objects.cc @@ -422,7 +422,7 @@ MaybeHandle Object::ConvertToLength(Isolate* isolate, Handle input) { ASSIGN_RETURN_ON_EXCEPTION(isolate, input, ToNumber(input), Object); if (input->IsSmi()) { - int value = std::max(Smi::cast(*input)->value(), 0); + int value = std::max(Smi::ToInt(*input), 0); return handle(Smi::FromInt(value), isolate); } double len = DoubleToInteger(input->Number()); @@ -440,7 +440,7 @@ MaybeHandle Object::ConvertToIndex( MessageTemplate::Template error_index) { if (input->IsUndefined(isolate)) return handle(Smi::kZero, isolate); ASSIGN_RETURN_ON_EXCEPTION(isolate, input, ToNumber(input), Object); - if (input->IsSmi() && Smi::cast(*input)->value() >= 0) return input; + if (input->IsSmi() && Smi::ToInt(*input) >= 0) return input; double len = DoubleToInteger(input->Number()) + 0.0; auto js_len = isolate->factory()->NewNumber(len); if (len < 0.0 || len > kMaxSafeInteger) { @@ -450,7 +450,7 @@ MaybeHandle Object::ConvertToIndex( } bool Object::BooleanValue() { - if (IsSmi()) return Smi::cast(this)->value() != 0; + if (IsSmi()) return Smi::ToInt(this) != 0; DCHECK(IsHeapObject()); Isolate* isolate = HeapObject::cast(this)->GetIsolate(); if (IsBoolean()) return IsTrue(isolate); @@ -1158,7 +1158,7 @@ Handle JSReceiver::GetDataProperty(LookupIterator* it) { bool Object::ToInt32(int32_t* value) { if (IsSmi()) { - *value = Smi::cast(this)->value(); + *value = Smi::ToInt(this); return true; } if (IsHeapNumber()) { @@ -2260,7 +2260,7 @@ Object* GetSimpleHash(Object* object) { // The object is either a Smi, a HeapNumber, a name, an odd-ball, a real JS // object, or a Harmony proxy. if (object->IsSmi()) { - uint32_t hash = ComputeIntegerHash(Smi::cast(object)->value()); + uint32_t hash = ComputeIntegerHash(Smi::ToInt(object)); return Smi::FromInt(hash & Smi::kMaxValue); } if (object->IsHeapNumber()) { @@ -5991,7 +5991,7 @@ void JSObject::MigrateSlowToFast(Handle object, // Compute the length of the instance descriptor. for (int i = 0; i < instance_descriptor_length; i++) { - int index = Smi::cast(iteration_order->get(i))->value(); + int index = Smi::ToInt(iteration_order->get(i)); DCHECK(dictionary->IsKey(isolate, dictionary->KeyAt(index))); PropertyKind kind = dictionary->DetailsAt(index).kind(); @@ -6056,7 +6056,7 @@ void JSObject::MigrateSlowToFast(Handle object, // Fill in the instance descriptor and the fields. int current_offset = 0; for (int i = 0; i < instance_descriptor_length; i++) { - int index = Smi::cast(iteration_order->get(i))->value(); + int index = Smi::ToInt(iteration_order->get(i)); Name* k = dictionary->NameAt(index); // Dictionary keys are internalized upon insertion. // TODO(jkummerow): Turn this into a DCHECK if it's not hit in the wild. @@ -7543,9 +7543,8 @@ bool JSObject::ReferencesObjectFromElements(FixedArray* elements, Object* object) { Isolate* isolate = elements->GetIsolate(); if (IsObjectElementsKind(kind) || kind == FAST_STRING_WRAPPER_ELEMENTS) { - int length = IsJSArray() - ? Smi::cast(JSArray::cast(this)->length())->value() - : elements->length(); + int length = IsJSArray() ? Smi::ToInt(JSArray::cast(this)->length()) + : elements->length(); for (int i = 0; i < length; ++i) { Object* element = elements->get(i); if (!element->IsTheHole(isolate) && element == object) return true; @@ -8125,10 +8124,9 @@ Maybe JSObject::PreventExtensionsWithTransition( if (!object->HasFixedTypedArrayElements() && !object->HasDictionaryElements() && !object->HasSlowStringWrapperElements()) { - int length = - object->IsJSArray() - ? Smi::cast(Handle::cast(object)->length())->value() - : object->elements()->length(); + int length = object->IsJSArray() + ? Smi::ToInt(Handle::cast(object)->length()) + : object->elements()->length(); new_element_dictionary = length == 0 ? isolate->factory()->empty_slow_element_dictionary() : object->GetElementsAccessor()->Normalize(object); @@ -8304,7 +8302,7 @@ bool JSObject::HasEnumerableElements() { case PACKED_ELEMENTS: case PACKED_DOUBLE_ELEMENTS: { int length = object->IsJSArray() - ? Smi::cast(JSArray::cast(object)->length())->value() + ? Smi::ToInt(JSArray::cast(object)->length()) : object->elements()->length(); return length > 0; } @@ -8312,7 +8310,7 @@ bool JSObject::HasEnumerableElements() { case HOLEY_ELEMENTS: { FixedArray* elements = FixedArray::cast(object->elements()); int length = object->IsJSArray() - ? Smi::cast(JSArray::cast(object)->length())->value() + ? Smi::ToInt(JSArray::cast(object)->length()) : elements->length(); Isolate* isolate = GetIsolate(); for (int i = 0; i < length; i++) { @@ -8322,7 +8320,7 @@ bool JSObject::HasEnumerableElements() { } case HOLEY_DOUBLE_ELEMENTS: { int length = object->IsJSArray() - ? Smi::cast(JSArray::cast(object)->length())->value() + ? Smi::ToInt(JSArray::cast(object)->length()) : object->elements()->length(); // Zero-length arrays would use the empty FixedArray... if (length == 0) return false; @@ -9860,7 +9858,7 @@ class CodeCache : public AllStatic { static inline int GetLinearUsage(FixedArray* linear_cache) { DCHECK_GT(linear_cache->length(), kEntrySize); - return Smi::cast(linear_cache->get(kLinearUsageIndex))->value(); + return Smi::ToInt(linear_cache->get(kLinearUsageIndex)); } }; @@ -10372,12 +10370,12 @@ int HandlerTable::LookupRange(int pc_offset, int* data_out, int innermost_end = std::numeric_limits::max(); #endif for (int i = 0; i < length(); i += kRangeEntrySize) { - int start_offset = Smi::cast(get(i + kRangeStartIndex))->value(); - int end_offset = Smi::cast(get(i + kRangeEndIndex))->value(); - int handler_field = Smi::cast(get(i + kRangeHandlerIndex))->value(); + int start_offset = Smi::ToInt(get(i + kRangeStartIndex)); + int end_offset = Smi::ToInt(get(i + kRangeEndIndex)); + int handler_field = Smi::ToInt(get(i + kRangeHandlerIndex)); int handler_offset = HandlerOffsetField::decode(handler_field); CatchPrediction prediction = HandlerPredictionField::decode(handler_field); - int handler_data = Smi::cast(get(i + kRangeDataIndex))->value(); + int handler_data = Smi::ToInt(get(i + kRangeDataIndex)); if (pc_offset >= start_offset && pc_offset < end_offset) { DCHECK_GE(start_offset, innermost_start); DCHECK_LT(end_offset, innermost_end); @@ -10397,8 +10395,8 @@ int HandlerTable::LookupRange(int pc_offset, int* data_out, // TODO(turbofan): Make sure table is sorted and use binary search. int HandlerTable::LookupReturn(int pc_offset) { for (int i = 0; i < length(); i += kReturnEntrySize) { - int return_offset = Smi::cast(get(i + kReturnOffsetIndex))->value(); - int handler_field = Smi::cast(get(i + kReturnHandlerIndex))->value(); + int return_offset = Smi::ToInt(get(i + kReturnOffsetIndex)); + int handler_field = Smi::ToInt(get(i + kReturnHandlerIndex)); if (pc_offset == return_offset) { return HandlerOffsetField::decode(handler_field); } @@ -12872,7 +12870,7 @@ MaybeHandle JSFunction::GetDerivedMap(Isolate* isolate, DCHECK(context->IsNativeContext()); Handle maybe_index = JSReceiver::GetDataProperty( constructor, isolate->factory()->native_context_index_symbol()); - int index = maybe_index->IsSmi() ? Smi::cast(*maybe_index)->value() + int index = maybe_index->IsSmi() ? Smi::ToInt(*maybe_index) : Context::OBJECT_FUNCTION_INDEX; Handle realm_constructor(JSFunction::cast(context->get(index))); prototype = handle(realm_constructor->prototype(), isolate); @@ -13131,7 +13129,7 @@ bool GetPositionInfoSlow(const Script* script, int position, } } // namespace -#define SMI_VALUE(x) (Smi::cast(x)->value()) +#define SMI_VALUE(x) (Smi::ToInt(x)) bool Script::GetPositionInfo(int position, PositionInfo* info, OffsetFlag offset_flag) const { DisallowHeapAllocation no_allocation; @@ -13431,7 +13429,7 @@ DebugInfo* SharedFunctionInfo::GetDebugInfo() const { int SharedFunctionInfo::debugger_hints() const { if (HasDebugInfo()) return GetDebugInfo()->debugger_hints(); - return Smi::cast(debug_info())->value(); + return Smi::ToInt(debug_info()); } void SharedFunctionInfo::set_debugger_hints(int value) { @@ -14525,12 +14523,12 @@ void DeoptimizationInputData::DeoptimizationInputDataPrint( void HandlerTable::HandlerTableRangePrint(std::ostream& os) { os << " from to hdlr\n"; for (int i = 0; i < length(); i += kRangeEntrySize) { - int pc_start = Smi::cast(get(i + kRangeStartIndex))->value(); - int pc_end = Smi::cast(get(i + kRangeEndIndex))->value(); - int handler_field = Smi::cast(get(i + kRangeHandlerIndex))->value(); + int pc_start = Smi::ToInt(get(i + kRangeStartIndex)); + int pc_end = Smi::ToInt(get(i + kRangeEndIndex)); + int handler_field = Smi::ToInt(get(i + kRangeHandlerIndex)); int handler_offset = HandlerOffsetField::decode(handler_field); CatchPrediction prediction = HandlerPredictionField::decode(handler_field); - int data = Smi::cast(get(i + kRangeDataIndex))->value(); + int data = Smi::ToInt(get(i + kRangeDataIndex)); os << " (" << std::setw(4) << pc_start << "," << std::setw(4) << pc_end << ") -> " << std::setw(4) << handler_offset << " (prediction=" << prediction << ", data=" << data << ")\n"; @@ -14541,8 +14539,8 @@ void HandlerTable::HandlerTableRangePrint(std::ostream& os) { void HandlerTable::HandlerTableReturnPrint(std::ostream& os) { os << " off hdlr (c)\n"; for (int i = 0; i < length(); i += kReturnEntrySize) { - int pc_offset = Smi::cast(get(i + kReturnOffsetIndex))->value(); - int handler_field = Smi::cast(get(i + kReturnHandlerIndex))->value(); + int pc_offset = Smi::ToInt(get(i + kReturnOffsetIndex)); + int handler_field = Smi::ToInt(get(i + kReturnHandlerIndex)); int handler_offset = HandlerOffsetField::decode(handler_field); CatchPrediction prediction = HandlerPredictionField::decode(handler_field); os << " " << std::setw(4) << pc_offset << " -> " << std::setw(4) @@ -15424,7 +15422,7 @@ static bool ShouldConvertToFastElements(JSObject* object, if (object->IsJSArray()) { Object* length = JSArray::cast(object)->length(); if (!length->IsSmi()) return false; - *new_capacity = static_cast(Smi::cast(length)->value()); + *new_capacity = static_cast(Smi::ToInt(length)); } else if (object->IsJSSloppyArgumentsObject()) { return false; } else { @@ -15731,9 +15729,8 @@ bool JSArray::WouldChangeReadOnlyLength(Handle array, template static int HoleyElementsUsage(JSObject* object, BackingStore* store) { Isolate* isolate = store->GetIsolate(); - int limit = object->IsJSArray() - ? Smi::cast(JSArray::cast(object)->length())->value() - : store->length(); + int limit = object->IsJSArray() ? Smi::ToInt(JSArray::cast(object)->length()) + : store->length(); int used = 0; for (int i = 0; i < limit; ++i) { if (!store->is_the_hole(isolate, i)) ++used; @@ -15747,7 +15744,7 @@ int JSObject::GetFastElementsUsage() { case PACKED_SMI_ELEMENTS: case PACKED_DOUBLE_ELEMENTS: case PACKED_ELEMENTS: - return IsJSArray() ? Smi::cast(JSArray::cast(this)->length())->value() + return IsJSArray() ? Smi::ToInt(JSArray::cast(this)->length()) : store->length(); case FAST_SLOPPY_ARGUMENTS_ELEMENTS: store = SloppyArgumentsElements::cast(store)->arguments(); @@ -15931,11 +15928,11 @@ class StringSharedKey : public HashTableKey { FixedArray* other_array = FixedArray::cast(other); SharedFunctionInfo* shared = SharedFunctionInfo::cast(other_array->get(0)); if (shared != *shared_) return false; - int language_unchecked = Smi::cast(other_array->get(2))->value(); + int language_unchecked = Smi::ToInt(other_array->get(2)); DCHECK(is_valid_language_mode(language_unchecked)); LanguageMode language_mode = static_cast(language_unchecked); if (language_mode != language_mode_) return false; - int position = Smi::cast(other_array->get(3))->value(); + int position = Smi::ToInt(other_array->get(3)); if (position != position_) return false; String* source = String::cast(other_array->get(1)); return source->Equals(*source_); @@ -17565,7 +17562,7 @@ Handle BaseNameDictionary::EnsureCapacity( // Iterate over the dictionary using the enumeration order and update // the dictionary with new enumeration indices. for (int i = 0; i < length; i++) { - int index = Smi::cast(iteration_order->get(i))->value(); + int index = Smi::ToInt(iteration_order->get(i)); DCHECK(dictionary->IsKey(dictionary->GetIsolate(), dictionary->KeyAt(index))); @@ -17790,7 +17787,7 @@ void BaseNameDictionary::CopyEnumKeysTo( storage->GetFirstElementAddress()); std::sort(start, start + length, cmp); for (int i = 0; i < length; i++) { - int index = Smi::cast(raw_storage->get(i))->value(); + int index = Smi::ToInt(raw_storage->get(i)); raw_storage->set(i, raw_dictionary->NameAt(index)); } } @@ -17867,7 +17864,7 @@ void BaseNameDictionary::CollectKeysTo( bool has_seen_symbol = false; for (int i = 0; i < array_size; i++) { - int index = Smi::cast(array->get(i))->value(); + int index = Smi::ToInt(array->get(i)); Object* key = dictionary->NameAt(index); if (key->IsSymbol()) { has_seen_symbol = true; @@ -17877,7 +17874,7 @@ void BaseNameDictionary::CollectKeysTo( } if (has_seen_symbol) { for (int i = 0; i < array_size; i++) { - int index = Smi::cast(array->get(i))->value(); + int index = Smi::ToInt(array->get(i)); Object* key = dictionary->NameAt(index); if (!key->IsSymbol()) continue; keys->AddKey(key, DO_NOT_CONVERT); @@ -17923,7 +17920,7 @@ Object* ObjectHashTable::Lookup(Handle key) { if (hash->IsUndefined(isolate)) { return isolate->heap()->the_hole_value(); } - return Lookup(isolate, key, Smi::cast(hash)->value()); + return Lookup(isolate, key, Smi::ToInt(hash)); } Object* ObjectHashTable::ValueAt(int entry) { @@ -18003,7 +18000,7 @@ Handle ObjectHashTable::Remove(Handle table, return table; } - return Remove(table, key, was_present, Smi::cast(hash)->value()); + return Remove(table, key, was_present, Smi::ToInt(hash)); } @@ -18237,7 +18234,7 @@ Handle OrderedHashTable::Rehash( } Object* hash = key->GetHash(); - int bucket = Smi::cast(hash)->value() & (new_buckets - 1); + int bucket = Smi::ToInt(hash) & (new_buckets - 1); Object* chain_entry = new_table->get(kHashTableStartIndex + bucket); new_table->set(kHashTableStartIndex + bucket, Smi::FromInt(new_entry)); int new_index = new_table->EntryToIndex(new_entry); @@ -18492,7 +18489,7 @@ bool SmallOrderedHashTable::HasKey(Isolate* isolate, Object* hash = key->GetHash(); if (hash->IsUndefined(isolate)) return false; - int entry = HashToFirstEntry(Smi::cast(hash)->value()); + int entry = HashToFirstEntry(Smi::ToInt(hash)); // Walk the chain in the bucket to find the key. while (entry != kNotFound) { @@ -18522,7 +18519,7 @@ Handle SmallOrderedHashTable::Rehash(Handle table, Object* key = table->KeyAt(old_entry); if (key->IsTheHole(isolate)) continue; - int hash = Smi::cast(key->GetHash())->value(); + int hash = Smi::ToInt(key->GetHash()); int bucket = new_table->HashToBucket(hash); int chain = new_table->GetFirstEntry(bucket); @@ -18591,7 +18588,7 @@ void OrderedHashTableIterator::Transition() { TableType* table = TableType::cast(this->table()); if (!table->IsObsolete()) return; - int index = Smi::cast(this->index())->value(); + int index = Smi::ToInt(this->index()); while (table->IsObsolete()) { TableType* next_table = table->NextTable(); @@ -18627,7 +18624,7 @@ bool OrderedHashTableIterator::HasMore() { Transition(); TableType* table = TableType::cast(this->table()); - int index = Smi::cast(this->index())->value(); + int index = Smi::ToInt(this->index()); int used_capacity = table->UsedCapacity(); while (index < used_capacity && table->KeyAt(index)->IsTheHole(isolate)) { @@ -19316,9 +19313,9 @@ int JSGeneratorObject::source_position() const { const JSAsyncGeneratorObject* async = IsJSAsyncGeneratorObject() ? JSAsyncGeneratorObject::cast(this) : nullptr; if (async != nullptr && async->awaited_promise()->IsJSPromise()) { - code_offset = Smi::cast(async->await_input_or_debug_pos())->value(); + code_offset = Smi::ToInt(async->await_input_or_debug_pos()); } else { - code_offset = Smi::cast(input_or_debug_pos())->value(); + code_offset = Smi::ToInt(input_or_debug_pos()); } // The stored bytecode offset is relative to a different base than what diff --git a/src/objects.h b/src/objects.h index 67323755c5..df90783ad6 100644 --- a/src/objects.h +++ b/src/objects.h @@ -1606,6 +1606,9 @@ class Smi: public Object { return Smi::FromInt(static_cast(value())); } + // Convert a Smi object to an int. + static inline int ToInt(const Object* object); + // Convert a value to a Smi object. static inline Smi* FromInt(int value) { DCHECK(Smi::IsValid(value)); diff --git a/src/objects/compilation-cache-inl.h b/src/objects/compilation-cache-inl.h index acf6e76510..42798ed5a0 100644 --- a/src/objects/compilation-cache-inl.h +++ b/src/objects/compilation-cache-inl.h @@ -48,10 +48,10 @@ uint32_t CompilationCacheShape::HashForObject(Isolate* isolate, DCHECK_EQ(4, val->length()); SharedFunctionInfo* shared = SharedFunctionInfo::cast(val->get(0)); String* source = String::cast(val->get(1)); - int language_unchecked = Smi::cast(val->get(2))->value(); + int language_unchecked = Smi::ToInt(val->get(2)); DCHECK(is_valid_language_mode(language_unchecked)); LanguageMode language_mode = static_cast(language_unchecked); - int position = Smi::cast(val->get(3))->value(); + int position = Smi::ToInt(val->get(3)); return StringSharedHash(source, shared, language_mode, position); } DCHECK_LT(2, val->length()); diff --git a/src/objects/debug-objects.cc b/src/objects/debug-objects.cc index f6685450f7..f686c99639 100644 --- a/src/objects/debug-objects.cc +++ b/src/objects/debug-objects.cc @@ -292,21 +292,21 @@ int CoverageInfo::StartSourcePosition(int slot_index) const { DCHECK(FLAG_block_coverage); DCHECK_LT(slot_index, SlotCount()); const int slot_start = CoverageInfo::FirstIndexForSlot(slot_index); - return Smi::cast(get(slot_start + kSlotStartSourcePositionIndex))->value(); + return Smi::ToInt(get(slot_start + kSlotStartSourcePositionIndex)); } int CoverageInfo::EndSourcePosition(int slot_index) const { DCHECK(FLAG_block_coverage); DCHECK_LT(slot_index, SlotCount()); const int slot_start = CoverageInfo::FirstIndexForSlot(slot_index); - return Smi::cast(get(slot_start + kSlotEndSourcePositionIndex))->value(); + return Smi::ToInt(get(slot_start + kSlotEndSourcePositionIndex)); } int CoverageInfo::BlockCount(int slot_index) const { DCHECK(FLAG_block_coverage); DCHECK_LT(slot_index, SlotCount()); const int slot_start = CoverageInfo::FirstIndexForSlot(slot_index); - return Smi::cast(get(slot_start + kSlotBlockCountIndex))->value(); + return Smi::ToInt(get(slot_start + kSlotBlockCountIndex)); } void CoverageInfo::InitializeSlot(int slot_index, int from_pos, int to_pos) { diff --git a/src/objects/dictionary.h b/src/objects/dictionary.h index 022bea8308..bb8e63b267 100644 --- a/src/objects/dictionary.h +++ b/src/objects/dictionary.h @@ -134,7 +134,7 @@ class BaseNameDictionary : public Dictionary { } int NextEnumerationIndex() { - return Smi::cast(this->get(kNextEnumerationIndexIndex))->value(); + return Smi::ToInt(this->get(kNextEnumerationIndexIndex)); } // Creates a new dictionary. diff --git a/src/objects/frame-array-inl.h b/src/objects/frame-array-inl.h index a0c82b8bab..5ada507b9f 100644 --- a/src/objects/frame-array-inl.h +++ b/src/objects/frame-array-inl.h @@ -44,7 +44,7 @@ bool FrameArray::IsAsmJsWasmFrame(int frame_ix) const { } int FrameArray::FrameCount() const { - const int frame_count = Smi::cast(get(kFrameCountIndex))->value(); + const int frame_count = Smi::ToInt(get(kFrameCountIndex)); DCHECK_LE(0, frame_count); return frame_count; } diff --git a/src/objects/hash-table.h b/src/objects/hash-table.h index 90a1163526..a9d81864b9 100644 --- a/src/objects/hash-table.h +++ b/src/objects/hash-table.h @@ -402,21 +402,17 @@ class OrderedHashTable : public FixedArray { // the key has been deleted. This does not shrink the table. static bool Delete(Isolate* isolate, Derived* table, Object* key); - int NumberOfElements() { - return Smi::cast(get(kNumberOfElementsIndex))->value(); - } + int NumberOfElements() { return Smi::ToInt(get(kNumberOfElementsIndex)); } int NumberOfDeletedElements() { - return Smi::cast(get(kNumberOfDeletedElementsIndex))->value(); + return Smi::ToInt(get(kNumberOfDeletedElementsIndex)); } // Returns the number of contiguous entries in the data table, starting at 0, // that either are real entries or have been deleted. int UsedCapacity() { return NumberOfElements() + NumberOfDeletedElements(); } - int NumberOfBuckets() { - return Smi::cast(get(kNumberOfBucketsIndex))->value(); - } + int NumberOfBuckets() { return Smi::ToInt(get(kNumberOfBucketsIndex)); } // Returns an index into |this| for the given entry. int EntryToIndex(int entry) { @@ -428,21 +424,21 @@ class OrderedHashTable : public FixedArray { int HashToEntry(int hash) { int bucket = HashToBucket(hash); Object* entry = this->get(kHashTableStartIndex + bucket); - return Smi::cast(entry)->value(); + return Smi::ToInt(entry); } int KeyToFirstEntry(Isolate* isolate, Object* key) { // This special cases for Smi, so that we avoid the HandleScope // creation below. if (key->IsSmi()) { - uint32_t hash = ComputeIntegerHash(Smi::cast(key)->value()); + uint32_t hash = ComputeIntegerHash(Smi::ToInt(key)); return HashToEntry(hash & Smi::kMaxValue); } HandleScope scope(isolate); Object* hash = key->GetHash(); // If the object does not have an identity hash, it was never used as a key if (hash->IsUndefined(isolate)) return kNotFound; - return HashToEntry(Smi::cast(hash)->value()); + return HashToEntry(Smi::ToInt(hash)); } int FindEntry(Isolate* isolate, Object* key) { @@ -459,7 +455,7 @@ class OrderedHashTable : public FixedArray { int NextChainEntry(int entry) { Object* next_entry = get(EntryToIndex(entry) + kChainOffset); - return Smi::cast(next_entry)->value(); + return Smi::ToInt(next_entry); } // use KeyAt(i)->IsTheHole(isolate) to determine if this is a deleted entry. @@ -475,7 +471,7 @@ class OrderedHashTable : public FixedArray { // When the table is obsolete we store the indexes of the removed holes. int RemovedIndexAt(int index) { - return Smi::cast(get(kRemovedHolesIndex + index))->value(); + return Smi::ToInt(get(kRemovedHolesIndex + index)); } static const int kNotFound = -1; @@ -869,7 +865,7 @@ class OrderedHashTableIterator : public JSObject { bool HasMore(); // Move the index forward one. - void MoveNext() { set_index(Smi::FromInt(Smi::cast(index())->value() + 1)); } + void MoveNext() { set_index(Smi::FromInt(Smi::ToInt(index()) + 1)); } // Returns the current key of the iterator. This should only be called when // |HasMore| returns true. diff --git a/src/objects/literal-objects.cc b/src/objects/literal-objects.cc index 551b03621e..22d2119645 100644 --- a/src/objects/literal-objects.cc +++ b/src/objects/literal-objects.cc @@ -31,7 +31,7 @@ int BoilerplateDescription::size() const { int BoilerplateDescription::backing_store_size() const { if (has_number_of_properties()) { // If present, the last entry contains the number of properties. - return Smi::cast(this->get(length() - 1))->value(); + return Smi::ToInt(this->get(length() - 1)); } // If the number is not given explicitly, we assume there are no // properties with computed names. diff --git a/src/objects/object-macros.h b/src/objects/object-macros.h index c3313e39da..e672af14c9 100644 --- a/src/objects/object-macros.h +++ b/src/objects/object-macros.h @@ -65,7 +65,7 @@ int holder::name() const { \ DCHECK(condition); \ Object* value = READ_FIELD(this, offset); \ - return Smi::cast(value)->value(); \ + return Smi::ToInt(value); \ } \ void holder::set_##name(int value) { \ DCHECK(condition); \ @@ -78,7 +78,7 @@ #define SYNCHRONIZED_SMI_ACCESSORS(holder, name, offset) \ int holder::synchronized_##name() const { \ Object* value = ACQUIRE_READ_FIELD(this, offset); \ - return Smi::cast(value)->value(); \ + return Smi::ToInt(value); \ } \ void holder::synchronized_set_##name(int value) { \ RELEASE_WRITE_FIELD(this, offset, Smi::FromInt(value)); \ @@ -87,7 +87,7 @@ #define RELAXED_SMI_ACCESSORS(holder, name, offset) \ int holder::relaxed_read_##name() const { \ Object* value = RELAXED_READ_FIELD(this, offset); \ - return Smi::cast(value)->value(); \ + return Smi::ToInt(value); \ } \ void holder::relaxed_write_##name(int value) { \ RELAXED_WRITE_FIELD(this, offset, Smi::FromInt(value)); \ diff --git a/src/objects/scope-info.cc b/src/objects/scope-info.cc index 496b3867a0..9a30b710d7 100644 --- a/src/objects/scope-info.cc +++ b/src/objects/scope-info.cc @@ -543,7 +543,7 @@ String* ScopeInfo::StackLocalName(int var) { int ScopeInfo::StackLocalIndex(int var) { DCHECK_LE(0, var); DCHECK_LT(var, StackLocalCount()); - int first_slot_index = Smi::cast(get(StackLocalFirstSlotIndex()))->value(); + int first_slot_index = Smi::ToInt(get(StackLocalFirstSlotIndex())); return first_slot_index + var; } @@ -558,7 +558,7 @@ VariableMode ScopeInfo::ContextLocalMode(int var) { DCHECK_LE(0, var); DCHECK_LT(var, ContextLocalCount()); int info_index = ContextLocalInfosIndex() + var; - int value = Smi::cast(get(info_index))->value(); + int value = Smi::ToInt(get(info_index)); return VariableModeField::decode(value); } @@ -566,7 +566,7 @@ InitializationFlag ScopeInfo::ContextLocalInitFlag(int var) { DCHECK_LE(0, var); DCHECK_LT(var, ContextLocalCount()); int info_index = ContextLocalInfosIndex() + var; - int value = Smi::cast(get(info_index))->value(); + int value = Smi::ToInt(get(info_index)); return InitFlagField::decode(value); } @@ -574,7 +574,7 @@ MaybeAssignedFlag ScopeInfo::ContextLocalMaybeAssignedFlag(int var) { DCHECK_LE(0, var); DCHECK_LT(var, ContextLocalCount()); int info_index = ContextLocalInfosIndex() + var; - int value = Smi::cast(get(info_index))->value(); + int value = Smi::ToInt(get(info_index)); return MaybeAssignedFlagField::decode(value); } @@ -590,7 +590,7 @@ bool ScopeInfo::VariableIsSynthetic(String* name) { int ScopeInfo::StackSlotIndex(String* name) { DCHECK(name->IsInternalizedString()); if (length() > 0) { - int first_slot_index = Smi::cast(get(StackLocalFirstSlotIndex()))->value(); + int first_slot_index = Smi::ToInt(get(StackLocalFirstSlotIndex())); int start = StackLocalNamesIndex(); int end = start + StackLocalCount(); for (int i = start; i < end; ++i) { @@ -610,7 +610,7 @@ int ScopeInfo::ModuleIndex(Handle name, VariableMode* mode, DCHECK_NOT_NULL(init_flag); DCHECK_NOT_NULL(maybe_assigned_flag); - int module_vars_count = Smi::cast(get(ModuleVariableCountIndex()))->value(); + int module_vars_count = Smi::ToInt(get(ModuleVariableCountIndex())); int entry = ModuleVariablesIndex(); for (int i = 0; i < module_vars_count; ++i) { String* var_name = String::cast(get(entry + kModuleVariableNameOffset)); @@ -689,7 +689,7 @@ int ScopeInfo::ParameterIndex(String* name) { int ScopeInfo::ReceiverContextSlotIndex() { if (length() > 0 && ReceiverVariableField::decode(Flags()) == CONTEXT) - return Smi::cast(get(ReceiverInfoIndex()))->value(); + return Smi::ToInt(get(ReceiverInfoIndex())); return -1; } @@ -698,7 +698,7 @@ int ScopeInfo::FunctionContextSlotIndex(String* name) { if (length() > 0) { if (FunctionVariableField::decode(Flags()) == CONTEXT && FunctionName() == name) { - return Smi::cast(get(FunctionNameInfoIndex() + 1))->value(); + return Smi::ToInt(get(FunctionNameInfoIndex() + 1)); } } return -1; @@ -752,17 +752,16 @@ void ScopeInfo::ModuleVariable(int i, String** name, int* index, InitializationFlag* init_flag, MaybeAssignedFlag* maybe_assigned_flag) { DCHECK_LE(0, i); - DCHECK_LT(i, Smi::cast(get(ModuleVariableCountIndex()))->value()); + DCHECK_LT(i, Smi::ToInt(get(ModuleVariableCountIndex()))); int entry = ModuleVariablesIndex() + i * kModuleVariableEntryLength; - int properties = - Smi::cast(get(entry + kModuleVariablePropertiesOffset))->value(); + int properties = Smi::ToInt(get(entry + kModuleVariablePropertiesOffset)); if (name != nullptr) { *name = String::cast(get(entry + kModuleVariableNameOffset)); } if (index != nullptr) { - *index = Smi::cast(get(entry + kModuleVariableIndexOffset))->value(); + *index = Smi::ToInt(get(entry + kModuleVariableIndexOffset)); DCHECK_NE(*index, 0); } if (mode != nullptr) { diff --git a/src/objects/scope-info.h b/src/objects/scope-info.h index 24f63549c8..e60ac99162 100644 --- a/src/objects/scope-info.h +++ b/src/objects/scope-info.h @@ -214,7 +214,7 @@ class ScopeInfo : public FixedArray { inline void Set##name(int value) { set(k##name, Smi::FromInt(value)); } \ inline int name() { \ if (length() > 0) { \ - return Smi::cast(get(k##name))->value(); \ + return Smi::ToInt(get(k##name)); \ } else { \ return 0; \ } \ diff --git a/src/objects/shared-function-info-inl.h b/src/objects/shared-function-info-inl.h index 4e0ab0ca93..ab5242e0bc 100644 --- a/src/objects/shared-function-info-inl.h +++ b/src/objects/shared-function-info-inl.h @@ -317,8 +317,7 @@ bool SharedFunctionInfo::HasBuiltinFunctionId() { BuiltinFunctionId SharedFunctionInfo::builtin_function_id() { DCHECK(HasBuiltinFunctionId()); - return static_cast( - Smi::cast(function_identifier())->value()); + return static_cast(Smi::ToInt(function_identifier())); } void SharedFunctionInfo::set_builtin_function_id(BuiltinFunctionId id) { diff --git a/src/profiler/heap-snapshot-generator.cc b/src/profiler/heap-snapshot-generator.cc index ce51ba91bd..3a3a5226e1 100644 --- a/src/profiler/heap-snapshot-generator.cc +++ b/src/profiler/heap-snapshot-generator.cc @@ -1623,9 +1623,9 @@ void V8HeapExplorer::ExtractElementReferences(JSObject* js_obj, int entry) { Isolate* isolate = js_obj->GetIsolate(); if (js_obj->HasObjectElements()) { FixedArray* elements = FixedArray::cast(js_obj->elements()); - int length = js_obj->IsJSArray() ? - Smi::cast(JSArray::cast(js_obj)->length())->value() : - elements->length(); + int length = js_obj->IsJSArray() + ? Smi::ToInt(JSArray::cast(js_obj)->length()) + : elements->length(); for (int i = 0; i < length; ++i) { if (!elements->get(i)->IsTheHole(isolate)) { SetElementReference(js_obj, entry, i, elements->get(i)); diff --git a/src/regexp/jsregexp.cc b/src/regexp/jsregexp.cc index 8296c29cd7..e705053611 100644 --- a/src/regexp/jsregexp.cc +++ b/src/regexp/jsregexp.cc @@ -335,7 +335,7 @@ bool RegExpImpl::CompileIrregexp(Handle re, // When arriving here entry can only be a smi representing an uncompiled // regexp. DCHECK(entry->IsSmi()); - int entry_value = Smi::cast(entry)->value(); + int entry_value = Smi::ToInt(entry); DCHECK_EQ(JSRegExp::kUninitializedValue, entry_value); #endif @@ -395,12 +395,12 @@ void RegExpImpl::SetIrregexpCaptureNameMap(FixedArray* re, } int RegExpImpl::IrregexpNumberOfCaptures(FixedArray* re) { - return Smi::cast(re->get(JSRegExp::kIrregexpCaptureCountIndex))->value(); + return Smi::ToInt(re->get(JSRegExp::kIrregexpCaptureCountIndex)); } int RegExpImpl::IrregexpNumberOfRegisters(FixedArray* re) { - return Smi::cast(re->get(JSRegExp::kIrregexpMaxRegisterCountIndex))->value(); + return Smi::ToInt(re->get(JSRegExp::kIrregexpMaxRegisterCountIndex)); } diff --git a/src/regexp/regexp-utils.cc b/src/regexp/regexp-utils.cc index 570a348f74..88ecb85dfa 100644 --- a/src/regexp/regexp-utils.cc +++ b/src/regexp/regexp-utils.cc @@ -152,7 +152,7 @@ bool RegExpUtils::IsUnmodifiedRegExp(Isolate* isolate, Handle obj) { // The smi check is required to omit ToLength(lastIndex) calls with possible // user-code execution on the fast path. Object* last_index = JSRegExp::cast(recv)->LastIndex(); - return last_index->IsSmi() && Smi::cast(last_index)->value() >= 0; + return last_index->IsSmi() && Smi::ToInt(last_index) >= 0; } int RegExpUtils::AdvanceStringIndex(Isolate* isolate, Handle string, diff --git a/src/runtime/runtime-array.cc b/src/runtime/runtime-array.cc index 9e6e5b70e0..cc73f59524 100644 --- a/src/runtime/runtime-array.cc +++ b/src/runtime/runtime-array.cc @@ -632,7 +632,7 @@ RUNTIME_FUNCTION(Runtime_ArrayIncludes_Slow) { Object::ToInteger(isolate, from_index)); if (V8_LIKELY(from_index->IsSmi())) { - int start_from = Smi::cast(*from_index)->value(); + int start_from = Smi::ToInt(*from_index); if (start_from < 0) { index = std::max(len + start_from, 0); } else { diff --git a/src/runtime/runtime-collections.cc b/src/runtime/runtime-collections.cc index 3ef66179cd..f579fc0a92 100644 --- a/src/runtime/runtime-collections.cc +++ b/src/runtime/runtime-collections.cc @@ -82,7 +82,7 @@ RUNTIME_FUNCTION(Runtime_SetIteratorClone) { return *isolate->factory()->NewJSSetIterator( handle(holder->map(), isolate), handle(OrderedHashSet::cast(holder->table()), isolate), - Smi::cast(holder->index())->value()); + Smi::ToInt(holder->index())); } @@ -122,7 +122,7 @@ RUNTIME_FUNCTION(Runtime_MapIteratorClone) { return *isolate->factory()->NewJSMapIterator( handle(holder->map(), isolate), handle(OrderedHashMap::cast(holder->table()), isolate), - Smi::cast(holder->index())->value()); + Smi::ToInt(holder->index())); } RUNTIME_FUNCTION(Runtime_GetWeakMapEntries) { diff --git a/src/runtime/runtime-debug.cc b/src/runtime/runtime-debug.cc index 7a508fe761..b58dce22b6 100644 --- a/src/runtime/runtime-debug.cc +++ b/src/runtime/runtime-debug.cc @@ -1557,7 +1557,7 @@ int ScriptLinePosition(Handle