feat: add console to global runtime

This commit is contained in:
pengfei.zhou 2021-11-29 10:29:26 +08:00 committed by osborn
parent 8ebccdc3fe
commit c11f0e79db
8 changed files with 125 additions and 4 deletions

View File

@ -40,6 +40,22 @@ var doric = (function (exports) {
return message.toString();
}
}
function log$9() {
var arguments$1 = arguments;
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments$1[_i];
}
var out = "";
for (var i = 0; i < arguments.length; i++) {
if (i > 0) {
out += ',';
}
out += toString$2(arguments$1[i]);
}
nativeLog('d', out);
}
function loge() {
var arguments$1 = arguments;
@ -56,6 +72,22 @@ var doric = (function (exports) {
}
nativeLog('e', out);
}
function logw() {
var arguments$1 = arguments;
var message = [];
for (var _i = 0; _i < arguments.length; _i++) {
message[_i] = arguments$1[_i];
}
var out = "";
for (var i = 0; i < arguments.length; i++) {
if (i > 0) {
out += ',';
}
out += toString$2(arguments$1[i]);
}
nativeLog('w', out);
}
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
@ -1462,6 +1494,13 @@ var doric = (function (exports) {
};
}
var global$2 = Function('return this')();
if (!Reflect.has(global$2, "console")) {
Reflect.set(global$2, "console", {
warn: logw,
error: loge,
log: log$9
});
}
var __timerId__ = 1;
var timerInfos = new Map;
var _setTimeout = global$2.setTimeout;

View File

@ -40,6 +40,16 @@ var doric = (function (exports) {
return message.toString();
}
}
function log(...args) {
let out = "";
for (let i = 0; i < arguments.length; i++) {
if (i > 0) {
out += ',';
}
out += toString(arguments[i]);
}
nativeLog('d', out);
}
function loge(...message) {
let out = "";
for (let i = 0; i < arguments.length; i++) {
@ -50,6 +60,16 @@ var doric = (function (exports) {
}
nativeLog('e', out);
}
function logw(...message) {
let out = "";
for (let i = 0; i < arguments.length; i++) {
if (i > 0) {
out += ',';
}
out += toString(arguments[i]);
}
nativeLog('w', out);
}
/*! *****************************************************************************
Copyright (C) Microsoft. All rights reserved.
@ -1458,6 +1478,13 @@ var doric = (function (exports) {
};
}
const global$1 = Function('return this')();
if (!Reflect.has(global$1, "console")) {
Reflect.set(global$1, "console", {
warn: logw,
error: loge,
log: log
});
}
let __timerId__ = 1;
const timerInfos = new Map;
const _setTimeout = global$1.setTimeout;

View File

@ -1487,6 +1487,13 @@ function jsObtainEntry(contextId) {
};
}
const global$2 = Function('return this')();
if (!Reflect.has(global$2, "console")) {
Reflect.set(global$2, "console", {
warn: logw,
error: loge,
log: log
});
}
let __timerId__ = 1;
const timerInfos = new Map;
const _setTimeout = global$2.setTimeout;

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
import { uniqueId } from "../util/uniqueId";
import { loge } from "../util/log";
import { loge, logw, log } from "../util/log";
import "reflect-metadata";
function hookBeforeNativeCall(context) {
if (context) {
@ -276,6 +276,13 @@ export function jsObtainEntry(contextId) {
};
}
const global = Function('return this')();
if (!Reflect.has(global, "console")) {
Reflect.set(global, "console", {
warn: logw,
error: loge,
log: log
});
}
let __timerId__ = 1;
const timerInfos = new Map;
const _setTimeout = global.setTimeout;

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
import { uniqueId } from "../util/uniqueId";
import { loge } from "../util/log";
import { loge, logw, log } from "../util/log";
import "reflect-metadata"
/**
@ -295,6 +295,13 @@ export function jsObtainEntry(contextId: string) {
}
const global = Function('return this')()
if (!Reflect.has(global, "console")) {
Reflect.set(global, "console", {
warn: logw,
error: loge,
log: log
})
}
let __timerId__ = 1
const timerInfos: Map<number, { callback: () => void, context?: Context }> = new Map

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
import { uniqueId } from "../util/uniqueId";
import { loge } from "../util/log";
import { loge, logw, log } from "../util/log";
import "reflect-metadata"
/**
@ -334,6 +334,13 @@ export function jsObtainEntry(contextId: string) {
}
const global = Function('return this')()
if (!Reflect.has(global, "console")) {
Reflect.set(global, "console", {
warn: logw,
error: loge,
log: log
})
}
let __timerId__ = 1
const timerInfos: Map<number, { callback: () => void, context?: Context }> = new Map

View File

@ -42,6 +42,16 @@ var doric = (function (exports) {
return message.toString();
}
}
function log(...args) {
let out = "";
for (let i = 0; i < arguments.length; i++) {
if (i > 0) {
out += ',';
}
out += toString(arguments[i]);
}
nativeLog('d', out);
}
function loge(...message) {
let out = "";
for (let i = 0; i < arguments.length; i++) {
@ -52,6 +62,16 @@ var doric = (function (exports) {
}
nativeLog('e', out);
}
function logw(...message) {
let out = "";
for (let i = 0; i < arguments.length; i++) {
if (i > 0) {
out += ',';
}
out += toString(arguments[i]);
}
nativeLog('w', out);
}
/*! *****************************************************************************
Copyright (C) Microsoft. All rights reserved.
@ -1460,6 +1480,13 @@ var doric = (function (exports) {
};
}
const global$1 = Function('return this')();
if (!Reflect.has(global$1, "console")) {
Reflect.set(global$1, "console", {
warn: logw,
error: loge,
log: log
});
}
let __timerId__ = 1;
const timerInfos = new Map;
const _setTimeout = global$1.setTimeout;

File diff suppressed because one or more lines are too long