summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRyan Dahl <ry@tinyclouds.org>2018-08-06 18:37:32 -0400
committerRyan Dahl <ry@tinyclouds.org>2018-08-08 18:35:26 -0700
commit51380bf39936e0bcb1cb671bb20e961e1bb18e7d (patch)
tree3bed337aa9d2f63fe497f5e2ea826dd499b4b00b /src
parent4a1ccdeadb44983b8966c4623f10c5a665a39517 (diff)
Organize libdeno functions.
Diffstat (limited to 'src')
-rw-r--r--src/binding.cc30
-rw-r--r--src/deno_dir.rs3
2 files changed, 26 insertions, 7 deletions
diff --git a/src/binding.cc b/src/binding.cc
index 19448ca2a..7015660e3 100644
--- a/src/binding.cc
+++ b/src/binding.cc
@@ -103,6 +103,7 @@ void HandleException(v8::Local<v8::Context> context,
d->last_exception = exception_str;
} else {
printf("Pre-Deno Exception %s\n", exception_str.c_str());
+ exit(1);
}
}
@@ -278,7 +279,7 @@ void InitializeContext(v8::Isolate* isolate, v8::Local<v8::Context> context,
auto global = context->Global();
auto deno_val = v8::Object::New(isolate);
- CHECK(global->Set(context, deno::v8_str("deno"), deno_val).FromJust());
+ CHECK(global->Set(context, deno::v8_str("libdeno"), deno_val).FromJust());
auto print_tmpl = v8::FunctionTemplate::New(isolate, Print);
auto print_val = print_tmpl->GetFunction(context).ToLocalChecked();
@@ -295,17 +296,34 @@ void InitializeContext(v8::Isolate* isolate, v8::Local<v8::Context> context,
skip_onerror = true;
{
auto source = deno::v8_str(js_source.c_str());
- CHECK(global->Set(context, deno::v8_str("mainSource"), source).FromJust());
+ CHECK(
+ deno_val->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);
+ v8::TryCatch try_catch(isolate);
+ v8::ScriptOrigin origin(v8_str("set_source_map.js"));
+ std::string source_map_parens = "(" + *source_map + ")";
+ auto source_map_v8_str = deno::v8_str(source_map_parens.c_str());
+ auto script = v8::Script::Compile(context, source_map_v8_str, &origin);
+ if (script.IsEmpty()) {
+ DCHECK(try_catch.HasCaught());
+ HandleException(context, try_catch.Exception());
+ return;
+ }
+ auto source_map_obj = script.ToLocalChecked()->Run(context);
+ if (source_map_obj.IsEmpty()) {
+ DCHECK(try_catch.HasCaught());
+ HandleException(context, try_catch.Exception());
+ return;
+ }
+ CHECK(deno_val
+ ->Set(context, deno::v8_str("mainSourceMap"),
+ source_map_obj.ToLocalChecked())
+ .FromJust());
}
}
skip_onerror = false;
diff --git a/src/deno_dir.rs b/src/deno_dir.rs
index cabd9ed92..09f37933b 100644
--- a/src/deno_dir.rs
+++ b/src/deno_dir.rs
@@ -189,7 +189,8 @@ impl DenoDir {
base.join(module_specifier)?
};
- let mut p = j.to_file_path()
+ let mut p = j
+ .to_file_path()
.unwrap()
.into_os_string()
.into_string()