This commit is contained in:
Dante
2026-05-21 23:40:20 -07:00
parent 3e2915dff7
commit 877a69d844
5737 changed files with 29796 additions and 1589684 deletions

View File

@ -29,7 +29,7 @@ class Cookie {
Create or update a cookie.
@param expireDelay In seconds. If null, the cookie expires at end of session.
**/
public static function set(name:String, value:String, ?expireDelay:Int, ?path:String, ?domain:String) {
public static function set(name:String, value:String, ?expireDelay:Int, ?path:String, ?domain:String, ?secure:Bool, ?sameSite:String) {
var s = name + "=" + StringTools.urlEncode(value);
if (expireDelay != null) {
var d = DateTools.delta(Date.now(), expireDelay * 1000);
@ -41,6 +41,12 @@ class Cookie {
if (domain != null) {
s += ";domain=" + domain;
}
if (secure == true) {
s += ";secure";
}
if (sameSite != null) {
s += ";SameSite=" + sameSite;
}
Browser.document.cookie = s;
}

View File

@ -34,6 +34,14 @@ class Lib {
js.Syntax.code("debugger");
}
/**
Inserts an `import` expression that loads JavaScript object from
a module or file specified in the `module` argument.
**/
public static inline function dynamicImport(module:String):js.lib.Promise<Dynamic> {
return js.Syntax.code("import({0})", module);
}
/**
Display an alert message box containing the given message.
@deprecated Use Browser.alert() instead.
@ -124,7 +132,7 @@ class Lib {
}
/**
Re-throw last cathed exception, preserving original stack information.
Re-throw last caught exception, preserving original stack information.
Calling this is only possible inside a catch statement.
**/

View File

@ -79,12 +79,8 @@
return (a == b) ? 0 : (((cast a) > (cast b)) ? 1 : -1);
}
public static function compareMethods(f1:Dynamic, f2:Dynamic):Bool {
if (f1 == f2)
return true;
if (!isFunction(f1) || !isFunction(f2))
return false;
return f1.scope == f2.scope && f1.method == f2.method && f1.method != null;
public static inline function compareMethods(f1:Dynamic, f2:Dynamic):Bool {
return f1 == f2;
}
@:access(js.Boot)

View File

@ -54,17 +54,24 @@ import js.Syntax;
@:pure
public static function parseInt(x:String):Null<Int> {
if(x != null) {
for(i in 0...x.length) {
var c = StringTools.fastCodeAt(x, i);
if(c <= 8 || (c >= 14 && c != ' '.code && c != '-'.code)) {
var nc = StringTools.fastCodeAt(x, i + 1);
var v = js.Lib.parseInt(x, (nc == "x".code || nc == "X".code) ? 16 : 10);
return Math.isNaN(v) ? null : cast v;
}
#if (js_es >= 5)
final v = js.Lib.parseInt(x);
#else
// before ES5, octal was supported in some implementations, so we need to explicitly use base 10 or 16
if (x == null)
return null;
var v:Float = Math.NaN;
for (i => c in StringTools.keyValueIterator(x)) {
if ((c <= 8 || c >= 14) && !(c == ' '.code || c == '-'.code || c == '+'.code)) {
final nc = js.Syntax.code("{0}[{1}]", x, i + 1);
v = js.Lib.parseInt(x, c == '0'.code && (nc == "x" || nc == "X") ? 16 : 10);
break;
}
}
return null;
#end
if (Math.isNaN(v))
return null;
return cast v;
}
public static inline function parseFloat(x:String):Float {
@ -77,7 +84,7 @@ import js.Syntax;
static function __init__():Void
untyped {
__feature__("js.Boot.getClass", String.prototype.__class__ = __feature__("Type.resolveClass", $hxClasses["String"] = String, String));
__feature__("js.Boot.getClass", Object.defineProperty(String.prototype, "__class__", {value: __feature__("Type.resolveClass", $hxClasses["String"] = String, String), enumerable: false, writable: true}));
__feature__("js.Boot.isClass", String.__name__ = __feature__("Type.getClassName", "String", true));
__feature__("Type.resolveClass", $hxClasses["Array"] = Array);
__feature__("js.Boot.isClass", Array.__name__ = __feature__("Type.getClassName", "Array", true));

View File

@ -62,7 +62,7 @@ class NativeStackTrace {
for (i in 0...stack.length) {
if(skip > i) continue;
var line = stack[i];
var matched:Null<Array<String>> = Syntax.code('{0}.match(/^ at ([A-Za-z0-9_. ]+) \\(([^)]+):([0-9]+):([0-9]+)\\)$/)', line);
var matched:Null<Array<String>> = Syntax.code("{0}.match(/^ at ([$A-Za-z0-9_. ]+) \\(([^)]+):([0-9]+):([0-9]+)\\)$/)", line);
if (matched != null) {
var path = matched[1].split(".");
if(path[0] == "$hxClasses") {

View File

@ -0,0 +1,50 @@
package haxe.atomic;
import js.lib.Atomics;
abstract AtomicInt(js.lib.Int32Array) {
public inline function new(value:Int) {
this = new js.lib.Int32Array(new js.lib.SharedArrayBuffer(js.lib.Int32Array.BYTES_PER_ELEMENT));
this[0] = value;
}
private function asArray():js.lib.Int32Array {
return this;
}
public inline function add(b:Int):Int {
return Atomics.add(asArray(), 0, b);
}
public inline function sub(b:Int):Int {
return Atomics.sub(asArray(), 0, b);
}
public inline function and(b:Int):Int {
return Atomics.and(asArray(), 0, b);
}
public inline function or(b:Int):Int {
return Atomics.or(asArray(), 0, b);
}
public inline function xor(b:Int):Int {
return Atomics.xor(asArray(), 0, b);
}
public inline function compareExchange(expected:Int, replacement:Int):Int {
return Atomics.compareExchange(asArray(), 0, expected, replacement);
}
public inline function exchange(value:Int):Int {
return Atomics.exchange(asArray(), 0, value);
}
public inline function load():Int {
return Atomics.load(asArray(), 0);
}
public inline function store(value:Int):Int {
return Atomics.store(asArray(), 0, value);
}
}

View File

@ -81,7 +81,7 @@ package haxe.ds;
public function toString():String {
var s = new StringBuf();
s.add("{");
s.add("[");
var it = keys();
for (i in it) {
s.add(i);
@ -90,7 +90,7 @@ package haxe.ds;
if (it.hasNext())
s.add(", ");
}
s.add("}");
s.add("]");
return s.toString();
}

View File

@ -27,13 +27,6 @@ import js.Lib;
@:coreApi
class ObjectMap<K:{}, V> implements haxe.Constraints.IMap<K, V> {
static var count:Int;
// initialize count through __init__ magic, because these are generated
// before normal static initializations for which ObjectMap should be ready to use
// see https://github.com/HaxeFoundation/haxe/issues/6792
static inline function __init__():Void
count = 0;
static inline function assignId(obj:{}):Int {
return Syntax.code('({0}.__id__ = {1})', obj, Lib.getNextHaxeUID());
@ -113,7 +106,7 @@ class ObjectMap<K:{}, V> implements haxe.Constraints.IMap<K, V> {
public function toString():String {
var s = new StringBuf();
s.add("{");
s.add("[");
var it = keys();
for (i in it) {
s.add(Std.string(i));
@ -122,7 +115,7 @@ class ObjectMap<K:{}, V> implements haxe.Constraints.IMap<K, V> {
if (it.hasNext())
s.add(", ");
}
s.add("}");
s.add("]");
return s.toString();
}

View File

@ -87,12 +87,12 @@ import haxe.DynamicAccess;
@:analyzer(no_optimize)
static function stringify(h:Dynamic):String {
var s = "{", first = true;
var s = "[", first = true;
js.Syntax.code("for (var key in {0}) {", h);
js.Syntax.code("\tif ({0}) {0} = false; else {1} += ',';", first, s);
js.Syntax.code("\t{0} += key + ' => ' + {1}({2}[key]);", s, Std.string, h);
js.Syntax.code("}");
return s + "}";
return s + "]";
}
}
@ -286,7 +286,7 @@ private class StringMapIterator<T> {
public function toString():String {
var s = new StringBuf();
s.add("{");
s.add("[");
var keys = arrayKeys();
for (i in 0...keys.length) {
var k = keys[i];
@ -296,7 +296,7 @@ private class StringMapIterator<T> {
if (i < keys.length - 1)
s.add(", ");
}
s.add("}");
s.add("]");
return s.toString();
}

View File

@ -0,0 +1,34 @@
package js.html;
import js.lib.Promise;
/**
The `BeforeInstallPromptEvent` is fired at the `Window.onbeforeinstallprompt` handler,
before a user is prompted to install a web site to a home screen.
@see https://developer.mozilla.org/en-US/docs/Web/API/BeforeInstallPromptEvent
**/
@:native("BeforeInstallPromptEvent")
extern class BeforeInstallPromptEvent extends Event {
/** The platforms on which this event was dispatched. **/
final platforms: Array<String>;
/** The user's choice to the install prompt. **/
final userChoice: Promise<BeforeInstallPromptUserChoice>;
/** Creates a new `BeforeInstallPromptEvent`. **/
function new();
/** Shows the install prompt. **/
function prompt(): Promise<Dynamic>;
}
typedef BeforeInstallPromptUserChoice = {
final outcome: BeforeInstallPromptUserChoiceOutcome;
}
enum abstract BeforeInstallPromptUserChoiceOutcome(String) {
var Accepted = "accepted";
var Dismissed = "dismissed";
}

View File

@ -391,7 +391,6 @@ extern class DOMElement extends Node {
Inserts a given element node at a given position relative to the element it is invoked upon.
@throws DOMError
**/
@:pure
function insertAdjacentElement( where : String, element : Element ) : Element;
/**
@ -504,8 +503,8 @@ extern class DOMElement extends Node {
Asynchronously asks the browser to make the element full-screen.
@throws DOMError
**/
function requestFullscreen() : Void;
function requestFullscreen(?options: FullscreenOptions) : js.lib.Promise<Void>;
/**
Allows to asynchronously ask for the pointer to be locked on the given element.
**/
@ -550,4 +549,4 @@ extern class DOMElement extends Node {
/** @throws DOMError */
@:overload( function( nodes : haxe.extern.Rest<String>) : Void {} )
function append( nodes : haxe.extern.Rest<Node> ) : Void;
}
}

View File

@ -0,0 +1,60 @@
/*
* Copyright (C)2005-2022 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package js.html;
/**
The `HTMLDialogElement` interface provides methods to manipulate `<dialog>` elements.
It inherits properties and methods from the `HTMLElement` interface.
@see <https://developer.mozilla.org/en-US/docs/Web/API/HTMLDialogElement>
**/
@:native("HTMLDialogElement")
extern class DialogElement extends Element {
/**
A `Boolean` reflecting the open HTML attribute, indicating whether the dialog is available for interaction.
**/
var open: Bool;
/**
A `DOMString` that sets or returns the return value for the dialog.
**/
var returnValue: String;
/**
Closes the dialog.
An optional `DOMString` may be passed as an argument, updating the `returnValue` of the the dialog.
**/
function close(?returnValue: String): Void;
/**
Displays the dialog modelessly, i.e. still allowing interaction with content outside of the dialog.
**/
function show(): Void;
/**
Displays the dialog as a modal, over the top of any other dialogs that might be present.
Interaction outside the dialog is blocked.
**/
function showModal(): Void;
}

View File

@ -510,8 +510,13 @@ extern class Document extends Node {
Releases the current mouse capture if it's on an element in this document.
**/
function releaseCapture() : Void;
function exitFullscreen() : Void;
/**
Requests that the element on this document which is currently being presented in fullscreen mode
be taken out of fullscreen mode, restoring the previous state of the screen.
**/
function exitFullscreen() : js.lib.Promise<Void>;
/**
Release the pointer lock.
**/

View File

@ -0,0 +1,40 @@
/*
* Copyright (C)2005-2022 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package js.html;
/**
An object that controls the behavior of the transition to fullscreen mode.
**/
typedef FullscreenOptions = {
/**
Controls whether or not to show navigation UI while the element is in fullscreen mode.
**/
var ?navigationUI: FullscreenOptionsNavigationUI;
}
enum abstract FullscreenOptionsNavigationUI(String) {
var Auto = "auto";
var Hide = "hide";
var Show = "show";
}

View File

@ -192,5 +192,6 @@ extern class HTMLDocument extends Document {
inline function createTableRowElement() : TableRowElement { return cast createElement("tr"); }
/** Shorthand for creating an HTML `<html>` element. */
inline function createHtmlElement() : HtmlElement { return cast createElement("html"); }
}
/** Shorthand for creating an HTML `<dialog>` element. */
inline function createDialoglElement() : DialogElement { return cast createElement("dialog"); }
}

View File

@ -20,8 +20,6 @@
* DEALINGS IN THE SOFTWARE.
*/
// This file is generated from mozilla\Window.webidl. Do not edit!
package js.html;
import js.lib.Promise;
@ -559,6 +557,11 @@ extern class Window extends EventTarget {
**/
function dump( str : String ) : Void;
/**
Creates a deep clone of a given value using the structured clone algorithm.
**/
function structuredClone<T>(value: T, ?options: {transfer: Array<Any>}): T;
/**
Toggles a user's ability to resize a window.
**/

View File

@ -20,8 +20,6 @@
* DEALINGS IN THE SOFTWARE.
*/
// This file is generated from mozilla\WorkerGlobalScope.webidl. Do not edit!
package js.html;
import js.lib.Promise;
@ -83,6 +81,12 @@ extern class WorkerGlobalScope extends EventTarget {
Allows you to write a message to stdout — i.e. in your terminal. This is the same as Firefox's `window.dump`, but for workers.
**/
function dump( ?str : String ) : Void;
/**
Creates a deep clone of a given value using the structured clone algorithm.
**/
function structuredClone<T>(value: T, ?options: {transfer: Array<Any>}): T;
/** @throws DOMError */
function btoa( btoa : String ) : String;
/** @throws DOMError */

View File

@ -0,0 +1,99 @@
package js.lib;
private typedef E<A, B> = haxe.extern.EitherType<A, B>;
private typedef IntTypedArray = E<Int8Array, E<Uint8Array, E<Int16Array, E<Uint16Array, E<Int32Array, Uint32Array>>>>>;
/**
The Atomics object provides atomic operations as static methods. They are used with SharedArrayBuffer and ArrayBuffer objects.
Documentation [Atomics](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics) by [Mozilla Contributors](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/contributors.txt), licensed under [CC-BY-SA 2.5](https://creativecommons.org/licenses/by-sa/2.5/).
**/
@:native("Atomics")
extern class Atomics {
/**
Adds the provided value to the existing value at the specified index of the array.
Returns the old value at that index.
This atomic operation guarantees that no other write happens until the modified value is written back.
**/
static function add(typedArray:IntTypedArray, index:Int, value:Int):Int;
/**
Computes a bitwise AND on the value at the specified index of the array with the provided value.
Returns the old value at that index.
This atomic operation guarantees that no other write happens until the modified value is written back.
**/
static function and(typedArray:IntTypedArray, index:Int, value:Int):Int;
/**
Stores a value at the specified index of the array, if it equals a value.
Returns the old value.
This atomic operation guarantees that no other write happens until the modified value is written back.
**/
static function compareExchange(typedArray:IntTypedArray, index:Int, expectedValue:Int, replacementValue:Int):Int;
/**
Stores a value at the specified index of the array.
Returns the old value.
This atomic operation guarantees that no other write happens until the modified value is written back.
**/
static function exchange(typedArray:IntTypedArray, index:Int, value:Int):Int;
/**
An optimization primitive that can be used to determine whether to use locks or atomic operations.
Returns `true` if an atomic operation on arrays of the given element size will be implemented using a hardware atomic operation (as opposed to a lock). Experts only.
**/
static function isLockFree(size:Int):Bool;
/**
Returns the value at the specified index of the array.
This atomic operation guarantees that no other write happens until the modified value is written back.
**/
static function load(typedArray:IntTypedArray, index:Int):Int;
/**
Notifies agents that are waiting on the specified index of the array.
Returns the number of agents that were notified.
**/
static function notify(typedArray:IntTypedArray, index:Int, ?count:Int):Int;
/**
Computes a bitwise OR on the value at the specified index of the array with the provided value.
Returns the old value at that index.
This atomic operation guarantees that no other write happens until the modified value is written back.
**/
static function or(typedArray:IntTypedArray, index:Int, value:Int):Int;
/**
Stores a value at the specified index of the array.
Returns the value.
This atomic operation guarantees that no other write happens until the modified value is written back.
**/
static function store(typedArray:IntTypedArray, index:Int, value:Int):Int;
/**
Subtracts a value at the specified index of the array.
Returns the old value at that index.
This atomic operation guarantees that no other write happens until the modified value is written back.
**/
static function sub(typedArray:IntTypedArray, index:Int, value:Int):Int;
/**
Verifies that the specified index of the array still contains a value and sleeps awaiting or times out.
Returns either "ok", "not-equal", or "timed-out". If waiting is not allowed in the calling agent then it throws an Error exception.
Most browsers will not allow wait() on the browser's main thread.)
**/
static function wait(typedArray:Int32Array, index:Int, value:Int, ?timeout:Int):WaitValue;
/**
Computes a bitwise XOR on the value at the specified index of the array with the provided value.
Returns the old value at that index.
This atomic operation guarantees that no other write happens until the modified value is written back.
**/
static function xor(typedArray:IntTypedArray, index:Int, value:Int):Int;
}
enum abstract WaitValue(String) {
var OK = "ok";
var NotEqual = "not-equal";
var TimedOut = "timed-out";
}

View File

@ -34,9 +34,13 @@ import haxe.extern.EitherType;
@see <https://developer.mozilla.org/en-US/docs/Web/API/BufferSource>
*/
@:forward
abstract BufferSource(ArrayBuffer) to ArrayBuffer from ArrayBuffer {
@:from public static inline function fromBufferView(view:ArrayBufferView) {
return cast view.buffer;
abstract BufferSource(Dynamic) from ArrayBuffer from ArrayBufferView {
public var byteLength(get, never): Int;
@:pure
inline function get_byteLength(): Int {
return this.byteLength;
}
}

View File

@ -59,7 +59,8 @@ extern class Promise<T> {
the first promise in the iterable that rejected. This method can be
useful for aggregating results of multiple promises.
**/
static function all(iterable:Array<Dynamic>):Promise<Array<Dynamic>>;
@:overload(function(iterable:Array<Dynamic>):Promise<Array<Dynamic>> {})
static function all<T>(iterable:Array<Promise<T>>):Promise<Array<T>>;
/**
Returns a promise that resolves after all of the given promises have either fulfilled or rejected,
@ -71,14 +72,16 @@ extern class Promise<T> {
In comparison, the Promise returned by `Promise.all` may be more appropriate if the tasks are dependent
on each other / if you'd like to immediately reject upon any of them rejecting.
**/
static function allSettled(iterable:Array<Dynamic>):Promise<Array<PromiseSettleOutcome>>;
@:overload(function(iterable:Array<Dynamic>):Promise<Array<PromiseSettleOutcome<Dynamic>>> {})
static function allSettled<T>(iterable:Array<Promise<T>>):Promise<Array<PromiseSettleOutcome<T>>>;
/**
Returns a promise that fulfills or rejects as soon as one of the
promises in the iterable fulfills or rejects, with the value or reason
from that promise.
**/
static function race(iterable:Array<Dynamic>):Promise<Dynamic>;
@:overload(function(iterable:Array<Dynamic>):Promise<Dynamic> {})
static function race<T>(iterable:Array<Promise<T>>):Promise<T>;
/** @throws DOMError */
function new(init:(resolve:(value:T) -> Void, reject:(reason:Dynamic) -> Void) -> Void):Void;
@ -129,9 +132,9 @@ typedef ThenableStruct<T> = {
function then<TOut>(onFulfilled:Null<PromiseHandler<T, TOut>>, ?onRejected:PromiseHandler<Dynamic, TOut>):Thenable<TOut>;
}
typedef PromiseSettleOutcome = {
typedef PromiseSettleOutcome<T> = {
var status:PromiseSettleStatus;
var ?value:Dynamic;
var ?value:T;
var ?reason:Dynamic;
}

View File

@ -0,0 +1,16 @@
package js.lib;
/**
The SharedArrayBuffer object is used to represent a generic, fixed-length raw binary data buffer, similar to the ArrayBuffer object, but in a way that they can be used to create views on shared memory.
A SharedArrayBuffer is not a Transferable Object, unlike an ArrayBuffer which is transferable.
Documentation [SharedArrayBuffer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer) by [Mozilla Contributors](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/contributors.txt), licensed under [CC-BY-SA 2.5](https://creativecommons.org/licenses/by-sa/2.5/).
**/
@:native("SharedArrayBuffer")
extern class SharedArrayBuffer {
final byteLength:Int;
function new(?length:Int):Void;
function slice(?begin:Int, ?end:Int):ArrayBuffer;
}

View File

@ -0,0 +1,38 @@
package js.lib;
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
/**
The `WeakRef` object lets you hold a weak reference to another object, without preventing that object from getting garbage-collected.
Documentation [WeakRef](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakRef) by [Mozilla Contributors](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakRef$history), licensed under [CC-BY-SA 2.5](https://creativecommons.org/licenses/by-sa/2.5/).
**/
@:native("WeakRef")
extern class WeakRef<T:{}> {
/**
Creates a new WeakRef object.
**/
@:pure function new(target:T);
/**
Returns the WeakRef object's target object, or null if the target object has been reclaimed.
**/
@:pure function deref():Null<T>;
}

View File

@ -0,0 +1,133 @@
/*
* Copyright (C)2005-2021 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package js.lib.intl;
/**
The `Intl.DisplayNames` object enables the consistent translation of language,
region and script display names.
**/
@:native("Intl.DisplayNames")
extern class DisplayNames {
/**
Creates a new `Intl.DisplayNames` object.
**/
@:overload(function(?locales: Array<String>, ?options: DisplayNamesOptions): Void {})
function new(?locales: String, ?options: DisplayNamesOptions);
/**
Receives a code and returns a string based on the locale and options
provided when instantiating `Intl.DisplayNames`.
**/
function of(code: String): String;
/**
Returns a new object with properties reflecting the locale and formatting options
computed during initialization of the object.
**/
function resolvedOptions(): DisplayNamesResolvedOptions;
/**
Returns an array containing those of the provided locales that are supported
in display names without having to fall back to the runtime's default locale.
**/
@:overload(function(locales: Array<String>, ?options: DisplayNamesSupportedLocalesOfOptions): Array<String> {})
static function supportedLocalesOf(locales: String, ?options: DisplayNamesSupportedLocalesOfOptions): Array<String>;
}
enum abstract DisplayNamesFallback(String) {
var Code = "code";
var None = "none";
}
typedef DisplayNamesOptions = {
/**
The fallback to use.
The default is `Code`.
**/
var fallback: DisplayNamesFallback;
/**
The locale matching algorithm to use.
The default is `BestFit`.
**/
var ?localeMatcher: LocaleMatcher;
/**
The formatting style to use.
The default is `Long`.
**/
var ?style: DisplayNamesStyle;
/**
The type to use.
The default is `Language`.
**/
var ?type: DisplayNamesType;
}
typedef DisplayNamesResolvedOptions = {
/**
The value provided for this property in the `options` argument of the constructor
or the default value (`Code`).
**/
final fallback: DisplayNamesFallback;
/**
The BCP 47 language tag for the locale actually used.
**/
final locale: String;
/**
The value provided for this property in the `options` argument of the constructor
or the default value (`Long`).
**/
final style: DisplayNamesStyle;
/**
The value provided for this property in the `options` argument of the constructor
or the default value (`Language`).
**/
final type: DisplayNamesType;
}
enum abstract DisplayNamesStyle(String) {
var Long = "long";
var Narrow = "narrow";
var Short = "short";
}
typedef DisplayNamesSupportedLocalesOfOptions = {
/**
The locale matching algorithm to use.
The default is `BestFit`.
*/
var ?localeMatcher: LocaleMatcher;
}
enum abstract DisplayNamesType(String) {
var Currency = "currency";
var Language = "language";
var Region = "region";
var Script = "script";
}

View File

@ -0,0 +1,121 @@
/*
* Copyright (C)2005-2021 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package js.lib.intl;
/**
The `Intl.ListFormat` object enables language-sensitive list formatting.
**/
@:native("Intl.ListFormat")
extern class ListFormat {
/**
Creates a new `Intl.ListFormat` object.
**/
@:overload(function(?locales: Array<String>, ?options: ListFormatOptions): Void {})
function new(?locales: String, ?options: ListFormatOptions);
/**
Returns a language-specific formatted string representing the elements of the list.
**/
function format(?list: Array<String>): String;
/**
Returns an array of objects representing the different components
that can be used to format a list of values in a locale-aware fashion.
**/
function formatToParts(?list: Array<String>): Array<ListFormatPart>;
/**
Returns an array containing those of the provided locales that are supported
without having to fall back to the runtime's default locale.
**/
@:overload(function(locales: Array<String>, ?options: ListFormatSupportedLocalesOfOptions): Array<String> {})
static function supportedLocalesOf(locales: String, ?options: ListFormatSupportedLocalesOfOptions): Array<String>;
}
typedef ListFormatOptions = {
/**
The locale matching algorithm to use.
The default is `BestFit`.
**/
var ?localeMatcher: LocaleMatcher;
/**
The length of the formatted message.
The default is `Long`.
**/
var ?style: ListFormatStyle;
/**
The format of output message.
**/
var ?type: ListFormatType;
}
typedef ListFormatPart = {
final type: ListFormatPartType;
final value: String;
}
enum abstract ListFormatPartType(String) {
/**
A value from the list.
**/
var Element = "element";
/**
A linguistic construct.
**/
var Literal = "literal";
}
enum abstract ListFormatStyle(String) {
var Long = "long";
var Narrow = "narrow";
var Short = "short";
}
typedef ListFormatSupportedLocalesOfOptions = {
/**
The locale matching algorithm to use.
The default is `BestFit`.
*/
var ?localeMatcher: LocaleMatcher;
}
enum abstract ListFormatType(String) {
/**
Stands for "and"-based lists.
**/
var Conjunction = "conjunction";
/**
Stands for "or"-based lists.
**/
var Disjunction = "disjunction";
/**
Stands for lists of values with units.
**/
var Unit = "unit";
}