Skip to content

Commit bc6a258

Browse files
committed
Applied suggestions
1 parent 2acd97f commit bc6a258

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

extension/wasm/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
# cmake-format -i CMakeLists.txt
1010
# ~~~
1111

12-
cmake_minimum_required(VERSION 3.24)
12+
cmake_minimum_required(VERSION 3.29)
1313

1414
project(executorch_wasm)
1515

@@ -27,7 +27,7 @@ if(NOT EXECUTORCH_ROOT)
2727
endif()
2828

2929
include(${EXECUTORCH_ROOT}/tools/cmake/Utils.cmake)
30-
set(_common_compile_options -Wno-deprecated-declarations -fPIC)
30+
set(_common_compile_options -Wno-deprecated-declarations -fPIC -Wall -Werror)
3131
set(_common_include_directories ${EXECUTORCH_ROOT}/..)
3232

3333
set(link_libraries)

extension/wasm/wasm_bindings.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
#define THROW_JS_ERROR(errorType, message, ...) \
1616
({ \
17-
char msg_buf[128]; \
17+
char msg_buf[256]; \
1818
snprintf(msg_buf, sizeof(msg_buf), message, ##__VA_ARGS__); \
1919
EM_ASM(throw new errorType(UTF8ToString($0)), msg_buf); \
2020
__builtin_unreachable(); \
@@ -96,18 +96,20 @@ class JsTensor {
9696
: tensor_(std::make_shared<Tensor>(tensor)) {}
9797

9898
const Tensor& get_tensor() const {
99+
THROW_IF_FALSE(tensor_, "Tensor is null");
99100
return *tensor_;
100101
}
101102

102103
ScalarType get_scalar_type() const {
104+
THROW_IF_FALSE(tensor_, "Tensor is null");
103105
return tensor_->scalar_type();
104106
}
105107
val get_data() const {
106108
switch (get_scalar_type()) {
107-
#define JS_CASE_TENSOR_TO_VAL_TYPE(T, NAME) \
108-
case ScalarType::NAME: \
109-
return val( \
110-
typed_memory_view(get_tensor().numel(), get_tensor().data_ptr<T>()));
109+
#define JS_CASE_TENSOR_TO_VAL_TYPE(T, NAME) \
110+
case ScalarType::NAME: \
111+
THROW_IF_FALSE(tensor_->data_ptr<T>(), "Tensor data is null"); \
112+
return val(typed_memory_view(tensor_->numel(), tensor_->data_ptr<T>()));
111113
JS_FORALL_SUPPORTED_TENSOR_TYPES(JS_CASE_TENSOR_TO_VAL_TYPE)
112114
default:
113115
THROW_JS_ERROR(
@@ -246,7 +248,7 @@ val to_val(EValue v) {
246248
return val(std::move(wrapper));
247249
} else {
248250
char tag_buf[32];
249-
runtime::tag_to_string(v.tag, tag_buf, 32);
251+
runtime::tag_to_string(v.tag, tag_buf, sizeof(tag_buf));
250252
THROW_JS_ERROR(TypeError, "Unsupported EValue type: %s", tag_buf);
251253
}
252254
}
@@ -340,6 +342,9 @@ class JsModule final {
340342
: buffer_(std::move(buffer)), module_(std::move(module)) {}
341343

342344
static std::unique_ptr<JsModule> load(val data) {
345+
if (data.isNull() || data.isUndefined()) {
346+
THROW_JS_ERROR(TypeError, "Data cannot be null or undefined");
347+
}
343348
if (data.isString()) {
344349
return std::make_unique<JsModule>(
345350
std::make_unique<Module>(data.as<std::string>()));

0 commit comments

Comments
 (0)