blob: f4949b0bc77ab24ded32b57b1887e3a6571f4293 [file]
// Copyright 2019 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// TODO(saelo): Consider also moving this into trusted space as
// UncompiledDataWithPreparseData is now in trusted space.
@cppObjectLayoutDefinition
extern class PreparseData extends HeapObject {
// TODO(v8:8983): Add declaration for variable-sized region.
data_length: int32;
children_length: int32;
}
@cppObjectLayoutDefinition
extern class InterpreterData extends ExposedTrustedObject {
bytecode_array: ProtectedPointer<BytecodeArray>;
interpreter_trampoline: ProtectedPointer<Code>;
}
type FunctionKind extends uint8 constexpr 'FunctionKind';
type FunctionSyntaxKind extends uint8 constexpr 'FunctionSyntaxKind';
type BailoutReason extends uint8 constexpr 'BailoutReason';
type CachedTieringDecision extends uint8 constexpr 'CachedTieringDecision';
@cppScope('SharedFunctionInfo')
bitfield struct SharedFunctionInfoFlags extends uint32 {
// Have FunctionKind first to make it cheaper to access.
function_kind: FunctionKind: 5 bit;
is_native: bool: 1 bit;
is_strict: bool: 1 bit;
function_syntax_kind: FunctionSyntaxKind: 3 bit;
is_class_constructor: bool: 1 bit;
has_duplicate_parameters: bool: 1 bit;
allow_lazy_compilation: bool: 1 bit;
function_map_index: uint32: 5 bit;
disabled_optimization_reason: BailoutReason: 4 bit;
requires_instance_members_initializer: bool: 1 bit;
construct_as_builtin: bool: 1 bit;
name_should_print_as_anonymous: bool: 1 bit;
has_reported_binary_coverage: bool: 1 bit;
is_top_level: bool: 1 bit;
properties_are_final: bool: 1 bit;
private_name_lookup_skips_outer_class: bool: 1 bit;
is_hoisted_in_context: bool: 1 bit;
}
@cppScope('SharedFunctionInfo')
bitfield struct SharedFunctionInfoFlags2 extends uint8 {
class_scope_has_private_brand: bool: 1 bit;
has_static_private_methods_or_accessors: bool: 1 bit;
// In case another bit is needed here it should be possible to combine
// is_sparkplug_compiling, cached_tiering_decision, and
// function_context_independent_compiled into a SharedTieringState enum using
// only 4 bits.
is_sparkplug_compiling: bool: 1 bit;
maglev_compilation_failed: bool: 1 bit;
cached_tiering_decision: CachedTieringDecision: 3 bit;
function_context_independent_compiled: bool: 1 bit;
}
@cppObjectLayoutDefinition
extern class SharedFunctionInfo extends HeapObject {
// For the sandbox, the SFI's function data is split into a trusted and an
// untrusted part.
// The field is treated as a custom weak pointer. We visit this field as a
// weak pointer if there is aged bytecode. If there is no bytecode or if the
// bytecode is young then we treat it as a strong pointer. This is done to
// support flushing of bytecode.
// TODO(chromium:1490564): we should see if these two fields can again be
// merged into a single field (when all possible data objects are moved into
// trusted space), or if we can turn this into a trusted code and an
// untrusted data field.
@customWeakMarking
trusted_function_data: TrustedPointer<ExposedTrustedObject>;
// TODO(chromium:1490564): if we cannot merge this field with the
// trusted_function_data in the future (see TODO above), then maybe consider
// renaming this field as untrusted_function_data may be a bit awkward.
untrusted_function_data: Object;
name_or_scope_info: String|NoSharedNameSentinel|ScopeInfo;
outer_scope_info_or_feedback_metadata: ScopeInfo|FeedbackMetadata|TheHole;
script: Script|Undefined;
// [length]: The function length - usually the number of declared parameters
// (always without the receiver). The value is only reliable when the function
// has been compiled.
length: uint16;
// [formal_parameter_count]: The number of declared parameters (or the special
// value kDontAdaptArgumentsSentinel to indicate that arguments are passed
// unaltered).
// In contrast to [length], formal_parameter_count includes the receiver.
//
// NOTE: SharedFunctionInfo objects are located inside the sandbox, so an
// attacker able to corrupt in-sandbox memory can change this field
// arbitrarily. As such, it is not safe to use this field for invoking a
// JSFunction or computing the size of stack frames (or similar use-cases
// that involve accessing out-of-sandbox memory such as the stack). Instead,
// for such purposes, a trusted parameter count must be used, the source of
// which depends on the concrete use case. For example, a (trusted) parameter
// count can be obtained from a BytecodeArray (e.g. for interpreting
// bytecode), a Code object (e.g. for deoptimizing optimized code), or the
// JSDispatchTable (e.g. for invoking a JSFunction).
formal_parameter_count: uint16;
function_token_offset: uint16;
// [expected_nof_properties]: Expected number of properties for the
// function. The value is only reliable when the function has been compiled.
expected_nof_properties: uint8;
flags2: SharedFunctionInfoFlags2;
flags: SharedFunctionInfoFlags;
// [function_literal_id] - uniquely identifies the FunctionLiteral this
// SharedFunctionInfo represents within its script, or -1 if this
// SharedFunctionInfo object doesn't correspond to a parsed FunctionLiteral.
function_literal_id: int32;
// [unique_id] - An identifier that's persistent even across GC.
// TODO(jgruber): Merge with function_literal_id by storing the base id on
// Script (since the literal id is used for table lookups).
unique_id: int32;
// Age used for code flushing.
// TODO(dinfuehr): Merge this field with function_literal_id to save memory.
age: uint16;
// Feedback Slot needed to instantiate Lazy Closure not instantiated during
// SetPrototypeProperties.
feedback_slot: uint16;
}
// A wrapper around a SharedFunctionInfo in trusted space.
// Can be useful in cases where a protected pointer reference to a
// SharedFunctionInfo is required, for example because it is stored inside an
// ProtectedFixedArray.
@cppObjectLayoutDefinition
extern class SharedFunctionInfoWrapper extends TrustedObject {
shared_info: SharedFunctionInfo;
}
const kDontAdaptArgumentsSentinel: constexpr int32
generates 'kDontAdaptArgumentsSentinel';
@export
macro LoadSharedFunctionInfoFormalParameterCountWithoutReceiver(
sfi: SharedFunctionInfo): uint16 {
let formalParameterCount = sfi.formal_parameter_count;
if (Convert<int32>(formalParameterCount) != kDontAdaptArgumentsSentinel) {
formalParameterCount =
Convert<uint16>(formalParameterCount - kJSArgcReceiverSlots);
}
return formalParameterCount;
}
@export
macro LoadSharedFunctionInfoFormalParameterCountWithReceiver(
sfi: SharedFunctionInfo): uint16 {
return sfi.formal_parameter_count;
}
@export
macro IsSharedFunctionInfoDontAdaptArguments(sfi: SharedFunctionInfo): bool {
const formalParameterCount = sfi.formal_parameter_count;
return Convert<int32>(formalParameterCount) == kDontAdaptArgumentsSentinel;
}
@abstract
@cppObjectLayoutDefinition
extern class UncompiledData extends ExposedTrustedObject {
inferred_name: String;
start_position: int32;
end_position: int32;
}
@cppObjectLayoutDefinition
extern class UncompiledDataWithoutPreparseData extends UncompiledData {}
@cppObjectLayoutDefinition
extern class UncompiledDataWithPreparseData extends UncompiledData {
preparse_data: PreparseData;
}
@cppObjectLayoutDefinition
extern class UncompiledDataWithoutPreparseDataWithJob extends
UncompiledDataWithoutPreparseData {
job: RawPtr;
}
@cppObjectLayoutDefinition
extern class UncompiledDataWithPreparseDataAndJob extends
UncompiledDataWithPreparseData {
job: RawPtr;
}
@useParentTypeChecker
type PodArrayOfIntegerPairs extends ByteArray
constexpr 'PodArray<std::pair<int32_t, int32_t>>';
@useParentTypeChecker
type FixedInt32Array extends ByteArray constexpr 'FixedInt32Array';
@useParentTypeChecker
type FixedUInt32Array extends ByteArray constexpr 'FixedUInt32Array';
@cppObjectLayoutDefinition
extern class OnHeapBasicBlockProfilerData extends HeapObject {
block_ids: FixedInt32Array;
counts: FixedUInt32Array;
branches: PodArrayOfIntegerPairs;
name: String;
schedule: String;
code: String;
hash: Smi;
}