mirror of
https://gitee.com/openharmony/arkui_ace_engine
synced 2024-11-27 09:12:41 +00:00
!43993 Second attempt: Fix for @Prop accepting V2 proxied value
Merge pull request !43993 from hennamyllys/fix_prop_interoperability
This commit is contained in:
commit
8b80c8f770
@ -4893,9 +4893,16 @@ class ObservedPropertyAbstractPU extends ObservedPropertyAbstract {
|
||||
FIXME this expects the Map, Set patch to go in
|
||||
*/
|
||||
checkIsSupportedValue(value) {
|
||||
let res = ((typeof value === 'object' && typeof value !== 'function' && !ObserveV2.IsObservedObjectV2(value) &&
|
||||
!ObserveV2.IsMakeObserved(value)) || typeof value === 'number' || typeof value === 'string' ||
|
||||
typeof value === 'boolean' || value === undefined || value === null);
|
||||
let res = ((typeof value === 'object' && typeof value !== 'function'
|
||||
&& !ObserveV2.IsObservedObjectV2(value)
|
||||
&& !ObserveV2.IsMakeObserved(value))
|
||||
// FIXME enable the check when V1-V2 interoperability is forbidden
|
||||
// && !ObserveV2.IsProxiedObservedV2(value))
|
||||
|| typeof value === 'number'
|
||||
|| typeof value === 'string'
|
||||
|| typeof value === 'boolean'
|
||||
|| value === undefined
|
||||
|| value === null);
|
||||
if (!res) {
|
||||
errorReport.varValueCheckFailed({
|
||||
customComponent: this.debugInfoOwningView(),
|
||||
@ -5378,6 +5385,7 @@ class ObservedPropertySimplePU extends ObservedPropertyPU {
|
||||
class SynchedPropertyOneWayPU extends ObservedPropertyAbstractPU {
|
||||
constructor(source, owningChildView, thisPropertyName) {
|
||||
super(owningChildView, thisPropertyName);
|
||||
this.setDecoratorInfo("@Prop");
|
||||
if (source && (typeof (source) === 'object') && ('subscribeMe' in source)) {
|
||||
// code path for @(Local)StorageProp, the source is a ObservedPropertyObject<C> in a LocalStorage)
|
||||
this.source_ = source;
|
||||
@ -5400,7 +5408,6 @@ class SynchedPropertyOneWayPU extends ObservedPropertyAbstractPU {
|
||||
if (this.source_ !== undefined) {
|
||||
this.resetLocalValue(this.source_.get(), /* needCopyObject */ true);
|
||||
}
|
||||
this.setDecoratorInfo("@Prop");
|
||||
|
||||
}
|
||||
/*
|
||||
@ -7631,9 +7638,8 @@ class SetMapProxyHandler {
|
||||
}
|
||||
return receiver;
|
||||
} : (typeof ret === 'function') ?
|
||||
// SendableSet can't be bound -> functions not observed
|
||||
ret.bind(SendableType.isSet(target) ? target : receiver) :
|
||||
ret;
|
||||
// Bind to target ==> functions not observed
|
||||
ret.bind(target) : ret;
|
||||
}
|
||||
if (target instanceof Map || (this.isMakeObserved_ && SendableType.isMap(target))) {
|
||||
if (key === 'get') {
|
||||
@ -7663,9 +7669,8 @@ class SetMapProxyHandler {
|
||||
}
|
||||
}
|
||||
return (typeof ret === 'function') ?
|
||||
// SendableMap can't be bound -> functions not observed
|
||||
ret.bind(SendableType.isMap(target) ? target : receiver) :
|
||||
ret;
|
||||
// Bind to target ==> functions not observed
|
||||
ret.bind(target) : ret;
|
||||
}
|
||||
set(target, key, value) {
|
||||
if (typeof key === 'symbol') {
|
||||
@ -7776,6 +7781,10 @@ class ObserveV2 {
|
||||
static IsObservedObjectV2(value) {
|
||||
return (value && typeof (value) === 'object' && value[ObserveV2.V2_DECO_META]);
|
||||
}
|
||||
// return true if given value is proxied observed object, either makeObserved or autoProxyObject
|
||||
static IsProxiedObservedV2(value) {
|
||||
return (value && typeof value === 'object' && value[ObserveV2.SYMBOL_PROXY_GET_TARGET]);
|
||||
}
|
||||
// return true given value is the return value of makeObserved
|
||||
static IsMakeObserved(value) {
|
||||
return (value && typeof (value) === 'object' && value[ObserveV2.SYMBOL_MAKE_OBSERVED]);
|
||||
|
@ -357,9 +357,17 @@ implements ISinglePropertyChangeSubscriber<T>, IMultiPropertiesChangeSubscriber,
|
||||
*/
|
||||
|
||||
protected checkIsSupportedValue(value: T): boolean {
|
||||
let res = ((typeof value === 'object' && typeof value !== 'function' && !ObserveV2.IsObservedObjectV2(value) &&
|
||||
!ObserveV2.IsMakeObserved(value)) || typeof value === 'number' || typeof value === 'string' ||
|
||||
typeof value === 'boolean' || value === undefined || value === null);
|
||||
let res = ((typeof value === 'object' && typeof value !== 'function'
|
||||
&& !ObserveV2.IsObservedObjectV2(value)
|
||||
&& !ObserveV2.IsMakeObserved(value))
|
||||
// FIXME enable the check when V1-V2 interoperability is forbidden
|
||||
// && !ObserveV2.IsProxiedObservedV2(value))
|
||||
|| typeof value === 'number'
|
||||
|| typeof value === 'string'
|
||||
|| typeof value === 'boolean'
|
||||
|| value === undefined
|
||||
|| value === null);
|
||||
|
||||
if (!res) {
|
||||
errorReport.varValueCheckFailed({
|
||||
customComponent: this.debugInfoOwningView(),
|
||||
|
@ -78,6 +78,7 @@ class SynchedPropertyOneWayPU<C> extends ObservedPropertyAbstractPU<C>
|
||||
owningChildView: IPropertySubscriber,
|
||||
thisPropertyName: PropertyInfo) {
|
||||
super(owningChildView, thisPropertyName);
|
||||
this.setDecoratorInfo("@Prop");
|
||||
|
||||
if (source && (typeof (source) === 'object') && ('subscribeMe' in source)) {
|
||||
// code path for @(Local)StorageProp, the source is a ObservedPropertyObject<C> in a LocalStorage)
|
||||
@ -102,7 +103,6 @@ class SynchedPropertyOneWayPU<C> extends ObservedPropertyAbstractPU<C>
|
||||
if (this.source_ !== undefined) {
|
||||
this.resetLocalValue(this.source_.get(), /* needCopyObject */ true);
|
||||
}
|
||||
this.setDecoratorInfo("@Prop");
|
||||
stateMgmtConsole.debug(`${this.debugInfo()}: constructor: done!`);
|
||||
}
|
||||
|
||||
|
@ -131,6 +131,11 @@ class ObserveV2 {
|
||||
return (value && typeof (value) === 'object' && value[ObserveV2.V2_DECO_META]);
|
||||
}
|
||||
|
||||
// return true if given value is proxied observed object, either makeObserved or autoProxyObject
|
||||
public static IsProxiedObservedV2(value: any): boolean {
|
||||
return (value && typeof value === 'object' && value[ObserveV2.SYMBOL_PROXY_GET_TARGET]);
|
||||
}
|
||||
|
||||
// return true given value is the return value of makeObserved
|
||||
public static IsMakeObserved(value: any): boolean {
|
||||
return (value && typeof (value) === 'object' && value[ObserveV2.SYMBOL_MAKE_OBSERVED]);
|
||||
|
@ -320,9 +320,8 @@ class SetMapProxyHandler {
|
||||
}
|
||||
return receiver;
|
||||
} : (typeof ret === 'function') ?
|
||||
// SendableSet can't be bound -> functions not observed
|
||||
ret.bind(SendableType.isSet(target) ? target : receiver) :
|
||||
ret;
|
||||
// Bind to target ==> functions not observed
|
||||
ret.bind(target) : ret;
|
||||
}
|
||||
|
||||
if (target instanceof Map || (this.isMakeObserved_ && SendableType.isMap(target))) {
|
||||
@ -351,9 +350,8 @@ class SetMapProxyHandler {
|
||||
}
|
||||
}
|
||||
return (typeof ret === 'function') ?
|
||||
// SendableMap can't be bound -> functions not observed
|
||||
ret.bind(SendableType.isMap(target) ? target : receiver) :
|
||||
ret;
|
||||
// Bind to target ==> functions not observed
|
||||
ret.bind(target) : ret;
|
||||
}
|
||||
|
||||
set(target: any, key: string | symbol, value: any): boolean {
|
||||
|
Loading…
Reference in New Issue
Block a user