Merge pull request #1694 from jareguo/temp

fix instantiate-jit if type is wrong
This commit is contained in:
Wang Nan
2017-06-05 09:52:14 +08:00
committed by GitHub
2 changed files with 18 additions and 1 deletions
+1 -1
View File
@@ -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);
+17
View File
@@ -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) {