From f22e0ccf9a47aef6bdc2a5947d21e7464d7a791e Mon Sep 17 00:00:00 2001 From: "pengfei.zhou" Date: Tue, 2 Mar 2021 18:19:35 +0800 Subject: [PATCH] feat:fix debugger error when call context before connect to device --- doric-js/bundle/doric-vm.js | 11 ++++++++++- doric-js/index.debug.ts | 16 +++++++++++++++- doric-js/lib/index.debug.js | 11 ++++++++++- 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/doric-js/bundle/doric-vm.js b/doric-js/bundle/doric-vm.js index 721aa2d3..36da51c8 100644 --- a/doric-js/bundle/doric-vm.js +++ b/doric-js/bundle/doric-vm.js @@ -4347,6 +4347,7 @@ function initNativeEnvironment(source) { }); }); } +global$1.context = jsObtainContext("FakeContext"); const entryHooks = []; global$1.Entry = function () { var _a, _b, _c; @@ -4368,7 +4369,9 @@ global$1.Entry = function () { initNativeEnvironment(source).then(ret => { contextId = ret; console.log("debugging context id: " + contextId); - global$1.context = jsObtainContext(contextId); + const realContext = jsObtainContext(contextId); + global$1.context.id = contextId; + global$1.context = realContext; entryHooks.forEach(e => e(contextId)); }); return arguments[0]; @@ -4398,6 +4401,12 @@ global$1.nativeLog = (type, msg) => { } } }; +global$1.nativeRequire = () => { + console.error("Do not call nativeRequire here"); +}; +global$1.nativeBridge = () => { + console.error("Do not call nativeBridge here"); +}; exports.AnimationSet = AnimationSet; exports.BOTTOM = BOTTOM; diff --git a/doric-js/index.debug.ts b/doric-js/index.debug.ts index 31d83c59..e92d6930 100644 --- a/doric-js/index.debug.ts +++ b/doric-js/index.debug.ts @@ -16,6 +16,7 @@ import * as doric from './src/runtime/sandbox' import WebSocket from "ws" import path from 'path' +import { BridgeContext } from './src/runtime/global'; type MSG = { type: "D2C" | "C2D" | "C2S" | "D2S" | "S2C" | "S2D", @@ -136,6 +137,7 @@ async function initNativeEnvironment(source: string) { }) } +global.context = doric.jsObtainContext("FakeContext"); const entryHooks: Function[] = [] global.Entry = function () { if (!!contextId) { @@ -157,7 +159,9 @@ global.Entry = function () { initNativeEnvironment(source).then(ret => { contextId = ret; console.log("debugging context id: " + contextId); - global.context = doric.jsObtainContext(contextId); + const realContext = doric.jsObtainContext(contextId); + global.context.id = contextId; + global.context = realContext; entryHooks.forEach(e => e(contextId)) }); return arguments[0]; @@ -192,4 +196,14 @@ global.nativeLog = (type: string, msg: string) => { } } +global.nativeRequire = () => { + console.error("Do not call nativeRequire here"); + return false; +} + +global.nativeBridge = () => { + console.error("Do not call nativeBridge here"); + return false; +} + export * from './index' \ No newline at end of file diff --git a/doric-js/lib/index.debug.js b/doric-js/lib/index.debug.js index 3b0470c6..eeee32cd 100644 --- a/doric-js/lib/index.debug.js +++ b/doric-js/lib/index.debug.js @@ -147,6 +147,7 @@ function initNativeEnvironment(source) { }); }); } +global.context = doric.jsObtainContext("FakeContext"); const entryHooks = []; global.Entry = function () { var _a, _b, _c; @@ -168,7 +169,9 @@ global.Entry = function () { initNativeEnvironment(source).then(ret => { contextId = ret; console.log("debugging context id: " + contextId); - global.context = doric.jsObtainContext(contextId); + const realContext = doric.jsObtainContext(contextId); + global.context.id = contextId; + global.context = realContext; entryHooks.forEach(e => e(contextId)); }); return arguments[0]; @@ -198,4 +201,10 @@ global.nativeLog = (type, msg) => { } } }; +global.nativeRequire = () => { + console.error("Do not call nativeRequire here"); +}; +global.nativeBridge = () => { + console.error("Do not call nativeBridge here"); +}; export * from './index';