dart:js_util library Null safety

Utility methods to manipulate package:js annotated JavaScript interop objects in cases where the name to call is not known at runtime.

You should only use these methods when the same effect cannot be achieved with @JS() annotations.

Properties

globalThis Object
read-only
objectPrototype Object?
Returns the Object prototype. Equivalent to Object.prototype.
read-only

Functions

add<T>(Object? first, Object? second) → T
Perform JavaScript addition (+) on two values.
callConstructor<T>(Object constr, List<Object?>? arguments) → T
callMethod<T>(Object o, String method, List<Object?> args) → T
createDartExport<T extends Object>(T dartObject) Object
Given a Dart object that is marked exportable, creates a JS object literal that forwards to that Dart class. Look at the @JSExport annotation to determine what constitutes "exportable" for a Dart class. The object literal will be a map of export names (which are either the written instance member names or their rename) to their respective Dart instance members.
createStaticInteropMock<T extends Object, U extends Object>(U dartMock, [Object? proto = null]) → T
Given a @staticInterop type T and an instance dartMock of a Dart class U that implements the external extension members of T, creates a forwarding mock.
dartify(Object? o) Object?
Effectively the inverse of jsify, dartify Takes a JavaScript object, and converts it to a Dart based object. Only JS primitives, arrays, or 'map' like JS objects are supported.
divide<T>(Object? first, Object? second) → T
Perform JavaScript division (/) on two values.
equal<T>(Object? first, Object? second) bool
Perform JavaScript equality comparison (==) on two values.
exponentiate<T>(Object? first, Object? second) → T
Perform JavaScript exponentiation (**) on two values.
getProperty<T>(Object o, Object name) → T
greaterThan<T>(Object? first, Object? second) bool
Perform JavaScript greater than comparison (>) of two values.
greaterThanOrEqual<T>(Object? first, Object? second) bool
Perform JavaScript greater than or equal comparison (>=) of two values.
hasProperty(Object o, Object name) bool
instanceof(Object? o, Object type) bool
Check whether o is an instance of type.
instanceOfString(Object? element, String objectType) bool
Like instanceof only takes a String for the object name instead of a constructor object.
isJavaScriptArray(dynamic value) bool
Returns true if a given object is a JavaScript array.
isJavaScriptSimpleObject(dynamic value) bool
Returns true if a given object is a simple JavaScript object.
jsify(Object object) → dynamic
Recursively converts a JSON-like collection to JavaScript compatible representation.
lessThan<T>(Object? first, Object? second) bool
Perform JavaScript less than comparison (<) of two values.
lessThanOrEqual<T>(Object? first, Object? second) bool
Perform JavaScript less than or equal comparison (<=) of two values.
modulo<T>(Object? first, Object? second) → T
Perform JavaScript remainder (%) on two values.
multiply<T>(Object? first, Object? second) → T
Perform JavaScript multiplication (*) on two values.
newObject<T>() → T
notEqual<T>(Object? first, Object? second) bool
Perform JavaScript inequality comparison (!=) on two values.
objectGetPrototypeOf(Object? object) Object?
Returns the prototype of a given object. Equivalent to Object.getPrototypeOf.
objectKeys(Object? object) List<Object?>
Returns the keys for a given object. Equivalent to Object.keys(object).
promiseToFuture<T>(Object jsPromise) Future<T>
Converts a JavaScript Promise to a Dart Future.
setProperty<T>(Object o, Object name, T? value) → T
strictEqual<T>(Object? first, Object? second) bool
Perform JavaScript strict equality comparison (===) on two values.
strictNotEqual<T>(Object? first, Object? second) bool
Perform JavaScript strict inequality comparison (!==) on two values.
subtract<T>(Object? first, Object? second) → T
Perform JavaScript subtraction (-) on two values.

Exceptions / Errors

NullRejectionException
Exception for when the promise is rejected with a null or undefined value.