add global object inject

This commit is contained in:
王劲鹏
2020-01-19 10:32:59 +08:00
committed by osborn
parent 2a16350c2b
commit 8ee5d24912
4 changed files with 76 additions and 25 deletions

View File

@@ -24,14 +24,6 @@ let global = new Function('return this')();
global.doric = doric;
global.context = doric.jsObtainContext(contextId);
global.Entry = doric.jsObtainEntry(contextId);
global.Environment = {
'platform': 'debugger',
'platformVersion': '1.0',
'appName': '',
'appVersion': '',
'screenWidth': 0,
'screenHeight': 0
};
// dev kit client
const devClient = new WebSocketClient('ws://localhost:7777');
devClient.on('open', function open() {
@@ -50,6 +42,31 @@ debugServer.on('connection', function connection(ws) {
ws.on('message', function incoming(message) {
let messageObject = JSON.parse(message);
switch (messageObject.cmd) {
case "injectGlobalJSObject":
console.log(messageObject.name);
let type = messageObject.type;
let value = messageObject.value;
let arg;
if (type.type === 0) {
arg = null;
}
else if (type === 1) {
arg = parseFloat(value);
}
else if (type === 2) {
arg = (value == 'true');
}
else if (type === 3) {
arg = value.toString();
}
else if (type === 4) {
arg = JSON.parse(value);
}
else if (type === 5) {
arg = JSON.parse(value);
}
Reflect.set(global, messageObject.name, arg);
break;
case "injectGlobalJSFunction":
console.log(messageObject.name);
Reflect.set(global, messageObject.name, function () {