feat: move global declare to @ms/ployfill
Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
34
packages/ployfill/src/global.ts
Normal file
34
packages/ployfill/src/global.ts
Normal file
@ -0,0 +1,34 @@
|
||||
import { XMLHttpRequest as xhr } from './xml-http-request'
|
||||
declare global {
|
||||
namespace NodeJS {
|
||||
interface Global {
|
||||
logger: any;
|
||||
debug: boolean;
|
||||
level: string;
|
||||
NashornEngineStartTime: number;
|
||||
setGlobal: (key: string, value: any) => void;
|
||||
noop: () => void;
|
||||
console: Console;
|
||||
}
|
||||
}
|
||||
var root: string;
|
||||
var base: Core;
|
||||
var XMLHttpRequest: typeof xhr;
|
||||
var ScriptEngineContextHolder: any;
|
||||
function engineLoad(str: string): any;
|
||||
interface Core {
|
||||
getClass(name: String): any;
|
||||
getProxyClass(): any;
|
||||
getInstance(): any;
|
||||
read(path: string): string;
|
||||
save(path: string, content: string): void;
|
||||
delete(path: string): void;
|
||||
}
|
||||
interface Console {
|
||||
ex(err: Error): void;
|
||||
stack(err: Error): string[];
|
||||
sender(...args: any): void;
|
||||
console(...args: any): void;
|
||||
}
|
||||
}
|
||||
export { }
|
@ -1,7 +1,17 @@
|
||||
import { XMLHttpRequest as xhr } from './xml-http-request'
|
||||
import './global'
|
||||
import '@ms/nashorn'
|
||||
import { XMLHttpRequest } from './xml-http-request'
|
||||
|
||||
var XMLHttpRequest = xhr;
|
||||
|
||||
export {
|
||||
XMLHttpRequest
|
||||
}
|
||||
let ployfillStartTime = new Date().getTime();
|
||||
console.info('Initialization Java Nashorn ployfill. Please wait...');
|
||||
// String contains ployfill
|
||||
Object.defineProperty(String.prototype, 'contains', {
|
||||
value: function(searchString: string, position: number) {
|
||||
return String.prototype.indexOf.call(this, searchString, position) > -1;
|
||||
}
|
||||
})
|
||||
// ES6 Map Symbol ployfill
|
||||
require('es6-map/implement');
|
||||
require('es6-symbol/implement');
|
||||
global.setGlobal('XMLHttpRequest', XMLHttpRequest)
|
||||
console.info('Java Nashorn ployfill loading completed... Cost (' + (new Date().getTime() - ployfillStartTime) / 1000 + 's)!');
|
||||
|
Reference in New Issue
Block a user