Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .zed/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"formatter": {
"external": {
"command": "bazel-bin/build/deps/formatters/clang-format",
"args": ["-i", "{buffer_path}"]
"arguments": ["-i", "{buffer_path}"]
}
}
},
Expand Down
36 changes: 21 additions & 15 deletions src/rust/gen-compile-cache/cxx-bridge.c++
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#include "cxx-bridge.h"

#include <workerd/jsg/compile-cache.h>
#include <workerd/jsg/type-wrapper.h>
#include <workerd/jsg/setup.h>
#include <workerd/jsg/type-wrapper.h>

#include <capnp/serialize.h>
#include <kj-rs/kj-rs.h>

#include <capnp/serialize.h>

using namespace kj_rs;
namespace workerd::rust::gen_compile_cache {

Expand Down Expand Up @@ -36,19 +37,24 @@ constexpr v8::ScriptCompiler::CompileOptions compileOptions = v8::ScriptCompiler
auto data = ccIsolate.runInLockScope([&](CompileCacheIsolate::Lock& isolateLock) {
return JSG_WITHIN_CONTEXT_SCOPE(isolateLock,
isolateLock.newContext<CompilerCacheContext>().getHandle(isolateLock), [&](jsg::Lock& js) {
auto resourceName = jsg::newExternalOneByteString(js, kj::from<Rust>(path));
v8::ScriptOrigin origin(resourceName, resourceLineOffset, resourceColumnOffset,
resourceIsSharedCrossOrigin, scriptId, {}, resourceIsOpaque, isWasm, isModule);

auto contentStr = jsg::newExternalOneByteString(js, kj::from<Rust>(source));
auto source = v8::ScriptCompiler::Source(contentStr, origin, nullptr);
auto module =
jsg::check(v8::ScriptCompiler::CompileModule(js.v8Isolate, &source, compileOptions));

auto codeCache = v8::ScriptCompiler::CreateCodeCache(module->GetUnboundModuleScript());
auto data = kj::arrayPtr(codeCache->data, codeCache->length).as<RustCopy>();
delete codeCache;
return data;
return js.tryCatch([&]() {
auto resourceName = jsg::newExternalOneByteString(js, kj::from<Rust>(path));
v8::ScriptOrigin origin(resourceName, resourceLineOffset, resourceColumnOffset,
resourceIsSharedCrossOrigin, scriptId, {}, resourceIsOpaque, isWasm, isModule);

auto contentStr = jsg::newExternalOneByteString(js, kj::from<Rust>(source));
auto source = v8::ScriptCompiler::Source(contentStr, origin, nullptr);
auto module =
jsg::check(v8::ScriptCompiler::CompileModule(js.v8Isolate, &source, compileOptions));

auto codeCache = v8::ScriptCompiler::CreateCodeCache(module->GetUnboundModuleScript());
auto data = kj::arrayPtr(codeCache->data, codeCache->length).as<RustCopy>();
delete codeCache;
return data;
}, [&](jsg::Value exception) -> ::rust::Vec<uint8_t> {
auto kjException = js.exceptionToKj(kj::mv(exception));
KJ_FAIL_REQUIRE("JavaScript compilation error", path, kjException.getDescription());
});
});
});

Expand Down
Loading