I have a script including another script and if the included script has 
errors, the inner `v8::TryCatch` object reports the outer script in the 
returned `v8::Message` instance. 

I set up the usual v8 callbacks and the outer script looks like this:

var app = new MyApp();

try {
    app.include("bad-script");
}
catch (err) {
   log("EXPECTED: bad-script: " + err);
}

The inner script is intentionally broken and in this case calls a 
non-existing function, but I also tried the same with broken syntax and the 
only difference is whether `v8::Script::Compile` reports an error or 
`v8::Script::Run`. 

// this function isn't defined anywhere
bad_call();

The C++ code looks like this (the v8 callback machinery is omitted for 
brevity). This is the code that runs the first script:

v8::Global<v8::Context> context;
v8::TryCatch try_catch(isolate);

v8::Local<v8::String> v8script = v8::String::NewFromUtf8(isolate, script.
c_str()).ToLocalChecked();
v8::Local<v8::Script> compiled_script;

v8::ScriptOrigin script_origin(v8::String::NewFromUtf8(isolate, "Script A"
));

if (!v8::Script::Compile(context.Get(isolate), v8script, &script_origin).
ToLocal(&compiled_script)) {
    ...
}

v8::Local<v8::Value> result;
if (!compiled_script->Run(scriptContext.Get(isolate)).ToLocal(&result)) {
    ...
}

This is the callback implementing the `include` method:

void MyApp::include(v8::Isolate *isolate, v8::Local<v8::String> name)
{
    v8::TryCatch try_catch(isolate);

    v8::Local<v8::String> v8script = v8::String::NewFromUtf8(isolate, 
"bad_call()").ToLocalChecked();

    v8::Local<v8::Script> compiled_script;
    v8::ScriptOrigin script_origin(name);

    if (!v8::Script::Compile(isolate->GetCurrentContext(), v8script, &
script_origin).ToLocal(&compiled_script)) {
        // same as in the Run call below if script contains syntax errors
        ...
    }

    v8::Local<v8::Value> result;
    if (!compiled_script->Run(isolate->GetCurrentContext()).ToLocal(&result
)) {
        v8::Local<v8::Message> errinfo = try_catch.Message();

        // srcline contains "app.include("bad-script");"
        v8::String::Utf8Value srcline(errinfo->GetSourceLine(isolate->
GetCurrentContext()).ToLocalChecked());

        // resname contains "Script A" instead of "bad-script"
        v8::String::Utf8Value resname(errinfo->GetScriptResourceName());
    }
}

I realize that only functions are associated with the specific script 
origin and if I call broken functions from "Script A", I get the proper 
script resource name in the main script processor, but in the case like the 
one above, there appears to be no way to figure out what went wrong and 
where in the included script. Any advice on how to get my hands on the 
source line of a broken included script?

Thanks!


-- 
-- 
v8-users mailing list
v8-users@googlegroups.com
http://groups.google.com/group/v8-users
--- 
You received this message because you are subscribed to the Google Groups 
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to v8-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to