summaryrefslogtreecommitdiff
path: root/deps/v8/src/objects/js-function.cc
diff options
context:
space:
mode:
Diffstat (limited to 'deps/v8/src/objects/js-function.cc')
-rw-r--r--deps/v8/src/objects/js-function.cc95
1 files changed, 62 insertions, 33 deletions
diff --git a/deps/v8/src/objects/js-function.cc b/deps/v8/src/objects/js-function.cc
index 3b446c9dd1..1640cb0d31 100644
--- a/deps/v8/src/objects/js-function.cc
+++ b/deps/v8/src/objects/js-function.cc
@@ -52,7 +52,7 @@ CodeKinds JSFunction::GetAvailableCodeKinds() const {
// Check the optimized code cache.
if (has_feedback_vector() && feedback_vector().has_optimized_code() &&
!feedback_vector().optimized_code().marked_for_deoptimization()) {
- CodeT code = feedback_vector().optimized_code();
+ Code code = feedback_vector().optimized_code();
DCHECK(CodeKindIsOptimizedJSFunction(code.kind()));
result |= CodeKindToCodeKindFlag(code.kind());
}
@@ -474,18 +474,19 @@ MaybeHandle<Object> JSWrappedFunction::Create(
// 8. If result is an Abrupt Completion, throw a TypeError exception.
if (is_abrupt.IsNothing()) {
DCHECK(isolate->has_pending_exception());
+ Handle<Object> pending_exception =
+ Handle<Object>(isolate->pending_exception(), isolate);
isolate->clear_pending_exception();
- // TODO(v8:11989): provide a non-observable inspection on the
- // pending_exception to the newly created TypeError.
- // https://github.com/tc39/proposal-shadowrealm/issues/353
// The TypeError thrown is created with creation Realm's TypeError
// constructor instead of the executing Realm's.
+ Handle<JSFunction> type_error_function =
+ Handle<JSFunction>(creation_context->type_error_function(), isolate);
+ Handle<String> string =
+ Object::NoSideEffectsToString(isolate, pending_exception);
THROW_NEW_ERROR_RETURN_VALUE(
isolate,
- NewError(Handle<JSFunction>(creation_context->type_error_function(),
- isolate),
- MessageTemplate::kCannotWrap),
+ NewError(type_error_function, MessageTemplate::kCannotWrap, string),
{});
}
DCHECK(is_abrupt.FromJust());
@@ -584,13 +585,15 @@ void JSFunction::CreateAndAttachFeedbackVector(
Handle<ClosureFeedbackCellArray> closure_feedback_cell_array =
handle(function->closure_feedback_cell_array(), isolate);
Handle<FeedbackVector> feedback_vector = FeedbackVector::New(
- isolate, shared, closure_feedback_cell_array, compiled_scope);
+ isolate, shared, closure_feedback_cell_array,
+ handle(function->raw_feedback_cell(isolate), isolate), compiled_scope);
+ USE(feedback_vector);
// EnsureClosureFeedbackCellArray should handle the special case where we need
// to allocate a new feedback cell. Please look at comment in that function
// for more details.
DCHECK(function->raw_feedback_cell() !=
isolate->heap()->many_closures_cell());
- function->raw_feedback_cell().set_value(*feedback_vector, kReleaseStore);
+ DCHECK_EQ(function->raw_feedback_cell().value(), *feedback_vector);
function->SetInterruptBudget(isolate);
DCHECK_EQ(v8_flags.log_function_events,
@@ -689,7 +692,7 @@ void SetInstancePrototype(Isolate* isolate, Handle<JSFunction> function,
// needed. At that point, a new initial map is created and the
// prototype is put into the initial map where it belongs.
function->set_prototype_or_initial_map(*value, kReleaseStore);
- if (value->IsJSObject()) {
+ if (value->IsJSObjectThatCanBeTrackedAsPrototype()) {
// Optimize as prototype to detach it from its transition tree.
JSObject::OptimizeAsPrototype(Handle<JSObject>::cast(value));
}
@@ -745,16 +748,17 @@ void JSFunction::SetInitialMap(Isolate* isolate, Handle<JSFunction> function,
void JSFunction::SetInitialMap(Isolate* isolate, Handle<JSFunction> function,
Handle<Map> map, Handle<HeapObject> prototype,
- Handle<JSFunction> constructor) {
+ Handle<HeapObject> constructor) {
if (map->prototype() != *prototype) {
Map::SetPrototype(isolate, map, prototype);
}
+ DCHECK_IMPLIES(!constructor->IsJSFunction(), map->InSharedHeap());
map->SetConstructor(*constructor);
function->set_prototype_or_initial_map(*map, kReleaseStore);
if (v8_flags.log_maps) {
LOG(isolate, MapEvent("InitialMap", Handle<Map>(), map, "",
SharedFunctionInfo::DebugName(
- handle(function->shared(), isolate))));
+ isolate, handle(function->shared(), isolate))));
}
}
@@ -820,6 +824,7 @@ bool CanSubclassHaveInobjectProperties(InstanceType instance_type) {
case JS_ASYNC_FROM_SYNC_ITERATOR_TYPE:
case JS_CONTEXT_EXTENSION_OBJECT_TYPE:
case JS_DATA_VIEW_TYPE:
+ case JS_RAB_GSAB_DATA_VIEW_TYPE:
case JS_DATE_TYPE:
case JS_GENERATOR_OBJECT_TYPE:
case JS_FUNCTION_TYPE:
@@ -898,7 +903,7 @@ bool CanSubclassHaveInobjectProperties(InstanceType instance_type) {
case BYTECODE_ARRAY_TYPE:
case BYTE_ARRAY_TYPE:
case CELL_TYPE:
- case CODE_TYPE:
+ case INSTRUCTION_STREAM_TYPE:
case FILLER_TYPE:
case FIXED_ARRAY_TYPE:
case SCRIPT_CONTEXT_TABLE_TYPE:
@@ -1103,7 +1108,7 @@ int TypedArrayElementsKindToRabGsabCtorIndex(ElementsKind elements_kind) {
} // namespace
-MaybeHandle<Map> JSFunction::GetDerivedRabGsabMap(
+MaybeHandle<Map> JSFunction::GetDerivedRabGsabTypedArrayMap(
Isolate* isolate, Handle<JSFunction> constructor,
Handle<JSReceiver> new_target) {
MaybeHandle<Map> maybe_map = GetDerivedMap(isolate, constructor, new_target);
@@ -1132,6 +1137,28 @@ MaybeHandle<Map> JSFunction::GetDerivedRabGsabMap(
return rab_gsab_map;
}
+MaybeHandle<Map> JSFunction::GetDerivedRabGsabDataViewMap(
+ Isolate* isolate, Handle<JSReceiver> new_target) {
+ Handle<Context> context =
+ handle(isolate->context().native_context(), isolate);
+ Handle<JSFunction> constructor = handle(context->data_view_fun(), isolate);
+ MaybeHandle<Map> maybe_map = GetDerivedMap(isolate, constructor, new_target);
+ Handle<Map> map;
+ if (!maybe_map.ToHandle(&map)) {
+ return MaybeHandle<Map>();
+ }
+ if (*map == constructor->initial_map()) {
+ return handle(Map::cast(context->js_rab_gsab_data_view_map()), isolate);
+ }
+
+ // This only happens when subclassing DataViews. Create a new map with the
+ // JS_RAB_GSAB_DATA_VIEW instance type. Note: the map is not cached and
+ // reused -> every data view gets a unique map, making ICs slow.
+ Handle<Map> rab_gsab_map = Map::Copy(isolate, map, "RAB / GSAB");
+ rab_gsab_map->set_instance_type(JS_RAB_GSAB_DATA_VIEW_TYPE);
+ return rab_gsab_map;
+}
+
int JSFunction::ComputeInstanceSizeWithMinSlack(Isolate* isolate) {
CHECK(has_initial_map());
if (initial_map().IsInobjectSlackTrackingInProgress()) {
@@ -1192,7 +1219,8 @@ Handle<String> JSFunction::GetDebugName(Handle<JSFunction> function) {
GetDataProperty(isolate, function, isolate->factory()->name_string());
if (name->IsString()) return Handle<String>::cast(name);
}
- return SharedFunctionInfo::DebugName(handle(function->shared(), isolate));
+ return SharedFunctionInfo::DebugName(isolate,
+ handle(function->shared(), isolate));
}
bool JSFunction::SetName(Handle<JSFunction> function, Handle<Name> name,
@@ -1221,8 +1249,7 @@ bool JSFunction::SetName(Handle<JSFunction> function, Handle<Name> name,
namespace {
Handle<String> NativeCodeFunctionSourceString(
- Handle<SharedFunctionInfo> shared_info) {
- Isolate* const isolate = shared_info->GetIsolate();
+ Isolate* isolate, Handle<SharedFunctionInfo> shared_info) {
IncrementalStringBuilder builder(isolate);
builder.AppendCStringLiteral("function ");
builder.AppendString(handle(shared_info->Name(), isolate));
@@ -1239,26 +1266,28 @@ Handle<String> JSFunction::ToString(Handle<JSFunction> function) {
// Check if {function} should hide its source code.
if (!shared_info->IsUserJavaScript()) {
- return NativeCodeFunctionSourceString(shared_info);
+ return NativeCodeFunctionSourceString(isolate, shared_info);
}
- // Check if we should print {function} as a class.
- Handle<Object> maybe_class_positions = JSReceiver::GetDataProperty(
- isolate, function, isolate->factory()->class_positions_symbol());
- if (maybe_class_positions->IsClassPositions()) {
- ClassPositions class_positions =
- ClassPositions::cast(*maybe_class_positions);
- int start_position = class_positions.start();
- int end_position = class_positions.end();
- Handle<String> script_source(
- String::cast(Script::cast(shared_info->script()).source()), isolate);
- return isolate->factory()->NewSubString(script_source, start_position,
- end_position);
+ if (IsClassConstructor(shared_info->kind())) {
+ // Check if we should print {function} as a class.
+ Handle<Object> maybe_class_positions = JSReceiver::GetDataProperty(
+ isolate, function, isolate->factory()->class_positions_symbol());
+ if (maybe_class_positions->IsClassPositions()) {
+ ClassPositions class_positions =
+ ClassPositions::cast(*maybe_class_positions);
+ int start_position = class_positions.start();
+ int end_position = class_positions.end();
+ Handle<String> script_source(
+ String::cast(Script::cast(shared_info->script()).source()), isolate);
+ return isolate->factory()->NewSubString(script_source, start_position,
+ end_position);
+ }
}
// Check if we have source code for the {function}.
if (!shared_info->HasSourceCode()) {
- return NativeCodeFunctionSourceString(shared_info);
+ return NativeCodeFunctionSourceString(isolate, shared_info);
}
// If this function was compiled from asm.js, use the recorded offset
@@ -1286,10 +1315,10 @@ Handle<String> JSFunction::ToString(Handle<JSFunction> function) {
// giving inconsistent call behaviour.
isolate->CountUsage(
v8::Isolate::UseCounterFeature::kFunctionTokenOffsetTooLongForToString);
- return NativeCodeFunctionSourceString(shared_info);
+ return NativeCodeFunctionSourceString(isolate, shared_info);
}
return Handle<String>::cast(
- SharedFunctionInfo::GetSourceCodeHarmony(shared_info));
+ SharedFunctionInfo::GetSourceCodeHarmony(isolate, shared_info));
}
// static