mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-01 07:42:38 +08:00
Merge pull request #1694 from jareguo/temp
fix instantiate-jit if type is wrong
This commit is contained in:
@@ -324,7 +324,7 @@ proto.enumerateCCClass = function (codeArray, obj, klass) {
|
|||||||
}
|
}
|
||||||
if (typeof val === 'object' && val instanceof cc.ValueType) {
|
if (typeof val === 'object' && val instanceof cc.ValueType) {
|
||||||
var defaultValue = CCClass.getDefault(defaultValue);
|
var defaultValue = CCClass.getDefault(defaultValue);
|
||||||
if (defaultValue.constructor === val.constructor) {
|
if ((defaultValue && defaultValue.constructor) === val.constructor) {
|
||||||
// fast case
|
// fast case
|
||||||
var targetExpression = LOCAL_OBJ + getPropAccessor(key);
|
var targetExpression = LOCAL_OBJ + getPropAccessor(key);
|
||||||
this.setValueType(codeArray, defaultValue, val, targetExpression);
|
this.setValueType(codeArray, defaultValue, val, targetExpression);
|
||||||
|
|||||||
@@ -262,6 +262,23 @@ function testInstantiate (module, match, instantiate) {
|
|||||||
|
|
||||||
cc.js.unregisterClass(Script);
|
cc.js.unregisterClass(Script);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('will not throw error if type is wrong', function () {
|
||||||
|
var Type = cc.Class({
|
||||||
|
properties: {
|
||||||
|
value: {
|
||||||
|
default: null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
var obj = new Type();
|
||||||
|
obj.value = cc.Vec2.ONE;
|
||||||
|
|
||||||
|
var cloned = instantiate(obj);
|
||||||
|
|
||||||
|
ok(cloned.value.equals(obj.value), 'same value');
|
||||||
|
});
|
||||||
}
|
}
|
||||||
testInstantiate('Instantiate',
|
testInstantiate('Instantiate',
|
||||||
function (obj, expect, info) {
|
function (obj, expect, info) {
|
||||||
|
|||||||
Reference in New Issue
Block a user