@nstudio/nativescript-compiler 9.2.0-alpha.14 → 9.2.0-alpha.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/driver/compile.js +4 -3
- package/dist/kotlin/arguments.js +2 -1
- package/dist/kotlin/builtins.js +14 -3
- package/dist/kotlin/class-constructor.js +3 -1
- package/dist/kotlin/class-methods.js +9 -2
- package/dist/kotlin/components.js +39 -14
- package/dist/kotlin/construction.js +4 -5
- package/dist/kotlin/conversion.js +16 -3
- package/dist/kotlin/core-api.js +14 -7
- package/dist/kotlin/declarations.js +1 -1
- package/dist/kotlin/expressions.js +10 -5
- package/dist/kotlin/modules.js +7 -3
- package/dist/kotlin/names.js +5 -2
- package/dist/kotlin/optional-chains.js +24 -5
- package/dist/kotlin/overrides.js +7 -2
- package/dist/kotlin/placement.js +5 -4
- package/dist/kotlin/translator.js +0 -39
- package/dist/kotlin/types.js +4 -5
- package/dist/kotlin/untyped-values.js +7 -1
- package/dist/program/program.js +3 -3
- package/dist/semantics/apis/array.js +11 -0
- package/dist/semantics/classes.js +24 -0
- package/dist/semantics/config.js +2 -0
- package/dist/semantics/forms/by-name.js +30 -18
- package/dist/semantics/globals.js +8 -2
- package/dist/semantics/lang.js +4 -0
- package/dist/semantics/ledger.js +0 -24
- package/dist/semantics/platform-globals.js +0 -16
- package/dist/semantics/refusals.js +1 -1
- package/dist/semantics/runtime.js +2 -0
- package/dist/semantics/throws.js +7 -0
- package/dist/semantics/worker-state.js +41 -1
- package/dist/swift/assignment.js +3 -0
- package/dist/swift/builtins.js +8 -10
- package/dist/swift/class-methods.js +3 -1
- package/dist/swift/construction.js +5 -1
- package/dist/swift/conversion.js +1 -1
- package/dist/swift/expressions.js +2 -4
- package/dist/swift/from-any.js +5 -0
- package/dist/swift/global-calls.js +8 -1
- package/dist/swift/object-classes.js +2 -1
- package/dist/swift/protocols.js +5 -16
- package/dist/swift/types.js +4 -3
- package/dist/targets/ios/build.js +22 -7
- package/docs/cli/compile-ios.md +1 -1
- package/kit-android/generated/kotlin/org/nativescript/kit/ui_core_properties_index.kt +6 -6
- package/kit-android/generated/kotlin/org/nativescript/kit/ui_core_view_view_common.kt +1 -1
- package/kit-android/src/main/kotlin/org/nativescript/kit/runtime/Collections.kt +15 -6
- package/kit-android/src/main/kotlin/org/nativescript/kit/runtime/Promise.kt +1 -1
- package/kit-apple/Overlays/xml-free/Core/ui.core.bindable.index.swift +13 -2
- package/kit-apple/Sources/NativeScriptKit/Core/FunctionCells.Arity1.swift +0 -12
- package/kit-apple/Sources/NativeScriptKit/Core/FunctionCells.Arity2.swift +0 -39
- package/kit-apple/Sources/NativeScriptKit/Core/FunctionCells.Arity3Plus.swift +0 -44
- package/kit-apple/Sources/NativeScriptKit/Core/application.application-common.swift +19 -2
- package/kit-apple/Sources/NativeScriptKit/Core/kit-index.json +87 -22
- package/kit-apple/Sources/NativeScriptKit/Core/text.text-common.swift +9 -1
- package/kit-apple/Sources/NativeScriptKit/Core/ui.core.bindable.index.swift +13 -2
- package/kit-apple/Sources/NativeScriptKit/Core/ui.core.view-base.index.swift +26 -2
- package/kit-apple/Sources/NativeScriptKit/Core/ui.layouts.liquid-glass-container.index.ios.swift +12 -2
- package/kit-apple/Sources/NativeScriptKit/Core/ui.layouts.root-layout.root-layout-common.swift +46 -6
- package/kit-apple/Sources/NativeScriptKit/Core/ui.list-view.index.ios.swift +37 -3
- package/kit-apple/Sources/NativeScriptKit/Core/ui.split-view.split-view-common.swift +12 -1
- package/kit-apple/Sources/NativeScriptKit/Core/ui.styling.css-selector.swift +50 -6
- package/kit-apple/Sources/NativeScriptKit/Core/ui.text-base.text-base-common.swift +13 -1
- package/kit-apple/Sources/NativeScriptKit/Runtime/Collections.swift +5 -1
- package/kit-apple/Sources/NativeScriptKit/Runtime/Dynamic.swift +13 -2
- package/kit-apple/Sources/NativeScriptKit/Runtime/Errors.swift +10 -2
- package/kit-apple/Sources/NativeScriptKit/Runtime/Functions.swift +57 -12
- package/kit-apple/Sources/NativeScriptKit/Runtime/Lowering.swift +12 -3
- package/kit-apple/Sources/NativeScriptKit/Runtime/Promise.swift +56 -29
- package/kit-apple/Sources/NativeScriptKit/Runtime/Realm.swift +92 -0
- package/kit-apple/Sources/NativeScriptKit/Runtime/Record.swift +25 -5
- package/kit-apple/Sources/NativeScriptKit/Runtime/RegExp.swift +13 -4
- package/kit-apple/Sources/NativeScriptKit/Runtime/RegExpEngine.swift +14 -5
- package/kit-apple/Sources/NativeScriptKit/Runtime/Symbol.swift +28 -6
- package/kit-apple/Sources/NativeScriptKit/Runtime/Threads.swift +2 -2
- package/kit-apple/Sources/NativeScriptKit/Runtime/Timers.swift +93 -47
- package/kit-apple/Sources/NativeScriptKit/Runtime/TypedArrays.swift +37 -9
- package/kit-apple/Sources/NativeScriptKit/Runtime/Values.swift +6 -4
- package/kit-apple/Sources/NativeScriptKit/Runtime/Views.swift +11 -2
- package/kit-apple/Sources/NativeScriptKit/Runtime/Workers.swift +680 -0
- package/package.json +1 -1
package/dist/swift/protocols.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
// Protocol conformance as Swift: the protocols a class implements and their witnesses.
|
|
2
2
|
import ts from 'typescript';
|
|
3
3
|
import { ident, isOptional, metatype, optionalType, RT } from "./syntax.js";
|
|
4
|
-
import { implementedInterfaces } from "../semantics/lang.js";
|
|
4
|
+
import { implementedInterfaces, isEmittedInterface } from "../semantics/lang.js";
|
|
5
5
|
import { UNKEYED } from "../semantics/shapes.js";
|
|
6
6
|
import { hasModifier, isLibDeclaration } from "../semantics/ast.js";
|
|
7
7
|
import { isCoreDeclaration } from "../program/core-facts.js";
|
|
8
8
|
import { isNamed, isUntyped, spelledType } from "../semantics/types.js";
|
|
9
|
-
import { programBase } from "../semantics/classes.js";
|
|
9
|
+
import { ownClassMember, programBase, redeclaredMember } from "../semantics/classes.js";
|
|
10
10
|
export const protocolsMethods = {
|
|
11
11
|
/** Whether a class's source base class (or one above it) implements an interface. */
|
|
12
12
|
baseImplements(cls, iface) {
|
|
@@ -35,7 +35,7 @@ export const protocolsMethods = {
|
|
|
35
35
|
const named = implementedInterfaces(this.checker, cls).map((i) => ({ name: this.heritageName(i), type: this.checker.getTypeAtLocation(i) }));
|
|
36
36
|
const met = [...(this.structural.get(cls) ?? [])].map((d) => ({ name: this.topName(d, d.name.text), type: this.checker.getTypeAtLocation(d.name) }));
|
|
37
37
|
const implemented = [...named, ...met.filter((m) => !named.some((n) => n.name === m.name))]
|
|
38
|
-
.filter((i) => !isLibDeclaration(i.type.getSymbol()?.declarations?.[0]) && !this.uncompiledType(i.type))
|
|
38
|
+
.filter((i) => isEmittedInterface(i.type) && !isLibDeclaration(i.type.getSymbol()?.declarations?.[0]) && !this.uncompiledType(i.type))
|
|
39
39
|
// An interface only a declaration file has is no Swift protocol (a plugin's `IHttpsResponseLegacy` in its `.d.ts`), unless core's
|
|
40
40
|
// that the kit has; nor is one the program has no declaration of (a plugin's `import { IOptions } from '.'`, which the platform
|
|
41
41
|
// suffix resolves to the importing file itself).
|
|
@@ -100,17 +100,6 @@ export const protocolsMethods = {
|
|
|
100
100
|
const decl = type.getSymbol()?.declarations?.find(ts.isInterfaceDeclaration);
|
|
101
101
|
if (!decl || !this.protocols.has(name))
|
|
102
102
|
return true;
|
|
103
|
-
const own = (name) => {
|
|
104
|
-
for (let c = cls; c; c = this.sourceBase(c)) {
|
|
105
|
-
const m = c.members.find((x) => x.name?.getText() === name);
|
|
106
|
-
if (m)
|
|
107
|
-
return m;
|
|
108
|
-
const param = c.members.find(ts.isConstructorDeclaration)?.parameters.find((p) => ts.isIdentifier(p.name) && p.name.text === name && ts.canHaveModifiers(p) && !!ts.getModifiers(p)?.length);
|
|
109
|
-
if (param)
|
|
110
|
-
return param;
|
|
111
|
-
}
|
|
112
|
-
return undefined;
|
|
113
|
-
};
|
|
114
103
|
const added = [];
|
|
115
104
|
// The protocol refines its interface's bases: their members are required too.
|
|
116
105
|
const inherited = type
|
|
@@ -123,13 +112,13 @@ export const protocolsMethods = {
|
|
|
123
112
|
continue;
|
|
124
113
|
if (this.fieldByOwnParameter(cls, req))
|
|
125
114
|
return false;
|
|
126
|
-
const m =
|
|
115
|
+
const m = ownClassMember(cls, name, this.checker);
|
|
127
116
|
// A parameter property or an inherited member the class does not declare: Swift checks it.
|
|
128
117
|
if (!m)
|
|
129
118
|
continue;
|
|
130
119
|
if (ts.isPropertySignature(req)) {
|
|
131
120
|
const want = req.questionToken ? optionalType(this.typeOf(req)) : this.typeOf(req);
|
|
132
|
-
const root =
|
|
121
|
+
const root = redeclaredMember(m, this.checker);
|
|
133
122
|
const fieldType = ts.isPropertyDeclaration(m) ? this.typeOf(m.name) : ts.isParameter(m) ? (!!m.questionToken && !isOptional(this.typeOf(m.name)) && !isUntyped(spelledType(this.typeOf(m.name))) ? optionalType(this.typeOf(m.name)) : this.typeOf(m.name)) : null;
|
|
134
123
|
const have = ts.isGetAccessorDeclaration(m) ? (this.narrowedFrom(m) ?? this.returnTypeOf(m)) : root ? this.redeclaredType(root) : fieldType;
|
|
135
124
|
if (have !== want)
|
package/dist/swift/types.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// TypeScript types as Swift types: representations, held and optional forms, shapes.
|
|
2
2
|
import ts from 'typescript';
|
|
3
3
|
import { DESCRIPTORS } from "./library.js";
|
|
4
|
-
import { WEB_DICTIONARIES,
|
|
4
|
+
import { WEB_DICTIONARIES, webClassName } from "../semantics/globals.js";
|
|
5
5
|
import { SPELLING, spell, functionParts, heldType, isFunctionLiteral, isFunctionType, isMethodValue, isOptional, nullishType, optionalElementsType, optionalType, returningAny, swiftString, RT } from "./syntax.js";
|
|
6
6
|
import { literalOverArray, membersOverTypeParameter, readByKey, definedField, untypedResultBinding, untypedResultField } from "../semantics/shapes.js";
|
|
7
7
|
import { ambientAddedMemberOf, ambientBase, augmentedPropertyRead, evolvingArrayRead, evolvingArrayType, isAmbientClass, isRegExpProtocol, mergedInterfaceMemberOf, statementLevel, tokenClassBase, undeclaredMemberOf, isArguments, nullableTypeNode } from "../semantics/lang.js";
|
|
@@ -176,8 +176,9 @@ export const typesMethods = {
|
|
|
176
176
|
};
|
|
177
177
|
// Core's own code and apps using DOM/core global typings: web classes declared in .d.ts map to the runtime's.
|
|
178
178
|
if (name && sym?.declarations?.length && sym.declarations.every((d) => d.getSourceFile().isDeclarationFile)) {
|
|
179
|
-
|
|
180
|
-
|
|
179
|
+
const web = webClassName(this.ledger, name);
|
|
180
|
+
if (web)
|
|
181
|
+
return web;
|
|
181
182
|
if (WEB_DICTIONARIES.includes(name) && (sym.declarations[0].getSourceFile().fileName === '/__shims__/globals.d.ts' || isLibDeclaration(sym.declarations[0])))
|
|
182
183
|
return 'Any?';
|
|
183
184
|
}
|
|
@@ -28,6 +28,7 @@ import { mirror, writeIfChanged } from "../../driver/mirror.js";
|
|
|
28
28
|
import { KIT_APPLE, PACKAGE } from "../../driver/paths.js";
|
|
29
29
|
import { compiledEnv } from "../../program/env.js";
|
|
30
30
|
import { programClassName } from "../../semantics/top-names.js";
|
|
31
|
+
import { sharedWorkerState, sharedWorkerStateError } from "../../semantics/worker-state.js";
|
|
31
32
|
/** The app as an Xcode project in `b.out`, built where `b.build` says. */
|
|
32
33
|
export async function writeIos(b) {
|
|
33
34
|
const { context, app, appDir, out, name, framework, adapter, behaviour, components, modules, program, checker, files: sourceFiles, infos, elementClasses, root, mounted, xml, pageSheets, sheets, xmlRunTimeFree, xmlMemberKeys, lines: sourceLines, shownSource, plugins, bindings: pluginBindings, pluginFiles, compiledPlugins, reach, properties, resolved, lenient: lenientApp, assignFields: assignsFields, allowUnapplied, unapplied, say, started } = b;
|
|
@@ -74,6 +75,12 @@ export async function writeIos(b) {
|
|
|
74
75
|
for (const [js, c] of Object.entries(nativeTable(m).classes))
|
|
75
76
|
if (c.kind === 'class' && !c.extension && c.module === m)
|
|
76
77
|
pluginNativeClasses.set(js, c.swift);
|
|
78
|
+
const allModuleFiles = [...new Set([...modules, ...components.map((c) => c.file), ...compiledPlugins])];
|
|
79
|
+
if (b.workers?.length) {
|
|
80
|
+
const writes = sharedWorkerState(program, b.workers.map((f) => f.replace(/\\/g, '/')), new Set(allModuleFiles.map((f) => f.replace(/\\/g, '/'))), resolved);
|
|
81
|
+
if (writes.length)
|
|
82
|
+
throw sharedWorkerStateError(writes, app);
|
|
83
|
+
}
|
|
77
84
|
const translator = new Translator(checker, infos, sourceFiles, {
|
|
78
85
|
...context.translation(),
|
|
79
86
|
pluginFiles,
|
|
@@ -95,6 +102,8 @@ export async function writeIos(b) {
|
|
|
95
102
|
appNativeClasses: Object.keys(appNative).filter((c) => !appNative[c].extension && appNative[c].kind === 'class'),
|
|
96
103
|
pluginNativeClasses,
|
|
97
104
|
pluginModules: native.modules,
|
|
105
|
+
workerScripts: new Map((b.workers ?? []).map((f) => [f.replace(/\\/g, '/'), relative(app, f).replace(/\\/g, '/')])),
|
|
106
|
+
resolveAlias: b.aliased ?? null,
|
|
98
107
|
allowUnapplied,
|
|
99
108
|
errors: b.allErrors ? (allowUnapplied ? [] : [...unapplied]) : null,
|
|
100
109
|
});
|
|
@@ -164,9 +173,14 @@ export async function writeIos(b) {
|
|
|
164
173
|
const shapes = SourceLines.strip((translator.interfacesOutside(new Set(translated.map((m) => m.file))) + translator.shapesCode()).trim());
|
|
165
174
|
if (shapes)
|
|
166
175
|
writeFileSync(join(sourcesDir, '__Objects.swift'), `// Compiled by ns-compiled: the app's object literals without a declared type.\nimport Foundation\nimport NativeScriptKit\n${native.modules.length || /\bUI[A-Z]/.test(shapes) ? `import UIKit\n${native.modules.map((m) => `import ${m}\n`).join('')}` : ''}${SDK_IMPORTS}\n${shapes}\n`);
|
|
167
|
-
const
|
|
176
|
+
const isWorker = (file) => !!translator.workerScripts?.has(file.replace(/\\/g, '/'));
|
|
177
|
+
const workerRegs = translated
|
|
178
|
+
.filter((m) => isWorker(m.file))
|
|
179
|
+
.map((m) => ` JSWorker.register(${swiftString(translator.workerScripts.get(m.file.replace(/\\/g, '/')))}) { ${m.init ? `${m.initThrows ? 'try ' : ''}${m.init}()` : ''} }\n`)
|
|
180
|
+
.join('');
|
|
181
|
+
const activeInits = translated.filter((m) => m.init && !isWorker(m.file));
|
|
168
182
|
const anyInitThrows = activeInits.some((m) => m.initThrows);
|
|
169
|
-
const inits = activeInits.length ? (anyInitThrows ? ` ${RT.jsReport} {\n${activeInits.map((m) => ` ${m.initThrows ? 'try ' : ''}${m.init}()\n`).join('')} }\n` : activeInits.map((m) => ` ${m.init}()\n`).join('')) : '';
|
|
183
|
+
const inits = workerRegs + (activeInits.length ? (anyInitThrows ? ` ${RT.jsReport} {\n${activeInits.map((m) => ` ${m.initThrows ? 'try ' : ''}${m.init}()\n`).join('')} }\n` : activeInits.map((m) => ` ${m.init}()\n`).join('')) : '');
|
|
170
184
|
// The app's CSS as its NativeScript build ships it: the AST core applies.
|
|
171
185
|
const css = kitAst(sheets);
|
|
172
186
|
const corePatchRefusal = corePatchRefused(app, nodeModules(app), 'ios');
|
|
@@ -325,11 +339,12 @@ export async function writeIos(b) {
|
|
|
325
339
|
removePods(out, name);
|
|
326
340
|
const resources = iosProjectResources({ app, appDir, out, name, pods: !!pods, say, stubbed: context.stubbedPlugins });
|
|
327
341
|
const extensions = iosExtensions({ app, out, bundle, packages, signing, team: resources.team, say });
|
|
328
|
-
// Script is single-threaded
|
|
329
|
-
//
|
|
330
|
-
const
|
|
331
|
-
|
|
332
|
-
|
|
342
|
+
// Script is single-threaded unless the app starts workers (each in its own isolated JSRealm on a worker thread).
|
|
343
|
+
// When workers are present, disable dynamic MainActor assertions in Debug too so worker threads can run realm-isolated code.
|
|
344
|
+
const hasWorkers = !!(b.workers && b.workers.length);
|
|
345
|
+
const swiftMode = { SWIFT_VERSION: '"6"', SWIFT_DEFAULT_ACTOR_ISOLATION: 'MainActor', ...(hasWorkers ? { OTHER_SWIFT_FLAGS: '"$(inherited) -Xfrontend -disable-dynamic-actor-isolation"' } : {}) };
|
|
346
|
+
// Release only: Debug keeps Swift 6's run-time isolation checks when no workers are present.
|
|
347
|
+
const swiftModeRelease = (...flags) => ` configs:\n Release:\n OTHER_SWIFT_FLAGS: "${['$(inherited)', ...(hasWorkers ? [] : ['-Xfrontend', '-disable-dynamic-actor-isolation']), ...flags].join(' ')}"\n`;
|
|
333
348
|
// The app's own Swift (App_Resources/iOS/src), compiled in the app's target, was written for Swift 5: the target keeps that mode,
|
|
334
349
|
// with the Swift 6 features the generated code relies on (a default argument evaluated in its function's isolation).
|
|
335
350
|
const appMode = native.appSwift ? { ...swiftMode, SWIFT_VERSION: '"5"', SWIFT_UPCOMING_FEATURE_ISOLATED_DEFAULT_VALUES: 'YES', SWIFT_UPCOMING_FEATURE_REGION_BASED_ISOLATION: 'YES', SWIFT_UPCOMING_FEATURE_INFER_SENDABLE_FROM_CAPTURES: 'YES', SWIFT_UPCOMING_FEATURE_GLOBAL_ACTOR_ISOLATED_TYPES_USABILITY: 'YES' } : swiftMode;
|
package/docs/cli/compile-ios.md
CHANGED
|
@@ -31,4 +31,4 @@ General | `$ ns compile ios [--for-device] [--team-id <Team>] [--provision <Prof
|
|
|
31
31
|
|
|
32
32
|
### Platform Notes
|
|
33
33
|
|
|
34
|
-
* `new Worker(...)` background threads are
|
|
34
|
+
* `new Worker(...)` background threads are supported in compiled iOS builds (`ns compile ios`) with per-worker realms, structured cloning, `ArrayBuffer` transfer, timers, and microtasks, matching Android (`ns compile android`).
|
|
@@ -1403,15 +1403,15 @@ open class CssProperty : JSExpando, JSKeysMade {
|
|
|
1403
1403
|
jsObjectOf(
|
|
1404
1404
|
"enumerable" to true,
|
|
1405
1405
|
"configurable" to true,
|
|
1406
|
-
"get" to JSMethod { __self, _ -> get(__self) },
|
|
1407
|
-
"set" to JSMethod { __self, __a -> setCssValue(__self, __a.getOrNull(0)) },
|
|
1406
|
+
"get" to JSMethod(0) { __self, _ -> get(__self) },
|
|
1407
|
+
"set" to JSMethod(1) { __self, __a -> setCssValue(__self, __a.getOrNull(0)) },
|
|
1408
1408
|
)
|
|
1409
1409
|
this.localValueDescriptor =
|
|
1410
1410
|
jsObjectOf(
|
|
1411
1411
|
"enumerable" to true,
|
|
1412
1412
|
"configurable" to true,
|
|
1413
|
-
"get" to JSMethod { __self, _ -> get(__self) },
|
|
1414
|
-
"set" to JSMethod { __self, __a -> setLocalValue(__self, __a.getOrNull(0)) },
|
|
1413
|
+
"get" to JSMethod(0) { __self, _ -> get(__self) },
|
|
1414
|
+
"set" to JSMethod(1) { __self, __a -> setLocalValue(__self, __a.getOrNull(0)) },
|
|
1415
1415
|
)
|
|
1416
1416
|
jsSet(Core_ui_core_properties_index.cssSymbolPropertyMap, key.key, this)
|
|
1417
1417
|
}
|
|
@@ -2592,7 +2592,7 @@ open class ShorthandProperty : JSExpando, JSKeysMade {
|
|
|
2592
2592
|
"configurable" to true,
|
|
2593
2593
|
"get" to jsGet(options, "getter"),
|
|
2594
2594
|
"set" to
|
|
2595
|
-
JSMethod { __self, __a ->
|
|
2595
|
+
JSMethod(1) { __self, __a ->
|
|
2596
2596
|
setCssValue(__self, jsConvertedStringOrNull(__a.getOrNull(0)))
|
|
2597
2597
|
},
|
|
2598
2598
|
)
|
|
@@ -2601,7 +2601,7 @@ open class ShorthandProperty : JSExpando, JSKeysMade {
|
|
|
2601
2601
|
"enumerable" to true,
|
|
2602
2602
|
"configurable" to true,
|
|
2603
2603
|
"get" to jsGet(options, "getter"),
|
|
2604
|
-
"set" to JSMethod { __self, __a -> setLocalValue(__self, __a.getOrNull(0)) },
|
|
2604
|
+
"set" to JSMethod(1) { __self, __a -> setLocalValue(__self, __a.getOrNull(0)) },
|
|
2605
2605
|
)
|
|
2606
2606
|
jsSet(Core_ui_core_properties_index.cssSymbolPropertyMap, key.key, this)
|
|
2607
2607
|
}
|
|
@@ -376,6 +376,8 @@ open class JSSet<T>() : Iterable<T>, JSReactiveConvertible {
|
|
|
376
376
|
* key order (integer-like keys ascending, then insertion order) and reference semantics.
|
|
377
377
|
*/
|
|
378
378
|
class JSRecord<V>(val obj: JSObject) : JSDynamic, JSReactiveConvertible {
|
|
379
|
+
internal var backing: JSDynamic? = null
|
|
380
|
+
|
|
379
381
|
constructor() : this(JSObject())
|
|
380
382
|
|
|
381
383
|
constructor(entries: List<Pair<String, V>>) : this() {
|
|
@@ -383,9 +385,12 @@ class JSRecord<V>(val obj: JSObject) : JSDynamic, JSReactiveConvertible {
|
|
|
383
385
|
}
|
|
384
386
|
|
|
385
387
|
@Suppress("UNCHECKED_CAST")
|
|
386
|
-
operator fun get(key: String): V? = obj[key] as V?
|
|
388
|
+
operator fun get(key: String): V? = if (obj.has(key)) obj[key] as V? else backing?.jsGet(key) as V?
|
|
387
389
|
|
|
388
|
-
operator fun set(key: String, value: V?) {
|
|
390
|
+
operator fun set(key: String, value: V?) {
|
|
391
|
+
obj[key] = value
|
|
392
|
+
backing?.jsSet(key, value)
|
|
393
|
+
}
|
|
389
394
|
|
|
390
395
|
fun delete(key: String): Boolean = obj.delete(key)
|
|
391
396
|
fun has(key: String): Boolean = obj.has(key)
|
|
@@ -396,8 +401,11 @@ class JSRecord<V>(val obj: JSObject) : JSDynamic, JSReactiveConvertible {
|
|
|
396
401
|
@Suppress("UNCHECKED_CAST")
|
|
397
402
|
val entries: JSArray<Pair<String, V>> get() = JSArray(obj.jsKeys.map { Pair(it, obj[it] as V) })
|
|
398
403
|
|
|
399
|
-
override fun jsGet(key: String): Any? = obj.jsGet(key)
|
|
400
|
-
override fun jsSet(key: String, value: Any?)
|
|
404
|
+
override fun jsGet(key: String): Any? = if (obj.has(key)) obj.jsGet(key) else backing?.jsGet(key)
|
|
405
|
+
override fun jsSet(key: String, value: Any?) {
|
|
406
|
+
obj.jsSet(key, value)
|
|
407
|
+
backing?.jsSet(key, value)
|
|
408
|
+
}
|
|
401
409
|
override val jsKeys: List<String> get() = obj.jsKeys
|
|
402
410
|
override val jsClassName: String? get() = null
|
|
403
411
|
|
|
@@ -408,14 +416,15 @@ class JSRecord<V>(val obj: JSObject) : JSDynamic, JSReactiveConvertible {
|
|
|
408
416
|
|
|
409
417
|
/**
|
|
410
418
|
* An untyped value read as a dictionary (`Record<string, V>`): a plain object is
|
|
411
|
-
* shared, so writes through either show in both; another object's own keys are copied
|
|
419
|
+
* shared, so writes through either show in both; another object's own keys are copied
|
|
420
|
+
* and its dynamic lookup (methods, getters) stays reachable as a fallback.
|
|
412
421
|
*/
|
|
413
422
|
@Suppress("UNCHECKED_CAST")
|
|
414
423
|
fun <V> jsRecordOrNull(value: Any?): JSRecord<V>? = when (value) {
|
|
415
424
|
null, JSNull -> null
|
|
416
425
|
is JSRecord<*> -> value as JSRecord<V>
|
|
417
426
|
is JSObject -> JSRecord(value)
|
|
418
|
-
is JSDynamic -> JSRecord<V>().also { r -> for (k in value.jsKeys) r.obj[k] = value.jsGet(k) }
|
|
427
|
+
is JSDynamic -> JSRecord<V>().also { r -> r.backing = value; for (k in value.jsKeys) r.obj[k] = value.jsGet(k) }
|
|
419
428
|
else -> throw JSException(JSTypeError("${jsTypeof(value)} is not an object"))
|
|
420
429
|
}
|
|
421
430
|
|
|
@@ -315,7 +315,7 @@ class JSPromise<T> internal constructor() : JSThenable, JSDynamic {
|
|
|
315
315
|
viewed?.let { source ->
|
|
316
316
|
val read = viewRead!!
|
|
317
317
|
source.performThen({ v ->
|
|
318
|
-
val typed = try { read(v) } catch (e: Throwable) { onRejected(jsCaught(e)); return@performThen }
|
|
318
|
+
val typed = try { read(jsBox(v)) } catch (e: Throwable) { onRejected(jsCaught(e)); return@performThen }
|
|
319
319
|
onFulfilled(typed)
|
|
320
320
|
}, onRejected)
|
|
321
321
|
return
|
|
@@ -1202,8 +1202,19 @@ open class Binding: JSDynamic, JSExpando, JSKeysMade, JSStaticKeyed {
|
|
|
1202
1202
|
return FunctionCell_AnyOpt_JSArray_String_Opt_to_JSArray_AnyOpt_Opt.script(
|
|
1203
1203
|
"resolveObjectsAndProperties", 2, self.resolveObjectsAndProperties)
|
|
1204
1204
|
case "prepareContextForExpression":
|
|
1205
|
-
return
|
|
1206
|
-
|
|
1205
|
+
return { (__f: @escaping (Any?, Any?, String, JSArray<Any?>?) throws -> Bool) -> JSFunctionObject in
|
|
1206
|
+
jsBoxedFunction(FunctionCell_AnyOpt_AnyOpt_String_JSArray_AnyOpt_Opt_to_Bool(f: __f)) {
|
|
1207
|
+
jsFunction("prepareContextForExpression", 3) { (__a: [Any?]) throws -> Any? in
|
|
1208
|
+
if __a.count <= 3 {
|
|
1209
|
+
return try self.prepareContextForExpression(
|
|
1210
|
+
jsArg(__a, 0), jsArg(__a, 1), (try jsConvertedString(jsArg(__a, 2))))
|
|
1211
|
+
}
|
|
1212
|
+
return try __f(
|
|
1213
|
+
jsArg(__a, 0), jsArg(__a, 1), (try jsConvertedString(jsArg(__a, 2))),
|
|
1214
|
+
jsArrayOrNil(jsArg(__a, 3), as: JSArray<Any?>.self, { $0 }))
|
|
1215
|
+
}
|
|
1216
|
+
}
|
|
1217
|
+
}(self.prepareContextForExpression)
|
|
1207
1218
|
default: break
|
|
1208
1219
|
}
|
|
1209
1220
|
case 30:
|
|
@@ -1505,18 +1505,6 @@ public struct FunctionCell_String_to_JSUint8ArrayOpt {
|
|
|
1505
1505
|
guard let value else { throw jsNoObject() }
|
|
1506
1506
|
return value
|
|
1507
1507
|
}
|
|
1508
|
-
public static func script(_ name: String, _ length: Int, _ __f: @escaping (String) throws -> JSUint8Array?)
|
|
1509
|
-
-> JSFunctionObject
|
|
1510
|
-
{
|
|
1511
|
-
jsBoxedFunction(Self(f: __f)) {
|
|
1512
|
-
jsFunction(name, length) { (__a: [Any?]) throws -> Any? in
|
|
1513
|
-
return try __f((try jsConvertedString(jsArg(__a, 0))))
|
|
1514
|
-
}
|
|
1515
|
-
}
|
|
1516
|
-
}
|
|
1517
|
-
public static func scriptOrNil(_ name: String, _ length: Int, _ __f: ((String) throws -> JSUint8Array?)?)
|
|
1518
|
-
-> JSFunctionObject?
|
|
1519
|
-
{ if let __f { return script(name, length, __f) } else { return nil } }
|
|
1520
1508
|
}
|
|
1521
1509
|
|
|
1522
1510
|
public struct FunctionCell_NSData_to_Void {
|
|
@@ -2018,21 +2018,6 @@ public struct FunctionCell_AnyOpt_JSArray_SelectorCore_Opt_to_JSArray_SelectorCo
|
|
|
2018
2018
|
guard let value else { throw jsNoObject() }
|
|
2019
2019
|
return value
|
|
2020
2020
|
}
|
|
2021
|
-
public static func script(
|
|
2022
|
-
_ name: String, _ length: Int, _ __f: @escaping (Any?, JSArray<SelectorCore>?) throws -> JSArray<SelectorCore>?
|
|
2023
|
-
) -> JSFunctionObject {
|
|
2024
|
-
jsBoxedFunction(Self(f: __f)) {
|
|
2025
|
-
jsFunction(name, length) { (__a: [Any?]) throws -> Any? in
|
|
2026
|
-
return try __f(
|
|
2027
|
-
jsArg(__a, 0),
|
|
2028
|
-
try jsArrayOrNil(
|
|
2029
|
-
jsArg(__a, 1), as: JSArray<SelectorCore>.self, { try (jsCastPresent($0) as SelectorCore) }))
|
|
2030
|
-
}
|
|
2031
|
-
}
|
|
2032
|
-
}
|
|
2033
|
-
public static func scriptOrNil(
|
|
2034
|
-
_ name: String, _ length: Int, _ __f: ((Any?, JSArray<SelectorCore>?) throws -> JSArray<SelectorCore>?)?
|
|
2035
|
-
) -> JSFunctionObject? { if let __f { return script(name, length, __f) } else { return nil } }
|
|
2036
2021
|
}
|
|
2037
2022
|
|
|
2038
2023
|
public struct FunctionCell_String_SelectorCoreOpt_to_Void {
|
|
@@ -3615,18 +3600,6 @@ public struct FunctionCell_ViewOpt_Bool_to_JSPromise_Void_Opt {
|
|
|
3615
3600
|
guard let value else { throw jsNoObject() }
|
|
3616
3601
|
return value
|
|
3617
3602
|
}
|
|
3618
|
-
public static func script(_ name: String, _ length: Int, _ __f: @escaping (View?, Bool) throws -> JSPromise<Void>?)
|
|
3619
|
-
-> JSFunctionObject
|
|
3620
|
-
{
|
|
3621
|
-
jsBoxedFunction(Self(f: __f)) {
|
|
3622
|
-
jsFunction(name, length) { (__a: [Any?]) throws -> Any? in
|
|
3623
|
-
return try __f((try jsCast(jsArg(__a, 0), View.self)), (try jsConvertedBool(jsArg(__a, 1))))
|
|
3624
|
-
}
|
|
3625
|
-
}
|
|
3626
|
-
}
|
|
3627
|
-
public static func scriptOrNil(_ name: String, _ length: Int, _ __f: ((View?, Bool) throws -> JSPromise<Void>?)?)
|
|
3628
|
-
-> JSFunctionObject?
|
|
3629
|
-
{ if let __f { return script(name, length, __f) } else { return nil } }
|
|
3630
3603
|
}
|
|
3631
3604
|
|
|
3632
3605
|
public struct FunctionCell_ViewOpt_AnyOpt_to_AnimationOpt {
|
|
@@ -3808,18 +3781,6 @@ public struct FunctionCell_Double_Double_to_Double {
|
|
|
3808
3781
|
guard let value else { throw jsNoObject() }
|
|
3809
3782
|
return value
|
|
3810
3783
|
}
|
|
3811
|
-
public static func script(_ name: String, _ length: Int, _ __f: @escaping (Double, Double) throws -> Double)
|
|
3812
|
-
-> JSFunctionObject
|
|
3813
|
-
{
|
|
3814
|
-
jsBoxedFunction(Self(f: __f)) {
|
|
3815
|
-
jsFunction(name, length) { (__a: [Any?]) throws -> Any? in
|
|
3816
|
-
return try __f((try jsConvertedNumber(jsArg(__a, 0))), (try jsConvertedNumber(jsArg(__a, 1))))
|
|
3817
|
-
}
|
|
3818
|
-
}
|
|
3819
|
-
}
|
|
3820
|
-
public static func scriptOrNil(_ name: String, _ length: Int, _ __f: ((Double, Double) throws -> Double)?)
|
|
3821
|
-
-> JSFunctionObject?
|
|
3822
|
-
{ if let __f { return script(name, length, __f) } else { return nil } }
|
|
3823
3784
|
}
|
|
3824
3785
|
|
|
3825
3786
|
public struct FunctionCell_ViewOpt_NSIndexPathOpt_to_Double {
|
|
@@ -362,20 +362,6 @@ public struct FunctionCell_AnyOpt_AnyOpt_String_JSArray_AnyOpt_Opt_to_Bool {
|
|
|
362
362
|
guard let value else { throw jsNoObject() }
|
|
363
363
|
return value
|
|
364
364
|
}
|
|
365
|
-
public static func script(
|
|
366
|
-
_ name: String, _ length: Int, _ __f: @escaping (Any?, Any?, String, JSArray<Any?>?) throws -> Bool
|
|
367
|
-
) -> JSFunctionObject {
|
|
368
|
-
jsBoxedFunction(Self(f: __f)) {
|
|
369
|
-
jsFunction(name, length) { (__a: [Any?]) throws -> Any? in
|
|
370
|
-
return try __f(
|
|
371
|
-
jsArg(__a, 0), jsArg(__a, 1), (try jsConvertedString(jsArg(__a, 2))),
|
|
372
|
-
jsArrayOrNil(jsArg(__a, 3), as: JSArray<Any?>.self, { $0 }))
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
public static func scriptOrNil(
|
|
377
|
-
_ name: String, _ length: Int, _ __f: ((Any?, Any?, String, JSArray<Any?>?) throws -> Bool)?
|
|
378
|
-
) -> JSFunctionObject? { if let __f { return script(name, length, __f) } else { return nil } }
|
|
379
365
|
}
|
|
380
366
|
|
|
381
367
|
public struct FunctionCell_ViewBaseOpt_AnyOpt_AnyOpt_to_AnyOpt {
|
|
@@ -1058,21 +1044,6 @@ public struct FunctionCell_ViewOpt_JSArray_String_Opt_String_Bool_to_Void {
|
|
|
1058
1044
|
guard let value else { throw jsNoObject() }
|
|
1059
1045
|
return value
|
|
1060
1046
|
}
|
|
1061
|
-
public static func script(
|
|
1062
|
-
_ name: String, _ length: Int, _ __f: @escaping (View?, JSArray<String>?, String, Bool) throws -> Void
|
|
1063
|
-
) -> JSFunctionObject {
|
|
1064
|
-
jsBoxedFunction(Self(f: __f)) {
|
|
1065
|
-
jsFunction(name, length) { (__a: [Any?]) throws -> Any? in
|
|
1066
|
-
try __f(
|
|
1067
|
-
(try jsCast(jsArg(__a, 0), View.self)), jsArrayOrNil(jsArg(__a, 1), { jsLenientString($0) }),
|
|
1068
|
-
(try jsConvertedString(jsArg(__a, 2))), (try jsConvertedBool(jsArg(__a, 3))))
|
|
1069
|
-
return nil
|
|
1070
|
-
}
|
|
1071
|
-
}
|
|
1072
|
-
}
|
|
1073
|
-
public static func scriptOrNil(
|
|
1074
|
-
_ name: String, _ length: Int, _ __f: ((View?, JSArray<String>?, String, Bool) throws -> Void)?
|
|
1075
|
-
) -> JSFunctionObject? { if let __f { return script(name, length, __f) } else { return nil } }
|
|
1076
1047
|
}
|
|
1077
1048
|
|
|
1078
1049
|
public struct FunctionCell_ViewOpt_JSArray_String_Opt_String_to_Void {
|
|
@@ -4395,21 +4366,6 @@ public struct FunctionCell_Double_Double_Double_to_Void {
|
|
|
4395
4366
|
guard let value else { throw jsNoObject() }
|
|
4396
4367
|
return value
|
|
4397
4368
|
}
|
|
4398
|
-
public static func script(_ name: String, _ length: Int, _ __f: @escaping (Double, Double, Double) throws -> Void)
|
|
4399
|
-
-> JSFunctionObject
|
|
4400
|
-
{
|
|
4401
|
-
jsBoxedFunction(Self(f: __f)) {
|
|
4402
|
-
jsFunction(name, length) { (__a: [Any?]) throws -> Any? in
|
|
4403
|
-
try __f(
|
|
4404
|
-
(try jsConvertedNumber(jsArg(__a, 0))), (try jsConvertedNumber(jsArg(__a, 1))),
|
|
4405
|
-
(try jsConvertedNumber(jsArg(__a, 2))))
|
|
4406
|
-
return nil
|
|
4407
|
-
}
|
|
4408
|
-
}
|
|
4409
|
-
}
|
|
4410
|
-
public static func scriptOrNil(_ name: String, _ length: Int, _ __f: ((Double, Double, Double) throws -> Void)?)
|
|
4411
|
-
-> JSFunctionObject?
|
|
4412
|
-
{ if let __f { return script(name, length, __f) } else { return nil } }
|
|
4413
4369
|
}
|
|
4414
4370
|
|
|
4415
4371
|
public struct FunctionCell_AnyOpt_Bool_AnyOpt_to_Void {
|
|
@@ -1504,8 +1504,25 @@ open class ApplicationCommon: JSDynamic, JSExpando, JSKeysMade, JSStaticKeyed {
|
|
|
1504
1504
|
case "_appCssLoaded": return self._appCssLoaded
|
|
1505
1505
|
case "_traitsWindow": return self._traitsWindow
|
|
1506
1506
|
case "applyCssClass":
|
|
1507
|
-
return
|
|
1508
|
-
|
|
1507
|
+
return {
|
|
1508
|
+
(__f: @escaping (View?, JSArray<String>?, String, Bool) throws -> Void) -> JSFunctionObject in
|
|
1509
|
+
jsBoxedFunction(FunctionCell_ViewOpt_JSArray_String_Opt_String_Bool_to_Void(f: __f)) {
|
|
1510
|
+
jsFunction("applyCssClass", 3) { (__a: [Any?]) throws -> Any? in
|
|
1511
|
+
if __a.count <= 3 {
|
|
1512
|
+
try self.applyCssClass(
|
|
1513
|
+
(try jsCast(jsArg(__a, 0), View.self)),
|
|
1514
|
+
jsArrayOrNil(jsArg(__a, 1), { jsLenientString($0) }),
|
|
1515
|
+
(try jsConvertedString(jsArg(__a, 2))))
|
|
1516
|
+
return nil
|
|
1517
|
+
}
|
|
1518
|
+
try __f(
|
|
1519
|
+
(try jsCast(jsArg(__a, 0), View.self)),
|
|
1520
|
+
jsArrayOrNil(jsArg(__a, 1), { jsLenientString($0) }),
|
|
1521
|
+
(try jsConvertedString(jsArg(__a, 2))), (try jsConvertedBool(jsArg(__a, 3))))
|
|
1522
|
+
return nil
|
|
1523
|
+
}
|
|
1524
|
+
}
|
|
1525
|
+
}(self.applyCssClass)
|
|
1509
1526
|
case "getWindowById":
|
|
1510
1527
|
return FunctionCell_String_to_NativeWindowOpt.script("getWindowById", 1, self.getWindowById)
|
|
1511
1528
|
case "resetRootView": return FunctionCell_AnyOpt_to_Void.script("resetRootView", 1, self.resetRootView)
|