Android support internal class

This commit is contained in:
pengfei.zhou
2020-09-04 18:22:45 +08:00
committed by osborn
parent a211ac8acb
commit 4df7df1327
16 changed files with 343 additions and 48 deletions

View File

@@ -2963,6 +2963,9 @@ function navigator(context) {
var moduleName = "navigator";
return {
push: function (source, config) {
if (typeof source === 'function') {
source = "_internal_://export?class=" + encodeURIComponent(source.name) + "&context=" + context.id;
}
if (config && config.extra) {
config.extra = JSON.stringify(config.extra);
}

View File

@@ -2295,6 +2295,9 @@ function navigator(context) {
const moduleName = "navigator";
return {
push: (source, config) => {
if (typeof source === 'function') {
source = `_internal_://export?class=${encodeURIComponent(source.name)}&context=${context.id}`;
}
if (config && config.extra) {
config.extra = JSON.stringify(config.extra);
}

View File

@@ -1280,6 +1280,7 @@ var doric = (function (exports) {
var Context = /** @class */ (function () {
function Context(id) {
this.callbacks = new Map;
this.classes = new Map;
this.id = id;
}
Context.prototype.hookBeforeNativeCall = function () {
@@ -1395,6 +1396,8 @@ var doric = (function (exports) {
function jsObtainEntry(contextId) {
var context = jsObtainContext(contextId);
var exportFunc = function (constructor) {
var _a;
(_a = context === null || context === void 0 ? void 0 : context.classes) === null || _a === void 0 ? void 0 : _a.set(constructor.name, constructor);
var ret = /** @class */ (function (_super) {
__extends(class_1, _super);
function class_1() {
@@ -1404,17 +1407,42 @@ var doric = (function (exports) {
}
return class_1;
}(constructor));
if (context) {
context.register(new ret);
}
context === null || context === void 0 ? void 0 : context.register(new ret);
return ret;
};
return function (args) {
if (args instanceof Array) {
return exportFunc;
return function () {
if (arguments.length === 1) {
var args = arguments[0];
if (args instanceof Array) {
args.forEach(function (clz) {
var _a;
(_a = context === null || context === void 0 ? void 0 : context.classes) === null || _a === void 0 ? void 0 : _a.set(clz.name, clz);
});
return exportFunc;
}
else {
return exportFunc(args);
}
}
else if (arguments.length === 2) {
var srcContextId = arguments[0];
var className = arguments[1];
var srcContext = gContexts.get(srcContextId);
if (srcContext) {
var clz = srcContext.classes.get(className);
if (clz) {
return exportFunc(clz);
}
else {
throw new Error("Cannot find class:" + className + " in context:" + srcContextId);
}
}
else {
throw new Error("Cannot find context for " + srcContextId);
}
}
else {
return exportFunc(args);
throw new Error("Entry arguments error:" + arguments);
}
};
}

View File

@@ -1256,6 +1256,7 @@ var doric = (function (exports) {
class Context {
constructor(id) {
this.callbacks = new Map;
this.classes = new Map;
this.id = id;
return new Proxy(this, {
get: (target, p) => {
@@ -1396,23 +1397,50 @@ var doric = (function (exports) {
function jsObtainEntry(contextId) {
const context = jsObtainContext(contextId);
const exportFunc = (constructor) => {
var _a;
(_a = context === null || context === void 0 ? void 0 : context.classes) === null || _a === void 0 ? void 0 : _a.set(constructor.name, constructor);
const ret = class extends constructor {
constructor() {
super(...arguments);
this.context = context;
}
};
if (context) {
context.register(new ret);
}
context === null || context === void 0 ? void 0 : context.register(new ret);
return ret;
};
return (args) => {
if (args instanceof Array) {
return exportFunc;
return function () {
if (arguments.length === 1) {
const args = arguments[0];
if (args instanceof Array) {
args.forEach(clz => {
var _a;
(_a = context === null || context === void 0 ? void 0 : context.classes) === null || _a === void 0 ? void 0 : _a.set(clz.name, clz);
});
return exportFunc;
}
else {
return exportFunc(args);
}
}
else if (arguments.length === 2) {
const srcContextId = arguments[0];
const className = arguments[1];
const srcContext = gContexts.get(srcContextId);
if (srcContext) {
const clz = srcContext.classes.get(className);
if (clz) {
return exportFunc(clz);
}
else {
throw new Error(`Cannot find class:${className} in context:${srcContextId}`);
}
}
else {
throw new Error(`Cannot find context for ${srcContextId}`);
}
}
else {
return exportFunc(args);
throw new Error(`Entry arguments error:${arguments}`);
}
};
}

View File

@@ -1279,6 +1279,7 @@ function jsCallReject(contextId, callbackId, args) {
class Context {
constructor(id) {
this.callbacks = new Map;
this.classes = new Map;
this.id = id;
return new Proxy(this, {
get: (target, p) => {
@@ -1419,23 +1420,50 @@ function jsCallEntityMethod(contextId, methodName, args) {
function jsObtainEntry(contextId) {
const context = jsObtainContext(contextId);
const exportFunc = (constructor) => {
var _a;
(_a = context === null || context === void 0 ? void 0 : context.classes) === null || _a === void 0 ? void 0 : _a.set(constructor.name, constructor);
const ret = class extends constructor {
constructor() {
super(...arguments);
this.context = context;
}
};
if (context) {
context.register(new ret);
}
context === null || context === void 0 ? void 0 : context.register(new ret);
return ret;
};
return (args) => {
if (args instanceof Array) {
return exportFunc;
return function () {
if (arguments.length === 1) {
const args = arguments[0];
if (args instanceof Array) {
args.forEach(clz => {
var _a;
(_a = context === null || context === void 0 ? void 0 : context.classes) === null || _a === void 0 ? void 0 : _a.set(clz.name, clz);
});
return exportFunc;
}
else {
return exportFunc(args);
}
}
else if (arguments.length === 2) {
const srcContextId = arguments[0];
const className = arguments[1];
const srcContext = gContexts.get(srcContextId);
if (srcContext) {
const clz = srcContext.classes.get(className);
if (clz) {
return exportFunc(clz);
}
else {
throw new Error(`Cannot find class:${className} in context:${srcContextId}`);
}
}
else {
throw new Error(`Cannot find context for ${srcContextId}`);
}
}
else {
return exportFunc(args);
throw new Error(`Entry arguments error:${arguments}`);
}
};
}
@@ -3762,6 +3790,9 @@ function navigator(context) {
const moduleName = "navigator";
return {
push: (source, config) => {
if (typeof source === 'function') {
source = `_internal_://export?class=${encodeURIComponent(source.name)}&context=${context.id}`;
}
if (config && config.extra) {
config.extra = JSON.stringify(config.extra);
}