-
Notifications
You must be signed in to change notification settings - Fork 311
feat(common): use the hotspot function provided by the ArkWeb JS engine to optimize the execution of defineProperties function in the common adaptation layer #3530
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
interface ILongque { | ||
/** | ||
* Harmony API version. | ||
* | ||
* @since 1 | ||
*/ | ||
version: number | ||
|
||
/** | ||
* Create a delegate object for `underlyingObject` or make the `initObject` a delegate for `underlyingObject`. | ||
* | ||
* @param underlyingObject The underlying object to be delegated. | ||
* @param initObject Optional initial delegate object. | ||
* @param propertyFilterFlags Optional property filter flags, must use predefined filter flags. | ||
* @return If no error throwed, returns the new created delegate object or the `initObject`. | ||
* | ||
* @since 1 | ||
*/ | ||
createDelegate: (underlyingObject: object, initObject?: object, propertyFilterFlags?: number) => object | ||
|
||
/** | ||
* The filter flag for `createDelegate`, skip all properties in prototype chain of `underlyingObject`. | ||
* | ||
* @since 1 | ||
*/ | ||
SKIP_PROTOTYPE_CHAIN: 1 | ||
|
||
/** | ||
* The filter flag for `createDelegate`, skip all properties that starts with '_'. | ||
* | ||
* @since 1 | ||
*/ | ||
SKIP_PREFIX_UNDERSCORE: 2 | ||
|
||
/** | ||
* The filter flag for `createDelegate`, skip all properties that starts with '$'. | ||
* | ||
* @since 1 | ||
*/ | ||
SKIP_PREFIX_DOLLAR: 4 | ||
|
||
/** | ||
* The filter flag for `createDelegate`, skip the 'constructor' property. | ||
* | ||
* @since 1 | ||
*/ | ||
SKIP_CONSTRUCTOR: 8 | ||
} | ||
|
||
interface Window { | ||
__Longque__: ILongque | ||
} | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// 龙雀: ArkWeb JS引擎名称 | ||
const __TINY__ = typeof window === 'undefined' ? null : window.__Longque__ | ||
|
||
export { __TINY__ } |
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -3,6 +3,7 @@ import * as compositionHooks from '@vue/composition-api' | |||||||||||
import * as vueHooks from 'vue' | ||||||||||||
import { bindFilter, emitter, getElementCssClass, getElementStatusClass } from '../utils' | ||||||||||||
import teleport from '../teleport' | ||||||||||||
import { __TINY__ } from '../__longque__' | ||||||||||||
|
||||||||||||
// vue2.7有version字段 | ||||||||||||
const isVueHooks = Boolean(Vue.version?.includes('2.7')) | ||||||||||||
|
@@ -179,7 +180,7 @@ const generateChildren = ($children) => { | |||||||||||
return children | ||||||||||||
} | ||||||||||||
|
||||||||||||
const defineProperties = (vm, instance, filter) => { | ||||||||||||
const originalDefineProperties = (vm, instance, filter) => { | ||||||||||||
for (const name in instance) { | ||||||||||||
if (typeof filter === 'function' && filter(name)) continue | ||||||||||||
|
||||||||||||
|
@@ -194,6 +195,13 @@ const defineProperties = (vm, instance, filter) => { | |||||||||||
return vm | ||||||||||||
} | ||||||||||||
|
||||||||||||
const harmonyDefineProperties = (vm, instance) => { | ||||||||||||
const propertyFilterFlags = __TINY__.SKIP_PREFIX_UNDERSCORE | __TINY__.SKIP_PREFIX_DOLLAR | __TINY__.SKIP_CONSTRUCTOR | ||||||||||||
__TINY__.createDelegate(instance, vm, propertyFilterFlags) | ||||||||||||
} | ||||||||||||
Comment on lines
+198
to
+201
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add error handling for the delegate creation. The const harmonyDefineProperties = (vm, instance) => {
const propertyFilterFlags = __TINY__.SKIP_PREFIX_UNDERSCORE | __TINY__.SKIP_PREFIX_DOLLAR | __TINY__.SKIP_CONSTRUCTOR
- __TINY__.createDelegate(instance, vm, propertyFilterFlags)
+ try {
+ __TINY__.createDelegate(instance, vm, propertyFilterFlags)
+ } catch (error) {
+ console.warn('Failed to create delegate, falling back to original implementation:', error)
+ return originalDefineProperties(vm, instance, filter)
+ }
+ return vm
}
🤖 Prompt for AI Agents
|
||||||||||||
|
||||||||||||
const defineProperties = __TINY__ ? harmonyDefineProperties : originalDefineProperties | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Consider runtime validation of TINY capabilities. The conditional assignment only checks for the existence of -const defineProperties = __TINY__ ? harmonyDefineProperties : originalDefineProperties
+const defineProperties = (__TINY__ && typeof __TINY__.createDelegate === 'function') ? harmonyDefineProperties : originalDefineProperties 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
|
||||||||||||
|
||||||||||||
const filter = (name) => name.indexOf('$') === 0 || name.indexOf('_') === 0 || name === 'constructor' | ||||||||||||
|
||||||||||||
const createVm = (vm, instance, context = undefined) => { | ||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make
__Longque__
optional to match runtime reality__Longque__
is not guaranteed to exist – your own runtime guard (typeof window === 'undefined' ? null : window.__Longque__
) proves that.Marking the property as mandatory will break type-checking when
strictNullChecks
is on, or when the file is imported in non-ArkWeb environments.📝 Committable suggestion
🤖 Prompt for AI Agents