Appearance
JSInt8Array
extension type JSInt8Array(JSInt8ArrayRepType) implements JSTypedArrayAnnotations: @JS('Int8Array')
A JavaScript Int8Array.
Constructors
JSInt8Array()
JSInt8Array([JSArrayBuffer buffer, int byteOffset, int length])Creates a JavaScript Int8Array with buffer as its backing storage, offset by byteOffset bytes, of size length.
If no buffer is provided, creates an empty Int8Array.
Implementation
dart
@Since('3.6')
external JSInt8Array([JSArrayBuffer buffer, int byteOffset, int length]);JSInt8Array.withLength()
JSInt8Array.withLength(int length)Creates a JavaScript Int8Array of size length whose elements are initialized to 0.
Implementation
dart
@Since('3.6')
external JSInt8Array.withLength(int length);Properties
hashCode no setter inherited
int get hashCodeThe hash code for this object.
A hash code is a single integer which represents the state of the object that affects operator == comparisons.
All objects have hash codes. The default hash code implemented by Object represents only the identity of the object, the same way as the default operator == implementation only considers objects equal if they are identical (see identityHashCode).
If operator == is overridden to use the object state instead, the hash code must also be changed to represent that state, otherwise the object cannot be used in hash based data structures like the default Set and Map implementations.
Hash codes must be the same for objects that are equal to each other according to operator ==. The hash code of an object should only change if the object changes in a way that affects equality. There are no further requirements for the hash codes. They need not be consistent between executions of the same program and there are no distribution guarantees.
Objects that are not equal are allowed to have the same hash code. It is even technically allowed that all instances have the same hash code, but if clashes happen too often, it may reduce the efficiency of hash-based data structures like HashSet or HashMap.
If a subclass overrides hashCode, it should override the operator == operator as well to maintain consistency.
Inherited from Object.
Implementation
dart
external int get hashCode;isDefinedAndNotNull extension no setter
bool get isDefinedAndNotNullAvailable on JSAny, provided by the NullableUndefineableJSAnyExtension extension
Implementation
dart
bool get isDefinedAndNotNull => !isUndefinedOrNull;isNull extension no setter
bool get isNullWhether this value corresponds to JavaScript null.
INFO
Currently, there is no way to distinguish between JavaScript undefined and JavaScript null when compiling to Wasm. Therefore, this getter should only be used for code that compiles to JavaScript and will throw when compiling to Wasm.
Available on JSAny, provided by the NullableUndefineableJSAnyExtension extension
Implementation
dart
external bool get isNull;isTruthy extension no setter
JSBoolean get isTruthyThe result of <code>!!this</code> in JavaScript.
Available on JSAny, provided by the JSAnyOperatorExtension extension
Implementation
dart
external JSBoolean get isTruthy;isUndefined extension no setter
bool get isUndefinedWhether this value corresponds to JavaScript undefined.
INFO
Currently, there is no way to distinguish between JavaScript undefined and JavaScript null when compiling to Wasm. Therefore, this getter should only be used for code that compiles to JavaScript and will throw when compiling to Wasm.
Available on JSAny, provided by the NullableUndefineableJSAnyExtension extension
Implementation
dart
external bool get isUndefined;isUndefinedOrNull extension no setter
bool get isUndefinedOrNullAvailable on JSAny, provided by the NullableUndefineableJSAnyExtension extension
Implementation
dart
bool get isUndefinedOrNull => this == null;not extension no setter
JSBoolean get notThe result of <code>!this</code> in JavaScript.
Available on JSAny, provided by the JSAnyOperatorExtension extension
Implementation
dart
external JSBoolean get not;runtimeType no setter inherited
Type get runtimeTypeA representation of the runtime type of the object.
Inherited from Object.
Implementation
dart
external Type get runtimeType;toDart extension no setter
Int8List get toDartConverts this JSInt8Array to a Int8List by either casting or wrapping it.
INFO
Depending on whether code is compiled to JavaScript or Wasm, this conversion will have different semantics.
When compiling to JavaScript, Int8Lists are JSInt8Arrays and this operation will be a cast.
When compiling to Wasm, the JSInt8Array is wrapped with a Int8List implementation and the wrapper is returned.
Modifications to this JSInt8Array will affect the returned Int8List and vice versa.
Available on JSInt8Array, provided by the JSInt8ArrayToInt8List extension
Implementation
dart
external Int8List get toDart;Methods
add() extension
The result of <code>this + any</code> in JavaScript.
Available on JSAny, provided by the JSAnyOperatorExtension extension
Implementation
dart
external JSAny add(JSAny? any);and() extension
The result of <code>this && any</code> in JavaScript.
Available on JSAny, provided by the JSAnyOperatorExtension extension
Implementation
dart
external JSAny? and(JSAny? any);callMethod() extension
R callMethod<R extends JSAny?>(
JSAny method, [
JSAny? arg1,
JSAny? arg2,
JSAny? arg3,
JSAny? arg4,
])Calls method on this JSObject with up to four arguments.
Returns the result of calling method, which must be an R.
This helper doesn't allow passing nulls, as it determines whether an argument is passed based on whether it was null or not. Prefer callMethodVarArgs if you need to pass nulls.
Available on JSObject, provided by the JSObjectUnsafeUtilExtension extension
Implementation
dart
R callMethod<R extends JSAny?>(
JSAny method, [
JSAny? arg1,
JSAny? arg2,
JSAny? arg3,
JSAny? arg4,
]) => _callMethod(method, arg1, arg2, arg3, arg4) as R;callMethodVarArgs() extension
Calls method on this JSObject with a variable number of arguments.
Returns the result of calling method, which must be an R.
Available on JSObject, provided by the JSObjectUnsafeUtilExtension extension
Implementation
dart
R callMethodVarArgs<R extends JSAny?>(
JSAny method, [
List<JSAny?>? arguments,
]) => _callMethodVarArgs(method, arguments) as R;dartify() extension
Object? dartify()Converts a JavaScript JSON-like value to the Dart equivalent if possible.
Effectively the inverse of NullableObjectUtilExtension.jsify, dartify takes a JavaScript JSON-like value and recursively converts it to a Dart object, doing the following:
- If the value is a string, number, boolean,
null,undefined,DataViewor a typed array, does the equivalenttoDartoperation if it exists and returns the result. - If the value is a simple JS object (the protoype is either
nullor JSObject), creates and returns a[Map]<Object?, Object?>whose keys are the recursively converted keys obtained fromObject.keysand its values are the associated values of the keys in the JS object. - If the value is a JS
Array, each item in it is recursively converted and added to a new[List]<Object?>, which is then returned. - Otherwise, the conversion is undefined.
If the value contains a cycle, the behavior is undefined.
INFO
Prefer using the specific conversion member like toDart if you know the JavaScript type as this method may perform many type-checks. You should generally call this method with values that only contain JSON-like values as the conversion may be platform- and compiler-specific otherwise.
Available on JSAny, provided by the JSAnyUtilityExtension extension
Implementation
dart
// TODO(srujzs): We likely need stronger tests for this method to ensure
// consistency. We should also limit the accepted types in this API to avoid
// confusion. Once the conversion for unrelated types is consistent across all
// backends, we can update the documentation to say that the value is
// internalized instead of the conversion being undefined.
external Object? dartify();delete() extension
Deletes the property with key property from this JSObject.
Uses JavaScript's delete to delete the property.
Available on JSObject, provided by the JSObjectUnsafeUtilExtension extension
Implementation
dart
external JSBoolean delete(JSAny property);divide() extension
The result of <code>this / any</code> in JavaScript.
Available on JSAny, provided by the JSAnyOperatorExtension extension
Implementation
dart
external JSAny divide(JSAny? any);equals() extension
The result of <code>this == any</code> in JavaScript.
Available on JSAny, provided by the JSAnyOperatorExtension extension
Implementation
dart
external JSBoolean equals(JSAny? any);exponentiate() extension
The result of <code>this ** any</code> in JavaScript.
Available on JSAny, provided by the JSAnyOperatorExtension extension
Implementation
dart
external JSAny exponentiate(JSAny? any);getProperty() extension
R getProperty<R extends JSAny?>(JSAny property)The value of the property key property of this JSObject.
Available on JSObject, provided by the JSObjectUnsafeUtilExtension extension
Implementation
dart
external R getProperty<R extends JSAny?>(JSAny property);greaterThan() extension
The result of <code>this > any</code> in JavaScript.
Available on JSAny, provided by the JSAnyOperatorExtension extension
Implementation
dart
external JSBoolean greaterThan(JSAny? any);greaterThanOrEqualTo() extension
The result of <code>this >= any</code> in JavaScript.
Available on JSAny, provided by the JSAnyOperatorExtension extension
Implementation
dart
external JSBoolean greaterThanOrEqualTo(JSAny? any);has() extension
Shorthand helper for hasProperty to check whether this JSObject contains the property key property, but takes and returns a Dart value.
Available on JSObject, provided by the JSObjectUnsafeUtilExtension extension
Implementation
dart
bool has(String property) => hasProperty(property.toJS).toDart;hasProperty() extension
Whether or not this JSObject contains the property key property.
Uses JavaScript's in to check.
Available on JSObject, provided by the JSObjectUnsafeUtilExtension extension
Implementation
dart
external JSBoolean hasProperty(JSAny property);instanceof() extension
bool instanceof(JSFunction constructor)Whether this <code>JSAny?</code> is an instanceof constructor.
Available on JSAny, provided by the JSAnyUtilityExtension extension
Implementation
dart
external bool instanceof(JSFunction constructor);instanceOfString() extension
Whether this <code>JSAny?</code> is an instanceof the constructor that is defined by constructorName, which is looked up in the globalContext.
If constructorName contains '.'s, the name is split into several parts in order to get the constructor. For example, library1.JSClass would involve fetching library1 off of the globalContext, and then fetching JSClass off of library1 to get the constructor.
If constructorName is empty or any of the parts or the constructor don't exist, returns false.
Available on JSAny, provided by the JSAnyUtilityExtension extension
Implementation
dart
bool instanceOfString(String constructorName) {
if (constructorName.isEmpty) return false;
final parts = constructorName.split('.');
JSObject? constructor = globalContext;
for (final part in parts) {
constructor = constructor?[part] as JSObject?;
if (constructor == null) return false;
}
return instanceof(constructor as JSFunction);
}isA() extension
bool isA<T extends JSAny?>()Whether this <code>JSAny?</code> is an instance of the JavaScript type that is declared by T.
Since the type-check this function emits is determined at compile-time, T needs to be an interop extension type that can also be determined at compile-time. In particular, isA can't be provided a generic type variable as a type argument.
This method uses a combination of null, typeof, and instanceof checks in order to do this check. Use this instead of is checks.
If T is a primitive JS type like JSString, this uses a typeof check that corresponds to that primitive type like typeofEquals('string').
If T is a non-primitive JS type like JSArray or an interop extension type on one, this uses an instanceof check using the name or the <code>@JS</code> rename of the given type like instanceOfString('Array'). Note that if you rename the library using the <code>@JS</code> annotation, this uses the rename in the instanceof check like instanceOfString('library1.JSClass').
To determine the JavaScript constructor to use as the second operand in the instanceof check, this function uses the JavaScript name associated with the extension type, which is either the argument given to the <code>@JS</code> annotation or the Dart declaration name. So, if you had an interop extension type JSClass that wraps JSArray without a rename, this does an instanceOfString('JSClass') check and not an instanceOfString('Array') check.
There are a few values for T that are exceptions to this rule:
JSTypedArray: AsTypedArraydoes not exist as a class in JavaScript, this does some prototype checking to makeisA<JSTypedArray>do the right thing.JSBoxedDartObject:isA<JSBoxedDartObject>will check if the value is a result of a previous ObjectToJSBoxedDartObject.toJSBox call.JSAny: If you do anisA<JSAny>check, it will only check fornull.- User interop types whose representation types are JS primitive types: This will result in an error to avoid confusion on whether the user interop type is used in the type-check. Use the primitive JS type as the value for
Tinstead. - User interop types that have an object literal constructor: This will result in an error as you likely want to use JSObject instead.
Available on JSAny, provided by the JSAnyUtilityExtension extension
Implementation
dart
@Since('3.4')
external bool isA<T extends JSAny?>();lessThan() extension
The result of <code>this < any</code> in JavaScript.
Available on JSAny, provided by the JSAnyOperatorExtension extension
Implementation
dart
external JSBoolean lessThan(JSAny? any);lessThanOrEqualTo() extension
The result of <code>this <= any</code> in JavaScript.
Available on JSAny, provided by the JSAnyOperatorExtension extension
Implementation
dart
external JSBoolean lessThanOrEqualTo(JSAny? any);modulo() extension
The result of <code>this % any</code> in JavaScript.
Available on JSAny, provided by the JSAnyOperatorExtension extension
Implementation
dart
external JSAny modulo(JSAny? any);multiply() extension
The result of <code>this * any</code> in JavaScript.
Available on JSAny, provided by the JSAnyOperatorExtension extension
Implementation
dart
external JSAny multiply(JSAny? any);noSuchMethod() inherited
dynamic noSuchMethod(Invocation invocation)Invoked when a nonexistent method or property is accessed.
A dynamic member invocation can attempt to call a member which doesn't exist on the receiving object. Example:
dart
dynamic object = 1;
object.add(42); // Statically allowed, run-time errorThis invalid code will invoke the noSuchMethod method of the integer 1 with an Invocation representing the .add(42) call and arguments (which then throws).
Classes can override noSuchMethod to provide custom behavior for such invalid dynamic invocations.
A class with a non-default noSuchMethod invocation can also omit implementations for members of its interface. Example:
dart
class MockList<T> implements List<T> {
noSuchMethod(Invocation invocation) {
log(invocation);
super.noSuchMethod(invocation); // Will throw.
}
}
void main() {
MockList().add(42);
}This code has no compile-time warnings or errors even though the MockList class has no concrete implementation of any of the List interface methods. Calls to List methods are forwarded to noSuchMethod, so this code will log an invocation similar to Invocation.method(#add, [42]) and then throw.
If a value is returned from noSuchMethod, it becomes the result of the original invocation. If the value is not of a type that can be returned by the original invocation, a type error occurs at the invocation.
The default behavior is to throw a NoSuchMethodError.
Inherited from Object.
Implementation
dart
@pragma("vm:entry-point")
@pragma("wasm:entry-point")
external dynamic noSuchMethod(Invocation invocation);notEquals() extension
The result of <code>this != any</code> in JavaScript.
Available on JSAny, provided by the JSAnyOperatorExtension extension
Implementation
dart
external JSBoolean notEquals(JSAny? any);or() extension
The result of <code>this || any</code> in JavaScript.
Available on JSAny, provided by the JSAnyOperatorExtension extension
Implementation
dart
external JSAny? or(JSAny? any);setProperty() extension
Write the value of property key property of this JSObject.
Available on JSObject, provided by the JSObjectUnsafeUtilExtension extension
Implementation
dart
external void setProperty(JSAny property, JSAny? value);strictEquals() extension
The result of <code>this === any</code> in JavaScript.
Available on JSAny, provided by the JSAnyOperatorExtension extension
Implementation
dart
external JSBoolean strictEquals(JSAny? any);strictNotEquals() extension
The result of <code>this !== any</code> in JavaScript.
Available on JSAny, provided by the JSAnyOperatorExtension extension
Implementation
dart
external JSBoolean strictNotEquals(JSAny? any);subtract() extension
The result of <code>this - any</code> in JavaScript.
Available on JSAny, provided by the JSAnyOperatorExtension extension
Implementation
dart
external JSAny subtract(JSAny? any);toString() inherited
String toString()A string representation of this object.
Some classes have a default textual representation, often paired with a static parse function (like int.parse). These classes will provide the textual representation as their string representation.
Other classes have no meaningful textual representation that a program will care about. Such classes will typically override toString to provide useful information when inspecting the object, mainly for debugging or logging.
Inherited from Object.
Implementation
dart
external String toString();typeofEquals() extension
Whether the result of typeof on this <code>JSAny?</code> is typeString.
Available on JSAny, provided by the JSAnyUtilityExtension extension
Implementation
dart
external bool typeofEquals(String typeString);unsignedRightShift() extension
The result of <code>this >>> any</code> in JavaScript.
Available on JSAny, provided by the JSAnyOperatorExtension extension
Implementation
dart
// TODO(srujzs): This should return `num` or `double` instead.
external JSNumber unsignedRightShift(JSAny? any);Operators
operator ==() inherited
The equality operator.
The default behavior for all Objects is to return true if and only if this object and other are the same object.
Override this method to specify a different equality relation on a class. The overriding method must still be an equivalence relation. That is, it must be:
Total: It must return a boolean for all arguments. It should never throw.
Reflexive: For all objects
o,o == omust be true.Symmetric: For all objects
o1ando2,o1 == o2ando2 == o1must either both be true, or both be false.Transitive: For all objects
o1,o2, ando3, ifo1 == o2ando2 == o3are true, theno1 == o3must be true.
The method should also be consistent over time, so whether two objects are equal should only change if at least one of the objects was modified.
If a subclass overrides the equality operator, it should override the hashCode method as well to maintain consistency.
Inherited from Object.
Implementation
dart
external bool operator ==(Object other);operator extension
Shorthand helper for getProperty to get the value of the property key property of this JSObject, but takes a Dart value.
Available on JSObject, provided by the JSObjectUnsafeUtilExtension extension
Implementation
dart
JSAny? operator [](String property) => getProperty(property.toJS);operator []=() extension
Shorthand helper for setProperty to write the value of the property key property of this JSObject, but takes a Dart value.
Available on JSObject, provided by the JSObjectUnsafeUtilExtension extension
Implementation
dart
void operator []=(String property, JSAny? value) =>
setProperty(property.toJS, value);