Commit 0f1204f2 authored by Dan Elphick's avatar Dan Elphick Committed by Commit Bot

[builtins] Eliminate all GetIsolates

Removes all explicit calls to GetIsolate() in builtins/ by passing it
through from calling functions and implicit calls via the Handle
constructor.

Bug: v8:7786
Cq-Include-Trybots: luci.v8.try:v8_linux_noi18n_rel_ng
Change-Id: I32e1cdee47075742e677a5f738a33ad30be515c6
Reviewed-on: https://chromium-review.googlesource.com/1079548Reviewed-by: 's avatarLeszek Swirski <leszeks@chromium.org>
Commit-Queue: Dan Elphick <delphick@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53456}
parent f86b1532
...@@ -491,7 +491,7 @@ class ArrayConcatVisitor { ...@@ -491,7 +491,7 @@ class ArrayConcatVisitor {
uint32_t bit_field_; uint32_t bit_field_;
}; };
uint32_t EstimateElementCount(Handle<JSArray> array) { uint32_t EstimateElementCount(Isolate* isolate, Handle<JSArray> array) {
DisallowHeapAllocation no_gc; DisallowHeapAllocation no_gc;
uint32_t length = static_cast<uint32_t>(array->length()->Number()); uint32_t length = static_cast<uint32_t>(array->length()->Number());
int element_count = 0; int element_count = 0;
...@@ -504,7 +504,6 @@ uint32_t EstimateElementCount(Handle<JSArray> array) { ...@@ -504,7 +504,6 @@ uint32_t EstimateElementCount(Handle<JSArray> array) {
// a 32-bit signed integer. // a 32-bit signed integer.
DCHECK_GE(static_cast<int32_t>(FixedArray::kMaxLength), 0); DCHECK_GE(static_cast<int32_t>(FixedArray::kMaxLength), 0);
int fast_length = static_cast<int>(length); int fast_length = static_cast<int>(length);
Isolate* isolate = array->GetIsolate();
FixedArray* elements = FixedArray::cast(array->elements()); FixedArray* elements = FixedArray::cast(array->elements());
for (int i = 0; i < fast_length; i++) { for (int i = 0; i < fast_length; i++) {
if (!elements->get(i)->IsTheHole(isolate)) element_count++; if (!elements->get(i)->IsTheHole(isolate)) element_count++;
...@@ -529,7 +528,6 @@ uint32_t EstimateElementCount(Handle<JSArray> array) { ...@@ -529,7 +528,6 @@ uint32_t EstimateElementCount(Handle<JSArray> array) {
} }
case DICTIONARY_ELEMENTS: { case DICTIONARY_ELEMENTS: {
NumberDictionary* dictionary = NumberDictionary::cast(array->elements()); NumberDictionary* dictionary = NumberDictionary::cast(array->elements());
Isolate* isolate = dictionary->GetIsolate();
int capacity = dictionary->Capacity(); int capacity = dictionary->Capacity();
for (int i = 0; i < capacity; i++) { for (int i = 0; i < capacity; i++) {
Object* key = dictionary->KeyAt(i); Object* key = dictionary->KeyAt(i);
...@@ -558,9 +556,8 @@ uint32_t EstimateElementCount(Handle<JSArray> array) { ...@@ -558,9 +556,8 @@ uint32_t EstimateElementCount(Handle<JSArray> array) {
return element_count; return element_count;
} }
void CollectElementIndices(Handle<JSObject> object, uint32_t range, void CollectElementIndices(Isolate* isolate, Handle<JSObject> object,
std::vector<uint32_t>* indices) { uint32_t range, std::vector<uint32_t>* indices) {
Isolate* isolate = object->GetIsolate();
ElementsKind kind = object->GetElementsKind(); ElementsKind kind = object->GetElementsKind();
switch (kind) { switch (kind) {
case PACKED_SMI_ELEMENTS: case PACKED_SMI_ELEMENTS:
...@@ -670,8 +667,8 @@ void CollectElementIndices(Handle<JSObject> object, uint32_t range, ...@@ -670,8 +667,8 @@ void CollectElementIndices(Handle<JSObject> object, uint32_t range,
if (!iter.IsAtEnd()) { if (!iter.IsAtEnd()) {
// The prototype will usually have no inherited element indices, // The prototype will usually have no inherited element indices,
// but we have to check. // but we have to check.
CollectElementIndices(PrototypeIterator::GetCurrent<JSObject>(iter), range, CollectElementIndices(
indices); isolate, PrototypeIterator::GetCurrent<JSObject>(iter), range, indices);
} }
} }
...@@ -804,7 +801,7 @@ bool IterateElements(Isolate* isolate, Handle<JSReceiver> receiver, ...@@ -804,7 +801,7 @@ bool IterateElements(Isolate* isolate, Handle<JSReceiver> receiver,
// Collect all indices in the object and the prototypes less // Collect all indices in the object and the prototypes less
// than length. This might introduce duplicates in the indices list. // than length. This might introduce duplicates in the indices list.
CollectElementIndices(array, length, &indices); CollectElementIndices(isolate, array, length, &indices);
std::sort(indices.begin(), indices.end()); std::sort(indices.begin(), indices.end());
size_t n = indices.size(); size_t n = indices.size();
FOR_WITH_HANDLE_SCOPE(isolate, size_t, j = 0, j, j < n, (void)0, { FOR_WITH_HANDLE_SCOPE(isolate, size_t, j = 0, j, j < n, (void)0, {
...@@ -891,7 +888,7 @@ Object* Slow_ArrayConcat(BuiltinArguments* args, Handle<Object> species, ...@@ -891,7 +888,7 @@ Object* Slow_ArrayConcat(BuiltinArguments* args, Handle<Object> species,
GetPackedElementsKind(array->GetElementsKind()); GetPackedElementsKind(array->GetElementsKind());
kind = GetMoreGeneralElementsKind(kind, array_kind); kind = GetMoreGeneralElementsKind(kind, array_kind);
} }
element_estimate = EstimateElementCount(array); element_estimate = EstimateElementCount(isolate, array);
} else { } else {
if (obj->IsHeapObject()) { if (obj->IsHeapObject()) {
kind = GetMoreGeneralElementsKind( kind = GetMoreGeneralElementsKind(
......
...@@ -108,10 +108,10 @@ BUILTIN(ConsoleTimeStamp) { ...@@ -108,10 +108,10 @@ BUILTIN(ConsoleTimeStamp) {
} }
namespace { namespace {
void InstallContextFunction(Handle<JSObject> target, const char* name, void InstallContextFunction(Isolate* isolate, Handle<JSObject> target,
Builtins::Name builtin_id, int context_id, const char* name, Builtins::Name builtin_id,
Handle<Object> context_name) { int context_id, Handle<Object> context_name) {
Factory* const factory = target->GetIsolate()->factory(); Factory* const factory = isolate->factory();
Handle<String> name_string = Handle<String> name_string =
Name::ToFunctionName(factory->InternalizeUtf8String(name)) Name::ToFunctionName(factory->InternalizeUtf8String(name))
...@@ -125,8 +125,7 @@ void InstallContextFunction(Handle<JSObject> target, const char* name, ...@@ -125,8 +125,7 @@ void InstallContextFunction(Handle<JSObject> target, const char* name,
fun->shared()->set_length(1); fun->shared()->set_length(1);
JSObject::AddProperty(fun, factory->console_context_id_symbol(), JSObject::AddProperty(fun, factory->console_context_id_symbol(),
handle(Smi::FromInt(context_id), target->GetIsolate()), handle(Smi::FromInt(context_id), isolate), NONE);
NONE);
if (context_name->IsString()) { if (context_name->IsString()) {
JSObject::AddProperty(fun, factory->console_context_name_symbol(), JSObject::AddProperty(fun, factory->console_context_name_symbol(),
context_name, NONE); context_name, NONE);
...@@ -152,17 +151,17 @@ BUILTIN(ConsoleContext) { ...@@ -152,17 +151,17 @@ BUILTIN(ConsoleContext) {
int id = isolate->last_console_context_id() + 1; int id = isolate->last_console_context_id() + 1;
isolate->set_last_console_context_id(id); isolate->set_last_console_context_id(id);
#define CONSOLE_BUILTIN_SETUP(call, name) \ #define CONSOLE_BUILTIN_SETUP(call, name) \
InstallContextFunction(context, #name, Builtins::kConsole##call, id, \ InstallContextFunction(isolate, context, #name, Builtins::kConsole##call, \
args.at(1)); id, args.at(1));
CONSOLE_METHOD_LIST(CONSOLE_BUILTIN_SETUP) CONSOLE_METHOD_LIST(CONSOLE_BUILTIN_SETUP)
#undef CONSOLE_BUILTIN_SETUP #undef CONSOLE_BUILTIN_SETUP
InstallContextFunction(context, "time", Builtins::kConsoleTime, id, InstallContextFunction(isolate, context, "time", Builtins::kConsoleTime, id,
args.at(1));
InstallContextFunction(context, "timeEnd", Builtins::kConsoleTimeEnd, id,
args.at(1));
InstallContextFunction(context, "timeStamp", Builtins::kConsoleTimeStamp, id,
args.at(1)); args.at(1));
InstallContextFunction(isolate, context, "timeEnd", Builtins::kConsoleTimeEnd,
id, args.at(1));
InstallContextFunction(isolate, context, "timeStamp",
Builtins::kConsoleTimeStamp, id, args.at(1));
return *context; return *context;
} }
......
...@@ -104,8 +104,7 @@ const char* kShortMonths[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", ...@@ -104,8 +104,7 @@ const char* kShortMonths[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
// ES6 section 20.3.1.16 Date Time String Format // ES6 section 20.3.1.16 Date Time String Format
double ParseDateTimeString(Handle<String> str) { double ParseDateTimeString(Isolate* isolate, Handle<String> str) {
Isolate* const isolate = str->GetIsolate();
str = String::Flatten(str); str = String::Flatten(str);
// TODO(bmeurer): Change DateParser to not use the FixedArray. // TODO(bmeurer): Change DateParser to not use the FixedArray.
Handle<FixedArray> tmp = Handle<FixedArray> tmp =
...@@ -174,10 +173,10 @@ void ToDateString(double time_val, Vector<char> str, DateCache* date_cache, ...@@ -174,10 +173,10 @@ void ToDateString(double time_val, Vector<char> str, DateCache* date_cache,
UNREACHABLE(); UNREACHABLE();
} }
Object* SetLocalDateValue(Handle<JSDate> date, double time_val) { Object* SetLocalDateValue(Isolate* isolate, Handle<JSDate> date,
double time_val) {
if (time_val >= -DateCache::kMaxTimeBeforeUTCInMs && if (time_val >= -DateCache::kMaxTimeBeforeUTCInMs &&
time_val <= DateCache::kMaxTimeBeforeUTCInMs) { time_val <= DateCache::kMaxTimeBeforeUTCInMs) {
Isolate* const isolate = date->GetIsolate();
time_val = isolate->date_cache()->ToUTC(static_cast<int64_t>(time_val)); time_val = isolate->date_cache()->ToUTC(static_cast<int64_t>(time_val));
} else { } else {
time_val = std::numeric_limits<double>::quiet_NaN(); time_val = std::numeric_limits<double>::quiet_NaN();
...@@ -211,7 +210,7 @@ BUILTIN(DateConstructor) { ...@@ -211,7 +210,7 @@ BUILTIN(DateConstructor) {
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, value, ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, value,
Object::ToPrimitive(value)); Object::ToPrimitive(value));
if (value->IsString()) { if (value->IsString()) {
time_val = ParseDateTimeString(Handle<String>::cast(value)); time_val = ParseDateTimeString(isolate, Handle<String>::cast(value));
} else { } else {
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, value, ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, value,
Object::ToNumber(value)); Object::ToNumber(value));
...@@ -290,7 +289,7 @@ BUILTIN(DateParse) { ...@@ -290,7 +289,7 @@ BUILTIN(DateParse) {
ASSIGN_RETURN_FAILURE_ON_EXCEPTION( ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
isolate, string, isolate, string,
Object::ToString(isolate, args.atOrUndefined(isolate, 1))); Object::ToString(isolate, args.atOrUndefined(isolate, 1)));
return *isolate->factory()->NewNumber(ParseDateTimeString(string)); return *isolate->factory()->NewNumber(ParseDateTimeString(isolate, string));
} }
// ES6 section 20.3.3.4 Date.UTC (year,month,date,hours,minutes,seconds,ms) // ES6 section 20.3.3.4 Date.UTC (year,month,date,hours,minutes,seconds,ms)
...@@ -368,7 +367,7 @@ BUILTIN(DatePrototypeSetDate) { ...@@ -368,7 +367,7 @@ BUILTIN(DatePrototypeSetDate) {
isolate->date_cache()->YearMonthDayFromDays(days, &year, &month, &day); isolate->date_cache()->YearMonthDayFromDays(days, &year, &month, &day);
time_val = MakeDate(MakeDay(year, month, value->Number()), time_within_day); time_val = MakeDate(MakeDay(year, month, value->Number()), time_within_day);
} }
return SetLocalDateValue(date, time_val); return SetLocalDateValue(isolate, date, time_val);
} }
// ES6 section 20.3.4.21 Date.prototype.setFullYear (year, month, date) // ES6 section 20.3.4.21 Date.prototype.setFullYear (year, month, date)
...@@ -401,7 +400,7 @@ BUILTIN(DatePrototypeSetFullYear) { ...@@ -401,7 +400,7 @@ BUILTIN(DatePrototypeSetFullYear) {
} }
} }
double time_val = MakeDate(MakeDay(y, m, dt), time_within_day); double time_val = MakeDate(MakeDay(y, m, dt), time_within_day);
return SetLocalDateValue(date, time_val); return SetLocalDateValue(isolate, date, time_val);
} }
// ES6 section 20.3.4.22 Date.prototype.setHours(hour, min, sec, ms) // ES6 section 20.3.4.22 Date.prototype.setHours(hour, min, sec, ms)
...@@ -438,7 +437,7 @@ BUILTIN(DatePrototypeSetHours) { ...@@ -438,7 +437,7 @@ BUILTIN(DatePrototypeSetHours) {
} }
time_val = MakeDate(day, MakeTime(h, m, s, milli)); time_val = MakeDate(day, MakeTime(h, m, s, milli));
} }
return SetLocalDateValue(date, time_val); return SetLocalDateValue(isolate, date, time_val);
} }
// ES6 section 20.3.4.23 Date.prototype.setMilliseconds(ms) // ES6 section 20.3.4.23 Date.prototype.setMilliseconds(ms)
...@@ -458,7 +457,7 @@ BUILTIN(DatePrototypeSetMilliseconds) { ...@@ -458,7 +457,7 @@ BUILTIN(DatePrototypeSetMilliseconds) {
int s = (time_within_day / 1000) % 60; int s = (time_within_day / 1000) % 60;
time_val = MakeDate(day, MakeTime(h, m, s, ms->Number())); time_val = MakeDate(day, MakeTime(h, m, s, ms->Number()));
} }
return SetLocalDateValue(date, time_val); return SetLocalDateValue(isolate, date, time_val);
} }
// ES6 section 20.3.4.24 Date.prototype.setMinutes ( min, sec, ms ) // ES6 section 20.3.4.24 Date.prototype.setMinutes ( min, sec, ms )
...@@ -490,7 +489,7 @@ BUILTIN(DatePrototypeSetMinutes) { ...@@ -490,7 +489,7 @@ BUILTIN(DatePrototypeSetMinutes) {
} }
time_val = MakeDate(day, MakeTime(h, m, s, milli)); time_val = MakeDate(day, MakeTime(h, m, s, milli));
} }
return SetLocalDateValue(date, time_val); return SetLocalDateValue(isolate, date, time_val);
} }
// ES6 section 20.3.4.25 Date.prototype.setMonth ( month, date ) // ES6 section 20.3.4.25 Date.prototype.setMonth ( month, date )
...@@ -517,7 +516,7 @@ BUILTIN(DatePrototypeSetMonth) { ...@@ -517,7 +516,7 @@ BUILTIN(DatePrototypeSetMonth) {
} }
time_val = MakeDate(MakeDay(year, m, dt), time_within_day); time_val = MakeDate(MakeDay(year, m, dt), time_within_day);
} }
return SetLocalDateValue(date, time_val); return SetLocalDateValue(isolate, date, time_val);
} }
// ES6 section 20.3.4.26 Date.prototype.setSeconds ( sec, ms ) // ES6 section 20.3.4.26 Date.prototype.setSeconds ( sec, ms )
...@@ -544,7 +543,7 @@ BUILTIN(DatePrototypeSetSeconds) { ...@@ -544,7 +543,7 @@ BUILTIN(DatePrototypeSetSeconds) {
} }
time_val = MakeDate(day, MakeTime(h, m, s, milli)); time_val = MakeDate(day, MakeTime(h, m, s, milli));
} }
return SetLocalDateValue(date, time_val); return SetLocalDateValue(isolate, date, time_val);
} }
// ES6 section 20.3.4.27 Date.prototype.setTime ( time ) // ES6 section 20.3.4.27 Date.prototype.setTime ( time )
...@@ -858,7 +857,7 @@ BUILTIN(DatePrototypeSetYear) { ...@@ -858,7 +857,7 @@ BUILTIN(DatePrototypeSetYear) {
dt = day; dt = day;
} }
double time_val = MakeDate(MakeDay(y, m, dt), time_within_day); double time_val = MakeDate(MakeDay(y, m, dt), time_within_day);
return SetLocalDateValue(date, time_val); return SetLocalDateValue(isolate, date, time_val);
} }
// ES6 section 20.3.4.37 Date.prototype.toJSON ( key ) // ES6 section 20.3.4.37 Date.prototype.toJSON ( key )
......
...@@ -173,7 +173,8 @@ BUILTIN(AsyncFunctionConstructor) { ...@@ -173,7 +173,8 @@ BUILTIN(AsyncFunctionConstructor) {
// Do not lazily compute eval position for AsyncFunction, as they may not be // Do not lazily compute eval position for AsyncFunction, as they may not be
// determined after the function is resumed. // determined after the function is resumed.
Handle<JSFunction> func = Handle<JSFunction>::cast(maybe_func); Handle<JSFunction> func = Handle<JSFunction>::cast(maybe_func);
Handle<Script> script = handle(Script::cast(func->shared()->script())); Handle<Script> script =
handle(Script::cast(func->shared()->script()), isolate);
int position = script->GetEvalPosition(); int position = script->GetEvalPosition();
USE(position); USE(position);
...@@ -191,7 +192,8 @@ BUILTIN(AsyncGeneratorFunctionConstructor) { ...@@ -191,7 +192,8 @@ BUILTIN(AsyncGeneratorFunctionConstructor) {
// Do not lazily compute eval position for AsyncFunction, as they may not be // Do not lazily compute eval position for AsyncFunction, as they may not be
// determined after the function is resumed. // determined after the function is resumed.
Handle<JSFunction> func = Handle<JSFunction>::cast(maybe_func); Handle<JSFunction> func = Handle<JSFunction>::cast(maybe_func);
Handle<Script> script = handle(Script::cast(func->shared()->script())); Handle<Script> script =
handle(Script::cast(func->shared()->script()), isolate);
int position = script->GetEvalPosition(); int position = script->GetEvalPosition();
USE(position); USE(position);
......
...@@ -534,7 +534,8 @@ BUILTIN(LocaleConstructor) { ...@@ -534,7 +534,8 @@ BUILTIN(LocaleConstructor) {
Handle<String> locale_string; Handle<String> locale_string;
if (tag->IsJSLocale() && if (tag->IsJSLocale() &&
Handle<JSLocale>::cast(tag)->locale()->IsString()) { Handle<JSLocale>::cast(tag)->locale()->IsString()) {
locale_string = Handle<String>(Handle<JSLocale>::cast(tag)->locale()); locale_string =
Handle<String>(Handle<JSLocale>::cast(tag)->locale(), isolate);
} else { } else {
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, locale_string, ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, locale_string,
Object::ToString(isolate, tag)); Object::ToString(isolate, tag));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment