19void ConstantExpressionInterface::I32Const(FullDecoder* decoder, Value*
result,
24void ConstantExpressionInterface::I64Const(FullDecoder* decoder, Value*
result,
29void ConstantExpressionInterface::F32Const(FullDecoder* decoder, Value*
result,
34void ConstantExpressionInterface::F64Const(FullDecoder* decoder, Value*
result,
39void ConstantExpressionInterface::S128Const(FullDecoder* decoder,
40 const Simd128Immediate& imm,
46void ConstantExpressionInterface::UnOp(FullDecoder* decoder,
WasmOpcode opcode,
47 const Value& input, Value*
result) {
50 case kExprExternConvertAny: {
57 case kExprAnyConvertExtern: {
58 const char* error_message =
nullptr;
72void ConstantExpressionInterface::BinOp(FullDecoder* decoder,
WasmOpcode opcode,
73 const Value& lhs,
const Value& rhs,
78 result->runtime_value = WasmValue(base::AddWithWraparound(
79 lhs.runtime_value.to_i32(), rhs.runtime_value.to_i32()));
82 result->runtime_value = WasmValue(base::SubWithWraparound(
83 lhs.runtime_value.to_i32(), rhs.runtime_value.to_i32()));
87 lhs.runtime_value.to_i32(), rhs.runtime_value.to_i32()));
90 result->runtime_value = WasmValue(base::AddWithWraparound(
91 lhs.runtime_value.to_i64(), rhs.runtime_value.to_i64()));
94 result->runtime_value = WasmValue(base::SubWithWraparound(
95 lhs.runtime_value.to_i64(), rhs.runtime_value.to_i64()));
99 lhs.runtime_value.to_i64(), rhs.runtime_value.to_i64()));
106void ConstantExpressionInterface::RefNull(FullDecoder* decoder, ValueType type,
109 result->runtime_value = WasmValue(
112 decoder->module_->canonical_type(type));
115void ConstantExpressionInterface::RefFunc(FullDecoder* decoder,
116 uint32_t function_index,
123 ModuleTypeIndex sig_index =
module_->functions[function_index].sig_index;
124 bool function_is_shared =
module_->type(sig_index).is_shared;
125 CanonicalValueType type =
129 DirectHandle<WasmFuncRef> func_ref =
135 result->runtime_value = WasmValue(func_ref, type);
138void ConstantExpressionInterface::GlobalGet(FullDecoder* decoder, Value*
result,
139 const GlobalIndexImmediate& imm) {
141 const WasmGlobal& global =
module_->globals[imm.index];
142 DCHECK(!global.mutability);
143 DirectHandle<WasmTrustedInstanceData> data =
145 CanonicalValueType type =
module_->canonical_type(global.type);
148 ? WasmValue(
reinterpret_cast<uint8_t*
>(
149 data->untagged_globals_buffer()->backing_store()) +
161 if (!type.has_descriptor()) {
166 DCHECK(type.has_descriptor());
169 module_->canonical_type_id(type.descriptor));
171 if (!IsWasmStruct(*maybe_obj)) {
173 error_ = MessageTemplate::kWasmTrapNullDereference;
180void ConstantExpressionInterface::StructNew(FullDecoder* decoder,
182 const Value& descriptor,
188 const StructType* struct_type = type.struct_type;
195 if (type.is_descriptor()) {
199 obj =
isolate_->
factory()->NewWasmStructUninitialized(struct_type, rtt);
207 reinterpret_cast<uint8_t*
>(obj->RawFieldAddress(
offset));
208 args[
i].runtime_value.Packed(struct_type->
field(
i)).CopyTo(address);
214 result->runtime_value = WasmValue(
215 obj, decoder->module_->canonical_type(
219void ConstantExpressionInterface::StringConst(FullDecoder* decoder,
220 const StringConstImmediate& imm,
227 const wasm::WasmStringRefLiteral&
literal =
228 module_->stringref_literals[imm.index];
229 const base::Vector<const uint8_t> module_bytes =
231 const base::Vector<const uint8_t> string_bytes = module_bytes.SubVector(
233 DirectHandle<String>
string =
241WasmValue DefaultValueForType(ValueType type, Isolate* isolate,
243 switch (type.kind()) {
249 return WasmValue(int64_t{0});
252 return WasmValue(0.0f);
254 return WasmValue(0.0);
258 return WasmValue(type.use_wasm_null()
261 module->canonical_type(type));
271void ConstantExpressionInterface::StructNewDefault(
272 FullDecoder* decoder,
const StructIndexImmediate& imm,
273 const Value& descriptor, Value*
result) {
275 DirectHandle<WasmTrustedInstanceData> data =
277 const TypeDefinition& type =
module_->type(imm.index);
278 const StructType* struct_type = type.struct_type;
281 DirectHandle<Map> rtt =
GetRtt(data, imm.index, type, descriptor);
282 if (rtt.is_null())
return;
284 DirectHandle<WasmStruct> obj;
285 if (type.is_descriptor()) {
289 obj =
isolate_->
factory()->NewWasmStructUninitialized(struct_type, rtt);
293 for (uint32_t
i = 0;
i < struct_type->field_count();
i++) {
294 int offset = struct_type->field_offset(
i);
295 ValueType ftype = struct_type->field(
i);
296 if (ftype.is_numeric()) {
298 reinterpret_cast<uint8_t*
>(obj->RawFieldAddress(
offset));
309 result->runtime_value = WasmValue(
310 obj, decoder->module_->canonical_type(
314void ConstantExpressionInterface::ArrayNew(FullDecoder* decoder,
315 const ArrayIndexImmediate& imm,
317 const Value& initial_value,
320 DirectHandle<WasmTrustedInstanceData> data =
322 DirectHandle<Map> rtt{
324 if (length.runtime_value.to_u32() >
326 error_ = MessageTemplate::kWasmTrapArrayTooLarge;
329 result->runtime_value = WasmValue(
331 length.runtime_value.to_u32(),
332 initial_value.runtime_value, rtt),
333 decoder->module_->canonical_type(
337void ConstantExpressionInterface::ArrayNewDefault(
338 FullDecoder* decoder,
const ArrayIndexImmediate& imm,
const Value& length,
341 Value initial_value(decoder->pc(), imm.array_type->element_type());
342 initial_value.runtime_value = DefaultValueForType(
343 imm.array_type->element_type(),
isolate_, decoder->module_);
344 return ArrayNew(decoder, imm, length, initial_value,
result);
347void ConstantExpressionInterface::ArrayNewFixed(
348 FullDecoder* decoder,
const ArrayIndexImmediate& array_imm,
349 const IndexImmediate& length_imm,
const Value elements[], Value*
result) {
351 DirectHandle<WasmTrustedInstanceData> data =
353 DirectHandle<Map> rtt{
354 Cast<Map>(data->managed_object_maps()->get(array_imm.index.index)),
356 base::Vector<WasmValue> element_values =
357 decoder->zone_->AllocateVector<WasmValue>(length_imm.index);
358 for (
size_t i = 0;
i < length_imm.index;
i++) {
359 element_values[
i] = elements[
i].runtime_value;
361 result->runtime_value = WasmValue(
363 element_values, rtt),
364 decoder->module_->canonical_type(
371void ConstantExpressionInterface::ArrayNewSegment(
372 FullDecoder* decoder,
const ArrayIndexImmediate& array_imm,
373 const IndexImmediate& segment_imm,
const Value& offset_value,
374 const Value& length_value, Value*
result) {
377 DirectHandle<WasmTrustedInstanceData> data =
380 DirectHandle<Map> rtt{
381 Cast<Map>(data->managed_object_maps()->get(array_imm.index.index)),
383 DCHECK_EQ(rtt->wasm_type_info()->type_index(),
384 decoder->module_->canonical_type_id(array_imm.index));
386 uint32_t length = length_value.runtime_value.to_u32();
387 uint32_t
offset = offset_value.runtime_value.to_u32();
390 error_ = MessageTemplate::kWasmTrapArrayTooLarge;
393 CanonicalValueType element_type = rtt->wasm_type_info()->element_type();
394 CanonicalValueType result_type =
395 rtt->wasm_type_info()->type().AsExactIfProposalEnabled();
396 if (element_type.is_numeric()) {
397 const WasmDataSegment& data_segment =
398 module_->data_segments[segment_imm.index];
399 uint32_t length_in_bytes =
400 length * array_imm.array_type->element_type().value_kind_size();
403 data_segment.source.length())) {
404 error_ = MessageTemplate::kWasmTrapDataSegmentOutOfBounds;
409 data->data_segment_starts()->get(segment_imm.index) +
offset;
410 DirectHandle<WasmArray> array_value =
413 result->runtime_value = WasmValue(array_value, result_type);
415 const wasm::WasmElemSegment* elem_segment =
416 &decoder->module_->elem_segments[segment_imm.index];
422 ? elem_segment->element_count
424 error_ = MessageTemplate::kWasmTrapElementSegmentOutOfBounds;
428 DirectHandle<Object> array_object =
431 segment_imm.index,
offset, length, rtt, element_type);
432 if (
IsSmi(*array_object)) {
436 result->runtime_value = WasmValue(array_object, result_type);
441void ConstantExpressionInterface::RefI31(FullDecoder* decoder,
442 const Value& input, Value*
result) {
444 Address raw = input.runtime_value.to_i32();
461void ConstantExpressionInterface::DoReturn(FullDecoder* decoder,
466 decoder->set_end(decoder->pc() + 1);
472DirectHandle<WasmTrustedInstanceData>
475 bool type_is_shared =
module_->type(index).is_shared;
V8_INLINE bool is_null() const
V8_WARN_UNUSED_RESULT MaybeHandle< String > NewStringFromUtf8(base::Vector< const char > str, AllocationType allocation=AllocationType::kYoung)
v8::internal::Factory * factory()
static constexpr int kMaxValue
static void store(Tagged< HeapObject > host, PtrType value)
static constexpr int MaxLength(uint32_t element_size_bytes)
static DirectHandle< WasmStruct > AllocateDescriptorUninitialized(Isolate *isolate, DirectHandle< WasmTrustedInstanceData > trusted_data, wasm::ModuleTypeIndex index, DirectHandle< Map > map)
static DirectHandle< WasmFuncRef > GetOrCreateFuncRef(Isolate *isolate, DirectHandle< WasmTrustedInstanceData > trusted_instance_data, int function_index)
CanonicalValueType AsExactIfProposalEnabled(Exactness exact=Exactness::kExact) const
static constexpr CanonicalValueType Ref(CanonicalTypeIndex index, bool shared, RefTypeKind kind)
static constexpr CanonicalValueType RefMaybeNull(CanonicalValueType type, Nullability nullable)
WasmValue computed_value_
DirectHandle< WasmTrustedInstanceData > trusted_instance_data_
WasmModule * outer_module_
DirectHandle< WasmTrustedInstanceData > shared_trusted_instance_data_
DirectHandle< WasmTrustedInstanceData > GetTrustedInstanceDataForTypeIndex(ModuleTypeIndex index)
DirectHandle< Map > GetRtt(DirectHandle< WasmTrustedInstanceData > data, ModuleTypeIndex index, const TypeDefinition &type, const Value &descriptor)
const WasmModule * module_
bool generate_value() const
uint32_t field_offset(uint32_t index) const
uint32_t field_count() const
ValueType field(uint32_t index) const
constexpr Nullability nullability() const
constexpr bool is_numeric() const
ValueType AsExactIfProposalEnabled(Exactness exact=Exactness::kExact) const
static constexpr ValueType Ref(ModuleTypeIndex index, bool shared, RefTypeKind kind)
base::Vector< const DirectHandle< Object > > args
ZoneVector< RpoNumber > & result
FunctionLiteral * literal
int16_t MulWithWraparound(int16_t a, int16_t b)
constexpr bool IsInBounds(T index, T length, T max)
constexpr bool IsInRange(T value, U lower_limit, U higher_limit)
WordWithBits< 128 > Simd128
MaybeDirectHandle< Object > JSToWasmObject(Isolate *isolate, DirectHandle< Object > value, CanonicalValueType expected, const char **error_message)
constexpr IndependentHeapType kWasmAnyRef
constexpr IndependentHeapType kWasmExternRef
constexpr IndependentHeapType kWasmRefI31
constexpr IndependentValueType kWasmS128
constexpr size_t kV8MaxWasmStringLiterals
DirectHandle< Object > WasmToJSObject(Isolate *isolate, DirectHandle< Object > value)
constexpr IndependentHeapType kWasmRefString
PerThreadAssertScopeDebugOnly< false, SAFEPOINTS_ASSERT, HEAP_ALLOCATION_ASSERT > DisallowGarbageCollection
wasm::WasmModule WasmModule
V8_INLINE constexpr bool IsSmi(TaggedImpl< kRefType, StorageType > obj)
V8_INLINE DirectHandle< T > direct_handle(Tagged< T > object, Isolate *isolate)
constexpr bool SmiValuesAre31Bits()
kMemory0SizeOffset Address kNewAllocationLimitAddressOffset Address kOldAllocationLimitAddressOffset uint8_t kGlobalsStartOffset kJumpTableStartOffset std::atomic< uint32_t > kTieringBudgetArrayOffset kDataSegmentStartsOffset kElementSegmentsOffset kInstanceObjectOffset kMemoryObjectsOffset tagged_globals_buffer
constexpr bool SmiValuesAre32Bits()
kInstanceDescriptorsOffset kTransitionsOrPrototypeInfoOffset IsNull(value)||IsJSProxy(value)||IsWasmObject(value)||(IsJSObject(value) &&(HeapLayout
Tagged< To > Cast(Tagged< From > value, const v8::SourceLocation &loc=INIT_SOURCE_LOCATION_IN_DEBUG)
#define DCHECK(condition)
#define DCHECK_LT(v1, v2)
#define DCHECK_EQ(v1, v2)
std::vector< WasmFunction > functions