add global object inject
This commit is contained in:
parent
2a16350c2b
commit
8ee5d24912
@ -120,6 +120,11 @@ public class RemoteJSExecutor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void injectGlobalJSObject(String name, JavaValue javaValue) {
|
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) {
|
public JSDecoder invokeMethod(String objectName, String functionName, JavaValue[] javaValues, boolean hashKey) {
|
||||||
|
@ -3752,14 +3752,6 @@ let global$2 = new Function('return this')();
|
|||||||
global$2.doric = doric;
|
global$2.doric = doric;
|
||||||
global$2.context = jsObtainContext(contextId);
|
global$2.context = jsObtainContext(contextId);
|
||||||
global$2.Entry = jsObtainEntry(contextId);
|
global$2.Entry = jsObtainEntry(contextId);
|
||||||
global$2.Environment = {
|
|
||||||
'platform': 'debugger',
|
|
||||||
'platformVersion': '1.0',
|
|
||||||
'appName': '',
|
|
||||||
'appVersion': '',
|
|
||||||
'screenWidth': 0,
|
|
||||||
'screenHeight': 0
|
|
||||||
};
|
|
||||||
// dev kit client
|
// dev kit client
|
||||||
const devClient = new WebSocketClient('ws://localhost:7777');
|
const devClient = new WebSocketClient('ws://localhost:7777');
|
||||||
devClient.on('open', function open() {
|
devClient.on('open', function open() {
|
||||||
@ -3778,6 +3770,31 @@ debugServer.on('connection', function connection(ws) {
|
|||||||
ws.on('message', function incoming(message) {
|
ws.on('message', function incoming(message) {
|
||||||
let messageObject = JSON.parse(message);
|
let messageObject = JSON.parse(message);
|
||||||
switch (messageObject.cmd) {
|
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":
|
case "injectGlobalJSFunction":
|
||||||
console.log(messageObject.name);
|
console.log(messageObject.name);
|
||||||
Reflect.set(global$2, messageObject.name, function () {
|
Reflect.set(global$2, messageObject.name, function () {
|
||||||
|
@ -25,15 +25,6 @@ global.doric = doric
|
|||||||
global.context = doric.jsObtainContext(contextId)
|
global.context = doric.jsObtainContext(contextId)
|
||||||
global.Entry = doric.jsObtainEntry(contextId)
|
global.Entry = doric.jsObtainEntry(contextId)
|
||||||
|
|
||||||
global.Environment = {
|
|
||||||
'platform': 'debugger',
|
|
||||||
'platformVersion': '1.0',
|
|
||||||
'appName': '',
|
|
||||||
'appVersion': '',
|
|
||||||
'screenWidth': 0,
|
|
||||||
'screenHeight': 0
|
|
||||||
}
|
|
||||||
|
|
||||||
// dev kit client
|
// dev kit client
|
||||||
const devClient = new WebSocketClient('ws://localhost:7777')
|
const devClient = new WebSocketClient('ws://localhost:7777')
|
||||||
devClient.on('open', function open() {
|
devClient.on('open', function open() {
|
||||||
@ -53,6 +44,27 @@ debugServer.on('connection', function connection(ws) {
|
|||||||
ws.on('message', function incoming(message: string) {
|
ws.on('message', function incoming(message: string) {
|
||||||
let messageObject = JSON.parse(message)
|
let messageObject = JSON.parse(message)
|
||||||
switch (messageObject.cmd) {
|
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":
|
case "injectGlobalJSFunction":
|
||||||
console.log(messageObject.name)
|
console.log(messageObject.name)
|
||||||
Reflect.set(global, messageObject.name, function () {
|
Reflect.set(global, messageObject.name, function () {
|
||||||
|
@ -24,14 +24,6 @@ let global = new Function('return this')();
|
|||||||
global.doric = doric;
|
global.doric = doric;
|
||||||
global.context = doric.jsObtainContext(contextId);
|
global.context = doric.jsObtainContext(contextId);
|
||||||
global.Entry = doric.jsObtainEntry(contextId);
|
global.Entry = doric.jsObtainEntry(contextId);
|
||||||
global.Environment = {
|
|
||||||
'platform': 'debugger',
|
|
||||||
'platformVersion': '1.0',
|
|
||||||
'appName': '',
|
|
||||||
'appVersion': '',
|
|
||||||
'screenWidth': 0,
|
|
||||||
'screenHeight': 0
|
|
||||||
};
|
|
||||||
// dev kit client
|
// dev kit client
|
||||||
const devClient = new WebSocketClient('ws://localhost:7777');
|
const devClient = new WebSocketClient('ws://localhost:7777');
|
||||||
devClient.on('open', function open() {
|
devClient.on('open', function open() {
|
||||||
@ -50,6 +42,31 @@ debugServer.on('connection', function connection(ws) {
|
|||||||
ws.on('message', function incoming(message) {
|
ws.on('message', function incoming(message) {
|
||||||
let messageObject = JSON.parse(message);
|
let messageObject = JSON.parse(message);
|
||||||
switch (messageObject.cmd) {
|
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":
|
case "injectGlobalJSFunction":
|
||||||
console.log(messageObject.name);
|
console.log(messageObject.name);
|
||||||
Reflect.set(global, messageObject.name, function () {
|
Reflect.set(global, messageObject.name, function () {
|
||||||
|
Reference in New Issue
Block a user