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 {
uint32_t bit_field_;
};
uint32_t EstimateElementCount(Handle<JSArray> array) {
uint32_t EstimateElementCount(Isolate* isolate, Handle<JSArray> array) {
DisallowHeapAllocation no_gc;
uint32_t length = static_cast<uint32_t>(array->length()->Number());
int element_count = 0;
......@@ -504,7 +504,6 @@ uint32_t EstimateElementCount(Handle<JSArray> array) {
// a 32-bit signed integer.
DCHECK_GE(static_cast<int32_t>(FixedArray::kMaxLength), 0);
int fast_length = static_cast<int>(length);
Isolate* isolate = array->GetIsolate();
FixedArray* elements = FixedArray::cast(array->elements());
for (int i = 0; i < fast_length; i++) {
if (!elements->get(i)->IsTheHole(isolate)) element_count++;
......@@ -529,7 +528,6 @@ uint32_t EstimateElementCount(Handle<JSArray> array) {
}
case DICTIONARY_ELEMENTS: {
NumberDictionary* dictionary = NumberDictionary::cast(array->elements());
Isolate* isolate = dictionary->GetIsolate();
int capacity = dictionary->Capacity();
for (int i = 0; i < capacity; i++) {
Object* key = dictionary->KeyAt(i);
......@@ -558,9 +556,8 @@ uint32_t EstimateElementCount(Handle<JSArray> array) {
return element_count;
}
void CollectElementIndices(Handle<JSObject> object, uint32_t range,
std::vector<uint32_t>* indices) {
Isolate* isolate = object->GetIsolate();
void CollectElementIndices(Isolate* isolate, Handle<JSObject> object,
uint32_t range, std::vector<uint32_t>* indices) {
ElementsKind kind = object->GetElementsKind();
switch (kind) {
case PACKED_SMI_ELEMENTS:
......@@ -670,8 +667,8 @@ void CollectElementIndices(Handle<JSObject> object, uint32_t range,
if (!iter.IsAtEnd()) {
// The prototype will usually have no inherited element indices,
// but we have to check.
CollectElementIndices(PrototypeIterator::GetCurrent<JSObject>(iter), range,
indices);
CollectElementIndices(
isolate, PrototypeIterator::GetCurrent<JSObject>(iter), range, indices);
}
}
......@@ -804,7 +801,7 @@ bool IterateElements(Isolate* isolate, Handle<JSReceiver> receiver,
// Collect all indices in the object and the prototypes less
// 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());
size_t n = indices.size();
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,
GetPackedElementsKind(array->GetElementsKind());
kind = GetMoreGeneralElementsKind(kind, array_kind);
}
element_estimate = EstimateElementCount(array);
element_estimate = EstimateElementCount(isolate, array);
} else {
if (obj->IsHeapObject()) {
kind = GetMoreGeneralElementsKind(
......
......@@ -108,10 +108,10 @@ BUILTIN(ConsoleTimeStamp) {
}
namespace {
void InstallContextFunction(Handle<JSObject> target, const char* name,
Builtins::Name builtin_id, int context_id,
Handle<Object> context_name) {
Factory* const factory = target->GetIsolate()->factory();
void InstallContextFunction(Isolate* isolate, Handle<JSObject> target,
const char* name, Builtins::Name builtin_id,
int context_id, Handle<Object> context_name) {
Factory* const factory = isolate->factory();
Handle<String> name_string =
Name::ToFunctionName(factory->InternalizeUtf8String(name))
......@@ -125,8 +125,7 @@ void InstallContextFunction(Handle<JSObject> target, const char* name,
fun->shared()->set_length(1);
JSObject::AddProperty(fun, factory->console_context_id_symbol(),
handle(Smi::FromInt(context_id), target->GetIsolate()),
NONE);
handle(Smi::FromInt(context_id), isolate), NONE);
if (context_name->IsString()) {
JSObject::AddProperty(fun, factory->console_context_name_symbol(),
context_name, NONE);
......@@ -152,17 +151,17 @@ BUILTIN(ConsoleContext) {
int id = isolate->last_console_context_id() + 1;
isolate->set_last_console_context_id(id);
#define CONSOLE_BUILTIN_SETUP(call, name) \
InstallContextFunction(context, #name, Builtins::kConsole##call, id, \
args.at(1));
#define CONSOLE_BUILTIN_SETUP(call, name) \
InstallContextFunction(isolate, context, #name, Builtins::kConsole##call, \
id, args.at(1));
CONSOLE_METHOD_LIST(CONSOLE_BUILTIN_SETUP)
#undef CONSOLE_BUILTIN_SETUP
InstallContextFunction(context, "time", Builtins::kConsoleTime, id,
args.at(1));
InstallContextFunction(context, "timeEnd", Builtins::kConsoleTimeEnd, id,
args.at(1));
InstallContextFunction(context, "timeStamp", Builtins::kConsoleTimeStamp, id,
InstallContextFunction(isolate, context, "time", Builtins::kConsoleTime, id,
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;
}
......
......@@ -104,8 +104,7 @@ const char* kShortMonths[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
// ES6 section 20.3.1.16 Date Time String Format
double ParseDateTimeString(Handle<String> str) {
Isolate* const isolate = str->GetIsolate();
double ParseDateTimeString(Isolate* isolate, Handle<String> str) {
str = String::Flatten(str);
// TODO(bmeurer): Change DateParser to not use the FixedArray.
Handle<FixedArray> tmp =
......@@ -174,10 +173,10 @@ void ToDateString(double time_val, Vector<char> str, DateCache* date_cache,
UNREACHABLE();
}
Object* SetLocalDateValue(Handle<JSDate> date, double time_val) {
Object* SetLocalDateValue(Isolate* isolate, Handle<JSDate> date,
double time_val) {
if (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));
} else {
time_val = std::numeric_limits<double>::quiet_NaN();
......@@ -211,7 +210,7 @@ BUILTIN(DateConstructor) {
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, value,
Object::ToPrimitive(value));
if (value->IsString()) {
time_val = ParseDateTimeString(Handle<String>::cast(value));
time_val = ParseDateTimeString(isolate, Handle<String>::cast(value));
} else {
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, value,
Object::ToNumber(value));
......@@ -290,7 +289,7 @@ BUILTIN(DateParse) {
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
isolate, string,
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)
......@@ -368,7 +367,7 @@ BUILTIN(DatePrototypeSetDate) {
isolate->date_cache()->YearMonthDayFromDays(days, &year, &month, &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)
......@@ -401,7 +400,7 @@ BUILTIN(DatePrototypeSetFullYear) {
}
}
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)
......@@ -438,7 +437,7 @@ BUILTIN(DatePrototypeSetHours) {
}
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)
......@@ -458,7 +457,7 @@ BUILTIN(DatePrototypeSetMilliseconds) {
int s = (time_within_day / 1000) % 60;
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 )
......@@ -490,7 +489,7 @@ BUILTIN(DatePrototypeSetMinutes) {
}
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 )
......@@ -517,7 +516,7 @@ BUILTIN(DatePrototypeSetMonth) {
}
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 )
......@@ -544,7 +543,7 @@ BUILTIN(DatePrototypeSetSeconds) {
}
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 )
......@@ -858,7 +857,7 @@ BUILTIN(DatePrototypeSetYear) {
dt = 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 )
......
......@@ -173,7 +173,8 @@ BUILTIN(AsyncFunctionConstructor) {
// Do not lazily compute eval position for AsyncFunction, as they may not be
// determined after the function is resumed.
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();
USE(position);
......@@ -191,7 +192,8 @@ BUILTIN(AsyncGeneratorFunctionConstructor) {
// Do not lazily compute eval position for AsyncFunction, as they may not be
// determined after the function is resumed.
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();
USE(position);
......
......@@ -534,7 +534,8 @@ BUILTIN(LocaleConstructor) {
Handle<String> locale_string;
if (tag->IsJSLocale() &&
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 {
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, locale_string,
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