feat: use dom types and set Proxy global
Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
parent
bf33381e30
commit
0b6c174e42
@ -18,13 +18,13 @@ interface RequestConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function request(config: RequestConfig) {
|
function request(config: RequestConfig) {
|
||||||
// @ts-ignore
|
|
||||||
let xhr = new XMLHttpRequest();
|
let xhr = new XMLHttpRequest();
|
||||||
xhr.open(config.method, config.url, false);
|
xhr.open(config.method, config.url, false);
|
||||||
for (const header in config.headers) {
|
for (const header in config.headers) {
|
||||||
xhr.setRequestHeader(header, config.headers[header]);
|
xhr.setRequestHeader(header, config.headers[header]);
|
||||||
}
|
}
|
||||||
let future = xhr.send(config.data);
|
let future = xhr.send(config.data);
|
||||||
|
// @ts-ignore
|
||||||
return future.get();
|
return future.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
"extends": "../../tsconfig.json",
|
"extends": "../../tsconfig.json",
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"baseUrl": "src",
|
"baseUrl": "src",
|
||||||
"outDir": "dist",
|
"outDir": "dist"
|
||||||
"declaration": true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,4 +1,3 @@
|
|||||||
import { XMLHttpRequest as xhr } from './xml-http-request'
|
|
||||||
declare global {
|
declare global {
|
||||||
namespace NodeJS {
|
namespace NodeJS {
|
||||||
interface Global {
|
interface Global {
|
||||||
@ -13,7 +12,6 @@ declare global {
|
|||||||
}
|
}
|
||||||
var root: string;
|
var root: string;
|
||||||
var base: Core;
|
var base: Core;
|
||||||
var XMLHttpRequest: typeof xhr;
|
|
||||||
var ScriptEngineContextHolder: any;
|
var ScriptEngineContextHolder: any;
|
||||||
function engineLoad(str: string): any;
|
function engineLoad(str: string): any;
|
||||||
interface Core {
|
interface Core {
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import './global'
|
import './global'
|
||||||
import '@ms/nashorn'
|
import '@ms/nashorn'
|
||||||
|
import { Proxy } from './proxy'
|
||||||
import { XMLHttpRequest } from './xml-http-request'
|
import { XMLHttpRequest } from './xml-http-request'
|
||||||
|
|
||||||
let ployfillStartTime = new Date().getTime();
|
let ployfillStartTime = new Date().getTime();
|
||||||
@ -13,5 +14,6 @@ Object.defineProperty(String.prototype, 'contains', {
|
|||||||
// ES6 Map Symbol ployfill
|
// ES6 Map Symbol ployfill
|
||||||
require('es6-map/implement');
|
require('es6-map/implement');
|
||||||
require('es6-symbol/implement');
|
require('es6-symbol/implement');
|
||||||
|
global.setGlobal('Proxy', Proxy)
|
||||||
global.setGlobal('XMLHttpRequest', XMLHttpRequest)
|
global.setGlobal('XMLHttpRequest', XMLHttpRequest)
|
||||||
console.info('Java Nashorn ployfill loading completed... Cost (' + (new Date().getTime() - ployfillStartTime) / 1000 + 's)!');
|
console.info('Java Nashorn ployfill loading completed... Cost (' + (new Date().getTime() - ployfillStartTime) / 1000 + 's)!');
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
let createProxy = eval(`
|
let createProxy = eval(`
|
||||||
function(handle){ return new JSAdapter(handle) }
|
function(handle){ return new JSAdapter(handle) }
|
||||||
`)
|
`)
|
||||||
export interface ProxyHandle extends ProxyHandler<object> {
|
export interface ProxyHandle extends ProxyHandler<any> {
|
||||||
// get: (target: any, name: string) => any
|
// get: (target: any, name: string) => any
|
||||||
// set: (target: any, name: string, value: any) => boolean
|
// set: (target: any, name: string, value: any) => boolean
|
||||||
// construct: (target: any, ...args: any[]) => any
|
// construct: (target: any, ...args: any[]) => any
|
||||||
@ -19,7 +19,7 @@ export class Proxy {
|
|||||||
return createProxy({
|
return createProxy({
|
||||||
__get__: (name: string) => handle.get ? handle.get(target, name, undefined) : target[name],
|
__get__: (name: string) => handle.get ? handle.get(target, name, undefined) : target[name],
|
||||||
__put__: (name: string, value: any) => handle.set ? handle.set(target, name, value, undefined) : target[name] = value,
|
__put__: (name: string, value: any) => handle.set ? handle.set(target, name, value, undefined) : target[name] = value,
|
||||||
__call__: (name: string, ...args: any) => handle.apply ? handle.apply(target[name], target, args) : target[name].apply(target, args),
|
__call__: (name: string, ...args: any) => handle.apply ? handle.apply(target, name, args) : target[name].apply(target, args),
|
||||||
__new__: (...args: any) => handle.construct ? handle.construct(target, args, target) : new target(...args),
|
__new__: (...args: any) => handle.construct ? handle.construct(target, args, target) : new target(...args),
|
||||||
__getIds__: () => handle.ownKeys ? handle.ownKeys(target) : Object.keys(target),
|
__getIds__: () => handle.ownKeys ? handle.ownKeys(target) : Object.keys(target),
|
||||||
__getValues__: () => handle.values ? handle.values(target) : Object.values(target),
|
__getValues__: () => handle.values ? handle.values(target) : Object.values(target),
|
Loading…
Reference in New Issue
Block a user