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() {
stopDebugging(true);
if (wsClient != null) {
wsClient.close();
wsClient = null;

View File

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

View File

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

View File

@ -4347,27 +4347,34 @@ function initNativeEnvironment(source) {
});
});
}
const entryHooks = [];
global$2.Entry = function () {
var _a, _b, _c;
if (!!contextId) {
return Reflect.apply(jsObtainEntry(contextId), doric, arguments);
}
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) {
throw new Error("Cannot find debugging file");
}
const source = path__default['default'].basename(jsFile);
const args = arguments;
entryHooks.push((contextId) => {
Reflect.apply(jsObtainEntry(contextId), doric, args);
});
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);
Reflect.apply(jsObtainEntry(contextId), doric, args);
entryHooks.forEach(e => e(contextId));
});
return arguments[0];
}
}
};
global$2.injectGlobal = (objName, obj) => {
Reflect.set(global$2, objName, JSON.parse(obj));

View File

@ -136,28 +136,34 @@ async function initNativeEnvironment(source: string) {
})
}
const entryHooks: Function[] = []
global.Entry = function () {
if (!!contextId) {
return Reflect.apply(doric.jsObtainEntry(contextId), doric, arguments);
} else {
console.log(new Error().stack)
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];
if (!jsFile) {
throw new Error("Cannot find debugging file");
}
const source = path.basename(jsFile)
const args = arguments
entryHooks.push((contextId: string) => {
Reflect.apply(doric.jsObtainEntry(contextId), doric, args);
})
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);
Reflect.apply(doric.jsObtainEntry(contextId), doric, args);
entryHooks.forEach(e => e(contextId))
});
return arguments[0];
}
}
}
global.injectGlobal = (objName: string, obj: string) => {

View File

@ -147,27 +147,34 @@ function initNativeEnvironment(source) {
});
});
}
const entryHooks = [];
global.Entry = function () {
var _a, _b, _c;
if (!!contextId) {
return Reflect.apply(doric.jsObtainEntry(contextId), doric, arguments);
}
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) {
throw new Error("Cannot find debugging file");
}
const source = path.basename(jsFile);
const args = arguments;
entryHooks.push((contextId) => {
Reflect.apply(doric.jsObtainEntry(contextId), doric, args);
});
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);
Reflect.apply(doric.jsObtainEntry(contextId), doric, args);
entryHooks.forEach(e => e(contextId));
});
return arguments[0];
}
}
};
global.injectGlobal = (objName, obj) => {
Reflect.set(global, objName, JSON.parse(obj));