Crash on dynamic import in interactive interpreter
System information
What is your operating system and version? Fedora Toolbox 34
What is your version of GJS? commit 124c196a
Bug information
Importing a module dynamically from the interactive interpreter causes a crash. The problem doesn't occur with the same code in a file or with the -c
command line switch.
Steps to reproduce
- Start the
gjs
interactive interpreter import('system').then(log).catch(logError);
Current behaviour
Crash:
Assertion failure: isObject(), at /usr/include/mozjs-78/js/Value.h:745
Segmentation fault (core dumped)
Stack trace:
#0 0x00007ffff7e0297d in JS::Value::toObject() const (this=0x7fffffffb310)
at /usr/include/mozjs-78/js/Value.h:745
#1 0x00007ffff7e046b0 in js::WrappedPtrOperations<JS::Value, JS::Handle<JS::Value> >::toObject() const (this=0x7fffffffb090)
at /usr/include/mozjs-78/js/Value.h:1182
#2 0x00007ffff7ea0c05 in gjs_dynamic_module_resolve(JSContext*, JS::Handle<JS::Value>, JS::Handle<JSString*>, JS::Handle<JSObject*>)
(cx=0x447860, importing_module_priv=..., specifier=..., internal_promise=...) at ../gjs/module.cpp:629
#3 0x00007ffff61536aa in js::StartDynamicModuleImport(JSContext*, JS::Handle<JSScript*>, JS::Handle<JS::Value>) (cx=0x7ffff77754c0, script=...,
script@entry=..., specifierArg=..., specifierArg@entry=...)
at /var/home/ptomato/workspace/mozjs/js/src/builtin/ModuleObject.cpp:1774
#4 0x00007ffff60b4811 in Interpret(JSContext*, js::RunState&)
(cx=0x7ffff77754c0, cx@entry=0x447860, state=<optimized out>)
at /var/home/ptomato/workspace/mozjs/js/src/vm/Interpreter.cpp:4445
#5 0x00007ffff60a2a17 in js::RunScript(JSContext*, js::RunState&)
(cx=cx@entry=0x447860, state=...)
at /var/home/ptomato/workspace/mozjs/js/src/vm/Interpreter.cpp:465
#6 0x00007ffff60b87c9 in js::ExecuteKernel(JSContext*, JS::Handle<JSScript*>, JS::Handle<JSObject*>, JS::Handle<JS::Value>, js::AbstractFramePtr, JS::MutableHandle<JS::Value>)
(cx=cx@entry=0x447860, script=script@entry=..., envChainArg=envChainArg@entry=..., newTargetValue=..., evalInFrame=evalInFrame@entry=..., result=...)
at /var/home/ptomato/workspace/mozjs/js/src/vm/Interpreter.cpp:840
#7 0x00007ffff60b8ed9 in js::Execute(JSContext*, JS::Handle<JSScript*>, JS::Handle<JSObject*>, JS::MutableHandle<JS::Value>)
(cx=cx@entry=0x447860, script=...,
script@entry=..., envChain=envChain@entry=..., rval=..., rval@entry=...)
at /var/home/ptomato/workspace/mozjs/js/src/vm/Interpreter.cpp:872
#8 0x00007ffff6281aeb in EvaluateSourceBuffer<mozilla::Utf8Unit>(JSContext*, js::ScopeKind, JS::Handle<JSObject*>, JS::ReadOnlyCompileOptions const&, JS::SourceText<mozilla::Utf8Unit>&, JS::MutableHandle<JS::Value>)
(cx=0x447860, scopeKind=js::ScopeKind::Global, env=..., optionsArg=<optimized out>, srcBuf=<optimized out>, rval=...)
at /var/home/ptomato/workspace/mozjs/js/src/vm/CompilationAndEvaluation.cpp:498
#9 JS::Evaluate(JSContext*, JS::ReadOnlyCompileOptions const&, JS::SourceText<mozilla::Utf8Unit>&, JS::MutableHandle<JS::Value>)
(cx=0x447860, options=<optimized out>, srcBuf=<optimized out>, rval=...)
at /var/home/ptomato/workspace/mozjs/js/src/vm/CompilationAndEvaluation.cpp:506
#10 0x00007ffff7eaa9bc in gjs_console_eval_and_print(JSContext*, std::string const&, int) (cx=0x447860, bytes="import('system').catch(logError)\n", lineno=2)
at ../modules/console.cpp:167
(rest of stack trace irrelevant)
Expected behaviour
The result should be the same as what happens when you run the same code from a file, or from the command line with -c
:
Gjs-Message: 22:00:10.493: JS LOG: <cannot convert value to string>
(indicating the module was imported and the module object logged)