@hippy/debug-server-next
Version:
Debug server for hippy.
142 lines (141 loc) • 6.32 kB
JavaScript
;
/*
* Tencent is pleased to support the open source community by making
* Hippy available.
*
* Copyright (C) 2017-2019 THL A29 Limited, a Tencent company.
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.runtimeMiddleWareManager = void 0;
const enum_chrome_mapping_1 = require("@hippy/devtools-protocol/dist/types/enum-chrome-mapping");
const global_id_1 = require("@debug-server-next/utils/global-id");
const debugger_middleware_1 = require("./debugger-middleware");
exports.runtimeMiddleWareManager = {
downwardMiddleWareListMap: {
[enum_chrome_mapping_1.ChromeEvent.RuntimeExecutionContextCreated]: ({ msg, sendToDevtools }) => {
var _a;
const eventRes = msg;
if ((_a = eventRes.params) === null || _a === void 0 ? void 0 : _a.context) {
if (!eventRes.params.context.origin) {
eventRes.params.context.origin = eventRes.params.context.name;
}
if (eventRes.params.context.frameId) {
eventRes.params.context.auxData = {
frameId: eventRes.params.context.frameId,
isDefault: true,
};
delete eventRes.params.context.frameId;
}
}
return sendToDevtools(eventRes);
},
[enum_chrome_mapping_1.ChromeCommand.RuntimeEvaluate]: ({ msg, sendToDevtools }) => {
var _a, _b, _c;
const lastScriptEval = (0, debugger_middleware_1.getLastScriptEval)();
const commandRes = msg;
if ((_a = commandRes.result) === null || _a === void 0 ? void 0 : _a.wasThrown) {
commandRes.result.result.subtype = 'error';
commandRes.result.exceptionDetails = {
exceptionId: 1,
text: commandRes.result.result.description,
url: '',
scriptId: lastScriptEval,
lineNumber: 1,
columnNumber: 0,
stackTrace: {
callFrames: [
{
functionName: '',
scriptId: lastScriptEval,
url: '',
lineNumber: 1,
columnNumber: 1,
},
],
},
};
}
else if ((_c = (_b = commandRes.result) === null || _b === void 0 ? void 0 : _b.result) === null || _c === void 0 ? void 0 : _c.preview) {
commandRes.result.result.preview.description = commandRes.result.result.description;
commandRes.result.result.preview.type = 'object';
}
return sendToDevtools(commandRes);
},
[enum_chrome_mapping_1.ChromeCommand.RuntimeGetProperties]: ({ msg, sendToDevtools }) => {
var _a;
const commandRes = msg;
const newPropertyDescriptors = [];
const properties = ((_a = commandRes.result) === null || _a === void 0 ? void 0 : _a.properties) || [];
for (let i = 0; i < (properties === null || properties === void 0 ? void 0 : properties.length); i += 1) {
if (properties[i].isOwn || properties[i].nativeGetter) {
properties[i].isOwn = true;
newPropertyDescriptors.push(properties[i]);
}
}
commandRes.result.result = null;
commandRes.result.result = newPropertyDescriptors;
return sendToDevtools(commandRes);
},
[enum_chrome_mapping_1.ChromeCommand.RuntimeEnable]: ({ msg, sendToDevtools }) => {
sendToDevtools({
method: enum_chrome_mapping_1.ChromeEvent.RuntimeExecutionContextCreated,
params: {
context: {
id: global_id_1.contextId.create(),
name: 'tdf',
origin: '',
},
},
});
return sendToDevtools(msg);
},
},
upwardMiddleWareListMap: {
[enum_chrome_mapping_1.ChromeCommand.RuntimeCompileScript]: async ({ msg, sendToDevtools }) => {
const convertedRes = {
id: msg.id,
method: msg.method,
result: {
scriptId: null,
exceptionDetails: null,
},
};
sendToDevtools(convertedRes);
return convertedRes;
},
[enum_chrome_mapping_1.ChromeCommand.RuntimeEvaluate]: async ({ msg, sendToApp }) => {
const req = msg;
return sendToApp({
id: req.id,
method: req.method,
params: {
expression: req.params.expression,
generatePreview: req.params.generatePreview,
includeCommandLineAPI: req.params.includeCommandLineAPI,
doNotPauseOnExceptionsAndMuteConsole: req.params.doNotPauseOnExceptionsAndMuteConsole,
objectGroup: req.params.objectGroup,
returnByValue: req.params.returnByValue,
saveResult: req.params.saveResult,
/**
* must set contextId is null, so the eval script will run in current JSContext
*/
// uniqueContextId: null,
// contextId: null,
},
});
},
},
};