提交 665de54e 编写于 作者: fxy060608's avatar fxy060608

wip(uts): compiler

上级 743f94da
...@@ -165,8 +165,8 @@ function normalizeArg(arg) { ...@@ -165,8 +165,8 @@ function normalizeArg(arg) {
} }
return arg; return arg;
} }
function initUtsInstanceMethod(async, opts) { function initUtsInstanceMethod(async, opts, instanceId) {
return initProxyFunction(async, opts); return initProxyFunction(async, opts, instanceId);
} }
function getProxy() { function getProxy() {
if (!proxy) { if (!proxy) {
...@@ -235,7 +235,7 @@ function initUtsStaticMethod(async, opts) { ...@@ -235,7 +235,7 @@ function initUtsStaticMethod(async, opts) {
opts.method = 's_' + opts.name; opts.method = 's_' + opts.name;
} }
} }
return initProxyFunction(async, opts); return initProxyFunction(async, opts, 0);
} }
const initUtsProxyFunction = initUtsStaticMethod; const initUtsProxyFunction = initUtsStaticMethod;
function initUtsProxyClass({ package: pkg, class: cls, constructor: { params: constructorParams }, methods, props, staticProps, staticMethods, }) { function initUtsProxyClass({ package: pkg, class: cls, constructor: { params: constructorParams }, methods, props, staticProps, staticMethods, }) {
...@@ -247,7 +247,10 @@ function initUtsProxyClass({ package: pkg, class: cls, constructor: { params: co ...@@ -247,7 +247,10 @@ function initUtsProxyClass({ package: pkg, class: cls, constructor: { params: co
constructor(...params) { constructor(...params) {
const target = {}; const target = {};
// 初始化实例 ID // 初始化实例 ID
const instanceId = initProxyFunction(false, shared.extend({ name: 'constructor', params: constructorParams }, baseOptions)).apply(null, params); const instanceId = initProxyFunction(false, shared.extend({ name: 'constructor', params: constructorParams }, baseOptions), 0).apply(null, params);
if (!instanceId) {
throw new Error(`new ${cls} is failed`);
}
return new Proxy(this, { return new Proxy(this, {
get(_, name) { get(_, name) {
if (!target[name]) { if (!target[name]) {
...@@ -255,10 +258,9 @@ function initUtsProxyClass({ package: pkg, class: cls, constructor: { params: co ...@@ -255,10 +258,9 @@ function initUtsProxyClass({ package: pkg, class: cls, constructor: { params: co
if (shared.hasOwn(methods, name)) { if (shared.hasOwn(methods, name)) {
const { async, params } = methods[name]; const { async, params } = methods[name];
target[name] = initUtsInstanceMethod(!!async, shared.extend({ target[name] = initUtsInstanceMethod(!!async, shared.extend({
id: instanceId,
name, name,
params, params,
}, baseOptions)); }, baseOptions), instanceId);
} }
else if (props.includes(name)) { else if (props.includes(name)) {
// 实例属性 // 实例属性
......
...@@ -133,8 +133,8 @@ function normalizeArg(arg) { ...@@ -133,8 +133,8 @@ function normalizeArg(arg) {
} }
return arg; return arg;
} }
function initUtsInstanceMethod(async, opts) { function initUtsInstanceMethod(async, opts, instanceId) {
return initProxyFunction(async, opts); return initProxyFunction(async, opts, instanceId);
} }
function getProxy() { function getProxy() {
if (!proxy) { if (!proxy) {
...@@ -203,7 +203,7 @@ function initUtsStaticMethod(async, opts) { ...@@ -203,7 +203,7 @@ function initUtsStaticMethod(async, opts) {
opts.method = 's_' + opts.name; opts.method = 's_' + opts.name;
} }
} }
return initProxyFunction(async, opts); return initProxyFunction(async, opts, 0);
} }
const initUtsProxyFunction = initUtsStaticMethod; const initUtsProxyFunction = initUtsStaticMethod;
function initUtsProxyClass({ package: pkg, class: cls, constructor: { params: constructorParams }, methods, props, staticProps, staticMethods, }) { function initUtsProxyClass({ package: pkg, class: cls, constructor: { params: constructorParams }, methods, props, staticProps, staticMethods, }) {
...@@ -215,7 +215,10 @@ function initUtsProxyClass({ package: pkg, class: cls, constructor: { params: co ...@@ -215,7 +215,10 @@ function initUtsProxyClass({ package: pkg, class: cls, constructor: { params: co
constructor(...params) { constructor(...params) {
const target = {}; const target = {};
// 初始化实例 ID // 初始化实例 ID
const instanceId = initProxyFunction(false, extend({ name: 'constructor', params: constructorParams }, baseOptions)).apply(null, params); const instanceId = initProxyFunction(false, extend({ name: 'constructor', params: constructorParams }, baseOptions), 0).apply(null, params);
if (!instanceId) {
throw new Error(`new ${cls} is failed`);
}
return new Proxy(this, { return new Proxy(this, {
get(_, name) { get(_, name) {
if (!target[name]) { if (!target[name]) {
...@@ -223,10 +226,9 @@ function initUtsProxyClass({ package: pkg, class: cls, constructor: { params: co ...@@ -223,10 +226,9 @@ function initUtsProxyClass({ package: pkg, class: cls, constructor: { params: co
if (hasOwn(methods, name)) { if (hasOwn(methods, name)) {
const { async, params } = methods[name]; const { async, params } = methods[name];
target[name] = initUtsInstanceMethod(!!async, extend({ target[name] = initUtsInstanceMethod(!!async, extend({
id: instanceId,
name, name,
params, params,
}, baseOptions)); }, baseOptions), instanceId);
} }
else if (props.includes(name)) { else if (props.includes(name)) {
// 实例属性 // 实例属性
......
...@@ -17,8 +17,12 @@ export function normalizeArg(arg: unknown) { ...@@ -17,8 +17,12 @@ export function normalizeArg(arg: unknown) {
return arg return arg
} }
function initUtsInstanceMethod(async: boolean, opts: ProxyFunctionOptions) { function initUtsInstanceMethod(
return initProxyFunction(async, opts) async: boolean,
opts: ProxyFunctionOptions,
instanceId: number
) {
return initProxyFunction(async, opts, instanceId)
} }
interface Parameter { interface Parameter {
...@@ -165,7 +169,7 @@ function initProxyFunction( ...@@ -165,7 +169,7 @@ function initProxyFunction(
companion, companion,
params: methodParams, params: methodParams,
}: ProxyFunctionOptions, }: ProxyFunctionOptions,
instanceId?: number instanceId: number
) { ) {
const invokeCallback = ({ const invokeCallback = ({
id, id,
...@@ -221,7 +225,7 @@ function initUtsStaticMethod(async: boolean, opts: ProxyFunctionOptions) { ...@@ -221,7 +225,7 @@ function initUtsStaticMethod(async: boolean, opts: ProxyFunctionOptions) {
opts.method = 's_' + opts.name opts.method = 's_' + opts.name
} }
} }
return initProxyFunction(async, opts) return initProxyFunction(async, opts, 0)
} }
export const initUtsProxyFunction = initUtsStaticMethod export const initUtsProxyFunction = initUtsStaticMethod
...@@ -245,9 +249,12 @@ export function initUtsProxyClass({ ...@@ -245,9 +249,12 @@ export function initUtsProxyClass({
// 初始化实例 ID // 初始化实例 ID
const instanceId = initProxyFunction( const instanceId = initProxyFunction(
false, false,
extend({ name: 'constructor', params: constructorParams }, baseOptions) extend({ name: 'constructor', params: constructorParams }, baseOptions),
0
).apply(null, params) as number ).apply(null, params) as number
if (!instanceId) {
throw new Error(`new ${cls} is failed`)
}
return new Proxy(this, { return new Proxy(this, {
get(_, name) { get(_, name) {
if (!target[name as string]) { if (!target[name as string]) {
...@@ -258,12 +265,12 @@ export function initUtsProxyClass({ ...@@ -258,12 +265,12 @@ export function initUtsProxyClass({
!!async, !!async,
extend( extend(
{ {
id: instanceId,
name, name,
params, params,
}, },
baseOptions baseOptions
) ),
instanceId
) )
} else if (props.includes(name as string)) { } else if (props.includes(name as string)) {
// 实例属性 // 实例属性
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册