From 318a7cdcfd427b2a1c34f00b9a3338bdec375bea Mon Sep 17 00:00:00 2001 From: coding Date: Tue, 9 Jan 2018 11:28:00 +0000 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=AE=89=E5=85=A8=E8=B5=B7=E8=A7=81?= =?UTF-8?q?=E6=9A=82=E6=97=B6=E5=B1=8F=E8=94=BDload=E6=96=B9=E6=B3=95?= =?UTF-8?q?=E5=92=8Cdisable=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/pw/yumc/MiaoScript/ScriptEngine.java | 2 +- src/main/resources/core/init.js | 20 +++++++++++-------- src/main/resources/core/require.js | 4 ++-- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/main/java/pw/yumc/MiaoScript/ScriptEngine.java b/src/main/java/pw/yumc/MiaoScript/ScriptEngine.java index 15973ab..3fc03e9 100644 --- a/src/main/java/pw/yumc/MiaoScript/ScriptEngine.java +++ b/src/main/java/pw/yumc/MiaoScript/ScriptEngine.java @@ -43,7 +43,7 @@ public class ScriptEngine { @SneakyThrows public void disableEngine() { - engine.invokeFunction("disable"); + engine.invokeFunction("engineDisable"); } public MiaoScriptEngine getEngine() { diff --git a/src/main/resources/core/init.js b/src/main/resources/core/init.js index 6c3d502..3ab460d 100644 --- a/src/main/resources/core/init.js +++ b/src/main/resources/core/init.js @@ -35,9 +35,13 @@ * 初始化模块 */ function loadRequire() { + global.engineLoad = load; + global.load = function __denyGlobalLoad__() { + throw new Error('系统内部不许允许使用 load 如需执行脚本 请使用 engineLoad !'); + } // 初始化加载器 - global.require = load(root + '/core/require.js')(root); - global.requireInternal = function (name) { + global.require = engineLoad(root + '/core/require.js')(root); + global.requireInternal = function requireInternal(name) { return require(root + '/internal/' + DetectServerType + '/' + name + '.js'); } } @@ -61,16 +65,16 @@ */ function loadServerLib() { var task = require('api/task'); - global.setTimeout = function (func, time, _async) { + global.setTimeout = function setTimeout(func, time, _async) { return _async ? task.laterAsync(func, time) : task.later(func, time); }; - global.clearTimeout = function (task) { + global.clearTimeout = function clearTimeout(task) { task.cancel(); }; - global.setInterval = function (func, time, _async) { + global.setInterval = function setInterval(func, time, _async) { return _async ? task.timerAsync(func, time) : task.timer(func, time); }; - global.clearInterval = function (task) { + global.clearInterval = function clearInterval(task) { task.cancel(); }; } @@ -95,9 +99,9 @@ /** * 关闭插件Hook */ - global.disable = function disable() { + global.engineDisable = function disable() { if (global.manager && global.manager.$) { global.manager.disable(); } } -})(global); \ No newline at end of file +})(global); diff --git a/src/main/resources/core/require.js b/src/main/resources/core/require.js index ba7aa98..dc6ed15 100644 --- a/src/main/resources/core/require.js +++ b/src/main/resources/core/require.js @@ -204,7 +204,7 @@ } base.save(cacheFile, "(function __init__(module, exports, require, __dirname, __filename) {" + origin + "});"); // 使用 load 可以保留行号和文件名称 - var compiledWrapper = load(cacheFile); + var compiledWrapper = engineLoad(cacheFile); try { base.delete(cacheFile); } catch (ex) { @@ -267,4 +267,4 @@ var cacheModules = []; console.debug("初始化 require 模块组件 父目录 ", _canonical(parent)); return exports(parent); -}); \ No newline at end of file +});