debugging add module support

This commit is contained in:
pengfei.zhou
2021-08-24 11:25:06 +08:00
committed by osborn
parent 0ffb14ec72
commit 20e6f5c96d
7 changed files with 65 additions and 4 deletions

View File

@@ -4644,6 +4644,18 @@ function initNativeEnvironment(source) {
const msg = JSON.parse(data);
const payload = msg.payload;
switch (msg.cmd) {
case "":
const { name, content } = payload;
Reflect.apply(jsRegisterModule, undefined, [
name,
Reflect.apply((function (__module) {
eval(`(function (module, exports, require) {
${content}
})(__module, __module.exports, doric.__require__)`);
return __module.exports;
}), undefined, [{ exports: {} }])
]);
break;
case "DEBUG_RES":
const contextId = msg.payload.contextId;
resolve(contextId);

View File

@@ -53,6 +53,24 @@ async function initNativeEnvironment(source: string) {
const msg = JSON.parse(data as string) as MSG
const payload = msg.payload
switch (msg.cmd) {
case "":
const { name, content } = payload as {
name: string,
content: string
}
Reflect.apply(
doric.jsRegisterModule,
undefined,
[
name,
Reflect.apply((function (__module: { exports: object }) {
eval(`(function (module, exports, require) {
${content}
})(__module, __module.exports, doric.__require__)`)
return __module.exports
}), undefined, [{ exports: {} }])
]);
break;
case "DEBUG_RES":
const contextId = msg.payload.contextId as string;
resolve(contextId);

View File

@@ -54,6 +54,18 @@ function initNativeEnvironment(source) {
const msg = JSON.parse(data);
const payload = msg.payload;
switch (msg.cmd) {
case "":
const { name, content } = payload;
Reflect.apply(doric.jsRegisterModule, undefined, [
name,
Reflect.apply((function (__module) {
eval(`(function (module, exports, require) {
${content}
})(__module, __module.exports, doric.__require__)`);
return __module.exports;
}), undefined, [{ exports: {} }])
]);
break;
case "DEBUG_RES":
const contextId = msg.payload.contextId;
resolve(contextId);