v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
constant-expression.cc
Go to the documentation of this file.
1// Copyright 2022 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
6
9#include "src/heap/factory.h"
10#include "src/objects/oddball.h"
11#include "src/roots/roots.h"
18
19namespace v8 {
20namespace internal {
21namespace wasm {
22
28
30 Zone* zone, ConstantExpression expr, ValueType expected,
31 const WasmModule* module, Isolate* isolate,
32 DirectHandle<WasmTrustedInstanceData> trusted_instance_data,
33 DirectHandle<WasmTrustedInstanceData> shared_trusted_instance_data) {
34 switch (expr.kind()) {
38 return WasmValue(expr.i32_value());
40 return WasmValue(expected.use_wasm_null()
41 ? Cast<Object>(isolate->factory()->wasm_null())
42 : Cast<Object>(isolate->factory()->null_value()),
43 module->canonical_type(ValueType::RefNull(expr.type())));
45 uint32_t index = expr.index();
46 bool function_is_shared =
47 module->type(module->functions[index].sig_index).is_shared;
50 isolate,
51 function_is_shared ? shared_trusted_instance_data
52 : trusted_instance_data,
53 index);
54 return WasmValue(value, module->canonical_type(expected));
55 }
57 WireBytesRef ref = expr.wire_bytes_ref();
58
59 base::Vector<const uint8_t> module_bytes =
60 trusted_instance_data->native_module()->wire_bytes();
61
62 const uint8_t* start = module_bytes.begin() + ref.offset();
63 const uint8_t* end = module_bytes.begin() + ref.end_offset();
64
66 // We have already validated the expression, so we might as well
67 // revalidate it as non-shared, which is strictly more permissive.
68 // TODO(14616): Rethink this.
69 constexpr bool kIsShared = false;
70 FunctionBody body(&sig, ref.offset(), start, end, kIsShared);
71 WasmDetectedFeatures detected;
73 {
74 // We need a scope for the decoder because its destructor resets some
75 // Zone elements, which has to be done before we reset the Zone
76 // afterwards.
77 // We use FullValidationTag so we do not have to create another template
78 // instance of WasmFullDecoder, which would cost us >50Kb binary code
79 // size.
82 decoder(zone, module, WasmEnabledFeatures::All(), &detected, body,
83 module, isolate, trusted_instance_data,
84 shared_trusted_instance_data);
85
86 decoder.DecodeFunctionBody();
87
88 result = decoder.interface().has_error()
89 ? ValueOrError(decoder.interface().error())
90 : ValueOrError(decoder.interface().computed_value());
91 }
92
93 zone->Reset();
94
95 return result;
96 }
97 }
98}
99
100} // namespace wasm
101} // namespace internal
102} // namespace v8
static constexpr T decode(U value)
Definition bit-field.h:66
constexpr T * begin() const
Definition vector.h:96
auto Returns(ReturnTypes... return_types) const
Definition signature.h:166
static DirectHandle< WasmFuncRef > GetOrCreateFuncRef(Isolate *isolate, DirectHandle< WasmTrustedInstanceData > trusted_instance_data, int function_index)
V8_EXPORT_PRIVATE WireBytesRef wire_bytes_ref() const
constexpr bool use_wasm_null() const
Definition value-type.h:462
static constexpr ValueType RefNull(ModuleTypeIndex index, bool shared, RefTypeKind kind)
Definition value-type.h:895
static constexpr WasmEnabledFeatures All()
int start
int end
ZoneVector< RpoNumber > & result
std::variant< WasmValue, MessageTemplate > ValueOrError
ValueOrError EvaluateConstantExpression(Zone *zone, ConstantExpression expr, ValueType expected, const WasmModule *module, Isolate *isolate, DirectHandle< WasmTrustedInstanceData > trusted_instance_data, DirectHandle< WasmTrustedInstanceData > shared_trusted_instance_data)
kWasmInternalFunctionIndirectPointerTag kProtectedInstanceDataOffset sig
Tagged< To > Cast(Tagged< From > value, const v8::SourceLocation &loc=INIT_SOURCE_LOCATION_IN_DEBUG)
Definition casting.h:150
Definition c-api.cc:87
#define DCHECK_EQ(v1, v2)
Definition logging.h:485
CanonicalValueType canonical_type(ValueType type) const