feat:debug support multi entry and fix some bugs

This commit is contained in:
pengfeizhou 2021-02-24 19:13:19 +08:00 committed by osborn
parent 0e7f68a2c2
commit d56281a77f
6 changed files with 51 additions and 31 deletions

View File

@ -64,6 +64,7 @@ public class DoricDev {
} }
public void closeDevMode() { public void closeDevMode() {
stopDebugging(true);
if (wsClient != null) { if (wsClient != null) {
wsClient.close(); wsClient.close();
wsClient = null; wsClient = null;

View File

@ -50,12 +50,8 @@ - (void)startDebug {
} }
- (void)stopDebug:(BOOL)resume { - (void)stopDebug:(BOOL)resume {
id <DoricDriverProtocol> driver = self.doricContext.driver; self.doricContext.driver = self.nativeDriver;
if ([driver isKindOfClass:DoricDebugDriver.class]) {
}
if (resume) { if (resume) {
self.doricContext.driver = self.nativeDriver;
[self.doricContext reload:self.doricContext.script]; [self.doricContext reload:self.doricContext.script];
} }
} }
@ -76,6 +72,7 @@ @implementation DoricDev
- (instancetype)init { - (instancetype)init {
if (self = [super init]) { if (self = [super init]) {
_callbacks = [NSHashTable hashTableWithOptions:NSPointerFunctionsWeakMemory]; _callbacks = [NSHashTable hashTableWithOptions:NSPointerFunctionsWeakMemory];
_reloadingContexts = [NSHashTable hashTableWithOptions:NSPointerFunctionsWeakMemory];
[DoricNativeDriver.instance.registry registerMonitor:[DoricDevMonitor new]]; [DoricNativeDriver.instance.registry registerMonitor:[DoricDevMonitor new]];
} }
return self; return self;
@ -104,6 +101,7 @@ - (void)openDevMode {
} }
- (void)closeDevMode { - (void)closeDevMode {
[self stopDebugging:YES];
if (self.wsClient) { if (self.wsClient) {
[self.wsClient close]; [self.wsClient close];
self.wsClient = nil; self.wsClient = nil;

View File

@ -106,6 +106,7 @@ @implementation DoricDevViewController
- (void)viewDidLoad { - (void)viewDidLoad {
[super viewDidLoad]; [super viewDidLoad];
self.title = @"Doric Devkit"; self.title = @"Doric Devkit";
self.edgesForExtendedLayout = UIRectEdgeNone;
self.view.backgroundColor = UIColor.whiteColor; self.view.backgroundColor = UIColor.whiteColor;
self.headerView = [[UIView new] also:^(UIView *it) { self.headerView = [[UIView new] also:^(UIView *it) {
it.width = self.view.width; it.width = self.view.width;

View File

@ -4347,26 +4347,33 @@ function initNativeEnvironment(source) {
}); });
}); });
} }
const entryHooks = [];
global$2.Entry = function () { global$2.Entry = function () {
var _a, _b, _c; var _a, _b, _c;
if (!!contextId) { if (!!contextId) {
return Reflect.apply(jsObtainEntry(contextId), doric, arguments); return Reflect.apply(jsObtainEntry(contextId), doric, arguments);
} }
else { else {
const jsFile = (_c = (_b = (_a = new Error().stack) === null || _a === void 0 ? void 0 : _a.split("\n").map(e => e.match(/at\s__decorate\s\((.*?)\)/)).find(e => !!e)) === null || _b === void 0 ? void 0 : _b[1].match(/(.*?\.js)/)) === null || _c === void 0 ? void 0 : _c[1]; console.log(new Error().stack);
const jsFile = (_c = (_b = (_a = new Error().stack) === null || _a === void 0 ? void 0 : _a.split("\n").map(e => e.match(/at\s__decorate.*?\s\((.*?)\)/)).find(e => !!e)) === null || _b === void 0 ? void 0 : _b[1].match(/(.*?\.js)/)) === null || _c === void 0 ? void 0 : _c[1];
if (!jsFile) { if (!jsFile) {
throw new Error("Cannot find debugging file"); throw new Error("Cannot find debugging file");
} }
const source = path__default['default'].basename(jsFile);
const args = arguments; const args = arguments;
console.log(`Debugging ${source}`); entryHooks.push((contextId) => {
initNativeEnvironment(source).then(ret => {
contextId = ret;
console.log("debugging context id: " + contextId);
global$2.context = jsObtainContext(contextId);
Reflect.apply(jsObtainEntry(contextId), doric, args); Reflect.apply(jsObtainEntry(contextId), doric, args);
}); });
return arguments[0]; if (entryHooks.length <= 1) {
const source = path__default['default'].basename(jsFile);
console.log(`Debugging ${source}`);
initNativeEnvironment(source).then(ret => {
contextId = ret;
console.log("debugging context id: " + contextId);
global$2.context = jsObtainContext(contextId);
entryHooks.forEach(e => e(contextId));
});
return arguments[0];
}
} }
}; };
global$2.injectGlobal = (objName, obj) => { global$2.injectGlobal = (objName, obj) => {

View File

@ -136,27 +136,33 @@ async function initNativeEnvironment(source: string) {
}) })
} }
const entryHooks: Function[] = []
global.Entry = function () { global.Entry = function () {
if (!!contextId) { if (!!contextId) {
return Reflect.apply(doric.jsObtainEntry(contextId), doric, arguments); return Reflect.apply(doric.jsObtainEntry(contextId), doric, arguments);
} else { } else {
console.log(new Error().stack)
const jsFile = new Error().stack?.split("\n") const jsFile = new Error().stack?.split("\n")
.map(e => e.match(/at\s__decorate\s\((.*?)\)/)) .map(e => e.match(/at\s__decorate.*?\s\((.*?)\)/))
.find(e => !!e)?.[1].match(/(.*?\.js)/)?.[1]; .find(e => !!e)?.[1].match(/(.*?\.js)/)?.[1];
if (!jsFile) { if (!jsFile) {
throw new Error("Cannot find debugging file"); throw new Error("Cannot find debugging file");
} }
const source = path.basename(jsFile)
const args = arguments const args = arguments
console.log(`Debugging ${source}`) entryHooks.push((contextId: string) => {
initNativeEnvironment(source).then(ret => {
contextId = ret;
console.log("debugging context id: " + contextId);
global.context = doric.jsObtainContext(contextId);
Reflect.apply(doric.jsObtainEntry(contextId), doric, args); Reflect.apply(doric.jsObtainEntry(contextId), doric, args);
}); })
return arguments[0]; if (entryHooks.length <= 1) {
const source = path.basename(jsFile)
console.log(`Debugging ${source}`)
initNativeEnvironment(source).then(ret => {
contextId = ret;
console.log("debugging context id: " + contextId);
global.context = doric.jsObtainContext(contextId);
entryHooks.forEach(e => e(contextId))
});
return arguments[0];
}
} }
} }

View File

@ -147,26 +147,33 @@ function initNativeEnvironment(source) {
}); });
}); });
} }
const entryHooks = [];
global.Entry = function () { global.Entry = function () {
var _a, _b, _c; var _a, _b, _c;
if (!!contextId) { if (!!contextId) {
return Reflect.apply(doric.jsObtainEntry(contextId), doric, arguments); return Reflect.apply(doric.jsObtainEntry(contextId), doric, arguments);
} }
else { else {
const jsFile = (_c = (_b = (_a = new Error().stack) === null || _a === void 0 ? void 0 : _a.split("\n").map(e => e.match(/at\s__decorate\s\((.*?)\)/)).find(e => !!e)) === null || _b === void 0 ? void 0 : _b[1].match(/(.*?\.js)/)) === null || _c === void 0 ? void 0 : _c[1]; console.log(new Error().stack);
const jsFile = (_c = (_b = (_a = new Error().stack) === null || _a === void 0 ? void 0 : _a.split("\n").map(e => e.match(/at\s__decorate.*?\s\((.*?)\)/)).find(e => !!e)) === null || _b === void 0 ? void 0 : _b[1].match(/(.*?\.js)/)) === null || _c === void 0 ? void 0 : _c[1];
if (!jsFile) { if (!jsFile) {
throw new Error("Cannot find debugging file"); throw new Error("Cannot find debugging file");
} }
const source = path.basename(jsFile);
const args = arguments; const args = arguments;
console.log(`Debugging ${source}`); entryHooks.push((contextId) => {
initNativeEnvironment(source).then(ret => {
contextId = ret;
console.log("debugging context id: " + contextId);
global.context = doric.jsObtainContext(contextId);
Reflect.apply(doric.jsObtainEntry(contextId), doric, args); Reflect.apply(doric.jsObtainEntry(contextId), doric, args);
}); });
return arguments[0]; if (entryHooks.length <= 1) {
const source = path.basename(jsFile);
console.log(`Debugging ${source}`);
initNativeEnvironment(source).then(ret => {
contextId = ret;
console.log("debugging context id: " + contextId);
global.context = doric.jsObtainContext(contextId);
entryHooks.forEach(e => e(contextId));
});
return arguments[0];
}
} }
}; };
global.injectGlobal = (objName, obj) => { global.injectGlobal = (objName, obj) => {