diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/binding.cc | 13 | ||||
-rw-r--r-- | src/from_filesystem.cc | 2 | ||||
-rw-r--r-- | src/internal.h | 4 | ||||
-rw-r--r-- | src/snapshot_creator.cc | 17 |
4 files changed, 28 insertions, 8 deletions
diff --git a/src/binding.cc b/src/binding.cc index 1c4deaa23..19448ca2a 100644 --- a/src/binding.cc +++ b/src/binding.cc @@ -270,7 +270,8 @@ bool Execute(v8::Local<v8::Context> context, const char* js_filename, } void InitializeContext(v8::Isolate* isolate, v8::Local<v8::Context> context, - const char* js_filename, const char* js_source) { + const char* js_filename, const std::string& js_source, + const std::string* source_map) { v8::HandleScope handle_scope(isolate); v8::Context::Scope context_scope(context); @@ -293,11 +294,19 @@ void InitializeContext(v8::Isolate* isolate, v8::Local<v8::Context> context, skip_onerror = true; { - auto source = deno::v8_str(js_source); + auto source = deno::v8_str(js_source.c_str()); CHECK(global->Set(context, deno::v8_str("mainSource"), source).FromJust()); bool r = deno::ExecuteV8StringSource(context, js_filename, source); CHECK(r); + + if (source_map != nullptr) { + CHECK_GT(source_map->length(), 1u); + std::string set_source_map = "setMainSourceMap( " + *source_map + " )"; + CHECK_GT(set_source_map.length(), source_map->length()); + r = deno::Execute(context, "set_source_map.js", set_source_map.c_str()); + CHECK(r); + } } skip_onerror = false; } diff --git a/src/from_filesystem.cc b/src/from_filesystem.cc index a47808b82..797659de0 100644 --- a/src/from_filesystem.cc +++ b/src/from_filesystem.cc @@ -32,7 +32,7 @@ Deno* NewFromFileSystem(void* data, deno_recv_cb cb) { { v8::HandleScope handle_scope(isolate); auto context = v8::Context::New(isolate); - InitializeContext(isolate, context, BUNDLE_LOCATION, js_source.c_str()); + InitializeContext(isolate, context, BUNDLE_LOCATION, js_source, nullptr); d->context.Reset(d->isolate, context); } diff --git a/src/internal.h b/src/internal.h index dc28112dc..0719bdc3e 100644 --- a/src/internal.h +++ b/src/internal.h @@ -20,6 +20,7 @@ struct deno_s { // TODO(ry) Remove these when we call deno_reply_start from Rust. char** deno_argv(); int deno_argc(); +struct deno_s* deno_from_isolate(v8::Isolate* isolate); } namespace deno { @@ -38,7 +39,8 @@ static intptr_t external_references[] = {reinterpret_cast<intptr_t>(Print), Deno* NewFromSnapshot(void* data, deno_recv_cb cb); void InitializeContext(v8::Isolate* isolate, v8::Local<v8::Context> context, - const char* js_filename, const char* js_source); + const char* js_filename, const std::string& js_source, + const std::string* source_map); void AddIsolate(Deno* d, v8::Isolate* isolate); diff --git a/src/snapshot_creator.cc b/src/snapshot_creator.cc index f821565e5..8038c9b13 100644 --- a/src/snapshot_creator.cc +++ b/src/snapshot_creator.cc @@ -22,14 +22,16 @@ v8::StartupData SerializeInternalFields(v8::Local<v8::Object> holder, int index, return {payload, size}; } -v8::StartupData MakeSnapshot(const char* js_filename, const char* js_source) { +v8::StartupData MakeSnapshot(const char* js_filename, + const std::string& js_source, + const std::string* source_map) { auto* creator = new v8::SnapshotCreator(external_references); auto* isolate = creator->GetIsolate(); v8::Isolate::Scope isolate_scope(isolate); { v8::HandleScope handle_scope(isolate); auto context = v8::Context::New(isolate); - InitializeContext(isolate, context, js_filename, js_source); + InitializeContext(isolate, context, js_filename, js_source, source_map); creator->SetDefaultContext(context, v8::SerializeInternalFieldsCallback( SerializeInternalFields, nullptr)); } @@ -45,18 +47,25 @@ v8::StartupData MakeSnapshot(const char* js_filename, const char* js_source) { int main(int argc, char** argv) { const char* snapshot_out_bin = argv[1]; const char* js_fn = argv[2]; + const char* source_map_fn = argv[3]; // Optional. v8::V8::SetFlagsFromCommandLine(&argc, argv, true); - CHECK_EQ(argc, 3); CHECK_NE(js_fn, nullptr); CHECK_NE(snapshot_out_bin, nullptr); std::string js_source; CHECK(deno::ReadFileToString(js_fn, &js_source)); + std::string source_map; + if (source_map_fn != nullptr) { + CHECK_EQ(argc, 4); + CHECK(deno::ReadFileToString(source_map_fn, &source_map)); + } + deno_init(); - auto snapshot_blob = deno::MakeSnapshot(js_fn, js_source.c_str()); + auto snapshot_blob = deno::MakeSnapshot( + js_fn, js_source, source_map_fn != nullptr ? &source_map : nullptr); std::string snapshot_str(snapshot_blob.data, snapshot_blob.raw_size); std::ofstream file_(snapshot_out_bin, std::ios::binary); |