Skip to content
Draft
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
3 changes: 3 additions & 0 deletions module.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <Python.h>

#include "third-party/quickjs.h"
#include "third-party/quickjs-libc.h"

// The data of the type _quickjs.Context.
typedef struct {
Expand Down Expand Up @@ -261,6 +262,8 @@ static PyObject *context_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
self->context = JS_NewContext(self->runtime);
self->has_time_limit = 0;
self->time_limit = 0;

JS_SetModuleLoaderFunc(self->runtime, NULL, js_module_loader, NULL);
}
return (PyObject *)self;
}
Expand Down
4 changes: 4 additions & 0 deletions test_module.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

export function value() {
return 42;
}
10 changes: 8 additions & 2 deletions test_quickjs.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,17 @@ def test_get(self):
self.assertEqual(self.context.get("z"), None)

def test_module(self):
self.context.module("""
self.context.module("""
import { value } from "./test_module.js";
export function test() {
return 42;
return value();
}

// export to the global context scope.
globalThis.test = test;
""")
test = self.context.get("test")
self.assertEqual(test(), 42)

def test_error(self):
with self.assertRaisesRegex(quickjs.JSException, "ReferenceError: missing is not defined"):
Expand Down
Loading