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

@ -120,6 +120,11 @@ public class RemoteJSExecutor {
}
public void injectGlobalJSObject(String name, JavaValue javaValue) {
webSocket.send(new JSONBuilder().put("cmd", "injectGlobalJSObject")
.put("name", name)
.put("type", javaValue.getType())
.put("value", javaValue.getValue()).toString()
);
}
public JSDecoder invokeMethod(String objectName, String functionName, JavaValue[] javaValues, boolean hashKey) {

View File

@ -3752,14 +3752,6 @@ let global$2 = new Function('return this')();
global$2.doric = doric;
global$2.context = jsObtainContext(contextId);
global$2.Entry = jsObtainEntry(contextId);
global$2.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() {
@ -3778,6 +3770,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$2, messageObject.name, arg);
break;
case "injectGlobalJSFunction":
console.log(messageObject.name);
Reflect.set(global$2, messageObject.name, function () {

View File

@ -25,15 +25,6 @@ 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() {
@ -53,6 +44,27 @@ debugServer.on('connection', function connection(ws) {
ws.on('message', function incoming(message: string) {
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 () {

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 () {