mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-20 23:52:40 +08:00
fix sync instantiate-jit (#7550)
* Refine type define * Fix TypedArray instantiation in Prefab (sync commit 0361c4eb4fe09021b8cecb8d2122fa05220e68fa) * resign instantiate-jit #5114
This commit is contained in:
@@ -354,6 +354,31 @@ class Parser {
|
||||
};
|
||||
this.objsToClear_iN$t.push(value);
|
||||
|
||||
for (let i = 0; i < value.length; ++i) {
|
||||
const statement = arrayVar + '[' + i + ']=';
|
||||
const expression = this.enumerateField(value, i, value[i]);
|
||||
writeAssignment(codeArray, statement, expression);
|
||||
}
|
||||
return codeArray;
|
||||
}
|
||||
|
||||
public instantiateTypedArray (value) {
|
||||
let type = value.constructor.name;
|
||||
if (value.length === 0) {
|
||||
return 'new ' + type;
|
||||
}
|
||||
|
||||
const arrayVar = LOCAL_ARRAY + (++this.localVariableId);
|
||||
const declaration = new Declaration(arrayVar, 'new ' + type + '(' + value.length + ')');
|
||||
const codeArray = [declaration];
|
||||
|
||||
// assign a _iN$t flag to indicate that this object has been parsed.
|
||||
value._iN$t = {
|
||||
globalVar: '', // the name of declared global variable used to access this object
|
||||
source: codeArray, // the source code array for this object
|
||||
};
|
||||
this.objsToClear_iN$t.push(value);
|
||||
|
||||
for (let i = 0; i < value.length; ++i) {
|
||||
if (value[i] !== 0) {
|
||||
const statement = arrayVar + '[' + i + ']=';
|
||||
@@ -384,6 +409,9 @@ class Parser {
|
||||
}
|
||||
return globalVar;
|
||||
}
|
||||
else if (ArrayBuffer.isView(value)) {
|
||||
return this.instantiateTypedArray(value);
|
||||
}
|
||||
else if (Array.isArray(value)) {
|
||||
return this.instantiateArray(value);
|
||||
}
|
||||
|
||||
@@ -435,11 +435,11 @@ function isTempClassId (id) {
|
||||
}
|
||||
|
||||
// id registration
|
||||
export const _idToClass: Record<string, Function> = createMap(true);
|
||||
export const _nameToClass: Record<string, Function> = createMap(true);
|
||||
export const _idToClass: Record<string, Constructor> = createMap(true);
|
||||
export const _nameToClass: Record<string, Constructor> = createMap(true);
|
||||
|
||||
function setup (tag: string, table: object) {
|
||||
return function (id: string, constructor: Function) {
|
||||
return function (id: string, constructor: Constructor) {
|
||||
// deregister old
|
||||
if (constructor.prototype.hasOwnProperty(tag)) {
|
||||
delete table[constructor.prototype[tag]];
|
||||
@@ -484,7 +484,7 @@ const doSetClassName = setup('__classname__', _nameToClass);
|
||||
* @param className
|
||||
* @param constructor
|
||||
*/
|
||||
export function setClassName (className: string, constructor: Function) {
|
||||
export function setClassName (className: string, constructor: Constructor) {
|
||||
doSetClassName(className, constructor);
|
||||
// auto set class id
|
||||
if (!constructor.prototype.hasOwnProperty(classIdTag)) {
|
||||
@@ -508,7 +508,7 @@ export function setClassName (className: string, constructor: Function) {
|
||||
* @param target Constructor of target class.
|
||||
* @param alias Alias to set. The name shall not have been set as class name or alias of another class.
|
||||
*/
|
||||
export function setClassAlias (target: Function, alias: string) {
|
||||
export function setClassAlias (target: Constructor, alias: string) {
|
||||
const nameRegistry = _nameToClass[alias];
|
||||
const idRegistry = _idToClass[alias];
|
||||
let ok = true;
|
||||
|
||||
Reference in New Issue
Block a user