mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-21 16:12:40 +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) {
|
||||
var defaultValue = CCClass.getDefault(defaultValue);
|
||||
if (defaultValue.constructor === val.constructor) {
|
||||
if ((defaultValue && defaultValue.constructor) === val.constructor) {
|
||||
// fast case
|
||||
var targetExpression = LOCAL_OBJ + getPropAccessor(key);
|
||||
this.setValueType(codeArray, defaultValue, val, targetExpression);
|
||||
|
||||
@@ -262,6 +262,23 @@ function testInstantiate (module, match, instantiate) {
|
||||
|
||||
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',
|
||||
function (obj, expect, info) {
|
||||
|
||||
Reference in New Issue
Block a user