diff --git a/src/builtins/builtins-api.cc b/src/builtins/builtins-api.cc index 0d0066dfb3..d77bc79238 100644 --- a/src/builtins/builtins-api.cc +++ b/src/builtins/builtins-api.cc @@ -223,7 +223,8 @@ MaybeHandle Builtins::InvokeApiFunction(Isolate* isolate, argv[cursor--] = *args[i]; } DCHECK_EQ(cursor, BuiltinArguments::kPaddingOffset); - argv[BuiltinArguments::kPaddingOffset] = isolate->heap()->the_hole_value(); + argv[BuiltinArguments::kPaddingOffset] = + ReadOnlyRoots(isolate).the_hole_value(); argv[BuiltinArguments::kArgcOffset] = Smi::FromInt(frame_argc); argv[BuiltinArguments::kTargetOffset] = *function; argv[BuiltinArguments::kNewTargetOffset] = *new_target; @@ -261,7 +262,7 @@ V8_WARN_UNUSED_RESULT static Object* HandleApiCallAsFunctionOrConstructor( // right answer. new_target = obj; } else { - new_target = isolate->heap()->undefined_value(); + new_target = ReadOnlyRoots(isolate).undefined_value(); } // Get the invocation callback from the function descriptor that was @@ -285,7 +286,7 @@ V8_WARN_UNUSED_RESULT static Object* HandleApiCallAsFunctionOrConstructor( args.length() - 1); Handle result_handle = custom.Call(call_data); if (result_handle.is_null()) { - result = isolate->heap()->undefined_value(); + result = ReadOnlyRoots(isolate).undefined_value(); } else { result = *result_handle; } diff --git a/src/builtins/builtins-array.cc b/src/builtins/builtins-array.cc index a109fa62e7..7dcba4262b 100644 --- a/src/builtins/builtins-array.cc +++ b/src/builtins/builtins-array.cc @@ -177,7 +177,7 @@ BUILTIN(ArrayPop) { Handle array = Handle::cast(receiver); uint32_t len = static_cast(Smi::ToInt(array->length())); - if (len == 0) return isolate->heap()->undefined_value(); + if (len == 0) return ReadOnlyRoots(isolate).undefined_value(); if (JSArray::HasReadOnlyLength(array)) { return CallJsIntrinsic(isolate, isolate->array_pop(), args); @@ -208,7 +208,7 @@ BUILTIN(ArrayShift) { Handle array = Handle::cast(receiver); int len = Smi::ToInt(array->length()); - if (len == 0) return heap->undefined_value(); + if (len == 0) return ReadOnlyRoots(heap).undefined_value(); if (JSArray::HasReadOnlyLength(array)) { return CallJsIntrinsic(isolate, isolate->array_shift(), args); @@ -962,7 +962,7 @@ Object* Slow_ArrayConcat(BuiltinArguments* args, Handle species, } case HOLEY_SMI_ELEMENTS: case PACKED_SMI_ELEMENTS: { - Object* the_hole = isolate->heap()->the_hole_value(); + Object* the_hole = ReadOnlyRoots(isolate).the_hole_value(); FixedArray* elements(FixedArray::cast(array->elements())); for (uint32_t i = 0; i < length; i++) { Object* element = elements->get(i); @@ -1018,14 +1018,14 @@ Object* Slow_ArrayConcat(BuiltinArguments* args, Handle species, for (int i = 0; i < argument_count; i++) { Handle obj((*args)[i], isolate); Maybe spreadable = IsConcatSpreadable(isolate, obj); - MAYBE_RETURN(spreadable, isolate->heap()->exception()); + MAYBE_RETURN(spreadable, ReadOnlyRoots(isolate).exception()); if (spreadable.FromJust()) { Handle object = Handle::cast(obj); if (!IterateElements(isolate, object, &visitor)) { - return isolate->heap()->exception(); + return ReadOnlyRoots(isolate).exception(); } } else { - if (!visitor.visit(0, obj)) return isolate->heap()->exception(); + if (!visitor.visit(0, obj)) return ReadOnlyRoots(isolate).exception(); visitor.increase_index_offset(1); } } @@ -1125,7 +1125,8 @@ BUILTIN(ArrayConcat) { if (Fast_ArrayConcat(isolate, &args).ToHandle(&result_array)) { return *result_array; } - if (isolate->has_pending_exception()) return isolate->heap()->exception(); + if (isolate->has_pending_exception()) + return ReadOnlyRoots(isolate).exception(); } // Reading @@species happens before anything else with a side effect, so // we can do it here to determine whether to take the fast path. @@ -1136,7 +1137,8 @@ BUILTIN(ArrayConcat) { if (Fast_ArrayConcat(isolate, &args).ToHandle(&result_array)) { return *result_array; } - if (isolate->has_pending_exception()) return isolate->heap()->exception(); + if (isolate->has_pending_exception()) + return ReadOnlyRoots(isolate).exception(); } return Slow_ArrayConcat(&args, species, isolate); } diff --git a/src/builtins/builtins-callsite.cc b/src/builtins/builtins-callsite.cc index 5ce0aa0155..ff04fa2dbe 100644 --- a/src/builtins/builtins-callsite.cc +++ b/src/builtins/builtins-callsite.cc @@ -28,7 +28,7 @@ namespace { Object* PositiveNumberOrNull(int value, Isolate* isolate) { if (value >= 0) return *isolate->factory()->NewNumberFromInt(value); - return isolate->heap()->null_value(); + return ReadOnlyRoots(isolate).null_value(); } Handle GetFrameArray(Isolate* isolate, Handle object) { @@ -76,7 +76,7 @@ BUILTIN(CallSitePrototypeGetFunction) { GetFrameIndex(isolate, recv)); StackFrameBase* frame = it.Frame(); - if (frame->IsStrict()) return isolate->heap()->undefined_value(); + if (frame->IsStrict()) return ReadOnlyRoots(isolate).undefined_value(); return *frame->GetFunction(); } @@ -127,7 +127,7 @@ BUILTIN(CallSitePrototypeGetThis) { GetFrameIndex(isolate, recv)); StackFrameBase* frame = it.Frame(); - if (frame->IsStrict()) return isolate->heap()->undefined_value(); + if (frame->IsStrict()) return ReadOnlyRoots(isolate).undefined_value(); return *frame->GetReceiver(); } diff --git a/src/builtins/builtins-collections.cc b/src/builtins/builtins-collections.cc index d8c306b593..9a642e7d3b 100644 --- a/src/builtins/builtins-collections.cc +++ b/src/builtins/builtins-collections.cc @@ -15,7 +15,7 @@ BUILTIN(MapPrototypeClear) { const char* const kMethodName = "Map.prototype.clear"; CHECK_RECEIVER(JSMap, map, kMethodName); JSMap::Clear(isolate, map); - return isolate->heap()->undefined_value(); + return ReadOnlyRoots(isolate).undefined_value(); } BUILTIN(SetPrototypeClear) { @@ -23,7 +23,7 @@ BUILTIN(SetPrototypeClear) { const char* const kMethodName = "Set.prototype.clear"; CHECK_RECEIVER(JSSet, set, kMethodName); JSSet::Clear(isolate, set); - return isolate->heap()->undefined_value(); + return ReadOnlyRoots(isolate).undefined_value(); } } // namespace internal diff --git a/src/builtins/builtins-console.cc b/src/builtins/builtins-console.cc index 5e459024c0..e19aefd273 100644 --- a/src/builtins/builtins-console.cc +++ b/src/builtins/builtins-console.cc @@ -78,7 +78,7 @@ void LogTimerEvent(Isolate* isolate, BuiltinArguments args, BUILTIN(Console##call) { \ ConsoleCall(isolate, args, &debug::ConsoleDelegate::call); \ RETURN_FAILURE_IF_SCHEDULED_EXCEPTION(isolate); \ - return isolate->heap()->undefined_value(); \ + return ReadOnlyRoots(isolate).undefined_value(); \ } CONSOLE_METHOD_LIST(CONSOLE_BUILTIN_IMPLEMENTATION) #undef CONSOLE_BUILTIN_IMPLEMENTATION @@ -87,21 +87,21 @@ BUILTIN(ConsoleTime) { LogTimerEvent(isolate, args, Logger::START); ConsoleCall(isolate, args, &debug::ConsoleDelegate::Time); RETURN_FAILURE_IF_SCHEDULED_EXCEPTION(isolate); - return isolate->heap()->undefined_value(); + return ReadOnlyRoots(isolate).undefined_value(); } BUILTIN(ConsoleTimeEnd) { LogTimerEvent(isolate, args, Logger::END); ConsoleCall(isolate, args, &debug::ConsoleDelegate::TimeEnd); RETURN_FAILURE_IF_SCHEDULED_EXCEPTION(isolate); - return isolate->heap()->undefined_value(); + return ReadOnlyRoots(isolate).undefined_value(); } BUILTIN(ConsoleTimeStamp) { LogTimerEvent(isolate, args, Logger::STAMP); ConsoleCall(isolate, args, &debug::ConsoleDelegate::TimeStamp); RETURN_FAILURE_IF_SCHEDULED_EXCEPTION(isolate); - return isolate->heap()->undefined_value(); + return ReadOnlyRoots(isolate).undefined_value(); } namespace { diff --git a/src/builtins/builtins-date.cc b/src/builtins/builtins-date.cc index 47e8a917c7..e6d5846cc7 100644 --- a/src/builtins/builtins-date.cc +++ b/src/builtins/builtins-date.cc @@ -872,7 +872,7 @@ BUILTIN(DatePrototypeToJson) { isolate, primitive, Object::ToPrimitive(receiver_obj, ToPrimitiveHint::kNumber)); if (primitive->IsNumber() && !std::isfinite(primitive->Number())) { - return isolate->heap()->null_value(); + return ReadOnlyRoots(isolate).null_value(); } else { Handle name = isolate->factory()->NewStringFromAsciiChecked("toISOString"); diff --git a/src/builtins/builtins-error.cc b/src/builtins/builtins-error.cc index 4e5276484f..0043c42810 100644 --- a/src/builtins/builtins-error.cc +++ b/src/builtins/builtins-error.cc @@ -75,7 +75,7 @@ BUILTIN(ErrorCaptureStackTrace) { RETURN_FAILURE_ON_EXCEPTION( isolate, JSObject::SetAccessor(object, name, error_stack, DONT_ENUM)); - return isolate->heap()->undefined_value(); + return ReadOnlyRoots(isolate).undefined_value(); } // ES6 section 19.5.3.4 Error.prototype.toString ( ) diff --git a/src/builtins/builtins-function.cc b/src/builtins/builtins-function.cc index 0e2d82a45d..d0e96847c9 100644 --- a/src/builtins/builtins-function.cc +++ b/src/builtins/builtins-function.cc @@ -237,7 +237,7 @@ Object* DoFunctionBind(Isolate* isolate, BuiltinArguments args) { Handle length(Smi::kZero, isolate); Maybe attributes = JSReceiver::GetPropertyAttributes(&length_lookup); - if (attributes.IsNothing()) return isolate->heap()->exception(); + if (attributes.IsNothing()) return ReadOnlyRoots(isolate).exception(); if (attributes.FromJust() != ABSENT) { Handle target_length; ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, target_length, @@ -305,7 +305,7 @@ BUILTIN(FunctionPrototypeToString) { // receivers for this method. if (FLAG_harmony_function_tostring && receiver->IsJSReceiver() && JSReceiver::cast(*receiver)->map()->is_callable()) { - return isolate->heap()->function_native_code_string(); + return ReadOnlyRoots(isolate).function_native_code_string(); } THROW_NEW_ERROR_RETURN_FAILURE( isolate, NewTypeError(MessageTemplate::kNotGeneric, diff --git a/src/builtins/builtins-global.cc b/src/builtins/builtins-global.cc index 4d3337f213..3c71a322f9 100644 --- a/src/builtins/builtins-global.cc +++ b/src/builtins/builtins-global.cc @@ -89,7 +89,7 @@ BUILTIN(GlobalEval) { if (!x->IsString()) return *x; if (!Builtins::AllowDynamicFunction(isolate, target, target_global_proxy)) { isolate->CountUsage(v8::Isolate::kFunctionConstructorReturnedUndefined); - return isolate->heap()->undefined_value(); + return ReadOnlyRoots(isolate).undefined_value(); } Handle function; ASSIGN_RETURN_FAILURE_ON_EXCEPTION( diff --git a/src/builtins/builtins-internal.cc b/src/builtins/builtins-internal.cc index 810d6e930d..3a1eb078d0 100644 --- a/src/builtins/builtins-internal.cc +++ b/src/builtins/builtins-internal.cc @@ -15,7 +15,7 @@ BUILTIN(Illegal) { UNREACHABLE(); } -BUILTIN(EmptyFunction) { return isolate->heap()->undefined_value(); } +BUILTIN(EmptyFunction) { return ReadOnlyRoots(isolate).undefined_value(); } BUILTIN(UnsupportedThrower) { HandleScope scope(isolate); diff --git a/src/builtins/builtins-intl.cc b/src/builtins/builtins-intl.cc index 6227c94a14..2a62dcb8b8 100644 --- a/src/builtins/builtins-intl.cc +++ b/src/builtins/builtins-intl.cc @@ -105,7 +105,7 @@ BUILTIN(StringPrototypeNormalizeIntl) { } if (U_FAILURE(status)) { - return isolate->heap()->undefined_value(); + return ReadOnlyRoots(isolate).undefined_value(); } RETURN_RESULT_OR_FAILURE( @@ -259,7 +259,7 @@ Object* FormatNumberToParts(Isolate* isolate, icu::NumberFormat* fmt, icu::FieldPositionIterator fp_iter; UErrorCode status = U_ZERO_ERROR; fmt->format(number, formatted, &fp_iter, status); - if (U_FAILURE(status)) return isolate->heap()->undefined_value(); + if (U_FAILURE(status)) return ReadOnlyRoots(isolate).undefined_value(); Handle result = factory->NewJSArray(0); int32_t length = formatted.length(); @@ -291,7 +291,7 @@ Object* FormatNumberToParts(Isolate* isolate, icu::NumberFormat* fmt, : IcuNumberFieldIdToNumberType(part.field_id, number, isolate); if (!AddElement(result, index, field_type_string, formatted, part.begin_pos, part.end_pos, isolate)) { - return isolate->heap()->undefined_value(); + return ReadOnlyRoots(isolate).undefined_value(); } ++index; } @@ -309,7 +309,7 @@ Object* FormatDateToParts(Isolate* isolate, icu::DateFormat* format, icu::FieldPosition fp; UErrorCode status = U_ZERO_ERROR; format->format(date_value, formatted, &fp_iter, status); - if (U_FAILURE(status)) return isolate->heap()->undefined_value(); + if (U_FAILURE(status)) return ReadOnlyRoots(isolate).undefined_value(); Handle result = factory->NewJSArray(0); int32_t length = formatted.length(); @@ -324,14 +324,14 @@ Object* FormatDateToParts(Isolate* isolate, icu::DateFormat* format, if (previous_end_pos < begin_pos) { if (!AddElement(result, index, IcuDateFieldIdToDateType(-1, isolate), formatted, previous_end_pos, begin_pos, isolate)) { - return isolate->heap()->undefined_value(); + return ReadOnlyRoots(isolate).undefined_value(); } ++index; } if (!AddElement(result, index, IcuDateFieldIdToDateType(fp.getField(), isolate), formatted, begin_pos, end_pos, isolate)) { - return isolate->heap()->undefined_value(); + return ReadOnlyRoots(isolate).undefined_value(); } previous_end_pos = end_pos; ++index; @@ -339,7 +339,7 @@ Object* FormatDateToParts(Isolate* isolate, icu::DateFormat* format, if (previous_end_pos < length) { if (!AddElement(result, index, IcuDateFieldIdToDateType(-1, isolate), formatted, previous_end_pos, length, isolate)) { - return isolate->heap()->undefined_value(); + return ReadOnlyRoots(isolate).undefined_value(); } } JSObject::ValidateElements(*result); diff --git a/src/builtins/builtins-math.cc b/src/builtins/builtins-math.cc index d390b5db31..df310bdfa1 100644 --- a/src/builtins/builtins-math.cc +++ b/src/builtins/builtins-math.cc @@ -43,7 +43,7 @@ BUILTIN(MathHypot) { } if (one_arg_is_nan) { - return isolate->heap()->nan_value(); + return ReadOnlyRoots(isolate).nan_value(); } if (max == 0) { diff --git a/src/builtins/builtins-number.cc b/src/builtins/builtins-number.cc index 46aa051484..7e701c1546 100644 --- a/src/builtins/builtins-number.cc +++ b/src/builtins/builtins-number.cc @@ -39,10 +39,10 @@ BUILTIN(NumberPrototypeToExponential) { isolate, fraction_digits, Object::ToInteger(isolate, fraction_digits)); double const fraction_digits_number = fraction_digits->Number(); - if (std::isnan(value_number)) return isolate->heap()->NaN_string(); + if (std::isnan(value_number)) return ReadOnlyRoots(isolate).NaN_string(); if (std::isinf(value_number)) { - return (value_number < 0.0) ? isolate->heap()->minus_Infinity_string() - : isolate->heap()->Infinity_string(); + return (value_number < 0.0) ? ReadOnlyRoots(isolate).minus_Infinity_string() + : ReadOnlyRoots(isolate).Infinity_string(); } if (fraction_digits_number < 0.0 || fraction_digits_number > kMaxFractionDigits) { @@ -93,10 +93,10 @@ BUILTIN(NumberPrototypeToFixed) { "toFixed() digits"))); } - if (std::isnan(value_number)) return isolate->heap()->NaN_string(); + if (std::isnan(value_number)) return ReadOnlyRoots(isolate).NaN_string(); if (std::isinf(value_number)) { - return (value_number < 0.0) ? isolate->heap()->minus_Infinity_string() - : isolate->heap()->Infinity_string(); + return (value_number < 0.0) ? ReadOnlyRoots(isolate).minus_Infinity_string() + : ReadOnlyRoots(isolate).Infinity_string(); } char* const str = DoubleToFixedCString( value_number, static_cast(fraction_digits_number)); @@ -155,10 +155,10 @@ BUILTIN(NumberPrototypeToPrecision) { Object::ToInteger(isolate, precision)); double const precision_number = precision->Number(); - if (std::isnan(value_number)) return isolate->heap()->NaN_string(); + if (std::isnan(value_number)) return ReadOnlyRoots(isolate).NaN_string(); if (std::isinf(value_number)) { - return (value_number < 0.0) ? isolate->heap()->minus_Infinity_string() - : isolate->heap()->Infinity_string(); + return (value_number < 0.0) ? ReadOnlyRoots(isolate).minus_Infinity_string() + : ReadOnlyRoots(isolate).Infinity_string(); } if (precision_number < 1.0 || precision_number > kMaxFractionDigits) { THROW_NEW_ERROR_RETURN_FAILURE( @@ -219,10 +219,10 @@ BUILTIN(NumberPrototypeToString) { } // Slow case. - if (std::isnan(value_number)) return isolate->heap()->NaN_string(); + if (std::isnan(value_number)) return ReadOnlyRoots(isolate).NaN_string(); if (std::isinf(value_number)) { - return (value_number < 0.0) ? isolate->heap()->minus_Infinity_string() - : isolate->heap()->Infinity_string(); + return (value_number < 0.0) ? ReadOnlyRoots(isolate).minus_Infinity_string() + : ReadOnlyRoots(isolate).Infinity_string(); } char* const str = DoubleToRadixCString(value_number, static_cast(radix_number)); diff --git a/src/builtins/builtins-object.cc b/src/builtins/builtins-object.cc index 83447860e3..927161d45f 100644 --- a/src/builtins/builtins-object.cc +++ b/src/builtins/builtins-object.cc @@ -29,8 +29,8 @@ BUILTIN(ObjectPrototypePropertyIsEnumerable) { isolate, object, JSReceiver::ToObject(isolate, args.receiver())); Maybe maybe = JSReceiver::GetOwnPropertyAttributes(object, name); - if (maybe.IsNothing()) return isolate->heap()->exception(); - if (maybe.FromJust() == ABSENT) return isolate->heap()->false_value(); + if (maybe.IsNothing()) return ReadOnlyRoots(isolate).exception(); + if (maybe.FromJust() == ABSENT) return ReadOnlyRoots(isolate).false_value(); return isolate->heap()->ToBoolean((maybe.FromJust() & DONT_ENUM) == 0); } @@ -92,12 +92,12 @@ Object* ObjectDefineAccessor(Isolate* isolate, Handle object, // throwing an exception. Maybe success = JSReceiver::DefineOwnProperty(isolate, receiver, name, &desc, kThrowOnError); - MAYBE_RETURN(success, isolate->heap()->exception()); + MAYBE_RETURN(success, ReadOnlyRoots(isolate).exception()); if (!success.FromJust()) { isolate->CountUsage(v8::Isolate::kDefineGetterOrSetterWouldThrow); } // 6. Return undefined. - return isolate->heap()->undefined_value(); + return ReadOnlyRoots(isolate).undefined_value(); } Object* ObjectLookupAccessor(Isolate* isolate, Handle object, @@ -123,13 +123,13 @@ Object* ObjectLookupAccessor(Isolate* isolate, Handle object, if (it.HasAccess()) continue; isolate->ReportFailedAccessCheck(it.GetHolder()); RETURN_FAILURE_IF_SCHEDULED_EXCEPTION(isolate); - return isolate->heap()->undefined_value(); + return ReadOnlyRoots(isolate).undefined_value(); case LookupIterator::JSPROXY: { PropertyDescriptor desc; Maybe found = JSProxy::GetOwnPropertyDescriptor( isolate, it.GetHolder(), it.GetName(), &desc); - MAYBE_RETURN(found, isolate->heap()->exception()); + MAYBE_RETURN(found, ReadOnlyRoots(isolate).exception()); if (found.FromJust()) { if (component == ACCESSOR_GETTER && desc.has_get()) { return *desc.get(); @@ -137,20 +137,20 @@ Object* ObjectLookupAccessor(Isolate* isolate, Handle object, if (component == ACCESSOR_SETTER && desc.has_set()) { return *desc.set(); } - return isolate->heap()->undefined_value(); + return ReadOnlyRoots(isolate).undefined_value(); } Handle prototype; ASSIGN_RETURN_FAILURE_ON_EXCEPTION( isolate, prototype, JSProxy::GetPrototype(it.GetHolder())); if (prototype->IsNull(isolate)) { - return isolate->heap()->undefined_value(); + return ReadOnlyRoots(isolate).undefined_value(); } return ObjectLookupAccessor(isolate, prototype, key, component); } case LookupIterator::INTEGER_INDEXED_EXOTIC: case LookupIterator::DATA: - return isolate->heap()->undefined_value(); + return ReadOnlyRoots(isolate).undefined_value(); case LookupIterator::ACCESSOR: { Handle maybe_pair = it.GetAccessors(); @@ -162,7 +162,7 @@ Object* ObjectLookupAccessor(Isolate* isolate, Handle object, } } - return isolate->heap()->undefined_value(); + return ReadOnlyRoots(isolate).undefined_value(); } } // namespace @@ -212,7 +212,7 @@ BUILTIN(ObjectFreeze) { if (object->IsJSReceiver()) { MAYBE_RETURN(JSReceiver::SetIntegrityLevel(Handle::cast(object), FROZEN, kThrowOnError), - isolate->heap()->exception()); + ReadOnlyRoots(isolate).exception()); } return *object; } @@ -257,7 +257,7 @@ BUILTIN(ObjectSetPrototypeOf) { // 4. Let status be ? O.[[SetPrototypeOf]](proto). // 5. If status is false, throw a TypeError exception. MAYBE_RETURN(JSReceiver::SetPrototype(receiver, proto, true, kThrowOnError), - isolate->heap()->exception()); + ReadOnlyRoots(isolate).exception()); // 6. Return O. return *receiver; @@ -291,20 +291,20 @@ BUILTIN(ObjectPrototypeSetProto) { // 2. If Type(proto) is neither Object nor Null, return undefined. Handle proto = args.at(1); if (!proto->IsNull(isolate) && !proto->IsJSReceiver()) { - return isolate->heap()->undefined_value(); + return ReadOnlyRoots(isolate).undefined_value(); } // 3. If Type(O) is not Object, return undefined. - if (!object->IsJSReceiver()) return isolate->heap()->undefined_value(); + if (!object->IsJSReceiver()) return ReadOnlyRoots(isolate).undefined_value(); Handle receiver = Handle::cast(object); // 4. Let status be ? O.[[SetPrototypeOf]](proto). // 5. If status is false, throw a TypeError exception. MAYBE_RETURN(JSReceiver::SetPrototype(receiver, proto, true, kThrowOnError), - isolate->heap()->exception()); + ReadOnlyRoots(isolate).exception()); // Return undefined. - return isolate->heap()->undefined_value(); + return ReadOnlyRoots(isolate).undefined_value(); } namespace { @@ -339,7 +339,7 @@ BUILTIN(ObjectIsExtensible) { object->IsJSReceiver() ? JSReceiver::IsExtensible(Handle::cast(object)) : Just(false); - MAYBE_RETURN(result, isolate->heap()->exception()); + MAYBE_RETURN(result, ReadOnlyRoots(isolate).exception()); return isolate->heap()->ToBoolean(result.FromJust()); } @@ -351,7 +351,7 @@ BUILTIN(ObjectIsFrozen) { ? JSReceiver::TestIntegrityLevel( Handle::cast(object), FROZEN) : Just(true); - MAYBE_RETURN(result, isolate->heap()->exception()); + MAYBE_RETURN(result, ReadOnlyRoots(isolate).exception()); return isolate->heap()->ToBoolean(result.FromJust()); } @@ -363,7 +363,7 @@ BUILTIN(ObjectIsSealed) { ? JSReceiver::TestIntegrityLevel( Handle::cast(object), SEALED) : Just(true); - MAYBE_RETURN(result, isolate->heap()->exception()); + MAYBE_RETURN(result, ReadOnlyRoots(isolate).exception()); return isolate->heap()->ToBoolean(result.FromJust()); } @@ -389,7 +389,7 @@ BUILTIN(ObjectGetOwnPropertyDescriptors) { PropertyDescriptor descriptor; Maybe did_get_descriptor = JSReceiver::GetOwnPropertyDescriptor( isolate, receiver, key, &descriptor); - MAYBE_RETURN(did_get_descriptor, isolate->heap()->exception()); + MAYBE_RETURN(did_get_descriptor, ReadOnlyRoots(isolate).exception()); if (!did_get_descriptor.FromJust()) continue; Handle from_descriptor = descriptor.ToObject(isolate); @@ -411,7 +411,7 @@ BUILTIN(ObjectPreventExtensions) { if (object->IsJSReceiver()) { MAYBE_RETURN(JSReceiver::PreventExtensions(Handle::cast(object), kThrowOnError), - isolate->heap()->exception()); + ReadOnlyRoots(isolate).exception()); } return *object; } @@ -423,7 +423,7 @@ BUILTIN(ObjectSeal) { if (object->IsJSReceiver()) { MAYBE_RETURN(JSReceiver::SetIntegrityLevel(Handle::cast(object), SEALED, kThrowOnError), - isolate->heap()->exception()); + ReadOnlyRoots(isolate).exception()); } return *object; } diff --git a/src/builtins/builtins-reflect.cc b/src/builtins/builtins-reflect.cc index bc596e0ccb..cc97caf6a9 100644 --- a/src/builtins/builtins-reflect.cc +++ b/src/builtins/builtins-reflect.cc @@ -38,12 +38,12 @@ BUILTIN(ReflectDefineProperty) { PropertyDescriptor desc; if (!PropertyDescriptor::ToPropertyDescriptor(isolate, attributes, &desc)) { - return isolate->heap()->exception(); + return ReadOnlyRoots(isolate).exception(); } Maybe result = JSReceiver::DefineOwnProperty( isolate, Handle::cast(target), name, &desc, kDontThrow); - MAYBE_RETURN(result, isolate->heap()->exception()); + MAYBE_RETURN(result, ReadOnlyRoots(isolate).exception()); return *isolate->factory()->ToBoolean(result.FromJust()); } @@ -67,7 +67,7 @@ BUILTIN(ReflectDeleteProperty) { Maybe result = JSReceiver::DeletePropertyOrElement( Handle::cast(target), name, LanguageMode::kSloppy); - MAYBE_RETURN(result, isolate->heap()->exception()); + MAYBE_RETURN(result, ReadOnlyRoots(isolate).exception()); return *isolate->factory()->ToBoolean(result.FromJust()); } @@ -115,8 +115,8 @@ BUILTIN(ReflectGetOwnPropertyDescriptor) { PropertyDescriptor desc; Maybe found = JSReceiver::GetOwnPropertyDescriptor( isolate, Handle::cast(target), name, &desc); - MAYBE_RETURN(found, isolate->heap()->exception()); - if (!found.FromJust()) return isolate->heap()->undefined_value(); + MAYBE_RETURN(found, ReadOnlyRoots(isolate).exception()); + if (!found.FromJust()) return ReadOnlyRoots(isolate).undefined_value(); return *desc.ToObject(isolate); } @@ -152,7 +152,7 @@ BUILTIN(ReflectIsExtensible) { Maybe result = JSReceiver::IsExtensible(Handle::cast(target)); - MAYBE_RETURN(result, isolate->heap()->exception()); + MAYBE_RETURN(result, ReadOnlyRoots(isolate).exception()); return *isolate->factory()->ToBoolean(result.FromJust()); } @@ -193,7 +193,7 @@ BUILTIN(ReflectPreventExtensions) { Maybe result = JSReceiver::PreventExtensions( Handle::cast(target), kDontThrow); - MAYBE_RETURN(result, isolate->heap()->exception()); + MAYBE_RETURN(result, ReadOnlyRoots(isolate).exception()); return *isolate->factory()->ToBoolean(result.FromJust()); } @@ -220,7 +220,7 @@ BUILTIN(ReflectSet) { isolate, receiver, name, Handle::cast(target)); Maybe result = Object::SetSuperProperty( &it, value, LanguageMode::kSloppy, Object::MAY_BE_STORE_FROM_KEYED); - MAYBE_RETURN(result, isolate->heap()->exception()); + MAYBE_RETURN(result, ReadOnlyRoots(isolate).exception()); return *isolate->factory()->ToBoolean(result.FromJust()); } @@ -245,7 +245,7 @@ BUILTIN(ReflectSetPrototypeOf) { Maybe result = JSReceiver::SetPrototype( Handle::cast(target), proto, true, kDontThrow); - MAYBE_RETURN(result, isolate->heap()->exception()); + MAYBE_RETURN(result, ReadOnlyRoots(isolate).exception()); return *isolate->factory()->ToBoolean(result.FromJust()); } diff --git a/src/builtins/builtins-regexp.cc b/src/builtins/builtins-regexp.cc index 3c24f30abc..86bf06b658 100644 --- a/src/builtins/builtins-regexp.cc +++ b/src/builtins/builtins-regexp.cc @@ -82,7 +82,7 @@ DEFINE_CAPTURE_GETTER(9) BUILTIN(RegExpInputGetter) { HandleScope scope(isolate); Handle obj(isolate->regexp_last_match_info()->LastInput(), isolate); - return obj->IsUndefined(isolate) ? isolate->heap()->empty_string() + return obj->IsUndefined(isolate) ? ReadOnlyRoots(isolate).empty_string() : String::cast(*obj); } @@ -93,7 +93,7 @@ BUILTIN(RegExpInputSetter) { ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, str, Object::ToString(isolate, value)); isolate->regexp_last_match_info()->SetLastInput(*str); - return isolate->heap()->undefined_value(); + return ReadOnlyRoots(isolate).undefined_value(); } // Getters for the static properties lastMatch, lastParen, leftContext, and @@ -110,7 +110,9 @@ BUILTIN(RegExpLastParenGetter) { HandleScope scope(isolate); Handle match_info = isolate->regexp_last_match_info(); const int length = match_info->NumberOfCaptureRegisters(); - if (length <= 2) return isolate->heap()->empty_string(); // No captures. + if (length <= 2) { + return ReadOnlyRoots(isolate).empty_string(); // No captures. + } DCHECK_EQ(0, length % 2); const int last_capture = (length / 2) - 1; diff --git a/src/builtins/builtins-sharedarraybuffer.cc b/src/builtins/builtins-sharedarraybuffer.cc index a847a5d892..a1b36c5fb6 100644 --- a/src/builtins/builtins-sharedarraybuffer.cc +++ b/src/builtins/builtins-sharedarraybuffer.cc @@ -93,7 +93,7 @@ BUILTIN(AtomicsWake) { isolate, sta, ValidateSharedIntegerTypedArray(isolate, array, true)); Maybe maybe_index = ValidateAtomicAccess(isolate, sta, index); - if (maybe_index.IsNothing()) return isolate->heap()->exception(); + if (maybe_index.IsNothing()) return ReadOnlyRoots(isolate).exception(); size_t i = maybe_index.FromJust(); uint32_t c; @@ -130,7 +130,7 @@ BUILTIN(AtomicsWait) { isolate, sta, ValidateSharedIntegerTypedArray(isolate, array, true)); Maybe maybe_index = ValidateAtomicAccess(isolate, sta, index); - if (maybe_index.IsNothing()) return isolate->heap()->exception(); + if (maybe_index.IsNothing()) return ReadOnlyRoots(isolate).exception(); size_t i = maybe_index.FromJust(); ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, value, @@ -139,13 +139,13 @@ BUILTIN(AtomicsWait) { double timeout_number; if (timeout->IsUndefined(isolate)) { - timeout_number = isolate->heap()->infinity_value()->Number(); + timeout_number = ReadOnlyRoots(isolate).infinity_value()->Number(); } else { ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, timeout, Object::ToNumber(timeout)); timeout_number = timeout->Number(); if (std::isnan(timeout_number)) - timeout_number = isolate->heap()->infinity_value()->Number(); + timeout_number = ReadOnlyRoots(isolate).infinity_value()->Number(); else if (timeout_number < 0) timeout_number = 0; } diff --git a/src/builtins/builtins-string.cc b/src/builtins/builtins-string.cc index af5f786175..b9f802e3f1 100644 --- a/src/builtins/builtins-string.cc +++ b/src/builtins/builtins-string.cc @@ -52,7 +52,7 @@ uc32 NextCodePoint(Isolate* isolate, BuiltinArguments args, int index) { BUILTIN(StringFromCodePoint) { HandleScope scope(isolate); int const length = args.length() - 1; - if (length == 0) return isolate->heap()->empty_string(); + if (length == 0) return ReadOnlyRoots(isolate).empty_string(); DCHECK_LT(0, length); // Optimistically assume that the resulting String contains only one byte @@ -64,7 +64,7 @@ BUILTIN(StringFromCodePoint) { for (index = 0; index < length; index++) { code = NextCodePoint(isolate, args, index); if (code < 0) { - return isolate->heap()->exception(); + return ReadOnlyRoots(isolate).exception(); } if (code > String::kMaxOneByteCharCode) { break; @@ -94,7 +94,7 @@ BUILTIN(StringFromCodePoint) { } code = NextCodePoint(isolate, args, index); if (code < 0) { - return isolate->heap()->exception(); + return ReadOnlyRoots(isolate).exception(); } } @@ -122,7 +122,7 @@ BUILTIN(StringPrototypeEndsWith) { Maybe is_reg_exp = RegExpUtils::IsRegExp(isolate, search); if (is_reg_exp.IsNothing()) { DCHECK(isolate->has_pending_exception()); - return isolate->heap()->exception(); + return ReadOnlyRoots(isolate).exception(); } if (is_reg_exp.FromJust()) { THROW_NEW_ERROR_RETURN_FAILURE( @@ -146,7 +146,7 @@ BUILTIN(StringPrototypeEndsWith) { } int start = end - search_string->length(); - if (start < 0) return isolate->heap()->false_value(); + if (start < 0) return ReadOnlyRoots(isolate).false_value(); str = String::Flatten(isolate, str); search_string = String::Flatten(isolate, search_string); @@ -169,10 +169,10 @@ BUILTIN(StringPrototypeEndsWith) { for (int i = 0; i < search_string->length(); i++) { if (str_reader.Get(start + i) != search_reader.Get(i)) { - return isolate->heap()->false_value(); + return ReadOnlyRoots(isolate).false_value(); } } - return isolate->heap()->true_value(); + return ReadOnlyRoots(isolate).true_value(); } // ES6 section 21.1.3.9 @@ -280,7 +280,7 @@ BUILTIN(StringPrototypeStartsWith) { Maybe is_reg_exp = RegExpUtils::IsRegExp(isolate, search); if (is_reg_exp.IsNothing()) { DCHECK(isolate->has_pending_exception()); - return isolate->heap()->exception(); + return ReadOnlyRoots(isolate).exception(); } if (is_reg_exp.FromJust()) { THROW_NEW_ERROR_RETURN_FAILURE( @@ -304,7 +304,7 @@ BUILTIN(StringPrototypeStartsWith) { } if (start + search_string->length() > str->length()) { - return isolate->heap()->false_value(); + return ReadOnlyRoots(isolate).false_value(); } FlatStringReader str_reader(isolate, String::Flatten(isolate, str)); @@ -313,10 +313,10 @@ BUILTIN(StringPrototypeStartsWith) { for (int i = 0; i < search_string->length(); i++) { if (str_reader.Get(start + i) != search_reader.Get(i)) { - return isolate->heap()->false_value(); + return ReadOnlyRoots(isolate).false_value(); } } - return isolate->heap()->true_value(); + return ReadOnlyRoots(isolate).true_value(); } #ifndef V8_INTL_SUPPORT diff --git a/src/builtins/builtins-symbol.cc b/src/builtins/builtins-symbol.cc index 1343a293bd..9ebb8c499d 100644 --- a/src/builtins/builtins-symbol.cc +++ b/src/builtins/builtins-symbol.cc @@ -57,7 +57,7 @@ BUILTIN(SymbolKeyFor) { result = symbol->name(); DCHECK(result->IsString()); } else { - result = isolate->heap()->undefined_value(); + result = ReadOnlyRoots(isolate).undefined_value(); } DCHECK_EQ(isolate->heap()->public_symbol_table()->SlowReverseLookup(*symbol), result); diff --git a/src/builtins/builtins-typed-array.cc b/src/builtins/builtins-typed-array.cc index 13404aa4c1..4ca09988fc 100644 --- a/src/builtins/builtins-typed-array.cc +++ b/src/builtins/builtins-typed-array.cc @@ -170,10 +170,10 @@ BUILTIN(TypedArrayPrototypeIncludes) { ASSIGN_RETURN_FAILURE_ON_EXCEPTION( isolate, array, JSTypedArray::Validate(isolate, args.receiver(), method)); - if (args.length() < 2) return isolate->heap()->false_value(); + if (args.length() < 2) return ReadOnlyRoots(isolate).false_value(); int64_t len = array->length_value(); - if (len == 0) return isolate->heap()->false_value(); + if (len == 0) return ReadOnlyRoots(isolate).false_value(); int64_t index = 0; if (args.length() > 2) { @@ -184,14 +184,15 @@ BUILTIN(TypedArrayPrototypeIncludes) { } // TODO(cwhan.tunz): throw. See the above comment in CopyWithin. - if (V8_UNLIKELY(array->WasNeutered())) return isolate->heap()->false_value(); + if (V8_UNLIKELY(array->WasNeutered())) + return ReadOnlyRoots(isolate).false_value(); Handle search_element = args.atOrUndefined(isolate, 1); ElementsAccessor* elements = array->GetElementsAccessor(); Maybe result = elements->IncludesValue(isolate, array, search_element, static_cast(index), static_cast(len)); - MAYBE_RETURN(result, isolate->heap()->exception()); + MAYBE_RETURN(result, ReadOnlyRoots(isolate).exception()); return *isolate->factory()->ToBoolean(result.FromJust()); } @@ -222,7 +223,7 @@ BUILTIN(TypedArrayPrototypeIndexOf) { Maybe result = elements->IndexOfValue(isolate, array, search_element, static_cast(index), static_cast(len)); - MAYBE_RETURN(result, isolate->heap()->exception()); + MAYBE_RETURN(result, ReadOnlyRoots(isolate).exception()); return *isolate->factory()->NewNumberFromInt64(result.FromJust()); } @@ -256,7 +257,7 @@ BUILTIN(TypedArrayPrototypeLastIndexOf) { ElementsAccessor* elements = array->GetElementsAccessor(); Maybe result = elements->LastIndexOfValue( isolate, array, search_element, static_cast(index)); - MAYBE_RETURN(result, isolate->heap()->exception()); + MAYBE_RETURN(result, ReadOnlyRoots(isolate).exception()); return *isolate->factory()->NewNumberFromInt64(result.FromJust()); } diff --git a/src/builtins/constants-table-builder.cc b/src/builtins/constants-table-builder.cc index 492fdc94ed..6dd390c795 100644 --- a/src/builtins/constants-table-builder.cc +++ b/src/builtins/constants-table-builder.cc @@ -12,7 +12,7 @@ namespace internal { BuiltinsConstantsTableBuilder::BuiltinsConstantsTableBuilder(Isolate* isolate) : isolate_(isolate), map_(isolate->heap()) { // Ensure this is only called once per Isolate. - DCHECK_EQ(isolate_->heap()->empty_fixed_array(), + DCHECK_EQ(ReadOnlyRoots(isolate_).empty_fixed_array(), isolate_->heap()->builtins_constants_table()); // And that the initial value of the builtins constants table can be treated @@ -30,7 +30,7 @@ uint32_t BuiltinsConstantsTableBuilder::AddObject(Handle object) { DCHECK(!isolate_->heap()->IsRootHandle(object, &root_list_index)); // Not yet finalized. - DCHECK_EQ(isolate_->heap()->empty_fixed_array(), + DCHECK_EQ(ReadOnlyRoots(isolate_).empty_fixed_array(), isolate_->heap()->builtins_constants_table()); // Must be on the main thread. @@ -60,7 +60,7 @@ void BuiltinsConstantsTableBuilder::PatchSelfReference( DCHECK(!isolate_->heap()->IsRootHandle(code_object, &root_list_index)); // Not yet finalized. - DCHECK_EQ(isolate_->heap()->empty_fixed_array(), + DCHECK_EQ(ReadOnlyRoots(isolate_).empty_fixed_array(), isolate_->heap()->builtins_constants_table()); DCHECK(isolate_->serializer_enabled()); @@ -72,7 +72,7 @@ void BuiltinsConstantsTableBuilder::PatchSelfReference( // During indirection generation, we always create a distinct marker for each // macro assembler. The canonical marker is only used when not generating a // snapshot. - DCHECK(*self_reference != isolate_->heap()->self_reference_marker()); + DCHECK(*self_reference != ReadOnlyRoots(isolate_).self_reference_marker()); #endif uint32_t key; @@ -85,7 +85,7 @@ void BuiltinsConstantsTableBuilder::PatchSelfReference( void BuiltinsConstantsTableBuilder::Finalize() { HandleScope handle_scope(isolate_); - DCHECK_EQ(isolate_->heap()->empty_fixed_array(), + DCHECK_EQ(ReadOnlyRoots(isolate_).empty_fixed_array(), isolate_->heap()->builtins_constants_table()); DCHECK(isolate_->serializer_enabled()); @@ -112,8 +112,8 @@ void BuiltinsConstantsTableBuilder::Finalize() { #ifdef DEBUG for (int i = 0; i < map_.size(); i++) { DCHECK(table->get(i)->IsHeapObject()); - DCHECK_NE(isolate_->heap()->undefined_value(), table->get(i)); - DCHECK_NE(isolate_->heap()->self_reference_marker(), table->get(i)); + DCHECK_NE(ReadOnlyRoots(isolate_).undefined_value(), table->get(i)); + DCHECK_NE(ReadOnlyRoots(isolate_).self_reference_marker(), table->get(i)); } #endif