diff --git a/files/en-us/_redirects.txt b/files/en-us/_redirects.txt index 207afe5ea365e5e..314eded985ebbee 100644 --- a/files/en-us/_redirects.txt +++ b/files/en-us/_redirects.txt @@ -15528,9 +15528,14 @@ /en-US/docs/Web/JavaScript/Reference/Symbols /en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol /en-US/docs/Web/JavaScript/Reference/arrow_functions /en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions /en-US/docs/Web/JavaScript/Reference/default_parameters /en-US/docs/Web/JavaScript/Reference/Functions/Default_parameters +/en-US/docs/Web/JavaScript/Reference/delete /en-US/docs/Web/JavaScript/Reference/Operators/delete /en-US/docs/Web/JavaScript/Reference/eval /en-US/docs/Web/JavaScript/Reference/Global_Objects/eval +/en-US/docs/Web/JavaScript/Reference/instanceof /en-US/docs/Web/JavaScript/Reference/Operators/instanceof +/en-US/docs/Web/JavaScript/Reference/new /en-US/docs/Web/JavaScript/Reference/Operators/new +/en-US/docs/Web/JavaScript/Reference/null /en-US/docs/Web/JavaScript/Reference/Operators/null /en-US/docs/Web/JavaScript/Reference/rest_parameters /en-US/docs/Web/JavaScript/Reference/Functions/rest_parameters /en-US/docs/Web/JavaScript/Reference/template_strings /en-US/docs/Web/JavaScript/Reference/Template_literals +/en-US/docs/Web/JavaScript/Reference/this /en-US/docs/Web/JavaScript/Reference/Operators/this /en-US/docs/Web/JavaScript/Same_origin_policy_for_JavaScript /en-US/docs/Web/Security/Defenses/Same-origin_policy /en-US/docs/Web/JavaScript/Shells /en-US/docs/Web/JavaScript/Reference/JavaScript_technologies_overview /en-US/docs/Web/JavaScript/The_performance_hazards_of__[[Prototype]]_mutation /en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/setPrototypeOf diff --git a/files/en-us/glossary/binding/index.md b/files/en-us/glossary/binding/index.md index ecaddc20f72455c..f84d3c3ad11ce5a 100644 --- a/files/en-us/glossary/binding/index.md +++ b/files/en-us/glossary/binding/index.md @@ -5,7 +5,7 @@ page-type: glossary-definition sidebar: glossarysidebar --- -In programming, a **binding** is an association of an {{glossary("identifier")}} with a value. Not all bindings are {{glossary("variable", "variables")}} — for example, function {{glossary("parameter", "parameters")}} and the binding created by the {{jsxref("Statements/try...catch", "catch (e)")}} block are not "variables" in the strict sense. In addition, some bindings are implicitly created by the language — for example, {{jsxref("Operators/this", "this")}} and [`new.target`](/en-US/docs/Web/JavaScript/Reference/Operators/new.target) in JavaScript. +In programming, a **binding** is an association of an {{glossary("identifier")}} with a value. Not all bindings are {{glossary("variable", "variables")}} — for example, function {{glossary("parameter", "parameters")}} and the binding created by the {{jsxref("Statements/try...catch", "catch (e)")}} block are not "variables" in the strict sense. In addition, some bindings are implicitly created by the language — for example, {{jsxref("this")}} and [`new.target`](/en-US/docs/Web/JavaScript/Reference/Operators/new.target) in JavaScript. A binding is {{glossary("mutable")}} if it can be re-assigned, and {{glossary("immutable")}} otherwise; this does _not_ mean that the value it holds is immutable. diff --git a/files/en-us/learn_web_development/core/scripting/object_basics/index.md b/files/en-us/learn_web_development/core/scripting/object_basics/index.md index f81237ea33dbecd..b286f15edf3fe76 100644 --- a/files/en-us/learn_web_development/core/scripting/object_basics/index.md +++ b/files/en-us/learn_web_development/core/scripting/object_basics/index.md @@ -348,7 +348,7 @@ frankie.introduceSelf(); // "Hi! I'm Frankie." ``` -This works fine but is a bit long-winded: we have to create an empty object, initialize it, and return it. A better way is to use a **constructor**. A constructor is just a function called using the {{jsxref("operators/new", "new")}} keyword. When you call a constructor, it will: +This works fine but is a bit long-winded: we have to create an empty object, initialize it, and return it. A better way is to use a **constructor**. A constructor is just a function called using the {{jsxref("new")}} keyword. When you call a constructor, it will: - create a new object - bind `this` to the new object, so you can refer to `this` in your constructor code diff --git a/files/en-us/mozilla/firefox/releases/38/index.md b/files/en-us/mozilla/firefox/releases/38/index.md index 0d9c120701fc9ad..82830a261f882db 100644 --- a/files/en-us/mozilla/firefox/releases/38/index.md +++ b/files/en-us/mozilla/firefox/releases/38/index.md @@ -61,7 +61,7 @@ Highlights: - Duplicated parameter name is no longer allowed when rest-parameter is present ([Firefox bug 1096376](https://bugzil.la/1096376)). - Duplicated parameter name is no longer allowed in arrow functions ([Firefox bug 1096377](https://bugzil.la/1096377)). - Duplicated parameter name is no longer allowed in concise method definitions ([Firefox bug 1096378](https://bugzil.la/1096378)). -- Warning is shown when {{jsxref("Map")}}/{{jsxref("Set")}}/{{jsxref("WeakMap")}} constructor is called without {{jsxref("Operators/new", "new")}} ([Firefox bug 1108930](https://bugzil.la/1108930)). +- Warning is shown when {{jsxref("Map")}}/{{jsxref("Set")}}/{{jsxref("WeakMap")}} constructor is called without {{jsxref("new")}} ([Firefox bug 1108930](https://bugzil.la/1108930)). - The {{jsxref("WeakMap.get", "get")}}, {{jsxref("WeakMap.has", "has")}}, and {{jsxref("WeakMap.delete", "delete")}} methods of {{jsxref("WeakMap")}} objects no longer throw when the `key` parameter is not an object ([Firefox bug 1127827](https://bugzil.la/1127827)). - The optional and non-standard second `fallback` parameter for {{jsxref("WeakMap.prototype.get()")}} has been removed ([Firefox bug 1127827](https://bugzil.la/1127827)). - When defining a [generator method](/en-US/docs/Web/JavaScript/Reference/Functions/Method_definitions), `set` and `get` are no longer invalid names ([Firefox bug 1073809](https://bugzil.la/1073809)). diff --git a/files/en-us/mozilla/firefox/releases/40/index.md b/files/en-us/mozilla/firefox/releases/40/index.md index 0f8fa77f79acf43..9358602c2cc29f4 100644 --- a/files/en-us/mozilla/firefox/releases/40/index.md +++ b/files/en-us/mozilla/firefox/releases/40/index.md @@ -56,7 +56,7 @@ _No change._ - Unreachable code after {{jsxref("Statements/return", "return")}} statement (including unreachable expression after {{jsxref("Statements/return", "semicolon-less return statements", "#Automatic_semicolon_insertion", 1)}}) will now show a warning in the console ([Firefox bug 1005110](https://bugzil.la/1005110), [Firefox bug 1151931](https://bugzil.la/1151931)). - {{jsxref("Symbol.match")}} has been added ([Firefox bug 1054755](https://bugzil.la/1054755)). - Passing an object which has a property named {{jsxref("Symbol.match")}} with a {{Glossary("truthy")}} value to {{jsxref("String.prototype.startsWith")}}, {{jsxref("String.prototype.endsWith")}}, and `String.prototype.contains` now throws a {{jsxref("TypeError")}} ([Firefox bug 1054755](https://bugzil.la/1054755)). -- {{jsxref("RegExp")}} function returns pattern itself if called without {{jsxref("Operators/new", "new")}} and pattern object has a property named {{jsxref("Symbol.match")}} with a {{Glossary("truthy")}} value, and the pattern object's `constructor` property equals to {{jsxref("RegExp")}} function. ([Firefox bug 1147817](https://bugzil.la/1147817)). +- {{jsxref("RegExp")}} function returns pattern itself if called without {{jsxref("new")}} and pattern object has a property named {{jsxref("Symbol.match")}} with a {{Glossary("truthy")}} value, and the pattern object's `constructor` property equals to {{jsxref("RegExp")}} function. ([Firefox bug 1147817](https://bugzil.la/1147817)). - Support for the non-standard JS1.7 destructuring for-in has been dropped ([Firefox bug 1083498](https://bugzil.la/1083498)). - [Non-standard initializer expressions](/en-US/docs/Web/JavaScript/Reference/Errors/Invalid_for-in_initializer) in [`for...in`](/en-US/docs/Web/JavaScript/Reference/Statements/for...in) loops are now ignored and will present a warning in the console. ([Firefox bug 748550](https://bugzil.la/748550) and [Firefox bug 1164741](https://bugzil.la/1164741)). - [`\u{xxxxxx}`](/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#unicode_code_point_escapes) Unicode code point escapes have been added ([Firefox bug 320500](https://bugzil.la/320500)). diff --git a/files/en-us/mozilla/firefox/releases/44/index.md b/files/en-us/mozilla/firefox/releases/44/index.md index 918e17b52d961d0..74f88be6705c721 100644 --- a/files/en-us/mozilla/firefox/releases/44/index.md +++ b/files/en-us/mozilla/firefox/releases/44/index.md @@ -83,7 +83,7 @@ Highlights: #### Changes - The [`let`](/en-US/docs/Web/JavaScript/Reference/Statements/let) and [`const`](/en-US/docs/Web/JavaScript/Reference/Statements/const) bindings in the global level have been made compliant with ES2015 semantics. See [Firefox bug 589199](https://bugzil.la/589199) and the blog post ["Breaking changes in let and const in Firefox Nightly 44"](https://blog.mozilla.org/addons/2015/10/14/breaking-changes-let-const-firefox-nightly-44/). In addition, `let` is now available to default Web JavaScript (strict and non-strict) and does not require a version opt-in anymore ([Firefox bug 932517](https://bugzil.la/932517)). -- If [typed arrays'](/en-US/docs/Web/JavaScript/Guide/Typed_arrays) (like {{jsxref("Int8Array", "Int8Array")}}) and {{jsxref("ArrayBuffer", "ArrayBuffer")}}) constructors are called as a function without the {{jsxref("Operators/new", "new")}} operator, a {{jsxref("TypeError")}} is now thrown as per the ES2015 specification ([Firefox bug 980945](https://bugzil.la/980945), [Firefox bug 1214936](https://bugzil.la/1214936)). +- If [typed arrays'](/en-US/docs/Web/JavaScript/Guide/Typed_arrays) (like {{jsxref("Int8Array", "Int8Array")}}) and {{jsxref("ArrayBuffer", "ArrayBuffer")}}) constructors are called as a function without the {{jsxref("new")}} operator, a {{jsxref("TypeError")}} is now thrown as per the ES2015 specification ([Firefox bug 980945](https://bugzil.la/980945), [Firefox bug 1214936](https://bugzil.la/1214936)). - The {{jsxref("RegExp")}} sticky flag now follows the ES2015 standard for [anchored sticky regular expressions](/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/sticky#anchored_sticky_flag) ([Firefox bug 773687](https://bugzil.la/773687)). - The JavaScript shell (SpiderMonkey's REPL) now defaults to the default, Web-compatible JS version (and not JS1.7+ anymore) ([Firefox bug 1192329](https://bugzil.la/1192329)). diff --git a/files/en-us/web/api/domtokenlist/foreach/index.md b/files/en-us/web/api/domtokenlist/foreach/index.md index 592b97282ebc91a..d0ed3c586aa0374 100644 --- a/files/en-us/web/api/domtokenlist/foreach/index.md +++ b/files/en-us/web/api/domtokenlist/foreach/index.md @@ -31,7 +31,7 @@ forEach(callback, thisArg) - : The array that `forEach()` is being applied to. - `thisArg` {{Optional_inline}} - - : The value to use as {{jsxref("Operators/this", "this")}} when executing `callback`. + - : The value to use as {{jsxref("this")}} when executing `callback`. ### Return value diff --git a/files/en-us/web/api/eventtarget/addeventlistener/index.md b/files/en-us/web/api/eventtarget/addeventlistener/index.md index e94c3a4d237b3c6..b2e93b859f65335 100644 --- a/files/en-us/web/api/eventtarget/addeventlistener/index.md +++ b/files/en-us/web/api/eventtarget/addeventlistener/index.md @@ -135,7 +135,7 @@ It is often desirable to reference the element on which the event handler was fi such as when using a generic handler for a set of similar elements. When attaching a handler function to an element using `addEventListener()`, -the value of {{jsxref("Operators/this","this")}} inside the handler will be a reference to +the value of {{jsxref("this")}} inside the handler will be a reference to the element. It will be the same as the value of the `currentTarget` property of the event argument that is passed to the handler. diff --git a/files/en-us/web/api/largestcontentfulpaint/presentationtime/index.md b/files/en-us/web/api/largestcontentfulpaint/presentationtime/index.md index 01fbebb8a136b4f..f131a63c6d8e70b 100644 --- a/files/en-us/web/api/largestcontentfulpaint/presentationtime/index.md +++ b/files/en-us/web/api/largestcontentfulpaint/presentationtime/index.md @@ -14,7 +14,7 @@ The `presentationTime` is optional — some browsers may choose always to return ## Value -A {{domxref("DOMHighResTimeStamp")}} or {{jsxref("Operators/null", "null")}} if the value is not exposed. +A {{domxref("DOMHighResTimeStamp")}} or {{jsxref("null")}} if the value is not exposed. ## Examples diff --git a/files/en-us/web/api/performanceelementtiming/presentationtime/index.md b/files/en-us/web/api/performanceelementtiming/presentationtime/index.md index 9d23d9da611b171..a778e913cbc50db 100644 --- a/files/en-us/web/api/performanceelementtiming/presentationtime/index.md +++ b/files/en-us/web/api/performanceelementtiming/presentationtime/index.md @@ -16,7 +16,7 @@ The `presentationTime` is optional — some browsers may choose always to return ## Value -A {{domxref("DOMHighResTimeStamp")}} or {{jsxref("Operators/null", "null")}} if the value is not exposed. +A {{domxref("DOMHighResTimeStamp")}} or {{jsxref("null")}} if the value is not exposed. ## Examples diff --git a/files/en-us/web/api/performancelonganimationframetiming/presentationtime/index.md b/files/en-us/web/api/performancelonganimationframetiming/presentationtime/index.md index 183c3afd6e269c7..1a4831789c8eb8f 100644 --- a/files/en-us/web/api/performancelonganimationframetiming/presentationtime/index.md +++ b/files/en-us/web/api/performancelonganimationframetiming/presentationtime/index.md @@ -16,7 +16,7 @@ The `presentationTime` is optional — some browsers may choose always to return ## Value -A {{domxref("DOMHighResTimeStamp")}} or {{jsxref("Operators/null", "null")}} if the value is not exposed. +A {{domxref("DOMHighResTimeStamp")}} or {{jsxref("null")}} if the value is not exposed. ## Examples diff --git a/files/en-us/web/api/performancepainttiming/presentationtime/index.md b/files/en-us/web/api/performancepainttiming/presentationtime/index.md index 03afa9af5a10e43..00f6b8f5d3c49d1 100644 --- a/files/en-us/web/api/performancepainttiming/presentationtime/index.md +++ b/files/en-us/web/api/performancepainttiming/presentationtime/index.md @@ -14,7 +14,7 @@ The `presentationTime` is optional — some browsers may choose always to return ## Value -A {{domxref("DOMHighResTimeStamp")}} or {{jsxref("Operators/null", "null")}} if the value is not exposed. +A {{domxref("DOMHighResTimeStamp")}} or {{jsxref("null")}} if the value is not exposed. ## Examples diff --git a/files/en-us/web/api/windowclient/navigate/index.md b/files/en-us/web/api/windowclient/navigate/index.md index d54d3d342dc1b66..31a75d0aa81b43c 100644 --- a/files/en-us/web/api/windowclient/navigate/index.md +++ b/files/en-us/web/api/windowclient/navigate/index.md @@ -25,7 +25,7 @@ navigate(url) ### Return value -A {{jsxref("Promise")}} that resolves to the existing {{domxref("WindowClient")}} if the URL is from the same origin as the service worker, or {{jsxref("Operators/null", "null")}} otherwise. +A {{jsxref("Promise")}} that resolves to the existing {{domxref("WindowClient")}} if the URL is from the same origin as the service worker, or {{jsxref("null")}} otherwise. ## Specifications diff --git a/files/en-us/web/javascript/guide/meta_programming/index.md b/files/en-us/web/javascript/guide/meta_programming/index.md index eee1d41dc950d2e..206b2c81ecb8e56 100644 --- a/files/en-us/web/javascript/guide/meta_programming/index.md +++ b/files/en-us/web/javascript/guide/meta_programming/index.md @@ -59,7 +59,7 @@ The following table summarizes the available traps available to `Proxy` objects. {{jsxref("Proxy/Proxy/getPrototypeOf", "handler.getPrototypeOf()")}} - {{jsxref("Object.getPrototypeOf()")}}
{{jsxref("Reflect.getPrototypeOf()")}}
{{jsxref("Object/proto", "__proto__")}}
{{jsxref("Object.prototype.isPrototypeOf()")}}
{{jsxref("Operators/instanceof", "instanceof")}} + {{jsxref("Object.getPrototypeOf()")}}
{{jsxref("Reflect.getPrototypeOf()")}}
{{jsxref("Object/proto", "__proto__")}}
{{jsxref("Object.prototype.isPrototypeOf()")}}
{{jsxref("instanceof")}} diff --git a/files/en-us/web/javascript/index.md b/files/en-us/web/javascript/index.md index 542eba1b49419cb..f8dbc8d417fd4e4 100644 --- a/files/en-us/web/javascript/index.md +++ b/files/en-us/web/javascript/index.md @@ -73,7 +73,7 @@ Browse the complete [JavaScript reference](/en-US/docs/Web/JavaScript/Reference) - [Standard objects](/en-US/docs/Web/JavaScript/Reference/Global_Objects) - : Get to know standard built-in objects: {{jsxref("Array")}}, {{jsxref("Boolean")}}, {{jsxref("Error")}}, {{jsxref("Function")}}, {{jsxref("JSON")}}, {{jsxref("Math")}}, {{jsxref("Number")}}, {{jsxref("Object")}}, {{jsxref("RegExp")}}, {{jsxref("String")}}, {{jsxref("Map")}}, {{jsxref("Set")}}, {{jsxref("WeakMap")}}, {{jsxref("WeakSet")}}, and others. - [Expressions and operators](/en-US/docs/Web/JavaScript/Reference/Operators) - - : Learn more about the behavior of JavaScript's operators {{jsxref("Operators/instanceof", "instanceof")}}, {{jsxref("Operators/typeof", "typeof")}}, {{jsxref("Operators/new", "new")}}, {{jsxref("Operators/this", "this")}}, the [operator precedence](/en-US/docs/Web/JavaScript/Reference/Operators/Operator_precedence), and more. + - : Learn more about the behavior of JavaScript's operators {{jsxref("instanceof")}}, {{jsxref("Operators/typeof", "typeof")}}, {{jsxref("new")}}, {{jsxref("this")}}, the [operator precedence](/en-US/docs/Web/JavaScript/Reference/Operators/Operator_precedence), and more. - [Statements and declarations](/en-US/docs/Web/JavaScript/Reference/Statements) - : Learn how {{jsxref("Statements/do...while", "do-while")}}, {{jsxref("Statements/for...in", "for-in")}}, {{jsxref("Statements/for...of", "for-of")}}, {{jsxref("Statements/try...catch", "try-catch")}}, {{jsxref("Statements/let", "let")}}, {{jsxref("Statements/var", "var")}}, {{jsxref("Statements/const", "const")}}, {{jsxref("Statements/if...else", "if-else")}}, {{jsxref("Statements/switch", "switch")}}, and more JavaScript statements and keywords work. - [Functions](/en-US/docs/Web/JavaScript/Reference/Functions) diff --git a/files/en-us/web/javascript/reference/classes/index.md b/files/en-us/web/javascript/reference/classes/index.md index f6f20dbb6600cb7..ea26d3f3e8369de 100644 --- a/files/en-us/web/javascript/reference/classes/index.md +++ b/files/en-us/web/javascript/reference/classes/index.md @@ -285,7 +285,7 @@ For how instances are created, see the {{jsxref("Classes/constructor", "construc ### Binding this with instance and static methods -When a static or instance method is called without a value for {{jsxref("Operators/this", "this")}}, such as by assigning the method to a variable and then calling it, the `this` value will be `undefined` inside the method. This behavior is the same even if the [`"use strict"`](/en-US/docs/Web/JavaScript/Reference/Strict_mode) directive isn't present, because code within the `class` body is always executed in strict mode. +When a static or instance method is called without a value for {{jsxref("this")}}, such as by assigning the method to a variable and then calling it, the `this` value will be `undefined` inside the method. This behavior is the same even if the [`"use strict"`](/en-US/docs/Web/JavaScript/Reference/Strict_mode) directive isn't present, because code within the `class` body is always executed in strict mode. ```js class Animal { diff --git a/files/en-us/web/javascript/reference/classes/static/index.md b/files/en-us/web/javascript/reference/classes/static/index.md index ffea3fa36025231..1da865c7ad27afd 100644 --- a/files/en-us/web/javascript/reference/classes/static/index.md +++ b/files/en-us/web/javascript/reference/classes/static/index.md @@ -173,7 +173,7 @@ StaticMethodCall.anotherStaticMethod(); ### Calling static members from a class constructor and other methods -Static members are not directly accessible using the {{jsxref("Operators/this", "this")}} keyword from +Static members are not directly accessible using the {{jsxref("this")}} keyword from non-static methods. You need to call them using the class name: `CLASSNAME.STATIC_METHOD_NAME()` / `CLASSNAME.STATIC_PROPERTY_NAME` or by calling the method as a property of diff --git a/files/en-us/web/javascript/reference/errors/bad_new_optional/index.md b/files/en-us/web/javascript/reference/errors/bad_new_optional/index.md index 3232c1c67782cad..46210306749052f 100644 --- a/files/en-us/web/javascript/reference/errors/bad_new_optional/index.md +++ b/files/en-us/web/javascript/reference/errors/bad_new_optional/index.md @@ -5,7 +5,7 @@ page-type: javascript-error sidebar: jssidebar --- -The JavaScript exception "new keyword cannot be used with an optional chain" occurs when the constructor of a {{jsxref("Operators/new", "new")}} expression is an [optional chain](/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining), or if there's an optional chain between the constructor and the parenthesized list of arguments. +The JavaScript exception "new keyword cannot be used with an optional chain" occurs when the constructor of a {{jsxref("new")}} expression is an [optional chain](/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining), or if there's an optional chain between the constructor and the parenthesized list of arguments. ## Message @@ -62,6 +62,6 @@ Note that there's no needs to use `?.` on the `new` expression itself: `new a()? ## See also -- {{jsxref("Operators/new", "new")}} +- {{jsxref("new")}} - [Optional chaining (`?.`)](/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining) - [Original discussion on whether "optional new" should be allowed](https://github.com/tc39/proposal-optional-chaining/issues/22) diff --git a/files/en-us/web/javascript/reference/errors/bad_super_call/index.md b/files/en-us/web/javascript/reference/errors/bad_super_call/index.md index d680dc6a37c5f47..d9bc77b1b443845 100644 --- a/files/en-us/web/javascript/reference/errors/bad_super_call/index.md +++ b/files/en-us/web/javascript/reference/errors/bad_super_call/index.md @@ -21,7 +21,7 @@ SyntaxError: super is not valid in this context. (Safari) ## What went wrong? -The `super()` call is used to invoke the base constructor of a derived class, so the base class can initialize the {{jsxref("Operators/this", "this")}} object. Using it anywhere else doesn't make sense. +The `super()` call is used to invoke the base constructor of a derived class, so the base class can initialize the {{jsxref("this")}} object. Using it anywhere else doesn't make sense. `super()` can also be defined in an arrow function that's nested within the constructor. However, it cannot be defined in any other kind of function. diff --git a/files/en-us/web/javascript/reference/errors/builtin_ctor_no_new/index.md b/files/en-us/web/javascript/reference/errors/builtin_ctor_no_new/index.md index 3d6f5f73b3c7dc0..b16f6f427a380b7 100644 --- a/files/en-us/web/javascript/reference/errors/builtin_ctor_no_new/index.md +++ b/files/en-us/web/javascript/reference/errors/builtin_ctor_no_new/index.md @@ -5,7 +5,7 @@ page-type: javascript-error sidebar: jssidebar --- -The JavaScript exception "calling a builtin X constructor without new is forbidden" occurs when you try to call a builtin constructor without using the {{jsxref("Operators/new", "new")}} keyword. All modern constructors, such as {{jsxref("Promise")}} and {{jsxref("Map")}}, must be called with `new`. +The JavaScript exception "calling a builtin X constructor without new is forbidden" occurs when you try to call a builtin constructor without using the {{jsxref("new")}} keyword. All modern constructors, such as {{jsxref("Promise")}} and {{jsxref("Map")}}, must be called with `new`. ## Message @@ -52,4 +52,4 @@ const m = new Map(); ## See also -- {{jsxref("Operators/new", "new")}} +- {{jsxref("new")}} diff --git a/files/en-us/web/javascript/reference/errors/class_ctor_no_new/index.md b/files/en-us/web/javascript/reference/errors/class_ctor_no_new/index.md index d6385d7fef63390..179e20fe172ccc1 100644 --- a/files/en-us/web/javascript/reference/errors/class_ctor_no_new/index.md +++ b/files/en-us/web/javascript/reference/errors/class_ctor_no_new/index.md @@ -5,7 +5,7 @@ page-type: javascript-error sidebar: jssidebar --- -The JavaScript exception "class constructors must be invoked with 'new'" occurs when a [class constructor](/en-US/docs/Web/JavaScript/Reference/Classes) is called without the {{jsxref("Operators/new", "new")}} keyword. All class constructors must be called with `new`. +The JavaScript exception "class constructors must be invoked with 'new'" occurs when a [class constructor](/en-US/docs/Web/JavaScript/Reference/Classes) is called without the {{jsxref("new")}} keyword. All class constructors must be called with `new`. ## Message @@ -47,4 +47,4 @@ new X(); ## See also - [Classes](/en-US/docs/Web/JavaScript/Reference/Classes) -- {{jsxref("Operators/new", "new")}} +- {{jsxref("new")}} diff --git a/files/en-us/web/javascript/reference/errors/invalid_derived_return/index.md b/files/en-us/web/javascript/reference/errors/invalid_derived_return/index.md index a54bde54b5efa81..1bc84f97aaab9ab 100644 --- a/files/en-us/web/javascript/reference/errors/invalid_derived_return/index.md +++ b/files/en-us/web/javascript/reference/errors/invalid_derived_return/index.md @@ -61,4 +61,4 @@ new Derived(); // { x: 1 } - [Classes](/en-US/docs/Web/JavaScript/Reference/Classes) - {{jsxref("Classes/extends", "extends")}} -- {{jsxref("Operators/new", "new")}} +- {{jsxref("new")}} diff --git a/files/en-us/web/javascript/reference/errors/super_not_called/index.md b/files/en-us/web/javascript/reference/errors/super_not_called/index.md index 1ec5121d12f4580..20355c9ff7f911c 100644 --- a/files/en-us/web/javascript/reference/errors/super_not_called/index.md +++ b/files/en-us/web/javascript/reference/errors/super_not_called/index.md @@ -5,7 +5,7 @@ page-type: javascript-error sidebar: jssidebar --- -The JavaScript exception "must call super constructor before using 'this' in derived class constructor" occurs when the {{jsxref("Operators/super", "super()")}} is not called for a given derived class constructor, and the derived constructor tries to access the value of {{jsxref("Operators/this", "this")}}, or the derived constructor has already returned and the return value is not an object. +The JavaScript exception "must call super constructor before using 'this' in derived class constructor" occurs when the {{jsxref("Operators/super", "super()")}} is not called for a given derived class constructor, and the derived constructor tries to access the value of {{jsxref("this")}}, or the derived constructor has already returned and the return value is not an object. ## Message diff --git a/files/en-us/web/javascript/reference/functions/get/index.md b/files/en-us/web/javascript/reference/functions/get/index.md index dea2743b3430ca4..13972fc06274c7f 100644 --- a/files/en-us/web/javascript/reference/functions/get/index.md +++ b/files/en-us/web/javascript/reference/functions/get/index.md @@ -103,7 +103,7 @@ Static getters and private getters use similar syntaxes, which are described in ### Deleting a getter using the `delete` operator -If you want to remove the getter, you can just {{jsxref("Operators/delete", "delete")}} it: +If you want to remove the getter, you can just {{jsxref("delete")}} it: ```js delete obj.latest; diff --git a/files/en-us/web/javascript/reference/functions/set/index.md b/files/en-us/web/javascript/reference/functions/set/index.md index c41c8381f176fe5..85f5303e01b09aa 100644 --- a/files/en-us/web/javascript/reference/functions/set/index.md +++ b/files/en-us/web/javascript/reference/functions/set/index.md @@ -116,7 +116,7 @@ Static setters and private setters use similar syntaxes, which are described in ### Removing a setter with the `delete` operator -If you want to remove the setter, you can just {{jsxref("Operators/delete", "delete")}} +If you want to remove the setter, you can just {{jsxref("delete")}} it: ```js diff --git a/files/en-us/web/javascript/reference/global_objects/array/foreach/index.md b/files/en-us/web/javascript/reference/global_objects/array/foreach/index.md index 0a7fde5bd32f842..11a1b924ab390ba 100644 --- a/files/en-us/web/javascript/reference/global_objects/array/foreach/index.md +++ b/files/en-us/web/javascript/reference/global_objects/array/foreach/index.md @@ -156,7 +156,7 @@ invoked. The callback uses it as its `this` value. > If passing the callback function used an > [arrow function expression](/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions), > the `thisArg` parameter could be omitted, -> since all arrow functions lexically bind the {{jsxref("Operators/this", "this")}} +> since all arrow functions lexically bind the {{jsxref("this")}} > value. ### An object copy function diff --git a/files/en-us/web/javascript/reference/global_objects/bigint/bigint/index.md b/files/en-us/web/javascript/reference/global_objects/bigint/bigint/index.md index 7fb3df376373a02..97d386b02819bed 100644 --- a/files/en-us/web/javascript/reference/global_objects/bigint/bigint/index.md +++ b/files/en-us/web/javascript/reference/global_objects/bigint/bigint/index.md @@ -34,7 +34,7 @@ A {{jsxref("BigInt")}} value. Number values must be integers and are converted t - {{jsxref("TypeError")}} - : Thrown in one of the following cases: - The parameter cannot be converted to a primitive. - - After conversion to a primitive, the result is {{jsxref("undefined")}}, {{jsxref("Operators/null", "null")}}, {{jsxref("symbol")}}. + - After conversion to a primitive, the result is {{jsxref("undefined")}}, {{jsxref("null")}}, {{jsxref("symbol")}}. - {{jsxref("SyntaxError")}} - : Thrown if the parameter is a string that cannot be parsed as a `BigInt`. diff --git a/files/en-us/web/javascript/reference/global_objects/error/error/index.md b/files/en-us/web/javascript/reference/global_objects/error/error/index.md index bca1ba48867ce6d..6e5ed7abe7ab53d 100644 --- a/files/en-us/web/javascript/reference/global_objects/error/error/index.md +++ b/files/en-us/web/javascript/reference/global_objects/error/error/index.md @@ -45,7 +45,7 @@ Error(message, fileName, lineNumber) ### Function call or new construction -When `Error` is used like a function, that is without {{jsxref("Operators/new", "new")}}, it will return an `Error` object. +When `Error` is used like a function, that is without {{jsxref("new")}}, it will return an `Error` object. Therefore, a mere call to `Error` will produce the same output that constructing an `Error` object via the `new` keyword would. ```js diff --git a/files/en-us/web/javascript/reference/global_objects/error/index.md b/files/en-us/web/javascript/reference/global_objects/error/index.md index 8ecb4c005d6aca3..f53bc8681af4b1f 100644 --- a/files/en-us/web/javascript/reference/global_objects/error/index.md +++ b/files/en-us/web/javascript/reference/global_objects/error/index.md @@ -100,7 +100,7 @@ try { ### Handling a specific error type -You can choose to handle only specific error types by testing the error type with the {{jsxref("Operators/instanceof", "instanceof")}} keyword: +You can choose to handle only specific error types by testing the error type with the {{jsxref("instanceof")}} keyword: ```js try { diff --git a/files/en-us/web/javascript/reference/global_objects/function/arguments/index.md b/files/en-us/web/javascript/reference/global_objects/function/arguments/index.md index 2eab2b177a48a92..07793be2bce8a29 100644 --- a/files/en-us/web/javascript/reference/global_objects/function/arguments/index.md +++ b/files/en-us/web/javascript/reference/global_objects/function/arguments/index.md @@ -23,7 +23,7 @@ The value of `arguments` is an array-like object corresponding to the arguments In the case of recursion, i.e., if function `f` appears several times on the call stack, the value of `f.arguments` represents the arguments corresponding to the most recent invocation of the function. -The value of the `arguments` property is normally {{jsxref("Operators/null", "null")}} if there is no outstanding invocation of the function in progress (that is, the function has been called but has not yet returned). +The value of the `arguments` property is normally {{jsxref("null")}} if there is no outstanding invocation of the function in progress (that is, the function has been called but has not yet returned). Note that the only behavior specified by the ECMAScript specification is that `Function.prototype` has an initial `arguments` accessor that unconditionally throws a {{jsxref("TypeError")}} for any `get` or `set` request (known as a "poison pill accessor"), and that implementations are not allowed to change this semantic for any function except non-strict plain functions. The actual behavior of the `arguments` property, if it's anything other than throwing an error, is implementation-defined. For example, Chrome defines it as an own data property, while Firefox and Safari extend the initial poison-pill `Function.prototype.arguments` accessor to specially handle `this` values that are non-strict functions. diff --git a/files/en-us/web/javascript/reference/global_objects/function/bind/index.md b/files/en-us/web/javascript/reference/global_objects/function/bind/index.md index 0996c243b23ac8e..8e27c8dd0d417d8 100644 --- a/files/en-us/web/javascript/reference/global_objects/function/bind/index.md +++ b/files/en-us/web/javascript/reference/global_objects/function/bind/index.md @@ -40,7 +40,7 @@ bind(thisArg, arg1, arg2, /* …, */ argN) ### Parameters - `thisArg` - - : The value to be passed as the `this` parameter to the target function `func` when the bound function is called. If the function is not in [strict mode](/en-US/docs/Web/JavaScript/Reference/Strict_mode), [`null`](/en-US/docs/Web/JavaScript/Reference/Operators/null) and [`undefined`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined) will be replaced with the global object, and primitive values will be converted to objects. The value is ignored if the bound function is constructed using the {{jsxref("Operators/new", "new")}} operator. + - : The value to be passed as the `this` parameter to the target function `func` when the bound function is called. If the function is not in [strict mode](/en-US/docs/Web/JavaScript/Reference/Strict_mode), [`null`](/en-US/docs/Web/JavaScript/Reference/Operators/null) and [`undefined`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined) will be replaced with the global object, and primitive values will be converted to objects. The value is ignored if the bound function is constructed using the {{jsxref("new")}} operator. - `arg1`, …, `argN` {{optional_inline}} - : Arguments to prepend to arguments provided to the bound function when invoking `func`. @@ -65,7 +65,7 @@ const boundLog2 = boundLog.bind("new this value", 3, 4); boundLog2(5, 6); // "this value", 1, 2, 3, 4, 5, 6 ``` -A bound function may also be constructed using the {{jsxref("Operators/new", "new")}} operator if its target function is constructable. Doing so acts as though the target function had instead been constructed. The prepended arguments are provided to the target function as usual, while the provided `this` value is ignored (because construction prepares its own `this`, as seen by the parameters of {{jsxref("Reflect.construct")}}). If the bound function is directly constructed, [`new.target`](/en-US/docs/Web/JavaScript/Reference/Operators/new.target) will be the target function instead. (That is, the bound function is transparent to `new.target`.) +A bound function may also be constructed using the {{jsxref("new")}} operator if its target function is constructable. Doing so acts as though the target function had instead been constructed. The prepended arguments are provided to the target function as usual, while the provided `this` value is ignored (because construction prepares its own `this`, as seen by the parameters of {{jsxref("Reflect.construct")}}). If the bound function is directly constructed, [`new.target`](/en-US/docs/Web/JavaScript/Reference/Operators/new.target) will be the target function instead. (That is, the bound function is transparent to `new.target`.) ```js class Base { @@ -213,7 +213,7 @@ class LateBloomer { ### Bound functions used as constructors -Bound functions are automatically suitable for use with the {{jsxref("Operators/new", "new")}} operator to construct new instances created by the target function. When a bound function is used to construct a value, the provided `this` is ignored. However, provided arguments are still prepended to the constructor call. +Bound functions are automatically suitable for use with the {{jsxref("new")}} operator to construct new instances created by the target function. When a bound function is used to construct a value, the provided `this` is ignored. However, provided arguments are still prepended to the constructor call. ```js function Point(x, y) { @@ -240,9 +240,9 @@ axisPoint instanceof YAxisPoint; // true new YAxisPoint(17, 42) instanceof Point; // true ``` -Note that you need not do anything special to create a bound function for use with {{jsxref("Operators/new", "new")}}. [`new.target`](/en-US/docs/Web/JavaScript/Reference/Operators/new.target), [`instanceof`](/en-US/docs/Web/JavaScript/Reference/Operators/instanceof), [`this`](/en-US/docs/Web/JavaScript/Reference/Operators/this) etc. all work as expected, as if the constructor was never bound. The only difference is that it can no longer be used for [`extends`](/en-US/docs/Web/JavaScript/Reference/Classes/extends). +Note that you need not do anything special to create a bound function for use with {{jsxref("new")}}. [`new.target`](/en-US/docs/Web/JavaScript/Reference/Operators/new.target), [`instanceof`](/en-US/docs/Web/JavaScript/Reference/Operators/instanceof), [`this`](/en-US/docs/Web/JavaScript/Reference/Operators/this) etc. all work as expected, as if the constructor was never bound. The only difference is that it can no longer be used for [`extends`](/en-US/docs/Web/JavaScript/Reference/Classes/extends). -The corollary is that you need not do anything special to create a bound function to be called plainly, even if you would rather require the bound function to only be called using {{jsxref("Operators/new", "new")}}. If you call it without `new`, the bound `this` is suddenly not ignored. +The corollary is that you need not do anything special to create a bound function to be called plainly, even if you would rather require the bound function to only be called using {{jsxref("new")}}. If you call it without `new`, the bound `this` is suddenly not ignored. ```js const emptyObj = {}; @@ -256,7 +256,7 @@ YAxisPoint(13); console.log(emptyObj); // { x: 0, y: 13 } ``` -If you wish to restrict a bound function to only be callable with {{jsxref("Operators/new", "new")}}, or only be callable without `new`, the target function must enforce that restriction, such as by checking `new.target !== undefined` or using a [class](/en-US/docs/Web/JavaScript/Reference/Classes) instead. +If you wish to restrict a bound function to only be callable with {{jsxref("new")}}, or only be callable without `new`, the target function must enforce that restriction, such as by checking `new.target !== undefined` or using a [class](/en-US/docs/Web/JavaScript/Reference/Classes) instead. ### Binding classes diff --git a/files/en-us/web/javascript/reference/global_objects/function/caller/index.md b/files/en-us/web/javascript/reference/global_objects/function/caller/index.md index e5e7fc8cc2b6ba3..705673d4548c341 100644 --- a/files/en-us/web/javascript/reference/global_objects/function/caller/index.md +++ b/files/en-us/web/javascript/reference/global_objects/function/caller/index.md @@ -19,7 +19,7 @@ The **`caller`** accessor property of {{jsxref("Function")}} instances returns t ## Description -If the function `f` was invoked by the top-level code, the value of `f.caller` is {{jsxref("Operators/null", "null")}}; otherwise it's the function that called `f`. If the function that called `f` is a strict mode function, the value of `f.caller` is also `null`. +If the function `f` was invoked by the top-level code, the value of `f.caller` is {{jsxref("null")}}; otherwise it's the function that called `f`. If the function that called `f` is a strict mode function, the value of `f.caller` is also `null`. Note that the only behavior specified by the ECMAScript specification is that `Function.prototype` has an initial `caller` accessor that unconditionally throws a {{jsxref("TypeError")}} for any `get` or `set` request (known as a "poison pill accessor"), and that implementations are not allowed to change this semantic for any function except non-strict plain functions, in which case it must not have the value of a strict mode function. The actual behavior of the `caller` property, if it's anything other than throwing an error, is implementation-defined. For example, Chrome defines it as an own data property, while Firefox and Safari extend the initial poison-pill `Function.prototype.caller` accessor to specially handle `this` values that are non-strict functions. diff --git a/files/en-us/web/javascript/reference/global_objects/globalthis/index.md b/files/en-us/web/javascript/reference/global_objects/globalthis/index.md index 39745d2f8eb630a..5a5cf8a683df16d 100644 --- a/files/en-us/web/javascript/reference/global_objects/globalthis/index.md +++ b/files/en-us/web/javascript/reference/global_objects/globalthis/index.md @@ -121,4 +121,4 @@ if (typeof globalThis.Intl === "undefined") { - [Polyfill of `globalThis` in `core-js`](https://github.com/zloirock/core-js#ecmascript-globalthis) - [es-shims polyfill of `globalThis`](https://www.npmjs.com/package/globalthis) -- {{jsxref("Operators/this", "this")}} +- {{jsxref("this")}} diff --git a/files/en-us/web/javascript/reference/global_objects/index.md b/files/en-us/web/javascript/reference/global_objects/index.md index 6ae8be7e0be440d..9da98b04c7266d5 100644 --- a/files/en-us/web/javascript/reference/global_objects/index.md +++ b/files/en-us/web/javascript/reference/global_objects/index.md @@ -9,7 +9,7 @@ This chapter documents all of JavaScript's standard, built-in objects, including The term "global objects" (or standard built-in objects) here is not to be confused with **the global object**. Here, "global objects" refer to **objects in the global scope**. -The **global object** itself can be accessed using the {{jsxref("Operators/this", "this")}} operator in the global scope. In fact, the global scope **consists of** the properties of the global object, including inherited properties, if any. +The **global object** itself can be accessed using the {{jsxref("this")}} operator in the global scope. In fact, the global scope **consists of** the properties of the global object, including inherited properties, if any. Other objects in the global scope are either [created by the user script](/en-US/docs/Web/JavaScript/Guide/Working_with_objects#creating_new_objects) or provided by the host application. The host objects available in browser contexts are documented in the [API reference](/en-US/docs/Web/API). diff --git a/files/en-us/web/javascript/reference/global_objects/iterator/from/index.md b/files/en-us/web/javascript/reference/global_objects/iterator/from/index.md index ea644199f09475a..0500f274bd83fb0 100644 --- a/files/en-us/web/javascript/reference/global_objects/iterator/from/index.md +++ b/files/en-us/web/javascript/reference/global_objects/iterator/from/index.md @@ -22,7 +22,7 @@ Iterator.from(object) ### Return value -If `object` is an iterable, its `[Symbol.iterator]()` method is called to obtain the iterator. Otherwise, `object` is assumed to be an iterator. If the iterator is already {{jsxref("Operators/instanceof", "instanceof")}} {{jsxref("Iterator")}} (which means it has `Iterator.prototype` in its prototype chain), it is returned directly. Otherwise, a new {{jsxref("Iterator")}} object is created that wraps the original iterator. +If `object` is an iterable, its `[Symbol.iterator]()` method is called to obtain the iterator. Otherwise, `object` is assumed to be an iterator. If the iterator is already {{jsxref("instanceof")}} {{jsxref("Iterator")}} (which means it has `Iterator.prototype` in its prototype chain), it is returned directly. Otherwise, a new {{jsxref("Iterator")}} object is created that wraps the original iterator. ## Description diff --git a/files/en-us/web/javascript/reference/global_objects/object/index.md b/files/en-us/web/javascript/reference/global_objects/object/index.md index b97153cc9a4b58c..601786940f18c23 100644 --- a/files/en-us/web/javascript/reference/global_objects/object/index.md +++ b/files/en-us/web/javascript/reference/global_objects/object/index.md @@ -43,7 +43,7 @@ Object.prototype.propertyIsEnumerable.call(obj, "foo"); // true; expected result ### Deleting a property from an object -There isn't any method in an Object itself to delete its own properties (such as {{jsxref("Map.prototype.delete()")}}). To do so, one must use the {{jsxref("Operators/delete", "delete")}} operator. +There isn't any method in an Object itself to delete its own properties (such as {{jsxref("Map.prototype.delete()")}}). To do so, one must use the {{jsxref("delete")}} operator. ### null-prototype objects diff --git a/files/en-us/web/javascript/reference/global_objects/object/isprototypeof/index.md b/files/en-us/web/javascript/reference/global_objects/object/isprototypeof/index.md index 2110bf4c0425364..5a0fa4d10de262f 100644 --- a/files/en-us/web/javascript/reference/global_objects/object/isprototypeof/index.md +++ b/files/en-us/web/javascript/reference/global_objects/object/isprototypeof/index.md @@ -81,7 +81,7 @@ console.log(Foo.prototype.isPrototypeOf(bar)); // true console.log(Object.prototype.isPrototypeOf(baz)); // true ``` -The `isPrototypeOf()` method — along with the {{jsxref("Operators/instanceof", "instanceof")}} operator — comes in particularly handy if you have code that can only function when dealing with objects descended from a specific prototype chain; e.g., to guarantee that certain methods or properties will be present on that object. +The `isPrototypeOf()` method — along with the {{jsxref("instanceof")}} operator — comes in particularly handy if you have code that can only function when dealing with objects descended from a specific prototype chain; e.g., to guarantee that certain methods or properties will be present on that object. For example, to execute some code that's only safe to run if a `baz` object has `Foo.prototype` in its prototype chain, you can do this: @@ -139,7 +139,7 @@ if (Foo.isFoo(baz)) { ## See also -- {{jsxref("Operators/instanceof", "instanceof")}} +- {{jsxref("instanceof")}} - {{jsxref("Object.getPrototypeOf()")}} - {{jsxref("Object.setPrototypeOf()")}} - [Inheritance and the prototype chain](/en-US/docs/Web/JavaScript/Guide/Inheritance_and_the_prototype_chain) diff --git a/files/en-us/web/javascript/reference/global_objects/object/proto/index.md b/files/en-us/web/javascript/reference/global_objects/object/proto/index.md index 25d65660388fcef..53621eb5f346ee4 100644 --- a/files/en-us/web/javascript/reference/global_objects/object/proto/index.md +++ b/files/en-us/web/javascript/reference/global_objects/object/proto/index.md @@ -17,7 +17,7 @@ sidebar: jsref > [!NOTE] > The use of `__proto__` is controversial and discouraged. Its existence and exact behavior have only been standardized as a legacy feature to ensure web compatibility, while it presents several [security issues](/en-US/docs/Web/Security/Attacks/Prototype_pollution) and footguns. For better support, prefer {{jsxref("Object.getPrototypeOf()")}}/{{jsxref("Reflect.getPrototypeOf()")}} and {{jsxref("Object.setPrototypeOf()")}}/{{jsxref("Reflect.setPrototypeOf()")}} instead. -The **`__proto__`** accessor property of {{jsxref("Object")}} instances exposes the [`[[Prototype]]`](/en-US/docs/Web/JavaScript/Guide/Inheritance_and_the_prototype_chain) (either an object or {{jsxref("Operators/null", "null")}}) of this object. +The **`__proto__`** accessor property of {{jsxref("Object")}} instances exposes the [`[[Prototype]]`](/en-US/docs/Web/JavaScript/Guide/Inheritance_and_the_prototype_chain) (either an object or {{jsxref("null")}}) of this object. The `__proto__` property can also be used in an object literal definition to set the object `[[Prototype]]` on creation, as an alternative to {{jsxref("Object.create()")}}. See: [object initializer / literal syntax](/en-US/docs/Web/JavaScript/Reference/Operators/Object_initializer). That syntax is standard and optimized for in implementations, and quite different from `Object.prototype.__proto__`. @@ -40,7 +40,7 @@ If used as a getter, returns the object's `[[Prototype]]`. The `__proto__` getter function exposes the value of the internal `[[Prototype]]` of an object. For objects created using an object literal (unless you use the [prototype setter](/en-US/docs/Web/JavaScript/Reference/Operators/Object_initializer#prototype_setter) syntax), this value is `Object.prototype`. For objects created using array literals, this value is [`Array.prototype`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array). For functions, this value is {{jsxref("Function.prototype")}}. You can read more about the prototype chain in [Inheritance and the prototype chain](/en-US/docs/Web/JavaScript/Guide/Inheritance_and_the_prototype_chain). -The `__proto__` setter allows the `[[Prototype]]` of an object to be mutated. The value provided must be an object or {{jsxref("Operators/null", "null")}}. Providing any other value will do nothing. +The `__proto__` setter allows the `[[Prototype]]` of an object to be mutated. The value provided must be an object or {{jsxref("null")}}. Providing any other value will do nothing. Unlike {{jsxref("Object.getPrototypeOf()")}} and {{jsxref("Object.setPrototypeOf()")}}, which are always available on `Object` as static properties and always reflect the `[[Prototype]]` internal property, the `__proto__` property doesn't always exist as a property on all objects, and as a result doesn't reflect `[[Prototype]]` reliably. diff --git a/files/en-us/web/javascript/reference/global_objects/proxy/proxy/construct/index.md b/files/en-us/web/javascript/reference/global_objects/proxy/proxy/construct/index.md index 7b5551a722a5dde..eb566fe993c5520 100644 --- a/files/en-us/web/javascript/reference/global_objects/proxy/proxy/construct/index.md +++ b/files/en-us/web/javascript/reference/global_objects/proxy/proxy/construct/index.md @@ -7,7 +7,7 @@ browser-compat: javascript.builtins.Proxy.handler.construct sidebar: jsref --- -The **`handler.construct()`** method is a trap for the `[[Construct]]` [object internal method](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy#object_internal_methods), which is used by operations such as the {{jsxref("Operators/new", "new")}} operator. In order for the new operation to be valid on the resulting Proxy object, the target used to initialize the proxy must itself be a valid constructor. +The **`handler.construct()`** method is a trap for the `[[Construct]]` [object internal method](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy#object_internal_methods), which is used by operations such as the {{jsxref("new")}} operator. In order for the new operation to be valid on the resulting Proxy object, the target used to initialize the proxy must itself be a valid constructor. {{InteractiveExample("JavaScript Demo: handler.construct()", "taller")}} @@ -77,7 +77,7 @@ The proxy's `[[Construct]]` internal method throws a {{jsxref("TypeError")}} if ### Trapping the new operator -The following code traps the {{jsxref("Operators/new", "new")}} operator. +The following code traps the {{jsxref("new")}} operator. ```js const p = new Proxy(function () {}, { @@ -103,7 +103,7 @@ const p = new Proxy(function () {}, { new p(); // TypeError is thrown ``` -The following code improperly initializes the proxy. The `target` in Proxy initialization must itself be a valid constructor for the {{jsxref("Operators/new", "new")}} operator. +The following code improperly initializes the proxy. The `target` in Proxy initialization must itself be a valid constructor for the {{jsxref("new")}} operator. ```js example-bad const p = new Proxy( @@ -130,5 +130,5 @@ new p(); // TypeError is thrown, "p" is not a constructor - {{jsxref("Proxy")}} - [`Proxy()` constructor](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy/Proxy) -- {{jsxref("Operators/new", "new")}} +- {{jsxref("new")}} - {{jsxref("Reflect.construct()")}} diff --git a/files/en-us/web/javascript/reference/global_objects/proxy/proxy/deleteproperty/index.md b/files/en-us/web/javascript/reference/global_objects/proxy/proxy/deleteproperty/index.md index 6c7f846918f419c..67f7da5a80d9a84 100644 --- a/files/en-us/web/javascript/reference/global_objects/proxy/proxy/deleteproperty/index.md +++ b/files/en-us/web/javascript/reference/global_objects/proxy/proxy/deleteproperty/index.md @@ -7,7 +7,7 @@ browser-compat: javascript.builtins.Proxy.handler.deleteProperty sidebar: jsref --- -The **`handler.deleteProperty()`** method is a trap for the `[[Delete]]` [object internal method](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy#object_internal_methods), which is used by operations such as the {{jsxref("Operators/delete", "delete")}} operator. +The **`handler.deleteProperty()`** method is a trap for the `[[Delete]]` [object internal method](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy#object_internal_methods), which is used by operations such as the {{jsxref("delete")}} operator. {{InteractiveExample("JavaScript Demo: handler.deleteProperty()", "taller")}} @@ -58,7 +58,7 @@ The following parameters are passed to the `deleteProperty()` method. `this` is The `deleteProperty()` method must return a {{jsxref("Boolean")}} indicating whether or not the property has been successfully deleted. Other values are [coerced to booleans](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean#boolean_coercion). -Many operations, including the {{jsxref("Operators/delete", "delete")}} operator when in [strict mode](/en-US/docs/Web/JavaScript/Reference/Strict_mode), throw a {{jsxref("TypeError")}} if the `[[Delete]]` internal method returns `false`. +Many operations, including the {{jsxref("delete")}} operator when in [strict mode](/en-US/docs/Web/JavaScript/Reference/Strict_mode), throw a {{jsxref("TypeError")}} if the `[[Delete]]` internal method returns `false`. ## Description @@ -83,7 +83,7 @@ The proxy's `[[Delete]]` internal method throws a {{jsxref("TypeError")}} if the ### Trapping the delete operator -The following code traps the {{jsxref("Operators/delete", "delete")}} operator. +The following code traps the {{jsxref("delete")}} operator. ```js const p = new Proxy( @@ -124,5 +124,5 @@ console.log(result2); // false - {{jsxref("Proxy")}} - [`Proxy()` constructor](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy/Proxy) -- {{jsxref("Operators/delete", "delete")}} +- {{jsxref("delete")}} - {{jsxref("Reflect.deleteProperty()")}} diff --git a/files/en-us/web/javascript/reference/global_objects/proxy/proxy/getprototypeof/index.md b/files/en-us/web/javascript/reference/global_objects/proxy/proxy/getprototypeof/index.md index 320222dc8a5aa6e..280097c42288cf0 100644 --- a/files/en-us/web/javascript/reference/global_objects/proxy/proxy/getprototypeof/index.md +++ b/files/en-us/web/javascript/reference/global_objects/proxy/proxy/getprototypeof/index.md @@ -65,7 +65,7 @@ This trap can intercept these operations: - {{jsxref("Reflect.getPrototypeOf()")}} - [`__proto__`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/proto) - {{jsxref("Object.prototype.isPrototypeOf()")}} -- {{jsxref("Operators/instanceof", "instanceof")}} +- {{jsxref("instanceof")}} Or any other operation that invokes the `[[GetPrototypeOf]]` [internal method](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy#object_internal_methods). diff --git a/files/en-us/web/javascript/reference/global_objects/proxy/proxy/index.md b/files/en-us/web/javascript/reference/global_objects/proxy/proxy/index.md index f5cd9945564ce6f..32ba76c1f6b4fcb 100644 --- a/files/en-us/web/javascript/reference/global_objects/proxy/proxy/index.md +++ b/files/en-us/web/javascript/reference/global_objects/proxy/proxy/index.md @@ -50,11 +50,11 @@ object. - {{jsxref("Proxy/Proxy/apply", "handler.apply()")}} - : A trap for a function call. - {{jsxref("Proxy/Proxy/construct", "handler.construct()")}} - - : A trap for the {{jsxref("Operators/new", "new")}} operator. + - : A trap for the {{jsxref("new")}} operator. - {{jsxref("Proxy/Proxy/defineProperty", "handler.defineProperty()")}} - : A trap for {{jsxref("Object.defineProperty")}}. - {{jsxref("Proxy/Proxy/deleteProperty", "handler.deleteProperty()")}} - - : A trap for the {{jsxref("Operators/delete", "delete")}} operator. + - : A trap for the {{jsxref("delete")}} operator. - {{jsxref("Proxy/Proxy/get", "handler.get()")}} - : A trap for getting property values. - {{jsxref("Proxy/Proxy/getOwnPropertyDescriptor", "handler.getOwnPropertyDescriptor()")}} diff --git a/files/en-us/web/javascript/reference/global_objects/reflect/construct/index.md b/files/en-us/web/javascript/reference/global_objects/reflect/construct/index.md index 2817ebdfe6e55bd..4c8ae30aa1bbc16 100644 --- a/files/en-us/web/javascript/reference/global_objects/reflect/construct/index.md +++ b/files/en-us/web/javascript/reference/global_objects/reflect/construct/index.md @@ -7,7 +7,7 @@ browser-compat: javascript.builtins.Reflect.construct sidebar: jsref --- -The **`Reflect.construct()`** static method is like the {{jsxref("Operators/new", "new")}} operator, but as a function. It is equivalent to calling `new target(...args)`. It additionally allows to specify a different [`new.target`](/en-US/docs/Web/JavaScript/Reference/Operators/new.target) value. +The **`Reflect.construct()`** static method is like the {{jsxref("new")}} operator, but as a function. It is equivalent to calling `new target(...args)`. It additionally allows to specify a different [`new.target`](/en-US/docs/Web/JavaScript/Reference/Operators/new.target) value. {{InteractiveExample("JavaScript Demo: Reflect.construct()", "taller")}} @@ -231,6 +231,6 @@ OneClass.apply(obj3, args); - [Polyfill of `Reflect.construct` in `core-js`](https://github.com/zloirock/core-js#ecmascript-reflect) - {{jsxref("Reflect")}} -- {{jsxref("Operators/new", "new")}} +- {{jsxref("new")}} - [`new.target`](/en-US/docs/Web/JavaScript/Reference/Operators/new.target) - [`handler.construct()`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy/Proxy/construct) diff --git a/files/en-us/web/javascript/reference/global_objects/reflect/deleteproperty/index.md b/files/en-us/web/javascript/reference/global_objects/reflect/deleteproperty/index.md index a91bae83d034029..2358c1cf552218f 100644 --- a/files/en-us/web/javascript/reference/global_objects/reflect/deleteproperty/index.md +++ b/files/en-us/web/javascript/reference/global_objects/reflect/deleteproperty/index.md @@ -7,7 +7,7 @@ browser-compat: javascript.builtins.Reflect.deleteProperty sidebar: jsref --- -The **`Reflect.deleteProperty()`** static method is like the {{jsxref("Operators/delete", "delete")}} operator, but as a function. It deletes a property from an object. +The **`Reflect.deleteProperty()`** static method is like the {{jsxref("delete")}} operator, but as a function. It deletes a property from an object. {{InteractiveExample("JavaScript Demo: Reflect.deleteProperty()", "taller")}} diff --git a/files/en-us/web/javascript/reference/global_objects/set/difference/index.md b/files/en-us/web/javascript/reference/global_objects/set/difference/index.md index a523eb95e6c3136..1346944450205e9 100644 --- a/files/en-us/web/javascript/reference/global_objects/set/difference/index.md +++ b/files/en-us/web/javascript/reference/global_objects/set/difference/index.md @@ -39,7 +39,7 @@ And using Venn diagram: ![A Venn diagram where two circles overlap. The difference of A and B is the part of A that is not overlapping B.](diagram.svg) -`difference()` accepts [set-like](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set#set-like_objects) objects as the `other` parameter. It requires {{jsxref("Operators/this", "this")}} to be an actual {{jsxref("Set")}} instance, because it directly retrieves the underlying data stored in `this` without invoking any user code. Then, its behavior depends on the sizes of `this` and `other`: +`difference()` accepts [set-like](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set#set-like_objects) objects as the `other` parameter. It requires {{jsxref("this")}} to be an actual {{jsxref("Set")}} instance, because it directly retrieves the underlying data stored in `this` without invoking any user code. Then, its behavior depends on the sizes of `this` and `other`: - If there are more elements in `this` than `other.size`, then it iterates over `other` by calling its `keys()` method, and constructs a new set with all elements in `this` that are not seen in `other`. - Otherwise, it iterates over the elements in `this`, and constructs a new set with all elements `e` in `this` that cause `other.has(e)` to return a [falsy](/en-US/docs/Glossary/Falsy) value. diff --git a/files/en-us/web/javascript/reference/global_objects/set/index.md b/files/en-us/web/javascript/reference/global_objects/set/index.md index 5cf3c05dcc9bb3a..a09027c50f2dabe 100644 --- a/files/en-us/web/javascript/reference/global_objects/set/index.md +++ b/files/en-us/web/javascript/reference/global_objects/set/index.md @@ -99,7 +99,7 @@ To make them more generalizable, these methods don't just accept `Set` objects, ### Set-like objects -All [set composition methods](#set_composition) require {{jsxref("Operators/this", "this")}} to be an actual `Set` instance, but their arguments just need to be set-like. A _set-like object_ is an object that provides the following: +All [set composition methods](#set_composition) require {{jsxref("this")}} to be an actual `Set` instance, but their arguments just need to be set-like. A _set-like object_ is an object that provides the following: - A {{jsxref("Set/size", "size")}} property that contains a number. - A {{jsxref("Set/has", "has()")}} method that takes an element and returns a boolean. diff --git a/files/en-us/web/javascript/reference/global_objects/set/intersection/index.md b/files/en-us/web/javascript/reference/global_objects/set/intersection/index.md index 7049502a34b3b3c..734c7d2e217561b 100644 --- a/files/en-us/web/javascript/reference/global_objects/set/intersection/index.md +++ b/files/en-us/web/javascript/reference/global_objects/set/intersection/index.md @@ -39,7 +39,7 @@ And using Venn diagram: ![A Venn diagram where two circles overlap. The intersection of A and B is the part where they overlap.](diagram.svg) -`intersection()` accepts [set-like](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set#set-like_objects) objects as the `other` parameter. It requires {{jsxref("Operators/this", "this")}} to be an actual {{jsxref("Set")}} instance, because it directly retrieves the underlying data stored in `this` without invoking any user code. Then, its behavior depends on the sizes of `this` and `other`: +`intersection()` accepts [set-like](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set#set-like_objects) objects as the `other` parameter. It requires {{jsxref("this")}} to be an actual {{jsxref("Set")}} instance, because it directly retrieves the underlying data stored in `this` without invoking any user code. Then, its behavior depends on the sizes of `this` and `other`: - If there are more elements in `this` than `other.size`, then it iterates over `other` by calling its `keys()` method, and constructs a new set with all elements produced that are also present in `this`. - Otherwise, it iterates over the elements in `this`, and constructs a new set with all elements `e` in `this` that cause `other.has(e)` to return a [truthy](/en-US/docs/Glossary/Truthy) value. diff --git a/files/en-us/web/javascript/reference/global_objects/set/isdisjointfrom/index.md b/files/en-us/web/javascript/reference/global_objects/set/isdisjointfrom/index.md index daf90801966d82b..56cc8430fecbc2b 100644 --- a/files/en-us/web/javascript/reference/global_objects/set/isdisjointfrom/index.md +++ b/files/en-us/web/javascript/reference/global_objects/set/isdisjointfrom/index.md @@ -38,7 +38,7 @@ And using Venn diagram: ![A Venn diagram with two circles. A and B are disjoint because the circles have no region of overlap.](diagram.svg) -`isDisjointFrom()` accepts [set-like](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set#set-like_objects) objects as the `other` parameter. It requires {{jsxref("Operators/this", "this")}} to be an actual {{jsxref("Set")}} instance, because it directly retrieves the underlying data stored in `this` without invoking any user code. Then, its behavior depends on the sizes of `this` and `other`: +`isDisjointFrom()` accepts [set-like](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set#set-like_objects) objects as the `other` parameter. It requires {{jsxref("this")}} to be an actual {{jsxref("Set")}} instance, because it directly retrieves the underlying data stored in `this` without invoking any user code. Then, its behavior depends on the sizes of `this` and `other`: - If there are more elements in `this` than `other.size`, then it iterates over `other` by calling its `keys()` method, and if any element in `other` is present in `this`, it returns `false` (and closes the `keys()` iterator by calling its `return()` method). Otherwise, it returns `true`. - Otherwise, it iterates over the elements in `this`, and returns `false` if any element `e` in `this` causes `other.has(e)` to return a [truthy](/en-US/docs/Glossary/Truthy) value. Otherwise, it returns `true`. diff --git a/files/en-us/web/javascript/reference/global_objects/set/issubsetof/index.md b/files/en-us/web/javascript/reference/global_objects/set/issubsetof/index.md index b4f1656f8a82b44..ed5ae3377833647 100644 --- a/files/en-us/web/javascript/reference/global_objects/set/issubsetof/index.md +++ b/files/en-us/web/javascript/reference/global_objects/set/issubsetof/index.md @@ -41,7 +41,7 @@ And using Venn diagram: > [!NOTE] > The _subset_ relationship is not _proper subset_, which means `isSubsetOf()` returns `true` if `this` and `other` contain the same elements. -`isSubsetOf()` accepts [set-like](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set#set-like_objects) objects as the `other` parameter. It requires {{jsxref("Operators/this", "this")}} to be an actual {{jsxref("Set")}} instance, because it directly retrieves the underlying data stored in `this` without invoking any user code. Then, its behavior depends on the sizes of `this` and `other`: +`isSubsetOf()` accepts [set-like](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set#set-like_objects) objects as the `other` parameter. It requires {{jsxref("this")}} to be an actual {{jsxref("Set")}} instance, because it directly retrieves the underlying data stored in `this` without invoking any user code. Then, its behavior depends on the sizes of `this` and `other`: - If there are more elements in `this` than `other.size`, then it directly returns `false`. - Otherwise, it iterates over the elements in `this`, and returns `false` if any element `e` in `this` causes `other.has(e)` to return a [falsy](/en-US/docs/Glossary/Falsy) value. Otherwise, it returns `true`. diff --git a/files/en-us/web/javascript/reference/global_objects/set/issupersetof/index.md b/files/en-us/web/javascript/reference/global_objects/set/issupersetof/index.md index 29b7b71e919a193..2297e7a545fed3d 100644 --- a/files/en-us/web/javascript/reference/global_objects/set/issupersetof/index.md +++ b/files/en-us/web/javascript/reference/global_objects/set/issupersetof/index.md @@ -41,7 +41,7 @@ And using Venn diagram: > [!NOTE] > The _superset_ relationship is not _proper superset_, which means `isSupersetOf()` returns `true` if `this` and `other` contain the same elements. -`isSupersetOf()` accepts [set-like](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set#set-like_objects) objects as the `other` parameter. It requires {{jsxref("Operators/this", "this")}} to be an actual {{jsxref("Set")}} instance, because it directly retrieves the underlying data stored in `this` without invoking any user code. Then, its behavior depends on the sizes of `this` and `other`: +`isSupersetOf()` accepts [set-like](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set#set-like_objects) objects as the `other` parameter. It requires {{jsxref("this")}} to be an actual {{jsxref("Set")}} instance, because it directly retrieves the underlying data stored in `this` without invoking any user code. Then, its behavior depends on the sizes of `this` and `other`: - If there are fewer elements in `this` than `other.size`, then it directly returns `false`. - Otherwise, it iterates over `other` by calling its `keys()` method, and if any element in `other` is not present in `this`, it returns `false` (and closes the `keys()` iterator by calling its `return()` method). Otherwise, it returns `true`. diff --git a/files/en-us/web/javascript/reference/global_objects/set/symmetricdifference/index.md b/files/en-us/web/javascript/reference/global_objects/set/symmetricdifference/index.md index 15ebf09d3ba952b..9ef56d6e0fcd058 100644 --- a/files/en-us/web/javascript/reference/global_objects/set/symmetricdifference/index.md +++ b/files/en-us/web/javascript/reference/global_objects/set/symmetricdifference/index.md @@ -38,7 +38,7 @@ And using Venn diagram: ![A Venn diagram where two circles overlap. The symmetric difference of A and B is the region contained by either circle but not both.](diagram.svg) -`symmetricDifference()` accepts [set-like](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set#set-like_objects) objects as the `other` parameter. It requires {{jsxref("Operators/this", "this")}} to be an actual {{jsxref("Set")}} instance, because it directly retrieves the underlying data stored in `this` without invoking any user code. Then, it iterates over `other` by calling its `keys()` method, and constructs a new set with all elements in `this` that are not seen in `other`, and all elements in `other` that are not seen in `this`. +`symmetricDifference()` accepts [set-like](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set#set-like_objects) objects as the `other` parameter. It requires {{jsxref("this")}} to be an actual {{jsxref("Set")}} instance, because it directly retrieves the underlying data stored in `this` without invoking any user code. Then, it iterates over `other` by calling its `keys()` method, and constructs a new set with all elements in `this` that are not seen in `other`, and all elements in `other` that are not seen in `this`. The order of elements in the returned set is first those in `this` followed by those in `other`. diff --git a/files/en-us/web/javascript/reference/global_objects/set/union/index.md b/files/en-us/web/javascript/reference/global_objects/set/union/index.md index ba3f038bf3b7512..fdd90bdbee72fdf 100644 --- a/files/en-us/web/javascript/reference/global_objects/set/union/index.md +++ b/files/en-us/web/javascript/reference/global_objects/set/union/index.md @@ -39,7 +39,7 @@ And using Venn diagram: ![A Venn diagram where two circles overlap. The symmetric difference of A and B is the region contained by either or both circles.](diagram.svg) -`union()` accepts [set-like](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set#set-like_objects) objects as the `other` parameter. It requires {{jsxref("Operators/this", "this")}} to be an actual {{jsxref("Set")}} instance, because it directly retrieves the underlying data stored in `this` without invoking any user code. Then, it iterates over `other` by calling its `keys()` method, and constructs a new set with all elements in `this`, followed by all elements in `other` that are not present in `this`. +`union()` accepts [set-like](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set#set-like_objects) objects as the `other` parameter. It requires {{jsxref("this")}} to be an actual {{jsxref("Set")}} instance, because it directly retrieves the underlying data stored in `this` without invoking any user code. Then, it iterates over `other` by calling its `keys()` method, and constructs a new set with all elements in `this`, followed by all elements in `other` that are not present in `this`. The order of elements in the returned set is first those in `this` followed by those in `other`. diff --git a/files/en-us/web/javascript/reference/global_objects/sharedarraybuffer/sharedarraybuffer/index.md b/files/en-us/web/javascript/reference/global_objects/sharedarraybuffer/sharedarraybuffer/index.md index 958f8a754b2a5eb..5dd5c136e345515 100644 --- a/files/en-us/web/javascript/reference/global_objects/sharedarraybuffer/sharedarraybuffer/index.md +++ b/files/en-us/web/javascript/reference/global_objects/sharedarraybuffer/sharedarraybuffer/index.md @@ -52,7 +52,7 @@ console.log(buffer.byteLength); // 8 ### Always use the new operator to create a SharedArrayBuffer -`SharedArrayBuffer` constructors are required to be constructed with a {{jsxref("Operators/new", "new")}} operator. Calling a `SharedArrayBuffer` constructor as a function without `new` will throw a {{jsxref("TypeError")}}. +`SharedArrayBuffer` constructors are required to be constructed with a {{jsxref("new")}} operator. Calling a `SharedArrayBuffer` constructor as a function without `new` will throw a {{jsxref("TypeError")}}. ```js example-bad const sab = SharedArrayBuffer(1024); diff --git a/files/en-us/web/javascript/reference/global_objects/string/index.md b/files/en-us/web/javascript/reference/global_objects/string/index.md index 431eb218b170410..f2e2c848a45e944 100644 --- a/files/en-us/web/javascript/reference/global_objects/string/index.md +++ b/files/en-us/web/javascript/reference/global_objects/string/index.md @@ -116,7 +116,7 @@ Note that JavaScript distinguishes between `String` objects and String literals (denoted by double or single quotes) and strings returned from `String` calls in a non-constructor context (that is, called without using -the {{jsxref("Operators/new", "new")}} keyword) are primitive strings. In contexts where a +the {{jsxref("new")}} keyword) are primitive strings. In contexts where a method is to be invoked on a primitive string or a property lookup occurs, JavaScript will automatically wrap the string primitive and call the method or perform the property lookup on the wrapper object instead. diff --git a/files/en-us/web/javascript/reference/global_objects/symbol/hasinstance/index.md b/files/en-us/web/javascript/reference/global_objects/symbol/hasinstance/index.md index 5964b58277488d6..2310f5be0ce5cf4 100644 --- a/files/en-us/web/javascript/reference/global_objects/symbol/hasinstance/index.md +++ b/files/en-us/web/javascript/reference/global_objects/symbol/hasinstance/index.md @@ -7,7 +7,7 @@ browser-compat: javascript.builtins.Symbol.hasInstance sidebar: jsref --- -The **`Symbol.hasInstance`** static data property represents the [well-known symbol](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol#well-known_symbols) `Symbol.hasInstance`. The {{jsxref("Operators/instanceof", "instanceof")}} operator looks up this symbol on its right-hand operand for the method used to determine if the constructor object recognizes an object as its instance. +The **`Symbol.hasInstance`** static data property represents the [well-known symbol](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol#well-known_symbols) `Symbol.hasInstance`. The {{jsxref("instanceof")}} operator looks up this symbol on its right-hand operand for the method used to determine if the constructor object recognizes an object as its instance. {{InteractiveExample("JavaScript Demo: Symbol.hasInstance")}} @@ -86,5 +86,5 @@ console.log(Animal[Symbol.hasInstance](cat)); // true ## See also -- {{jsxref("Operators/instanceof", "instanceof")}} +- {{jsxref("instanceof")}} - [`Function.prototype[Symbol.hasInstance]()`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/Symbol.hasInstance) diff --git a/files/en-us/web/javascript/reference/global_objects/symbol/index.md b/files/en-us/web/javascript/reference/global_objects/symbol/index.md index 4e54ec7e0be1d9b..3bc83e465a3448b 100644 --- a/files/en-us/web/javascript/reference/global_objects/symbol/index.md +++ b/files/en-us/web/javascript/reference/global_objects/symbol/index.md @@ -26,7 +26,7 @@ The above code creates three new Symbols. Note that `Symbol("foo")` does not coe Symbol("foo") === Symbol("foo"); // false ``` -The following syntax with the {{jsxref("Operators/new", "new")}} operator will throw a {{jsxref("TypeError")}}: +The following syntax with the {{jsxref("new")}} operator will throw a {{jsxref("TypeError")}}: ```js example-bad const sym = new Symbol(); // TypeError @@ -61,7 +61,7 @@ Because registered symbols can be arbitrarily created anywhere, they behave almo ### Well-known Symbols -All static properties of the `Symbol` constructor are Symbols themselves, whose values are constant across realms. They are known as _well-known Symbols_, and their purpose is to serve as "protocols" for certain built-in JavaScript operations, allowing users to customize the language's behavior. For example, if a constructor function has a method with {{jsxref("Symbol.hasInstance")}} as its name, this method will encode its behavior with the {{jsxref("Operators/instanceof", "instanceof")}} operator. +All static properties of the `Symbol` constructor are Symbols themselves, whose values are constant across realms. They are known as _well-known Symbols_, and their purpose is to serve as "protocols" for certain built-in JavaScript operations, allowing users to customize the language's behavior. For example, if a constructor function has a method with {{jsxref("Symbol.hasInstance")}} as its name, this method will encode its behavior with the {{jsxref("instanceof")}} operator. Prior to well-known Symbols, JavaScript used normal properties to implement certain built-in operations. For example, the [`JSON.stringify`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify) function will attempt to call each object's `toJSON()` method, and the [`String`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/String) function will call the object's `toString()` and `valueOf()` methods. However, as more operations are added to the language, designating each operation a "magic property" can break backward compatibility and make the language's behavior harder to reason with. Well-known Symbols allow the customizations to be "invisible" from normal code, which typically only read string properties. @@ -90,7 +90,7 @@ The static properties are all well-known Symbols. In these Symbols' descriptions - {{jsxref("Symbol.dispose")}} - : A method that disposes resources of the object when the object goes out of scope. Used by the [`using`](/en-US/docs/Web/JavaScript/Reference/Statements/using) declaration. - {{jsxref("Symbol.hasInstance")}} - - : A method determining if a constructor object recognizes an object as its instance. Used by {{jsxref("Operators/instanceof", "instanceof")}}. + - : A method determining if a constructor object recognizes an object as its instance. Used by {{jsxref("instanceof")}}. - {{jsxref("Symbol.isConcatSpreadable")}} - : A Boolean value indicating if an object should be flattened to its array elements. Used by {{jsxref("Array.prototype.concat()")}}. - {{jsxref("Symbol.iterator")}} diff --git a/files/en-us/web/javascript/reference/global_objects/symbol/symbol/index.md b/files/en-us/web/javascript/reference/global_objects/symbol/symbol/index.md index b6fa7fbf6600fef..1471fb132292701 100644 --- a/files/en-us/web/javascript/reference/global_objects/symbol/symbol/index.md +++ b/files/en-us/web/javascript/reference/global_objects/symbol/symbol/index.md @@ -67,7 +67,7 @@ Symbol("foo") === Symbol("foo"); // false ### new Symbol() -The following syntax with the {{jsxref("Operators/new", "new")}} operator will throw a +The following syntax with the {{jsxref("new")}} operator will throw a {{jsxref("TypeError")}}: ```js example-bad diff --git a/files/en-us/web/javascript/reference/index.md b/files/en-us/web/javascript/reference/index.md index e3f369ebe229b8b..cc87bac39b6306b 100644 --- a/files/en-us/web/javascript/reference/index.md +++ b/files/en-us/web/javascript/reference/index.md @@ -193,7 +193,7 @@ If you are new to JavaScript, start with the [guide](/en-US/docs/Web/JavaScript/ ### Primary expressions -- {{jsxref("Operators/this", "this")}} +- {{jsxref("this")}} - [Literals](/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#literals) - {{jsxref("Array", "[]")}} - {{jsxref("Operators/Object_initializer", "{}")}} @@ -210,7 +210,7 @@ If you are new to JavaScript, start with the [guide](/en-US/docs/Web/JavaScript/ - {{jsxref("Operators/Property_accessors", "Property accessors", "", 1)}} - {{jsxref("Operators/Optional_chaining", "?.")}} -- {{jsxref("Operators/new", "new")}} +- {{jsxref("new")}} - {{jsxref("Operators/new.target", "new.target")}} - {{jsxref("Operators/import.meta", "import.meta")}} - {{jsxref("Operators/super", "super")}} @@ -225,7 +225,7 @@ If you are new to JavaScript, start with the [guide](/en-US/docs/Web/JavaScript/ ### Unary operators -- {{jsxref("Operators/delete", "delete")}} +- {{jsxref("delete")}} - {{jsxref("Operators/void", "void")}} - {{jsxref("Operators/typeof", "typeof")}} - {{jsxref("Operators/Unary_plus", "+")}} @@ -249,7 +249,7 @@ If you are new to JavaScript, start with the [guide](/en-US/docs/Web/JavaScript/ - {{jsxref("Operators/Greater_than", ">")}} (Greater than) - {{jsxref("Operators/Less_than_or_equal", "<=")}} - {{jsxref("Operators/Greater_than_or_equal", ">=")}} -- {{jsxref("Operators/instanceof", "instanceof")}} +- {{jsxref("instanceof")}} - {{jsxref("Operators/in", "in")}} ### Equality operators diff --git a/files/en-us/web/javascript/reference/lexical_grammar/index.md b/files/en-us/web/javascript/reference/lexical_grammar/index.md index e5ee6a17a78a5d6..8e0915a279ba588 100644 --- a/files/en-us/web/javascript/reference/lexical_grammar/index.md +++ b/files/en-us/web/javascript/reference/lexical_grammar/index.md @@ -212,7 +212,7 @@ These keywords cannot be used as identifiers for variables, functions, classes, - {{jsxref("Statements/continue", "continue")}} - {{jsxref("Statements/debugger", "debugger")}} - {{jsxref("Statements/switch", "default")}} -- {{jsxref("Operators/delete", "delete")}} +- {{jsxref("delete")}} - {{jsxref("Statements/do...while", "do")}} - {{jsxref("Statements/if...else", "else")}} - {{jsxref("Statements/export", "export")}} @@ -224,13 +224,13 @@ These keywords cannot be used as identifiers for variables, functions, classes, - {{jsxref("Statements/if...else", "if")}} - {{jsxref("Statements/import", "import")}} - {{jsxref("Operators/in", "in")}} -- {{jsxref("Operators/instanceof", "instanceof")}} -- {{jsxref("Operators/new", "new")}} -- {{jsxref("Operators/null", "null")}} +- {{jsxref("instanceof")}} +- {{jsxref("new")}} +- {{jsxref("null")}} - {{jsxref("Statements/return", "return")}} - {{jsxref("Operators/super", "super")}} - {{jsxref("Statements/switch", "switch")}} -- {{jsxref("Operators/this", "this")}} +- {{jsxref("this")}} - {{jsxref("Statements/throw", "throw")}} - [`true`](#boolean_literal) - {{jsxref("Statements/try...catch", "try")}} diff --git a/files/en-us/web/javascript/reference/operators/grouping/index.md b/files/en-us/web/javascript/reference/operators/grouping/index.md index 38ae33bab2781ef..0ef83807ed2e30f 100644 --- a/files/en-us/web/javascript/reference/operators/grouping/index.md +++ b/files/en-us/web/javascript/reference/operators/grouping/index.md @@ -159,5 +159,5 @@ For more advice on working with ASI, see its [reference section](/en-US/docs/Web ## See also - [Operator precedence](/en-US/docs/Web/JavaScript/Reference/Operators/Operator_precedence) -- {{jsxref("Operators/delete", "delete")}} +- {{jsxref("delete")}} - {{jsxref("Operators/typeof", "typeof")}} diff --git a/files/en-us/web/javascript/reference/operators/index.md b/files/en-us/web/javascript/reference/operators/index.md index 29af1f6dacf6311..d51807bdbe3adfe 100644 --- a/files/en-us/web/javascript/reference/operators/index.md +++ b/files/en-us/web/javascript/reference/operators/index.md @@ -16,7 +16,7 @@ For an alphabetical listing see the sidebar on the left. Basic keywords and general expressions in JavaScript. These expressions have the highest precedence (higher than [operators](/en-US/docs/Web/JavaScript/Reference/Operators/Operator_precedence)). -- {{jsxref("Operators/this", "this")}} +- {{jsxref("this")}} - : The `this` keyword refers to a special property of an execution context. - [Literals](/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#literals) - : Basic `null`, boolean, number, and string literals. @@ -49,10 +49,10 @@ Left values are the destination of an assignment. - : Member operators provide access to a property or method of an object (`object.property` and `object["property"]`). - {{jsxref("Operators/Optional_chaining", "?.")}} - : The optional chaining operator returns `undefined` instead of causing an error if a reference is [nullish](/en-US/docs/Glossary/Nullish) ([`null`](/en-US/docs/Web/JavaScript/Reference/Operators/null) or [`undefined`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined)). -- {{jsxref("Operators/new", "new")}} +- {{jsxref("new")}} - : The `new` operator creates an instance of a constructor. - {{jsxref("Operators/new.target", "new.target")}} - - : In constructors, `new.target` refers to the constructor that was invoked by {{jsxref("Operators/new", "new")}}. + - : In constructors, `new.target` refers to the constructor that was invoked by {{jsxref("new")}}. - {{jsxref("Operators/import.meta", "import.meta")}} - : An object exposing context-specific metadata to a JavaScript module. - {{jsxref("Operators/super", "super")}} @@ -77,7 +77,7 @@ Postfix/prefix increment and postfix/prefix decrement operators. A unary operation is an operation with only one operand. -- {{jsxref("Operators/delete", "delete")}} +- {{jsxref("delete")}} - : The `delete` operator deletes a property from an object. - {{jsxref("Operators/void", "void")}} - : The `void` operator evaluates an expression and discards its return value. @@ -123,7 +123,7 @@ A comparison operator compares its operands and returns a boolean value based on - : Less than or equal operator. - {{jsxref("Operators/Greater_than_or_equal", ">=")}} - : Greater than or equal operator. -- {{jsxref("Operators/instanceof", "instanceof")}} +- {{jsxref("instanceof")}} - : The `instanceof` operator determines whether an object is an instance of another object. - {{jsxref("Operators/in", "in")}} - : The `in` operator determines whether an object has a given property. diff --git a/files/en-us/web/javascript/reference/operators/operator_precedence/index.md b/files/en-us/web/javascript/reference/operators/operator_precedence/index.md index c57145cd4a746e6..6e954a540b01171 100644 --- a/files/en-us/web/javascript/reference/operators/operator_precedence/index.md +++ b/files/en-us/web/javascript/reference/operators/operator_precedence/index.md @@ -277,7 +277,7 @@ Several general notes about the table: [3] - {{jsxref("Operators/new", "new")}} with argument list
new x(y) + {{jsxref("new")}} with argument list
new x(y) [4] @@ -291,7 +291,7 @@ Several general notes about the table: 16: new n/a - {{jsxref("Operators/new", "new")}} without argument list
new x + {{jsxref("new")}} without argument list
new x 15: postfix operators diff --git a/files/en-us/web/javascript/reference/operators/optional_chaining/index.md b/files/en-us/web/javascript/reference/operators/optional_chaining/index.md index 3f47091f04a229a..fee6aeb7c1a9b28 100644 --- a/files/en-us/web/javascript/reference/operators/optional_chaining/index.md +++ b/files/en-us/web/javascript/reference/operators/optional_chaining/index.md @@ -147,7 +147,7 @@ String?.raw`Hello, world!`; String.raw?.`Hello, world!`; // SyntaxError: Invalid tagged template on optional chain ``` -The constructor of {{jsxref("Operators/new", "new")}} expressions cannot be an optional chain (see [SyntaxError: new keyword cannot be used with an optional chain](/en-US/docs/Web/JavaScript/Reference/Errors/Bad_new_optional)): +The constructor of {{jsxref("new")}} expressions cannot be an optional chain (see [SyntaxError: new keyword cannot be used with an optional chain](/en-US/docs/Web/JavaScript/Reference/Errors/Bad_new_optional)): ```js-nolint example-bad new Intl?.DateTimeFormat(); // SyntaxError: Invalid optional chain from new expression diff --git a/files/en-us/web/javascript/reference/operators/spread_syntax/index.md b/files/en-us/web/javascript/reference/operators/spread_syntax/index.md index b3de7651c26036c..fb03a3ead8b98a6 100644 --- a/files/en-us/web/javascript/reference/operators/spread_syntax/index.md +++ b/files/en-us/web/javascript/reference/operators/spread_syntax/index.md @@ -101,7 +101,7 @@ myFunction(-1, ...args, 2, ...[3]); #### Apply for new operator -When calling a constructor with {{jsxref("Operators/new", "new")}}, it's not possible to **directly** use an array and `apply()`, because `apply()` _calls_ the target function instead of _constructing_ it, which means, among other things, that [`new.target`](/en-US/docs/Web/JavaScript/Reference/Operators/new.target) will be `undefined`. However, an array can be easily used with `new` thanks to spread syntax: +When calling a constructor with {{jsxref("new")}}, it's not possible to **directly** use an array and `apply()`, because `apply()` _calls_ the target function instead of _constructing_ it, which means, among other things, that [`new.target`](/en-US/docs/Web/JavaScript/Reference/Operators/new.target) will be `undefined`. However, an array can be easily used with `new` thanks to spread syntax: ```js const dateFields = [1970, 0, 1]; // 1 Jan 1970 diff --git a/files/en-us/web/javascript/reference/operators/this/index.md b/files/en-us/web/javascript/reference/operators/this/index.md index 37771d69cfacba9..5fb2808d3658eba 100644 --- a/files/en-us/web/javascript/reference/operators/this/index.md +++ b/files/en-us/web/javascript/reference/operators/this/index.md @@ -178,7 +178,7 @@ console.log(boundFoo() === globalObject); // true #### Constructors -When a function is used as a constructor (with the {{jsxref("Operators/new", "new")}} keyword), its `this` is bound to the new object being constructed, no matter which object the constructor function is accessed on. The value of `this` becomes the value of the `new` expression unless the constructor returns another non–primitive value. +When a function is used as a constructor (with the {{jsxref("new")}} keyword), its `this` is bound to the new object being constructed, no matter which object the constructor function is accessed on. The value of `this` becomes the value of the `new` expression unless the constructor returns another non–primitive value. ```js function C() { diff --git a/files/en-us/web/javascript/reference/operators/typeof/index.md b/files/en-us/web/javascript/reference/operators/typeof/index.md index 45b65d70c9b6ab5..2dd593f97aa2a30 100644 --- a/files/en-us/web/javascript/reference/operators/typeof/index.md +++ b/files/en-us/web/javascript/reference/operators/typeof/index.md @@ -243,5 +243,5 @@ For checking potentially non-existent variables that would otherwise throw a {{j ## See also -- {{jsxref("Operators/instanceof", "instanceof")}} +- {{jsxref("instanceof")}} - [`document.all` willful violation of the standard](https://github.com/tc39/ecma262/issues/668) diff --git a/files/en-us/web/javascript/reference/statements/var/index.md b/files/en-us/web/javascript/reference/statements/var/index.md index 5970cbfdce20f35..bd0b93698542c1e 100644 --- a/files/en-us/web/javascript/reference/statements/var/index.md +++ b/files/en-us/web/javascript/reference/statements/var/index.md @@ -74,7 +74,7 @@ for (var a of [1, 2, 3]); console.log(a); // 3 ``` -In a script, a variable declared using `var` is added as a non-configurable property of the global object. This means its property descriptor cannot be changed and it cannot be deleted using {{jsxref("Operators/delete", "delete")}}. JavaScript has automatic memory management, and it would make no sense to be able to use the `delete` operator on a global variable. +In a script, a variable declared using `var` is added as a non-configurable property of the global object. This means its property descriptor cannot be changed and it cannot be deleted using {{jsxref("delete")}}. JavaScript has automatic memory management, and it would make no sense to be able to use the `delete` operator on a global variable. ```js-nolint example-bad "use strict"; diff --git a/files/en-us/webassembly/index.md b/files/en-us/webassembly/index.md index 5389e024c734f53..b2ee57b30e4e445 100644 --- a/files/en-us/webassembly/index.md +++ b/files/en-us/webassembly/index.md @@ -25,9 +25,7 @@ It is a low-level assembly-like language with a compact binary format that runs WebAssembly is designed to complement and run alongside JavaScript — using the WebAssembly JavaScript APIs, you can load WebAssembly modules into a JavaScript app and share functionality between the two. This allows you to take advantage of WebAssembly's performance and power and JavaScript's expressiveness and flexibility in the same app, even if you don't know how to write WebAssembly code. -WebAssembly has big implications for the web platform, not only because it provides a way for code written in multiple languages to run on the web at near-native speed, but also because it enables client apps to run on the web that previously could not. - -And what's even better is that it is being developed as a web standard via the [W3C WebAssembly Working Group](https://www.w3.org/groups/wg/wasm/) and [Community Group](https://www.w3.org/community/webassembly/) with active participation from all major browser vendors. +WebAssembly provides a way for code written in multiple languages to run on the web at near-native speed, and it enables client apps to run on the web that previously could not. ## Guides diff --git a/files/en-us/webassembly/reference/definitions/index.md b/files/en-us/webassembly/reference/definitions/index.md index c5955f20d079ebd..5b5229be594133e 100644 --- a/files/en-us/webassembly/reference/definitions/index.md +++ b/files/en-us/webassembly/reference/definitions/index.md @@ -19,6 +19,8 @@ This set of pages details the top-level module definition features available in - : Creates a new global. - [`table`](/en-US/docs/WebAssembly/Reference/Definitions/table) - : Creates a new table. +- [`tag`](/en-US/docs/WebAssembly/Reference/Definitions/tag) + - : Declares an exception type that can be thrown in the module. ## Specifications diff --git a/files/en-us/webassembly/reference/definitions/tag/index.md b/files/en-us/webassembly/reference/definitions/tag/index.md new file mode 100644 index 000000000000000..38a253b6bd9958c --- /dev/null +++ b/files/en-us/webassembly/reference/definitions/tag/index.md @@ -0,0 +1,282 @@ +--- +title: "tag: Wasm definition" +short-title: tag +slug: WebAssembly/Reference/Definitions/tag +page-type: webassembly-instruction +browser-compat: webassembly.definitions.tag +sidebar: webassemblysidebar +--- + +The **`tag`** [definition](/en-US/docs/WebAssembly/Reference/Definitions) declares an exception type that can be thrown in the module. + +{{InteractiveExample("Wat Demo: tag", "tabbed-taller")}} + +```wat interactive-example +(module + ;; Declare an exception tag $my_error with two i32 parameters + (tag $my_error (param i32) (param i32)) + + ;; Import console.log + (import "env" "log" (func $log (param i32))) + + ;; Define $try_and_catch function that tries running the $might_throw function + ;; and catches the $my_error exception if thrown, returning the exception's + ;; arguments from the block + (func $try_and_catch (param $value i32) + (block $handler (result i32) (result i32) + (try_table (catch $my_error $handler) + (call $might_throw (local.get $value)) + ) + (return) + ) + + ;; Log the exception's arguments + call $log + call $log + ) + + (func $might_throw (param $value i32) + ;; If value is negative, throw an exception + (local.get $value) + (i32.const 0) + (i32.lt_s) + (if + (then + ;; Push the error code onto the stack, then throw + (i32.const 0) ;; error code + (i32.const 42) ;; error payload + (throw $my_error) ;; throw $my_error exception + ) + ) + ) + + ;; Export $try_and_catch function + (export "try_and_catch" (func $try_and_catch)) +) +``` + +```js interactive-example +// Import object containing console.log +const env = { + log: console.log, +}; + +WebAssembly.instantiateStreaming(fetch("{%wasm-url%}"), { env }).then( + (result) => { + // Negative value causes function to throw + result.instance.exports.try_and_catch(-1); + }, +); +``` + +## Syntax + +```plain +tag identifier parameters +``` + +- `tag` + - : The `tag` definition type. Must always be included first. +- `identifier` {{optional_inline}} + - : An identifying name for the tag. This must begin with a `$` symbol, for example `$my_error`. +- `parameters` + - : One or more values specifying the exception type's parameters and their types. Each one consists of: + - The keyword `param` + - The type of the parameter. This can be any [Wasm type](/en-US/docs/WebAssembly/Reference/Value_types). + +## Description + +The WebAssembly `tag` definition allows exception types to be defined for the module. Each one consists of an optional identifying name preceded by a `$` symbol, followed by one or more parameter definitions. For example: + +```wat +(tag $my_error (param i32)) +``` + +Later in the module, you can reference the exception type by its identifying name, `$my_error` in this case. + +> [!NOTE] +> If an `identifier` is not specified, the tag can be identified by its tag index number — `0` for the first specified tag, `1` for the second, etc. + +For example, the following function takes an `i32` parameter and evaluates whether it is less than `0` using the [`lt_s`](/en-US/docs/WebAssembly/Reference/Numeric/lt_s) instruction. If this is the case, we throw an exception of type `$my_error`, passing it a value of `42`, which could represent an error code or payload. + +```wat +(func $might_throw (param $value i32) + (local.get $value) + (i32.const 0) + (i32.lt_s) + (if + (then + (i32.const 42) + (throw $my_error) + ) + ) +) +``` + +The thrown exception could then be handled and the payload accessed using a Wasm try/catch block. You can see an example in the [Try it](#try_it) section at the top of the page; also see the following pages for more examples: + +- [`try_table`](/en-US/docs/WebAssembly/Reference/Exception_handling/try_table) +- [`catch`](/en-US/docs/WebAssembly/Reference/Exception_handling/try_table/catch) +- [`catch_all`](/en-US/docs/WebAssembly/Reference/Exception_handling/try_table/catch_all) +- [`catch_ref`](/en-US/docs/WebAssembly/Reference/Exception_handling/try_table/catch_ref) +- [`catch_all_ref`](/en-US/docs/WebAssembly/Reference/Exception_handling/try_table/catch_all_ref) + +### Handling Wasm exceptions in JavaScript + +Alternatively, if the function that throws the exception is exported, the exception can be handled via a regular JavaScript [`try...catch`](/en-US/docs/Web/JavaScript/Reference/Statements/try...catch) statement. + +For example, we could export the `$might_throw` function seen earlier like this: + +```wat +(export "might_throw" (func $might_throw)) +``` + +To access the exception's payload, you have to export the tag as well: + +```wat +(export "my_error" (tag $my_error)) +``` + +Back over in the JavaScript, we can instantiate the module and then call the exported function (via the [`exports`](/en-US/docs/WebAssembly/Reference/JavaScript_interface/Instance/exports) object) with a number argument that is less than `0` to cause it to throw the `$my_error` exception. We can also access the exported tag via the `exports` object. + +We can then access the exception payload inside the `catch` block via the [`Exception.getArg()`](/en-US/docs/WebAssembly/Reference/JavaScript_interface/Exception/getArg) method. + +```js +let myErrorTag; + +WebAssembly.instantiateStreaming(fetch("module.wasm")).then((result) => { + myErrorTag = result.instance.exports.my_error; + try { + result.instance.exports.might_throw(-1); // negative value causes function to throw + } catch (e) { + if (e instanceof WebAssembly.Exception && e.is(myErrorTag)) { + console.log("Error code:", e.getArg(myErrorTag, 0)); + } else { + throw e; // throw other errors + } + } +}); +``` + +You can see this in action along with a complete explanation in our [Full JavaScript exception handling example](#full_javascript_exception_handling_example) example later on. + +### Creating tags in JavaScript + +It is also possible to create a Wasm tag from within the JavaScript host using the [`WebAssembly.Tag()`](/en-US/docs/WebAssembly/Reference/JavaScript_interface/Tag/Tag) constructor: + +For example: + +```js +const myErrorTag = new WebAssembly.Tag({ parameters: ["i32"] }); +``` + +You can import it into the module: + +```js +const env = { + my_error: myErrorTag, +}; + +WebAssembly.instantiateStreaming(fetch("module.wasm"), { env }); +``` + +Then, reference it inside the Wasm module like so: + +```wat +(module + (tag $my_error (import "env" "my_error") (param i32)) + + ... +) +``` + +## Examples + +### Full JavaScript exception handling example + +In this example, we demonstrate how to handle a Wasm exception defined and thrown inside a Wasm module from the associated JavaScript host. + +#### Wasm + +In our Wasm module, we start by defining an exception tag called `$my_error` with a single `i32` parameter, then export it. We then define a function called `$might_throw` that takes a single `i32` parameter, checks whether it is less than `0`, and then throws the `$my_error` exception if so, with a payload of `42`. Finally, we export the `$might_throw` function. + +```html hidden live-sample___tag_definition +

+``` + +```wat live-sample___tag_definition +(module + (tag $my_error (param i32)) + (export "my_error" (tag $my_error)) + + (func $might_throw (param $value i32) + (local.get $value) + (i32.const 0) + (i32.lt_s) + (if + (then + (i32.const 42) + (throw $my_error) + ) + ) + ) + + (export "might_throw" (func $might_throw)) +) +``` + +#### JavaScript + +We begin our script by defining a variable called `myErrorTag`, grabbing a reference to an output {{htmlelement("p")}} to output results into, and instantiating our Wasm module using [`WebAssembly.instantiateStreaming()`](/en-US/docs/WebAssembly/Reference/JavaScript_interface/instantiateStreaming_static). + +```js live-sample___tag_definition +let myErrorTag; +const output = document.querySelector("p"); +const wasm = WebAssembly.instantiateStreaming(fetch("{%wasm-url%}")); +``` + +When the `instantiateStreaming()` promise resolves, we set the `myErrorTag` variable equal to the exported `my_error` tag, then try running the exported `might_throw()` function inside a `try` block with a negative number argument to make it throw. + +Inside the respective `catch` block, the thrown Wasm exception will be available in the `error` object will be a [`WebAssembly.Exception`](/en-US/docs/WebAssembly/Reference/JavaScript_interface/Exception) instance. We check that this is true using `error instanceof WebAssembly.Exception`, and whether the `error` object represents an exception of the exported `myErrorTag` type (using the [`is()`](/en-US/docs/WebAssembly/Reference/JavaScript_interface/Exception/is) method). + +If both of these are true, we access the Wasm exception payload using the [`getArg()`](/en-US/docs/WebAssembly/Reference/JavaScript_interface/Exception/getArg) method and write it to the output `

`. If not, we write the error object to the output `

`. + +```js live-sample___tag_definition +wasm.then((result) => { + myErrorTag = result.instance.exports.my_error; + try { + result.instance.exports.might_throw(-1); + } catch (error) { + if (error instanceof WebAssembly.Exception && error.is(myErrorTag)) { + output.textContent = `Error code: ${error.getArg(myErrorTag, 0)}`; + } else { + output.textContent = `Error: ${error}`; // report other errors + } + } +}); +``` + +#### Result + +{{embedlivesample("tag_definition", "100%", 60)}} + +## Specifications + +{{Specifications}} + +## Browser compatibility + +{{Compat}} + +## See also + +- [`throw`](/en-US/docs/WebAssembly/Reference/Exception_handling/throw) instruction +- [`throw_ref`](/en-US/docs/WebAssembly/Reference/Exception_handling/throw_ref) instruction +- [`try_table`](/en-US/docs/WebAssembly/Reference/Exception_handling/try_table) instruction + - [`catch`](/en-US/docs/WebAssembly/Reference/Exception_handling/try_table/catch) clause + - [`catch_all`](/en-US/docs/WebAssembly/Reference/Exception_handling/try_table/catch_all) clause + - [`catch_ref`](/en-US/docs/WebAssembly/Reference/Exception_handling/try_table/catch_ref) clause + - [`catch_all_ref`](/en-US/docs/WebAssembly/Reference/Exception_handling/try_table/catch_all_ref) clause +- [`exnref`](/en-US/docs/WebAssembly/Reference/Value_types/exnref) type +- [`WebAssembly.Exception`](/en-US/docs/WebAssembly/Reference/JavaScript_interface/Exception) JavaScript interface +- [`WebAssembly.Tag`](/en-US/docs/WebAssembly/Reference/JavaScript_interface/Tag) JavaScript interface diff --git a/files/en-us/webassembly/reference/exception_handling/index.md b/files/en-us/webassembly/reference/exception_handling/index.md new file mode 100644 index 000000000000000..0b13f4491e115f2 --- /dev/null +++ b/files/en-us/webassembly/reference/exception_handling/index.md @@ -0,0 +1,38 @@ +--- +title: WebAssembly exception handling instructions +slug: WebAssembly/Reference/Exception_handling +page-type: landing-page +sidebar: webassemblysidebar +--- + +WebAssembly exception handling instructions. + +## Throw + +- [`throw`](/en-US/docs/WebAssembly/Reference/Exception_handling/throw) + - : Throws an exception of a specified type, as defined by a [`tag`](/en-US/docs/WebAssembly/Reference/Definitions/tag) definition. +- [`throw_ref`](/en-US/docs/WebAssembly/Reference/Exception_handling/throw_ref) + - : Rethrows a previously-thrown exception represented by an [`exnref`](/en-US/docs/WebAssembly/Reference/Value_types/exnref) value. + +## Try + +- [`try_table`](/en-US/docs/WebAssembly/Reference/Exception_handling/try_table) + - : Enables you to test a block of code to see whether it throws an exception, handling the exception with a [catch clause](#catch_clauses) clause if so. + +### Catch clauses + +- [`catch`](/en-US/docs/WebAssembly/Reference/Exception_handling/try_table/catch) + - : Catches exceptions matching a specified error `tag`, pushing the exception payload to the stack. +- [`catch_all`](/en-US/docs/WebAssembly/Reference/Exception_handling/try_table/catch_all) + - : Catches any exception and pushes nothing to the stack. +- [`catch_ref`](/en-US/docs/WebAssembly/Reference/Exception_handling/try_table/catch_ref) + - : Catches exceptions matching a specified error `tag`, pushing the exception payload and an [`exnref`](/en-US/docs/WebAssembly/Reference/Value_types/exnref) value representing the exception to the stack. +- [`catch_all_ref`](/en-US/docs/WebAssembly/Reference/Exception_handling/try_table/catch_all_ref) + - : Catches any exception and pushes an `exnref` value representing the exception to the stack. + +## See also + +- [`exnref`](/en-US/docs/WebAssembly/Reference/Value_types/exnref) type +- [`tag`](/en-US/docs/WebAssembly/Reference/Definitions/tag) definition +- [`WebAssembly.Exception`](/en-US/docs/WebAssembly/Reference/JavaScript_interface/Exception) JavaScript interface +- [`WebAssembly.Tag`](/en-US/docs/WebAssembly/Reference/JavaScript_interface/Tag) JavaScript interface diff --git a/files/en-us/webassembly/reference/exception_handling/throw/index.md b/files/en-us/webassembly/reference/exception_handling/throw/index.md new file mode 100644 index 000000000000000..7d8a83920633c64 --- /dev/null +++ b/files/en-us/webassembly/reference/exception_handling/throw/index.md @@ -0,0 +1,105 @@ +--- +title: "throw: Wasm exception handling instruction" +short-title: throw +slug: WebAssembly/Reference/Exception_handling/throw +page-type: webassembly-instruction +browser-compat: webassembly.instructions.throw +sidebar: webassemblysidebar +--- + +The **`throw`** [exception handling](/en-US/docs/WebAssembly/Reference/Exception_handling) instruction throws an exception of a specified type, as defined by a [tag](/en-US/docs/WebAssembly/Reference/Definitions/tag) definition. + +{{InteractiveExample("Wat Demo: throw", "tabbed-taller")}} + +```wat interactive-example +(module + ;; Import the error tag from JS + (tag $my_error (import "env" "my_error") (param i32)) + + (func $might_throw (param $value i32) + ;; If value is negative, run the if block + (local.get $value) + (i32.const 0) + (i32.lt_s) + (if + (then + ;; Push the error code onto the stack, then throw an exception + (i32.const 42) ;; error code payload + (throw $my_error) ;; throw with the tag + ) + ) + ) + (export "might_throw" (func $might_throw)) +) +``` + +```js interactive-example +// Define error tag in JS +const myErrorTag = new WebAssembly.Tag({ parameters: ["i32"] }); + +// Import the tag into the module +const env = { + my_error: myErrorTag, +}; + +WebAssembly.instantiateStreaming(fetch("{%wasm-url%}"), { env }).then( + (result) => { + try { + // Negative value causes function to throw + result.instance.exports.might_throw(-1); + } catch (e) { + if (e instanceof WebAssembly.Exception && e.is(myErrorTag)) { + // 0 is the first payload value, which is equal to 42 + const errorCode = e.getArg(myErrorTag, 0); + console.log("Error code:", errorCode); + } else { + // Throw other errors + throw e; + } + } + }, +); +``` + +## Syntax + +```plain +throw identifier +``` + +- `throw` + - : The `throw` instruction. +- `identifier` + - : An identifier for the exception tag type to throw. This can be: + - An identifying name, as defined by the [`identifier`](/en-US/docs/WebAssembly/Reference/Definitions/tag#identifier) of the corresponding tag type. + - A tag index number — `0` to identify the first specified tag, `1` for the second, etc. + +### Type + +```plain +[payload1, payload2, payloadN] -> [] +``` + +- `payload` values + - : The payload values, which typically represents identifying error codes. + +The payload values can be retrieved when the exception is caught, either by clauses such as [`catch`](/en-US/docs/WebAssembly/Reference/Exception_handling/try_table/catch) and [`catch_ref`](/en-US/docs/WebAssembly/Reference/Exception_handling/try_table/catch_ref), or in JavaScript via a [`try...catch`](/en-US/docs/Web/JavaScript/Reference/Statements/try...catch) statement. + +See the [`tag`](/en-US/docs/WebAssembly/Reference/Definitions/tag) definition reference page for examples of both. + +### Binary encoding + +| Instruction | Binary format | Example text => binary | +| ----------- | --------------- | ------------------------------------------------------ | +| `throw` | `0x08 x:tagidx` | `(throw $tag (i32.const 42))` => `0x41 0x2a 0x08 0x00` | + +## See also + +- [`throw_ref`](/en-US/docs/WebAssembly/Reference/Exception_handling/throw_ref) instruction +- [`try_table`](/en-US/docs/WebAssembly/Reference/Exception_handling/try_table) instruction + - [`catch`](/en-US/docs/WebAssembly/Reference/Exception_handling/try_table/catch) clause + - [`catch_all`](/en-US/docs/WebAssembly/Reference/Exception_handling/try_table/catch_all) clause + - [`catch_ref`](/en-US/docs/WebAssembly/Reference/Exception_handling/try_table/catch_ref) clause + - [`catch_all_ref`](/en-US/docs/WebAssembly/Reference/Exception_handling/try_table/catch_all_ref) clause +- [`exnref`](/en-US/docs/WebAssembly/Reference/Value_types/exnref) type +- [`tag`](/en-US/docs/WebAssembly/Reference/Definitions/tag) definition diff --git a/files/en-us/webassembly/reference/exception_handling/throw_ref/index.md b/files/en-us/webassembly/reference/exception_handling/throw_ref/index.md new file mode 100644 index 000000000000000..c7dbec7b99946e5 --- /dev/null +++ b/files/en-us/webassembly/reference/exception_handling/throw_ref/index.md @@ -0,0 +1,123 @@ +--- +title: "throw_ref: Wasm exception handling instruction" +short-title: throw_ref +slug: WebAssembly/Reference/Exception_handling/throw_ref +page-type: webassembly-instruction +browser-compat: webassembly.instructions.throw_ref +sidebar: webassemblysidebar +--- + +The **`throw_ref`** [exception handling](/en-US/docs/WebAssembly/Reference/Exception_handling) instruction rethrows a previously-thrown exception represented by an [`exnref`](/en-US/docs/WebAssembly/Reference/Value_types/exnref) value. + +{{InteractiveExample("Wat Demo: throw_ref", "tabbed-taller")}} + +```wat interactive-example +(module + ;; Import error tag + (tag $my_error (import "env" "my_error") (param i32)) + + (func $try_and_rethrow (param $value i32) + ;; Define a variable to store an exnref + (local $err exnref) + + (block $handler (result i32 exnref) + (try_table (catch_ref $my_error $handler) + (call $might_throw (local.get $value)) + ) + (return) + ) + + ;; catch_ref returns error value and exnref + ;; Stack is now: i32, exnref (exnref on top) + (local.set $err) ;; pop exnref + (drop) ;; drop the i32 payload + (local.get $err) ;; push exnref back + (throw_ref) + ) + + ;; Function that throws an error of type $my_error + ;; when its parameter is less than 0 + (func $might_throw (param $value i32) + (local.get $value) + (i32.const 0) + (i32.lt_s) + (if + (then + (i32.const 42) + (throw $my_error) + ) + ) + ) + + (export "try_and_rethrow" (func $try_and_rethrow)) +) +``` + +```js interactive-example +// Define error tag in JS +const myErrorTag = new WebAssembly.Tag({ parameters: ["i32"] }); + +// Import the tag into the module +const env = { + my_error: myErrorTag, +}; + +WebAssembly.instantiateStreaming(fetch("{%wasm-url%}"), { env }).then( + (result) => { + try { + // Negative value causes function to throw + result.instance.exports.try_and_rethrow(-1); + } catch (e) { + if (e instanceof WebAssembly.Exception && e.is(myErrorTag)) { + // 0 is the first payload value, which is equal to 42 + const errorCode = e.getArg(myErrorTag, 0); + console.log("Error code:", errorCode); + } else { + // Throw other errors + throw e; + } + } + }, +); +``` + +## Syntax + +```plain +throw_ref +``` + +- `throw_ref` + - : The `throw_ref` instruction. + +### Type + +```plain +[exception] -> [] +``` + +- `exception` + - : The exception to rethrow, which must be an `exnref` value. + +### Binary encoding + +| Instruction | Binary format | Example text => binary | +| ----------- | ------------- | ---------------------- | +| `throw_ref` | `0x0a` | `throw_ref` => `0x0a` | + +## Description + +A `throw_ref` instruction can be used to rethrow a previously-thrown exception, as represented by an [`exnref`](/en-US/docs/WebAssembly/Reference/Value_types/exnref) value. Values of type `exnref` are pushed onto the stack by [`catch_ref`](/en-US/docs/WebAssembly/Reference/Exception_handling/try_table/catch_ref) and [`catch_all_ref`](/en-US/docs/WebAssembly/Reference/Exception_handling/try_table/catch_all_ref) clauses. + +Generally, rethrowing exceptions is useful because you might want to perform an action such as cleanup or logging but then still let users know that an error ocurred. + +## See also + +- [`throw`](/en-US/docs/WebAssembly/Reference/Exception_handling/throw) instruction +- [`try_table`](/en-US/docs/WebAssembly/Reference/Exception_handling/try_table) instruction + - [`catch`](/en-US/docs/WebAssembly/Reference/Exception_handling/try_table/catch) clause + - [`catch_all`](/en-US/docs/WebAssembly/Reference/Exception_handling/try_table/catch_all) clause + - [`catch_ref`](/en-US/docs/WebAssembly/Reference/Exception_handling/try_table/catch_ref) clause + - [`catch_all_ref`](/en-US/docs/WebAssembly/Reference/Exception_handling/try_table/catch_all_ref) clause +- [`exnref`](/en-US/docs/WebAssembly/Reference/Value_types/exnref) type +- [`tag`](/en-US/docs/WebAssembly/Reference/Definitions/tag) definition diff --git a/files/en-us/webassembly/reference/exception_handling/try_table/catch/index.md b/files/en-us/webassembly/reference/exception_handling/try_table/catch/index.md new file mode 100644 index 000000000000000..53edd90adb963cc --- /dev/null +++ b/files/en-us/webassembly/reference/exception_handling/try_table/catch/index.md @@ -0,0 +1,143 @@ +--- +title: "catch: try_table clause" +short-title: catch +slug: WebAssembly/Reference/Exception_handling/try_table/catch +page-type: webassembly-instruction +browser-compat: webassembly.instructions.try_table.catch +sidebar: webassemblysidebar +--- + +The **`catch`** clause catches exceptions matching a specified error [`tag`](/en-US/docs/WebAssembly/Reference/Definitions/tag), pushing the exception payload to the stack. + +{{InteractiveExample("Wat Demo: catch", "tabbed-taller")}} + +```wat interactive-example +(module + ;; Import error tag and console.log + (tag $my_error (import "env" "my_error") (param i32)) + (import "env" "log" (func $log (param i32))) + + (func $try_and_catch (param $value i32) + (block $handler (result i32) + ;; In try_table block, catch thrown exception of type $my_error + (try_table (catch $my_error $handler) + (call $might_throw (local.get $value)) + ) + (return) + ) + ;; Log value returned by handler block + call $log + ) + + ;; Function that throws an error of type $my_error + ;; when its parameter is less than 0 + (func $might_throw (param $value i32) + (local.get $value) + (i32.const 0) + (i32.lt_s) + (if + (then + ;; Throw exception with payload of 42 + (i32.const 42) + (throw $my_error) + ) + ) + ) + + (export "try_and_catch" (func $try_and_catch)) +) + +``` + +```js interactive-example +// Define error tag in JS +const myErrorTag = new WebAssembly.Tag({ parameters: ["i32"] }); + +// Import error tag and console.log into the module +const env = { + my_error: myErrorTag, // import the tag into the module + log: console.log, +}; + +WebAssembly.instantiateStreaming(fetch("{%wasm-url%}"), { env }).then( + // Negative value causes function to throw + (result) => result.instance.exports.try_and_catch(-1), +); +``` + +## Syntax + +```plain +catch tag_identifier block_identifier +``` + +- `catch` + - : The `catch` clause. +- `tag_identifier` + - : The identifier for the exception type to catch. This can be: + - An identifying name, as defined by the [`identifier`](/en-US/docs/WebAssembly/Reference/Definitions/tag#identifier) of the corresponding tag type. + - A tag index number — `0` to identify the first specified tag, `1` for the second, etc. +- `block_identifier` + - : The identifier for the [`block`](/en-US/docs/WebAssembly/Reference/Control_flow/block) to branch to when the exception is caught. This can be: + - An identifying name, as defined by the identifier of the corresponding block. + - A block index number — `0` to identify the innermost block, `1` for the next innermost, etc. + +### Type + +```plain +[] -> [payload*] +``` + +- `payload*` + - : Zero or more payload values created by the thrown exception, which typically represent identifying error codes. + +These values are not pushed onto the stack directly at the site of the `catch` clause, rather they are pushed onto the stack at the site of the block branched to when the exception is thrown. + +### Binary encoding + +| Clause | Catch type byte | +| ------- | --------------- | +| `catch` | `0x00` | + +`catch` is not a standalone instruction — instead, it is encoded as a clause within a `try_table` instruction with a byte of `0x00`. A `try_table` with a single `catch` clause: + +```wat +(try_table (catch $my_error $handler) ... ) +``` + +would be encoded like this: + +```plain +... 0x01 0x00 0x00 0x00 ... +``` + +## Description + +The `catch` clause can be included inside a [`try_table`](/en-US/docs/WebAssembly/Reference/Exception_handling/try_table) block to catch exceptions with a specific error [`tag`](/en-US/docs/WebAssembly/Reference/Definitions/tag). When such an exception is thrown, the code branches to the specified `block`, at which point the exception's payload values are pushed to the stack. + +`catch` is useful when you don't need to rethrow an exception, but you do want to report that a specific exception type has been thrown. + +The referenced block must declare a result type that matches the exception's payload. In the example shown earlier, the exception type is defined with a single `i32` parameter in its `tag` definition: + +```wat +(tag $my_error (import "env" "my_error") (param i32)) +``` + +When the exception is caught, the block branched to specifies the same data type for its `result`: + +```wat +(block $handler (result i32) + ... +) +``` + +## See also + +- [`throw`](/en-US/docs/WebAssembly/Reference/Exception_handling/throw) instruction +- [`throw_ref`](/en-US/docs/WebAssembly/Reference/Exception_handling/throw_ref) instruction +- [`try_table`](/en-US/docs/WebAssembly/Reference/Exception_handling/try_table) instruction + - [`catch_all`](/en-US/docs/WebAssembly/Reference/Exception_handling/try_table/catch_all) clause + - [`catch_ref`](/en-US/docs/WebAssembly/Reference/Exception_handling/try_table/catch_ref) clause + - [`catch_all_ref`](/en-US/docs/WebAssembly/Reference/Exception_handling/try_table/catch_all_ref) clause +- [`exnref`](/en-US/docs/WebAssembly/Reference/Value_types/exnref) type +- [`tag`](/en-US/docs/WebAssembly/Reference/Definitions/tag) definition diff --git a/files/en-us/webassembly/reference/exception_handling/try_table/catch_all/index.md b/files/en-us/webassembly/reference/exception_handling/try_table/catch_all/index.md new file mode 100644 index 000000000000000..08a4e5dc5e65cd4 --- /dev/null +++ b/files/en-us/webassembly/reference/exception_handling/try_table/catch_all/index.md @@ -0,0 +1,128 @@ +--- +title: "catch_all: try_table clause" +short-title: catch_all +slug: WebAssembly/Reference/Exception_handling/try_table/catch_all +page-type: webassembly-instruction +browser-compat: webassembly.instructions.try_table.catch_all +sidebar: webassemblysidebar +--- + +The **`catch_all`** clause catches any exception and pushes nothing to the stack. + +{{InteractiveExample("Wat Demo: catch_all", "tabbed-taller")}} + +```wat interactive-example +(module + ;; Import the error tag and the log function + (tag $my_error (import "env" "my_error") (param i32)) + (import "env" "log" (func $log)) + + (func $try_and_catch (param $value i32) + ;; catch_all catches any exception thrown + (block $handler + (try_table (catch_all $handler) + (call $might_throw (local.get $value)) + ) + (return) + ) + ;; Call log to notify user that exception has been thrown + call $log + ) + + ;; Function that throws an error of type $my_error + ;; when its parameter is less than 0 + (func $might_throw (param $value i32) + (local.get $value) + (i32.const 0) + (i32.lt_s) + (if + (then + (i32.const 42) + (throw $my_error) + ) + ) + ) + + (export "try_and_catch" (func $try_and_catch)) +) +``` + +```js interactive-example +// Define error tag in JS +const myErrorTag = new WebAssembly.Tag({ parameters: ["i32"] }); + +// Import the tag and the log function into the module +const env = { + my_error: myErrorTag, + log: () => { + console.log("An error was caught!"); + }, +}; + +WebAssembly.instantiateStreaming(fetch("{%wasm-url%}"), { env }).then( + // Negative value causes function to throw + (result) => result.instance.exports.try_and_catch(-1), +); +``` + +## Syntax + +```plain +catch_all block_identifier +``` + +- `catch_all` + - : The `catch_all` clause. +- `block_identifier` + - : The identifier for the [`block`](/en-US/docs/WebAssembly/Reference/Control_flow/block) to branch to when the exception is caught. This can be: + - An identifying name, as defined by the identifier of the corresponding block. + - A block index number — `0` to identify the innermost block, `1` for the next innermost, etc. + +### Type + +```plain +[] -> [] +``` + +### Binary encoding + +| Clause | catch_all type byte | +| ----------- | ------------------- | +| `catch_all` | `0x02` | + +`catch_all` is not a standalone clause — instead, it is encoded as a clause within a `try_table` instruction with a byte of `0x02`. A `try_table` with a single `catch_all` clause: + +```wat +(try_table (catch_all $handler) ... ) +``` + +would be encoded like this: + +```plain +... 0x01 0x02 0x00 ... +``` + +## Description + +The `catch_all` clause can be included inside a [`try_table`](/en-US/docs/WebAssembly/Reference/Exception_handling/try_table) block to catch any thrown exceptions. When an exception is thrown, the code branches to the specified `block`. + +`catch_all` is useful when you don't need to rethrow an exception, and you don't want to catch a specific exception, but you do want to report that an exception of some kind has been thrown. + +In the case of `catch_all`, the referenced block doesn't need to declare a result type that matches the exception's payload, because no result is pushed to the stack. In the example shown earlier, the `block` has no result type declared: + +```wat +(block $handler + ... +) +``` + +## See also + +- [`throw`](/en-US/docs/WebAssembly/Reference/Exception_handling/throw) instruction +- [`throw_ref`](/en-US/docs/WebAssembly/Reference/Exception_handling/throw_ref) instruction +- [`try_table`](/en-US/docs/WebAssembly/Reference/Exception_handling/try_table) instruction + - [`catch`](/en-US/docs/WebAssembly/Reference/Exception_handling/try_table/catch) clause + - [`catch_ref`](/en-US/docs/WebAssembly/Reference/Exception_handling/try_table/catch_ref) clause + - [`catch_all_ref`](/en-US/docs/WebAssembly/Reference/Exception_handling/try_table/catch_all_ref) clause +- [`exnref`](/en-US/docs/WebAssembly/Reference/Value_types/exnref) type +- [`tag`](/en-US/docs/WebAssembly/Reference/Definitions/tag) definition diff --git a/files/en-us/webassembly/reference/exception_handling/try_table/catch_all_ref/index.md b/files/en-us/webassembly/reference/exception_handling/try_table/catch_all_ref/index.md new file mode 100644 index 000000000000000..c2de1a83b3b786b --- /dev/null +++ b/files/en-us/webassembly/reference/exception_handling/try_table/catch_all_ref/index.md @@ -0,0 +1,142 @@ +--- +title: "catch_all_ref: try_table clause" +short-title: catch_all_ref +slug: WebAssembly/Reference/Exception_handling/try_table/catch_all_ref +page-type: webassembly-instruction +browser-compat: webassembly.instructions.try_table.catch_all_ref +sidebar: webassemblysidebar +--- + +The **`catch_all_ref`** clause catches any exception and pushes an [`exnref`](/en-US/docs/WebAssembly/Reference/Value_types/exnref) value representing the exception to the stack. + +{{InteractiveExample("Wat Demo: catch_all_ref", "tabbed-taller")}} + +```wat interactive-example +(module + ;; Import the error tag and the log function + (tag $my_error (import "env" "my_error") (param i32)) + (import "env" "log" (func $log)) + + (func $try_and_catch (param $value i32) + ;; Define a variable to store an exnref + (local $err exnref) + ;; catch_all_ref catches any exception thrown and pushes an exnref + (block $handler (result exnref) + (try_table (catch_all_ref $handler) + (call $might_throw (local.get $value)) + ) + (return) + ) + ;; Save exnref before calling log to notify user + ;; that exception has been thrown + (local.set $err) + (call $log) + ;; Restore exnref + (local.get $err) + ;; rethrow original exception + (throw_ref) + ) + + ;; Function that throws an error of type $my_error + ;; when its parameter is less than 0 + (func $might_throw (param $value i32) + (local.get $value) + (i32.const 0) + (i32.lt_s) + (if + (then + (i32.const 42) + (throw $my_error) + ) + ) + ) + (export "try_and_catch" (func $try_and_catch)) +) +``` + +```js interactive-example +// Define error tag in JS +const myErrorTag = new WebAssembly.Tag({ parameters: ["i32"] }); + +// Import the tag and the log function into the module +const env = { + my_error: myErrorTag, + log: () => { + console.log("An error was caught!"); + }, +}; + +WebAssembly.instantiateStreaming(fetch("{%wasm-url%}"), { env }).then( + // Negative value causes function to throw + (result) => result.instance.exports.try_and_catch(-1), +); +``` + +## Syntax + +```plain +catch_all_ref block_identifier +``` + +- `catch_all_ref` + - : The `catch_all_ref` clause. +- `block_identifier` + - : The identifier for the [`block`](/en-US/docs/WebAssembly/Reference/Control_flow/block) to branch to when the exception is caught. This can be: + - An identifying name, as defined by the identifier of the corresponding block. + - A block index number — `0` to identify the innermost block, `1` for the next innermost, etc. + +### Type + +```plain +[] -> [exception_ref] +``` + +- `exception_ref` + - : An [`exnref`](/en-US/docs/WebAssembly/Reference/Value_types/exnref) value representing the thrown exception. + +This value is not pushed onto the stack directly at the site of the `catch_all_ref` clause, rather it is pushed onto the stack at the site of the block branched to when the exception is thrown. + +### Binary encoding + +| Clause | catch_all_ref type byte | +| --------------- | ----------------------- | +| `catch_all_ref` | `0x03` | + +`catch_all_ref` is not a standalone instruction — instead, it is encoded as a clause within a `try_table` instruction with a byte of `0x03`. A `try_table` with a single `catch_all_ref` clause: + +```wat +(try_table (catch_all_ref $handler) ... ) +``` + +would be encoded like this: + +```plain +... 0x01 0x03 0x00 ... +``` + +## Description + +The `catch_all_ref` clause can be included inside a [`try_table`](/en-US/docs/WebAssembly/Reference/Exception_handling/try_table) block to catch any thrown exceptions. When an exception is thrown, the code branches to the specified `block`, at which point an [`exnref`](/en-US/docs/WebAssembly/Reference/Value_types/exnref) value representing the thrown exception is pushed to the stack. + +The exception can then be rethrown using a [`throw_ref`](/en-US/docs/WebAssembly/Reference/Exception_handling/throw_ref) instruction. + +`catch_all_ref` is useful when you want to report that some kind of exception has been thrown, but you also want to rethrow the exception. You might for example want to perform an action such as cleanup or logging but then still let users know that an error ocurred. + +The referenced block must declare a result type that matches the pushed `exnref`. In the example shown earlier, the block branched to when the exception is caught specifies an `exnref` type in its `result`: + +```wat +(block $handler (result exnref) + ... +) +``` + +## See also + +- [`throw`](/en-US/docs/WebAssembly/Reference/Exception_handling/throw) instruction +- [`throw_ref`](/en-US/docs/WebAssembly/Reference/Exception_handling/throw_ref) instruction +- [`try_table`](/en-US/docs/WebAssembly/Reference/Exception_handling/try_table) instruction + - [`catch`](/en-US/docs/WebAssembly/Reference/Exception_handling/try_table/catch) clause + - [`catch_all`](/en-US/docs/WebAssembly/Reference/Exception_handling/try_table/catch_all) clause + - [`catch_ref`](/en-US/docs/WebAssembly/Reference/Exception_handling/try_table/catch_ref) clause +- [`exnref`](/en-US/docs/WebAssembly/Reference/Value_types/exnref) type +- [`tag`](/en-US/docs/WebAssembly/Reference/Definitions/tag) definition diff --git a/files/en-us/webassembly/reference/exception_handling/try_table/catch_ref/index.md b/files/en-us/webassembly/reference/exception_handling/try_table/catch_ref/index.md new file mode 100644 index 000000000000000..67942b7db53816d --- /dev/null +++ b/files/en-us/webassembly/reference/exception_handling/try_table/catch_ref/index.md @@ -0,0 +1,163 @@ +--- +title: "catch_ref: try_table clause" +short-title: catch_ref +slug: WebAssembly/Reference/Exception_handling/try_table/catch_ref +page-type: webassembly-instruction +browser-compat: webassembly.instructions.try_table.catch_ref +sidebar: webassemblysidebar +--- + +The **`catch_ref`** clause catches exceptions matching a specified error [`tag`](/en-US/docs/WebAssembly/Reference/Definitions/tag), pushing the exception payload and an [`exnref`](/en-US/docs/WebAssembly/Reference/Value_types/exnref) value representing the exception to the stack. + +{{InteractiveExample("Wat Demo: catch_ref", "tabbed-taller")}} + +```wat interactive-example +(module + ;; Import error tag + (tag $my_error (import "env" "my_error") (param i32)) + + (func $try_and_rethrow (param $value i32) + ;; Define a variable to store an exnref + (local $err exnref) + + (block $handler (result i32 exnref) + (try_table (catch_ref $my_error $handler) + (call $might_throw (local.get $value)) + ) + (return) + ) + + ;; catch_ref returns error value and exnref + ;; Stack is now: i32, exnref (exnref on top) + (local.set $err) ;; pop exnref + (drop) ;; drop the i32 payload + (local.get $err) ;; push exnref back + (throw_ref) + ) + + ;; Function that throws an error of type $my_error + ;; when its parameter is less than 0 + (func $might_throw (param $value i32) + (local.get $value) + (i32.const 0) + (i32.lt_s) + (if + (then + (i32.const 42) + (throw $my_error) + ) + ) + ) + + (export "try_and_rethrow" (func $try_and_rethrow)) +) +``` + +```js interactive-example +// Define error tag in JS +const myErrorTag = new WebAssembly.Tag({ parameters: ["i32"] }); + +// Import the tag into the module +const env = { + my_error: myErrorTag, +}; + +WebAssembly.instantiateStreaming(fetch("{%wasm-url%}"), { env }).then( + (result) => { + try { + // Negative value causes function to throw + result.instance.exports.try_and_rethrow(-1); + } catch (e) { + if (e instanceof WebAssembly.Exception && e.is(myErrorTag)) { + // 0 is the first payload value, which is equal to 42 + const errorCode = e.getArg(myErrorTag, 0); + console.log("Error code:", errorCode); + } else { + // Throw other errors + throw e; + } + } + }, +); +``` + +## Syntax + +```plain +catch_ref tag_identifier block_identifier +``` + +- `catch_ref` + - : The `catch_ref` clause. +- `tag_identifier` + - : The identifier for the exception type to catch. This can be: + - An identifying name, as defined by the [`identifier`](/en-US/docs/WebAssembly/Reference/Definitions/tag#identifier) of the corresponding tag type. + - A tag index number — `0` to identify the first specified tag, `1` for the second, etc. +- `block_identifier` + - : The identifier for the [`block`](/en-US/docs/WebAssembly/Reference/Control_flow/block) to branch to when the exception is caught. This can be: + - An identifying name, as defined by the identifier of the corresponding block. + - A block index number — `0` to identify the innermost block, `1` for the next innermost, etc. + +### Type + +```plain +[] -> [payload*, exception_ref] +``` + +- `payload*` + - : Zero or more payload values created by the thrown exception, which typically represent identifying error codes. +- `exception_ref` + - : An [`exnref`](/en-US/docs/WebAssembly/Reference/Value_types/exnref) value representing the thrown exception. + +These values are not pushed onto the stack directly at the site of the `catch_ref` clause, rather they are pushed onto the stack at the site of the block branched to when the exception is thrown. + +### Binary encoding + +| Clause | catch_ref type byte | +| ----------- | ------------------- | +| `catch_ref` | `0x01` | + +`catch_ref` is not a standalone instruction — instead, it is encoded as a clause within a `try_table` instruction with a byte of `0x01`. A `try_table` with a single `catch_ref` clause: + +```wat +(try_table (catch_ref $my_error $handler) ... ) +``` + +would be encoded like this: + +```plain +... 0x01 0x01 0x00 0x00 ... +``` + +## Description + +The `catch_ref` clause can be included inside a [`try_table`](/en-US/docs/WebAssembly/Reference/Exception_handling/try_table) block to catch exceptions with a specific error [`tag`](/en-US/docs/WebAssembly/Reference/Definitions/tag). When such an exception is thrown, the code branches to the specified `block`, at which point the exception's payload values and an [`exnref`](/en-US/docs/WebAssembly/Reference/Value_types/exnref) value representing the thrown exception are pushed to the stack. + +The exception can then be rethrown using a [`throw_ref`](/en-US/docs/WebAssembly/Reference/Exception_handling/throw_ref) instruction. + +`catch_ref` is useful when you want to report that a specific exception type has been thrown, but you also want to rethrow the exception. You might for example want to perform an action such as cleanup or logging but then still let users know that a specific error ocurred. + +The referenced block must declare a result type that matches the exception's payload and the `exnref`. In the example shown earlier, the exception type is defined with a single `i32` parameter in its `tag` definition: + +```wat +(tag $my_error (import "env" "my_error") (param i32)) +``` + +When the exception is caught, the block branched to specifies the same data type for the payload plus an `exnref` type in its `result`: + +```wat +(block $handler (result i32 exnref) + ... +) +``` + +## See also + +- [`throw`](/en-US/docs/WebAssembly/Reference/Exception_handling/throw) instruction +- [`throw_ref`](/en-US/docs/WebAssembly/Reference/Exception_handling/throw_ref) instruction +- [`try_table`](/en-US/docs/WebAssembly/Reference/Exception_handling/try_table) instruction + - [`catch`](/en-US/docs/WebAssembly/Reference/Exception_handling/try_table/catch) clause + - [`catch_all`](/en-US/docs/WebAssembly/Reference/Exception_handling/try_table/catch_all) clause + - [`catch_all_ref`](/en-US/docs/WebAssembly/Reference/Exception_handling/try_table/catch_all_ref) clause +- [`exnref`](/en-US/docs/WebAssembly/Reference/Value_types/exnref) type +- [`tag`](/en-US/docs/WebAssembly/Reference/Definitions/tag) definition diff --git a/files/en-us/webassembly/reference/exception_handling/try_table/index.md b/files/en-us/webassembly/reference/exception_handling/try_table/index.md new file mode 100644 index 000000000000000..3b62f3c053912fa --- /dev/null +++ b/files/en-us/webassembly/reference/exception_handling/try_table/index.md @@ -0,0 +1,287 @@ +--- +title: "try_table: Wasm exception handling instruction" +short-title: try_table +slug: WebAssembly/Reference/Exception_handling/try_table +page-type: webassembly-instruction +browser-compat: webassembly.instructions.try_table +sidebar: webassemblysidebar +--- + +The **`try_table`** [exception handling](/en-US/docs/WebAssembly/Reference/Exception_handling) instruction enables you to test a block of code to see whether it throws an exception, handling the exception with a `catch` clause if so. + +{{InteractiveExample("Wat Demo: try_table", "tabbed-taller")}} + +```wat interactive-example +(module + ;; Import error tag and console.log + (tag $my_error (import "env" "my_error") (param i32)) + (import "env" "log" (func $log (param i32))) + + (func $try_and_catch (param $value i32) + (block $handler (result i32) + ;; In try_table block, catch thrown exception + (try_table (catch $my_error $handler) + (call $might_throw (local.get $value)) + ) + (return) + ) + ;; Log value returned by handler block + call $log + ) + + ;; Function that throws an error of type $my_error + ;; when its parameter is less than 0 + (func $might_throw (param $value i32) + (local.get $value) + (i32.const 0) + (i32.lt_s) + (if + (then + ;; Throw exception with payload of 42 + (i32.const 42) + (throw $my_error) + ) + ) + ) + + (export "try_and_catch" (func $try_and_catch)) +) +``` + +```js interactive-example +// Define error tag in JS +const myErrorTag = new WebAssembly.Tag({ parameters: ["i32"] }); + +// Import error tag and console.log into the module +const env = { + my_error: myErrorTag, // import the tag into the module + log: console.log, +}; + +WebAssembly.instantiateStreaming(fetch("{%wasm-url%}"), { env }).then( + // Negative value causes function to throw + (result) => result.instance.exports.try_and_catch(-1), +); +``` + +## Syntax + +```plain +try_table blocktype catch* instruction* +``` + +- `try_table` + - : The `try_table` instruction. +- `blocktype` {{optional_inline}} + - : Specifies one or more parameters that will be passed into the `try_table` block and provided as a result value after the block has run. +- `catch*` + - : One or more `catch` clauses, each representing criteria for catching exceptions, and specifying a [`block`](/en-US/docs/WebAssembly/Reference/Control_flow/block) to branch to as a result. Each clause can be one of the following: + - [`catch`](/en-US/docs/WebAssembly/Reference/Exception_handling/try_table/catch) + - [`catch_all`](/en-US/docs/WebAssembly/Reference/Exception_handling/try_table/catch_all) + - [`catch_ref`](/en-US/docs/WebAssembly/Reference/Exception_handling/try_table/catch_ref) + - [`catch_all_ref`](/en-US/docs/WebAssembly/Reference/Exception_handling/try_table/catch_all_ref) +- `instruction*` + - : Zero or more instructions to execute inside the try block. + +### Type + +```plain +[param*] -> [result*] +``` + +- `param*` + - : Zero or more param values consumed by the `try_table` block, as declared by the `blocktype`. +- `result*` + - : Zero or more result values produced by the `try_table` block, as declared by the `blocktype`. + +### Binary encoding + +| Instruction | Binary format | +| ----------- | -------------------------------------------------------- | +| `try_table` | `0x1f bt:blocktype n:u32 (ct:catch)^n instruction* 0x0b` | + +A basic `try_table` with a single `catch` clause: + +```wat +(try_table (catch $my_error $handler) + ;; instructions ... +) +``` + +Would be encoded like so: + +```plain +0x1f 0x40 0x01 0x00 0x00 0x00 ...instructions binary... 0x0b +``` + +## Description + +A `try_table` instruction, when combined with `catch` clauses, creates the Wasm equivalent of a JavaScript [`try...catch`](/en-US/docs/Web/JavaScript/Reference/Statements/try...catch) statement. The instructions inside the `try_table` block are run, and if an exception is thrown that is caught by the available `catch` clauses, the code branches to the specified outer [`block`](/en-US/docs/WebAssembly/Reference/Control_flow/block), and the values produced by the `catch` clause are pushed onto the stack. + +The different `catch` clauses behave as follows: + +- [`catch`](/en-US/docs/WebAssembly/Reference/Exception_handling/try_table/catch) + - : If an exception with a matching tag is thrown, branch to the specified `block`, pushing the payload values onto the stack. +- [`catch_all`](/en-US/docs/WebAssembly/Reference/Exception_handling/try_table/catch_all) + - : If any exception is thrown, branch to the specified `block`, pushing nothing onto the stack. +- [`catch_ref`](/en-US/docs/WebAssembly/Reference/Exception_handling/try_table/catch_ref) + - : If an exception with a matching tag is thrown, branch to the specified `block`, pushing the payload values and an [`exnref`](/en-US/docs/WebAssembly/Reference/Value_types/exnref) value representing the exception onto the stack. +- [`catch_all_ref`](/en-US/docs/WebAssembly/Reference/Exception_handling/try_table/catch_all_ref) + - : If any exception is thrown, branch to the specified `block`, pushing an [`exnref`](/en-US/docs/WebAssembly/Reference/Value_types/exnref) value representing the exception onto the stack. + +Each `catch` clause that branches to an outer `block` must produce values matching that `block`'s result type when a thrown exception is caught. + +### Blocktype parameters + +The optional blocktype parameters will be passed into the `try_table` block and provided as a result value after the block has run. The value can be specified before the `try_table` block, or inside. For example: + +```wat +;; Push an i32 +i32.const 42 + +;; pops an i32 as the param +try_table (param i32) + ;; The single i32 const 42 is still on the stack +end +``` + +Or: + +```wat +try_table (result i32) + ;; Push an i32 + i32.const 42 + + ;; The end of the block pops the results +end + +;; The result i32 is now available to be used here +``` + +Or you can use any combination of these structures. + +## Examples + +### Handling multiple exceptions + +This example shows how to handle multiple exceptions in a single `try_table` structure. + +#### JavaScript + +In our script, we start by grabbing a reference to a {{htmlelement("p")}} element that we will output results to. We then define two different error tags to represent a type error and a range error using the [`WebAssembly.Tag()`](/en-US/docs/WebAssembly/Reference/JavaScript_interface/Tag/Tag) constructor. + +```html hidden live-sample___multiple-exceptions +

+``` + +```js live-sample___multiple-exceptions +const output = document.querySelector("p"); + +const typeErrorTag = new WebAssembly.Tag({ parameters: ["i32"] }); +const rangeErrorTag = new WebAssembly.Tag({ parameters: ["i32", "i32"] }); +``` + +Next, we compile and instantiate our Wasm module using the [`WebAssembly.instantiateStreaming()`](/en-US/docs/WebAssembly/Reference/JavaScript_interface/instantiateStreaming_static) method, importing the two error tags and a function to log results to the `

` element. + +We invoke the exported Wasm `try_multiple()` function available on the WebAssembly [`Instance`](/en-US/docs/WebAssembly/Reference/JavaScript_interface/Instance) [`exports`](/en-US/docs/WebAssembly/Reference/JavaScript_interface/Instance/exports) object multiple times, passing it two different parameters to throw different exceptions, and then finally one value that doesn't throw an exception. + +```js live-sample___multiple-exceptions +async function init() { + const { instance } = await WebAssembly.instantiateStreaming( + fetch("{%wasm-url%}"), + { + env: { + type_error: typeErrorTag, + range_error: rangeErrorTag, + log: (code) => { + output.textContent += `Error code: ${code} | `; + }, + }, + }, + ); + + instance.exports.try_multiple(-1); // Throws type_error, logs 10 + instance.exports.try_multiple(101); // Throws range_error, logs 99 + instance.exports.try_multiple(50); // Doesn't throw +} + +init(); +``` + +#### Wasm + +In our Wasm module, we first import our two error tags and log function. We then create a function called `$try_multiple` that has two nested `block`s to handle `$type_error`s and `$range_error`s, respectively. In the middle of the `block`s is a `try_table` structure containing two `catch` clauses, one to catch each type of error. We then call the `$might_throw` function defined later on to see whether it throws any exceptions: + +- If a `$type_error` is thrown, we branch to the `$on_type_error` `block` and log the payload value. +- If a `$range_error` is thrown, we branch to the `$on_range_error` `block`, drop the first of the two payload values and log the second one, then return out of the `block`. +- If no exception is thrown, we just return out of the `block`. + +The `$might_throw` function itself takes a single parameter, and checks its value. If the value is less than `0`, it throws a `$type_error` with error code `10`. If the value is greater than `100`, it throws a `$range_error` with code `99`. + +```wat live-sample___multiple-exceptions +(module + (tag $type_error (import "env" "type_error") (param i32)) + (tag $range_error (import "env" "range_error") (param i32 i32)) ;; carries two values + (import "env" "log" (func $log (param i32))) + + (func $try_multiple (param $value i32) + (block $on_type_error (result i32) + (block $on_range_error (result i32 i32) + (try_table + (catch $type_error $on_type_error) + (catch $range_error $on_range_error) + (call $might_throw (local.get $value)) + ) + (return) ;; no exception thrown + ) + ;; $range_error was caught — stack has i32 i32 + (drop) ;; drop second payload value + (call $log) ;; log first payload value + (return) + ) + ;; $type_error was caught — stack has i32 + (call $log) ;; log the payload + ) + + (func $might_throw (param $value i32) + (local.get $value) + (i32.const 0) + (i32.lt_s) + (if + (then + (i32.const 10) + (throw $type_error) + ) + ) + (local.get $value) + (i32.const 100) + (i32.gt_s) + (if + (then + (i32.const 99) + (i32.const 100) + (throw $range_error) + ) + ) + ) + + (export "try_multiple" (func $try_multiple)) +) +``` + +#### Result + +{{embedlivesample("multiple-exceptions", "100%", 100)}} + +We call the `try_multiple()` function three times. The first time throws a `$type_error`, so error code `10` is logged. The second throws a `$range_error`, so error code `99` is logged. The third does not throw an exception. + +## See also + +- [`throw`](/en-US/docs/WebAssembly/Reference/Exception_handling/throw) instruction +- [`throw_ref`](/en-US/docs/WebAssembly/Reference/Exception_handling/throw_ref) instruction + - [`catch`](/en-US/docs/WebAssembly/Reference/Exception_handling/try_table/catch) clause + - [`catch_all`](/en-US/docs/WebAssembly/Reference/Exception_handling/try_table/catch_all) clause + - [`catch_ref`](/en-US/docs/WebAssembly/Reference/Exception_handling/try_table/catch_ref) clause + - [`catch_all_ref`](/en-US/docs/WebAssembly/Reference/Exception_handling/try_table/catch_all_ref) clause +- [`exnref`](/en-US/docs/WebAssembly/Reference/Value_types/exnref) type +- [`tag`](/en-US/docs/WebAssembly/Reference/Definitions/tag) definition diff --git a/files/en-us/webassembly/reference/javascript_interface/exception/exception/index.md b/files/en-us/webassembly/reference/javascript_interface/exception/exception/index.md index 699993c69ab3d14..7fcfbabc5e738e9 100644 --- a/files/en-us/webassembly/reference/javascript_interface/exception/exception/index.md +++ b/files/en-us/webassembly/reference/javascript_interface/exception/exception/index.md @@ -6,13 +6,7 @@ browser-compat: webassembly.api.Exception.Exception sidebar: webassemblysidebar --- -The **`WebAssembly.Exception()`** constructor is used to create a new [`WebAssembly.Exception`](/en-US/docs/WebAssembly/Reference/JavaScript_interface/Exception). - -The constructor accepts a [`Tag`](/en-US/docs/WebAssembly/Reference/JavaScript_interface/Exception) argument and a `payload` array of data fields. -The data types of each of the payload elements must match the corresponding data type specified in the `Tag`. - -The constructor may also take an `options` object. -The `options.traceStack` property can be set `true` (by default it is `false`) to indicate that a Wasm stack trace may be attached to the exception's [`stack`](/en-US/docs/WebAssembly/Reference/JavaScript_interface/Exception/stack) property. +The **`WebAssembly.Exception()`** constructor is used to create a new [`WebAssembly.Exception`](/en-US/docs/WebAssembly/Reference/JavaScript_interface/Exception) object instance. ## Syntax @@ -24,7 +18,7 @@ new Exception(tag, payload, options) ### Parameters - `tag` - - : A [`WebAssembly.Tag`](/en-US/docs/WebAssembly/Reference/JavaScript_interface/Tag) defining the data types expected for each of the values in the `payload`. + - : A [`WebAssembly.Tag`](/en-US/docs/WebAssembly/Reference/JavaScript_interface/Tag) instance defining the data types expected for each of the values in the `payload`. - `payload` - : An array of one or more data fields comprising the payload of the exception. The elements must match the data types of the corresponding elements in the `tag`. @@ -33,16 +27,48 @@ new Exception(tag, payload, options) - : An object with the following optional fields: - `traceStack` {{optional_inline}} {{non-standard_inline}} - : `true` if the `Exception` may have a stack trace attached to its [`stack`](/en-US/docs/WebAssembly/Reference/JavaScript_interface/Exception/stack) property, otherwise `false`. - This is `false` by default (if `options` or `options.traceStack` are not provided). + Defaults to `false`. ### Exceptions - `TypeError` - : The `payload` and `tag` sequences do not have the same number of elements and/or the elements are not of matching types. +## Description + +The [`Exception()`](/en-US/docs/WebAssembly/Reference/JavaScript_interface/Exception/Exception) constructor accepts a [`WebAssembly.Tag`](/en-US/docs/WebAssembly/Reference/JavaScript_interface/Tag), an array of values, and an `options` object as arguments. +The tag uniquely defines the _type_ of an exception, including the order of its arguments and their data types. +The same tag that was used to create the `Exception` is required to access the arguments of a thrown exception (using [`Exception.prototype.getArg()`](/en-US/docs/WebAssembly/Reference/JavaScript_interface/Exception/getArg)). + ## Examples -This example shows the creation of an exception using a simple tag. +### Basic usage + +You would not normally use this contructor to manually create a Wasm exception. Instead, a `WebAssembly.Exception` object is normally created when handling Wasm exceptions, for example: + +```js +WebAssembly.instantiateStreaming(fetch("module.wasm"), { env }).then( + (result) => { + try { + // Cause function to throw + result.instance.exports.throw(-1); + } catch (e) { + if (e instanceof WebAssembly.Exception && e.is(myErrorTag)) { + const errorCode = e.getArg(myErrorTag, 0); // 0 = first payload value + console.log("Error code:", errorCode); // 42 + } else { + throw e; // throw other errors + } + } + }, +); +``` + +For a working example, see the [`throw`](/en-US/docs/WebAssembly/Reference/Exception_handling/throw) instruction reference page. + +### Manual usage + +This example shows manual creation of an `WebAssembly.Exception` instance. ```js // Create tag and use it to create an exception @@ -50,7 +76,8 @@ const tag = new WebAssembly.Tag({ parameters: ["i32", "f32"] }); const exception = new WebAssembly.Exception(tag, [42, 42.3]); ``` -The [`stack` example](/en-US/docs/WebAssembly/Reference/JavaScript_interface/Exception/stack#examples) shows the creation of an exception that uses the `options` parameter. +> [!NOTE] +> The [`stack` example](/en-US/docs/WebAssembly/Reference/JavaScript_interface/Exception/stack#examples) shows the creation of an exception that uses the `options` parameter. ## Specifications diff --git a/files/en-us/webassembly/reference/javascript_interface/exception/getarg/index.md b/files/en-us/webassembly/reference/javascript_interface/exception/getarg/index.md index f1af1cc032cbb48..fb79c94faab8800 100644 --- a/files/en-us/webassembly/reference/javascript_interface/exception/getarg/index.md +++ b/files/en-us/webassembly/reference/javascript_interface/exception/getarg/index.md @@ -6,14 +6,7 @@ browser-compat: webassembly.api.Exception.getArg sidebar: webassemblysidebar --- -The **`getArg()`** prototype method of the [`Exception`](/en-US/docs/WebAssembly/Reference/JavaScript_interface/Exception) object can be used to get the value of a specified item in the exception's data arguments. - -The method passes a [`WebAssembly.Tag`](/en-US/docs/WebAssembly/Reference/JavaScript_interface/Tag) and will only succeed if the thrown `Exception` was created using the same tag, otherwise it will throw a `TypeError`. -This ensures that the exception can only be read if the calling code has access to the tag. -Tags that are neither imported into or exported from the WebAssembly code are internal, and their associated [`WebAssembly.Exception`](/en-US/docs/WebAssembly/Reference/JavaScript_interface/Exception) cannot be queried using this method! - -> [!NOTE] -> It is not enough that the tag has an identical sequence of data types — it must have the same _identity_ (be the same tag) as was used to create the exception. +The **`getArg()`** method of the [`Exception`](/en-US/docs/WebAssembly/Reference/JavaScript_interface/Exception) object can be used to get the value of a specified item in the exception's data arguments. ## Syntax @@ -26,7 +19,7 @@ getArg(exceptionTag, index) - `exceptionTag` - : A [`WebAssembly.Tag`](/en-US/docs/WebAssembly/Reference/JavaScript_interface/Tag) that must match the tag associated with this exception. - `index` - - : The index of the value in the data arguments to return, 0-indexed. + - : The index of the value in the data arguments to return. ### Return value @@ -39,14 +32,20 @@ The value of the argument at `index`. - {{jsxref("RangeError")}} - : The value of the `index` parameter is greater than or equal to the number of fields in the data. -## Examples +## Description -In order to get the values of an exception, the tag must be "known" to the calling code; -it may be either imported into or exported from the calling code. +The `getArg()` method accepts a [`WebAssembly.Tag`](/en-US/docs/WebAssembly/Reference/JavaScript_interface/Tag) as a parameter and will only succeed if the thrown `Exception` was created using the same tag, otherwise it will throw a `TypeError`. +This ensures that the exception can only be read if the calling code has access to the tag. +Tags that are neither imported into or exported from the WebAssembly code are internal, and their associated exceptions cannot be queried using this method. + +> [!NOTE] +> It is not enough that the tag has an identical sequence of data types — it must have the same _identity_ (be the same tag) as was used to create the exception. + +## Examples -### Getting exception value from imported tag +### Getting exception values from an imported tag -Consider the following WebAssembly code, which is assumed to be compiled to a file "example.wasm". +Consider the following WebAssembly code, which is assumed to be compiled to a file called `example.wasm`. This imports a tag, which it refers to internally as `$tagname`, and exports a method `run` that can be called by external code to throw an exception using the tag. ```wat @@ -68,7 +67,7 @@ This imports a tag, which it refers to internally as `$tagname`, and exports a m ) ``` -The code below calls [`WebAssembly.instantiateStreaming`](/en-US/docs/WebAssembly/Reference/JavaScript_interface/instantiateStreaming_static) to import the "example.wasm" file, passing in an "import object" (`importObject`) that includes a new [`WebAssembly.Tag`](/en-US/docs/WebAssembly/Reference/JavaScript_interface/Tag) named `tagToImport`. +The code below calls [`WebAssembly.instantiateStreaming`](/en-US/docs/WebAssembly/Reference/JavaScript_interface/instantiateStreaming_static) to import the `example.wasm` file, passing in an import object (`importObject`) that includes a new [`WebAssembly.Tag`](/en-US/docs/WebAssembly/Reference/JavaScript_interface/Tag) named `tagToImport`. The import object defines an object with properties that match the `import` statement in the WebAssembly code. Once the file is instantiated, the code calls the exported WebAssembly `run()` method, which will immediately throw an exception. @@ -99,9 +98,9 @@ example.js:41 getArg 0 : 1 ``` The code catches the exception and uses `getArg()` to print the value at the first index. -In this case, it is just "1". +In this case, the value is `1`. -### Getting exception value from an exported tag +### Getting exception values from an exported tag The process for using an exported tag is very similar to that shown in the previous section. Here is the same WebAssembly module, simply replacing the import with an export. @@ -123,8 +122,8 @@ Here is the same WebAssembly module, simply replacing the import with an export. ) ``` -The JavaScript is similar too. In this case, we have no imports, but instead we get the exported tag and use that to get the argument. -To make it a little more "safe", here we also test that we have the right tag using the [`is()` method](/en-US/docs/WebAssembly/Reference/JavaScript_interface/Exception/is). +The JavaScript is similar too. In this case, we have no imports; instead, we get the exported tag and use that to get the argument. +We also test that we have the right tag using the [`is()` method](/en-US/docs/WebAssembly/Reference/JavaScript_interface/Exception/is). ```js let tagExportedFromWasm; diff --git a/files/en-us/webassembly/reference/javascript_interface/exception/index.md b/files/en-us/webassembly/reference/javascript_interface/exception/index.md index 5cdd8a7d8d69c68..3dadbb8cb343a83 100644 --- a/files/en-us/webassembly/reference/javascript_interface/exception/index.md +++ b/files/en-us/webassembly/reference/javascript_interface/exception/index.md @@ -8,24 +8,12 @@ sidebar: webassemblysidebar {{AvailableInWorkers}} -The **`WebAssembly.Exception`** object represents a runtime exception thrown from WebAssembly to JavaScript, or thrown from JavaScript to a WebAssembly exception handler. - -The [constructor](/en-US/docs/WebAssembly/Reference/JavaScript_interface/Exception/Exception) accepts a [`WebAssembly.Tag`](/en-US/docs/WebAssembly/Reference/JavaScript_interface/Tag), an array of values, and an `options` object as arguments. -The tag uniquely defines the _type_ of an exception, including the order of its arguments and their data types. -The same tag that was used to create the `Exception` is required to access the arguments of a thrown exception. -Methods are provided to test whether an exception matches a particular tag, and also to get a particular value by index (if the exception matches specified tag). - -JavaScript and other client code can only access WebAssembly exception values, and vice versa, when the associated tag is shared (you can't just use another tag that happens to define the same data types). -Without the matching tag, exceptions can be caught and re-thrown, but they can't be inspected. - -In order to make exception-throwing faster, exceptions thrown from WebAssembly generally do not include a stack trace. -WebAssembly code that needs to provide a stack trace must call a JavaScript function to create the exception, passing `options.traceStack=true` parameter in the constructor. -The constructor may then return an exception with a stack trace attached to the [`stack`](/en-US/docs/WebAssembly/Reference/JavaScript_interface/Exception/stack) property. +The **`WebAssembly.Exception`** object represents a runtime exception thrown in a Wasm module. ## Constructor - [`WebAssembly.Exception()`](/en-US/docs/WebAssembly/Reference/JavaScript_interface/Exception/Exception) - - : Creates a new `WebAssembly.Exception` object. + - : Creates a new `WebAssembly.Exception` object instance. ## Instance methods @@ -38,7 +26,56 @@ The constructor may then return an exception with a stack trace attached to the ## Instance properties - [`Exception.prototype.stack`](/en-US/docs/WebAssembly/Reference/JavaScript_interface/Exception/stack) {{non-standard_inline}} - - : Returns the stack trace for the exception, or `undefined`. + - : Returns the stack trace for the exception. + +## Description + +When handling Wasm exceptions from the JavaScript host, caught exceptions will have a `WebAssembly.Exception` object type. + +For example, you could start by constructing an error tag type using the [`WebAssembly.Tag()`](/en-US/docs/WebAssembly/Reference/JavaScript_interface/Tag/Tag) constructor, like this: + +```js +const myErrorTag = new WebAssembly.Tag({ parameters: ["i32"] }); +``` + +You can then import it into a Wasm module like this: + +```js +const env = { + my_error: myErrorTag, +}; + +WebAssembly.instantiateStreaming(fetch("module.wasm"), { env }).then( ... ) +``` + +You could then try running an exported Wasm function in a [`try...catch`](/en-US/docs/Web/JavaScript/Reference/Statements/try...catch) statement. If the function throws, the error propagated to the `catch` block will be a [`WebAssembly.Exception`](/en-US/docs/WebAssembly/Reference/JavaScript_interface/Exception) object instance. + +```js +WebAssembly.instantiateStreaming(fetch("module.wasm"), { env }).then( + (result) => { + try { + // Cause function to throw + result.instance.exports.throw(-1); + } catch (e) { + if (e instanceof WebAssembly.Exception && e.is(myErrorTag)) { + const errorCode = e.getArg(myErrorTag, 0); // 0 = first payload value + console.log("Error code:", errorCode); // 42 + } else { + throw e; // throw other errors + } + } + }, +); +``` + +You can check whether it has the same exception type we defined earlier (`myErrorTag`) using [`Exception.prototype.is()`](/en-US/docs/WebAssembly/Reference/JavaScript_interface/Exception/is), and then access the exception's payload using [`Exception.prototype.getArg()`](/en-US/docs/WebAssembly/Reference/JavaScript_interface/Exception/getArg)). + +JavaScript and other client code can only access WebAssembly exception values, and vice versa, when the associated tag is shared (you can't just use another tag that happens to define the same data types). +Without the matching tag, exceptions can be caught and re-thrown, but they can't be inspected. + +In order to make exception-throwing faster, exceptions thrown from WebAssembly generally do not include a stack trace. +WebAssembly code that needs to provide a stack trace must call a JavaScript function to create the exception, passing `options.traceStack=true` parameter in the constructor. +The constructor may then return an exception with a stack trace attached to the [`stack`](/en-US/docs/WebAssembly/Reference/JavaScript_interface/Exception/stack) property. ## Examples diff --git a/files/en-us/webassembly/reference/javascript_interface/exception/is/index.md b/files/en-us/webassembly/reference/javascript_interface/exception/is/index.md index ce0b3d6488b42da..2203a0f092588c3 100644 --- a/files/en-us/webassembly/reference/javascript_interface/exception/is/index.md +++ b/files/en-us/webassembly/reference/javascript_interface/exception/is/index.md @@ -6,13 +6,10 @@ browser-compat: webassembly.api.Exception.is sidebar: webassemblysidebar --- -The **`is()`** prototype method of the [`Exception`](/en-US/docs/WebAssembly/Reference/JavaScript_interface/Exception) object can be used to test if the `Exception` matches a given tag. +The **`is()`** method of the [`Exception`](/en-US/docs/WebAssembly/Reference/JavaScript_interface/Exception) object can be used to test if the `Exception` matches a given tag. The method might be used to test that a tag is correct before passing it to [`Exception.prototype.getArg()`](/en-US/docs/WebAssembly/Reference/JavaScript_interface/Exception/getArg) to get the passed values. -It can be used on tags created in JavaScript or created in WebAssembly code and exported to JavaScript. - -> [!NOTE] -> It is not enough that the tag has an identical sequence of data types — it must have the same _identity_ (be the same tag) as was used to create the exception. +It can be used on tags created in JavaScript and those created in WebAssembly code and exported to JavaScript. ## Syntax @@ -27,7 +24,9 @@ is(tag) ### Return value -A boolean `true` if the specified tag matches the exception, and `false` otherwise. +A boolean value — `true` if the specified tag matches the exception, and `false` otherwise. + +To return `true`, it is not enough for the tag to have an identical sequence of data types — it must have the same _identity_ (be the same tag) as was used to create the exception. ## Examples @@ -40,22 +39,22 @@ const exception1 = new WebAssembly.Exception(tag1, [42, 42.3]); // Verify that "tag1" matches this exception console.log(`Tag1: ${exception1.is(tag1)}`); - -// Log output: -// Tag1: true ``` +This will log `Tag1: true` to the console. + We can also demonstrate that this exception will not match another tag even if the tag is created with the same parameters. ```js // Create a new tag (with same parameters) and verify it does not match the exception const tag2 = new WebAssembly.Tag({ parameters: ["i32", "f64"] }); console.log(`Tag2: ${exception1.is(tag2)}`); - -// Log output: -// Tag2: false ``` +This will log `Tag2: false` to the console. + +For a full working example, see the [`throw`](/en-US/docs/WebAssembly/Reference/Exception_handling/throw) instruction reference page. + ## Specifications {{Specifications}} diff --git a/files/en-us/webassembly/reference/javascript_interface/exception/stack/index.md b/files/en-us/webassembly/reference/javascript_interface/exception/stack/index.md index 265758beb8c4865..110e8fb1f305a85 100644 --- a/files/en-us/webassembly/reference/javascript_interface/exception/stack/index.md +++ b/files/en-us/webassembly/reference/javascript_interface/exception/stack/index.md @@ -10,36 +10,38 @@ sidebar: webassemblysidebar {{non-standard_header}} -The read-only **`stack`** property of an object instance of type [`WebAssembly.Exception`](/en-US/docs/WebAssembly/Reference/JavaScript_interface/Exception) _may_ contain a stack trace. - -Exceptions from WebAssembly code do not include a stack trace by default. - -If WebAssembly code needs to provide a stack trace, it must call a JavaScript function to create the exception, passing `options.traceStack=true` parameter in the [constructor](/en-US/docs/WebAssembly/Reference/JavaScript_interface/Exception/Exception). -The virtual machine can then attach a stack trace to the exception object returned by the constructor. - -> [!NOTE] -> Stack traces are not normally sent from WebAssembly code to improve performance. -> The ability to add stack traces to these exceptions is provided for developer tooling, and is not generally recommended for broader use. +The **`stack`** read-only property of the [`WebAssembly.Exception`](/en-US/docs/WebAssembly/Reference/JavaScript_interface/Exception) object _may_ contain a stack trace. ## Value A string containing the stack trace, or {{jsxref("undefined")}} if no trace has been assigned. The stack trace string lists the locations of each operation on the stack in WebAssembly format. -This is a human-readable string indicating the URL, name of the function type called, the function index, and its offset in the module binary. +This is a human-readable string indicating the URL, name of the function type called, function index, and its offset in the module binary. It has approximately this format (see [stack trace conventions](https://webassembly.github.io/spec/web-api/index.html#conventions) in the specification for more information): ```plain ${url}:wasm-function[${funcIndex}]:${pcOffset} ``` +## Description + +Exceptions from WebAssembly code do not include a stack trace by default. + +If WebAssembly code needs to provide a stack trace, it must call a JavaScript function to create the exception, passing the `options.traceStack=true` parameter in the [constructor](/en-US/docs/WebAssembly/Reference/JavaScript_interface/Exception/Exception). +The virtual machine can then attach a stack trace to the exception object returned by the constructor. + +> [!NOTE] +> Stack traces are not normally sent from WebAssembly code to improve performance. +> The ability to add stack traces to these exceptions is provided for developer tooling, and is not generally recommended for broader use. + ## Examples This example demonstrate how to throw an exception from WebAssembly that includes a stack trace. -Consider the following WebAssembly code, which is assumed to be compiled to a file named **example.wasm**. +Consider the following WebAssembly code, which is assumed to be compiled to a file named `example.wasm`. This imports a tag, which it refers to as `$tagname` internally, and imports a function that it refers to as `$throwExnWithStack`. -It exports the method `run` that can be called by external code to call `$throwExnWithStack` (and hence the JavaScript function). +It exports the method `run` that can be called by external code to call `$throwExnWithStack`. ```wat (module @@ -57,10 +59,10 @@ It exports the method `run` that can be called by external code to call `$throwE ) ``` -The JavaScript code below defines a new tag `tag` and the function `throwExceptionWithStack`. +The JavaScript code below defines a new tag `tag` and the function `throwExceptionWithStack()`. These are passed to the WebAssembly module in the `importObject` when it is instantiated. -Once the file is instantiated, the code calls the exported WebAssembly `run()` method, which will immediately throw an exception. +Once the module is instantiated, the code calls the exported WebAssembly `run()` method, which will immediately throw an exception. The stack is then logged from the `catch` statement. ```js @@ -93,7 +95,7 @@ WebAssembly.instantiateStreaming(fetch("example.wasm"), importObject) // @http:///main.js:82:38 ``` -The most "relevant" part of this code is the line where the exception is created: +The most significant part of this code is the line where the exception is created: ```js new WebAssembly.Exception(tag, [param], { traceStack: true }); diff --git a/files/en-us/webassembly/reference/javascript_interface/index.md b/files/en-us/webassembly/reference/javascript_interface/index.md index 96a280f0e9088d6..162a519081c8781 100644 --- a/files/en-us/webassembly/reference/javascript_interface/index.md +++ b/files/en-us/webassembly/reference/javascript_interface/index.md @@ -41,6 +41,11 @@ The primary uses for the `WebAssembly` object are: - [`WebAssembly.Exception`](/en-US/docs/WebAssembly/Reference/JavaScript_interface/Exception) - : A WebAssembly exception object that can be thrown, caught, and rethrown both within and across WebAssembly/JavaScript boundaries. +## Static properties + +- [`WebAssembly.JSTag`](/en-US/docs/WebAssembly/Reference/JavaScript_interface/JSTag_static) + - : A built-in [`WebAssembly.Tag`](/en-US/docs/WebAssembly/Reference/JavaScript_interface/Tag) representing exceptions thrown in the JavaScript host — it allows exceptions thrown in JavaScript to be handled from inside a Wasm module. + ## Static methods - [`WebAssembly.compile()`](/en-US/docs/WebAssembly/Reference/JavaScript_interface/compile_static) diff --git a/files/en-us/webassembly/reference/javascript_interface/jstag_static/index.md b/files/en-us/webassembly/reference/javascript_interface/jstag_static/index.md new file mode 100644 index 000000000000000..9b4034de29d3d88 --- /dev/null +++ b/files/en-us/webassembly/reference/javascript_interface/jstag_static/index.md @@ -0,0 +1,77 @@ +--- +title: WebAssembly.JSTag +slug: WebAssembly/Reference/JavaScript_interface/JSTag_static +page-type: webassembly-static-property +browser-compat: webassembly.api.JSTag +sidebar: webassemblysidebar +--- + +The **`JSTag`** read-only static property of the [`WebAssembly`](/en-US/docs/WebAssembly/Reference/JavaScript_interface) interface is a built-in [`WebAssembly.Tag`](/en-US/docs/WebAssembly/Reference/JavaScript_interface/Tag) representing exceptions thrown in the JavaScript host — it allows exceptions thrown in JavaScript to be handled from inside a Wasm module. + +{{InteractiveExample("WebAssembly.JSTag demo", "tabbed-taller")}} + +```wat interactive-example +(module + (tag $js_tag (import "env" "js_tag") (param externref)) + (import "env" "do_work" (func $do_work)) + (import "env" "log" (func $log (param externref))) + + (func $try_and_catch + (block $handler (result externref) + (try_table (catch $js_tag $handler) + ;; Call a JS function that throws + (call $do_work) + ) + (return) + ) + ;; The JS Error object is on the stack as an externref + ;; Pass it back to JS for logging + (call $log) + ) + + (export "try_and_catch" (func $try_and_catch)) +) +``` + +```js interactive-example +async function run() { + const { instance } = await WebAssembly.instantiateStreaming( + fetch("{%wasm-url%}"), + { + env: { + js_tag: WebAssembly.JSTag, + // This JS function throws, which Wasm will catch via JSTag + do_work: () => { + throw new Error("An exception was thrown in JS"); + }, + log: (error) => { + // errRef is the JS Error object passed back as an externref + console.log(error.message); + }, + }, + }, + ); + + instance.exports.try_and_catch(); +} + +run(); +``` + +## Value + +A [`WebAssembly.Tag`](/en-US/docs/WebAssembly/Reference/JavaScript_interface/Tag) with a type of [`externref`](/en-US/docs/WebAssembly/Reference/Value_types/externref) (`(tag (param externref))`). + +## Specifications + +{{Specifications}} + +## Browser compatibility + +{{Compat}} + +## See also + +- [WebAssembly](/en-US/docs/WebAssembly) overview +- [`WebAssembly.Tag`](/en-US/docs/WebAssembly/Reference/JavaScript_interface/Tag) +- [tag](/en-US/docs/WebAssembly/Reference/Definitions/tag) Wasm definition diff --git a/files/en-us/webassembly/reference/javascript_interface/tag/index.md b/files/en-us/webassembly/reference/javascript_interface/tag/index.md index e6eb12eeea4e360..d4c1266bd59cea5 100644 --- a/files/en-us/webassembly/reference/javascript_interface/tag/index.md +++ b/files/en-us/webassembly/reference/javascript_interface/tag/index.md @@ -6,39 +6,101 @@ browser-compat: webassembly.api.Tag sidebar: webassemblysidebar --- -The **`WebAssembly.Tag`** object defines a _type_ of a WebAssembly exception that can be thrown to/from WebAssembly code. - -When creating a [`WebAssembly.Exception`](/en-US/docs/WebAssembly/Reference/JavaScript_interface/Exception), the tag defines the data types and order of the values carried by the exception. -The same unique tag instance must be used to access the values of the exception (for example, when using [`Exception.prototype.getArg()`](/en-US/docs/WebAssembly/Reference/JavaScript_interface/Exception/getArg)). - -[Constructing](/en-US/docs/WebAssembly/Reference/JavaScript_interface/Tag/Tag) an instance of `Tag` creates a new unique tag. -This tag can be passed to a WebAssembly module as a tag import, where it will become a typed tag defined in the _tag section_ of the WebAssembly module. -You can also export a tag defined in a module and use it to inspect exceptions thrown from the module. - -> [!NOTE] -> You can't access the values of an exception with a new tag that just happens to have the same parameters; it's a different tag! -> This ensures that WebAssembly modules can keep exception information internal if required. -> Code can still catch and rethrow exceptions that it does not understand. +The **`WebAssembly.Tag`** object represents a WebAssembly exception _type_ that can be thrown in a Wasm module. ## Constructor - [`WebAssembly.Tag()`](/en-US/docs/WebAssembly/Reference/JavaScript_interface/Tag/Tag) - - : Creates a new `WebAssembly.Tag` object. + - : Creates a new `WebAssembly.Tag` object instance. ## Instance methods - [`Tag.prototype.type()`](/en-US/docs/WebAssembly/Reference/JavaScript_interface/Tag/type) - : Returns the object defining the data-types array for the tag (as set in its constructor). +## Description + +WebAssembly modules can define exception types using the [`tag`](/en-US/docs/WebAssembly/Reference/Definitions/tag) module definition. Exceptions of those types can then be thrown using the [`throw`](/en-US/docs/WebAssembly/Reference/Exception_handling/throw) instruction, and caught and handled using [`try_table`](/en-US/docs/WebAssembly/Reference/Exception_handling/try_table) blocks containing [catch clauses](/en-US/docs/WebAssembly/Reference/Exception_handling#catch_clauses). + +If wished, you can define a Wasm exception type in the JavaScript host using the [`WebAssembly.Tag()`](/en-US/docs/WebAssembly/Reference/JavaScript_interface/Tag/Tag) constructor, before importing it into the Wasm module to use there. + +One of the main advantages of defining Wasm exception types in JavaScript is that you need the exception type available when handling an exception in JavaScript. Having it defined in JavaScript saves you having to export it from the Wasm module. + +So for example, you can start by constructing an error tag type like this: + +```js +const myErrorTag = new WebAssembly.Tag({ parameters: ["i32"] }); +``` + +You can then import it into a Wasm module like this: + +```js +const env = { + my_error: myErrorTag, +}; + +WebAssembly.instantiateStreaming(fetch("module.wasm"), { env }).then( ... ) +``` + +Inside the Wasm module, you'd import the error tag and throw an exception of that type somewhere in your code: + +```wat +(tag $my_error (import "env" "my_error") (param i32)) + +(func $throw (param $value i32) + + ... + + (i32.const 42) ;; error code payload + (throw $my_error) ;; throw exception type $my_error + + ... + +) + +(export "throw" (func $throw)) +``` + +Back in the JavaScript, you could then try running the exported `throw()` function in a [`try...catch`](/en-US/docs/Web/JavaScript/Reference/Statements/try...catch) statement. If the function throws, the error propagated to the `catch` block will be a [`WebAssembly.Exception`](/en-US/docs/WebAssembly/Reference/JavaScript_interface/Exception) object instance. + +```js +WebAssembly.instantiateStreaming(fetch("module.wasm"), { env }).then( + (result) => { + try { + // Cause function to throw + result.instance.exports.throw(-1); + } catch (e) { + if (e instanceof WebAssembly.Exception && e.is(myErrorTag)) { + const errorCode = e.getArg(myErrorTag, 0); // 0 = first payload value + console.log("Error code:", errorCode); // 42 + } else { + throw e; // throw other errors + } + } + }, +); +``` + +You can check whether it has the same exception type we defined earlier (`myErrorTag`) using [`Exception.prototype.is()`](/en-US/docs/WebAssembly/Reference/JavaScript_interface/Exception/is), and then access the exception's payload using [`Exception.prototype.getArg()`](/en-US/docs/WebAssembly/Reference/JavaScript_interface/Exception/getArg)). + +> [!NOTE] +> You can't access the values of an exception with a new tag that just happens to have the same parameters; it's a different tag! +> This ensures that WebAssembly modules can keep exception information internal if required. +> Code can still catch and rethrow exceptions that it does not understand. + ## Examples -This code snippet creates a new `Tag` instance. +For a working example of handling a Wasm exception in JavaScript, see the [`throw`](/en-US/docs/WebAssembly/Reference/Exception_handling/throw) instruction reference page. + +### Basic usage + +This code snippet creates a new `Tag` instance: ```js const tagToImport = new WebAssembly.Tag({ parameters: ["i32", "f32"] }); ``` -The snippet below shows how we might pass it to a module **example.wasm** during instantiation, using an "import object". +The snippet below shows how we might import it into a Wasm module during instantiation: ```js const importObject = { @@ -58,15 +120,12 @@ The WebAssembly module might then import the tag as shown below: ```wat (module - (import "extmod" "exttag" (tag $tagname (param i32 f32)) + (import "extmod" "exttag" (tag $tagname (param i32 f32))) ) ``` If the tag was used to throw an exception that propagated to JavaScript, we could use the tag to inspect its values. -> [!NOTE] -> There are many alternatives. We could also use the tag to create a [`WebAssembly.Exception`](/en-US/docs/WebAssembly/Reference/JavaScript_interface/Exception) and throw that from a function called by WebAssembly. - ## Specifications {{Specifications}} @@ -80,3 +139,5 @@ If the tag was used to throw an exception that propagated to JavaScript, we coul - [WebAssembly](/en-US/docs/WebAssembly) overview - [WebAssembly concepts](/en-US/docs/WebAssembly/Guides/Concepts) - [Using the WebAssembly JavaScript API](/en-US/docs/WebAssembly/Guides/Using_the_JavaScript_API) +- [`tag`](/en-US/docs/WebAssembly/Reference/Definitions/tag) definition +- [`exnref`](/en-US/docs/WebAssembly/Reference/Types/exnref) type diff --git a/files/en-us/webassembly/reference/javascript_interface/tag/tag/index.md b/files/en-us/webassembly/reference/javascript_interface/tag/tag/index.md index 24c5e045b3ec225..4066647f0db6f6e 100644 --- a/files/en-us/webassembly/reference/javascript_interface/tag/tag/index.md +++ b/files/en-us/webassembly/reference/javascript_interface/tag/tag/index.md @@ -6,7 +6,7 @@ browser-compat: webassembly.api.Tag.Tag sidebar: webassemblysidebar --- -The **`WebAssembly.Tag()`** constructor creates a new [`WebAssembly.Tag`](/en-US/docs/WebAssembly/Reference/JavaScript_interface/Tag) object. +The **`WebAssembly.Tag()`** constructor creates a new [`WebAssembly.Tag`](/en-US/docs/WebAssembly/Reference/JavaScript_interface/Tag) object instance. ## Syntax @@ -19,18 +19,20 @@ new WebAssembly.Tag(type) - `type` - : An object that can contain the following members: - `parameters` - - : An array of [data types](/en-US/docs/WebAssembly/Guides/Understanding_the_text_format#types) (`"i32"`, `"i64"`, `"f32"`, `"f64"`, `"v128"`, `"externref"`, `"anyfunc"`). + - : An array of strings representing the exception type's parameters and their types. The strings can be any [Wasm type](/en-US/docs/WebAssembly/Reference/Value_types). ### Exceptions - {{jsxref("TypeError")}} - - : Thrown if at least one of these conditions are met: + - : Thrown if at least one of these conditions is true: - The `type` parameter is not an object. - The `type.parameters` property is not supplied. - - The `type.parameters` contains an unsupported data type. + - The `type.parameters` property contains an unsupported data type. ## Examples +### Basic usage + This creates a tag with two values. ```js @@ -50,3 +52,5 @@ const tag = new WebAssembly.Tag({ parameters: ["i32", "i64"] }); - [WebAssembly](/en-US/docs/WebAssembly) overview - [WebAssembly concepts](/en-US/docs/WebAssembly/Guides/Concepts) - [Using the WebAssembly JavaScript API](/en-US/docs/WebAssembly/Guides/Using_the_JavaScript_API) +- [`tag`](/en-US/docs/WebAssembly/Reference/Definitions/tag) definition +- [`exnref`](/en-US/docs/WebAssembly/Reference/Value_types/exnref) type diff --git a/files/en-us/webassembly/reference/javascript_interface/tag/type/index.md b/files/en-us/webassembly/reference/javascript_interface/tag/type/index.md index 9b55b5c67b85aca..91f586bd6bd8bfc 100644 --- a/files/en-us/webassembly/reference/javascript_interface/tag/type/index.md +++ b/files/en-us/webassembly/reference/javascript_interface/tag/type/index.md @@ -6,7 +6,7 @@ browser-compat: webassembly.api.Tag.type sidebar: webassemblysidebar --- -The **`type()`** prototype method of the [`Tag`](/en-US/docs/WebAssembly/Reference/JavaScript_interface/Tag) object can be used to get the sequence of data types associated with the tag. +The **`type()`** method of the [`Tag`](/en-US/docs/WebAssembly/Reference/JavaScript_interface/Tag) object can be used to get the sequence of data types associated with the tag. ## Syntax @@ -26,17 +26,19 @@ This is a copy of the `type` object that was originally passed into the [`Tag()` ## Examples -This code snippet creates a tag defining two data types and then exports them using `type()`. -The result is printed to the console: +This code snippet creates a tag defining two data types and then retrieves them using `type()`: ```js const tag = new WebAssembly.Tag({ parameters: ["i32", "i64"] }); console.log(tag.type()); +``` + +The object logged to the console will look like so: -// Console output: -// Object { parameters: (2) […] } -// parameters: Array [ "i32", "i64" ] -// : Object { … } +```js +{ + parameters: ["i32", "i64"]; +} ``` ## Specifications diff --git a/files/en-us/webassembly/reference/value_types/exnref/index.md b/files/en-us/webassembly/reference/value_types/exnref/index.md new file mode 100644 index 000000000000000..1e9c9866e050eed --- /dev/null +++ b/files/en-us/webassembly/reference/value_types/exnref/index.md @@ -0,0 +1,107 @@ +--- +title: "exnref: Wasm value type" +short-title: exnref +slug: WebAssembly/Reference/Value_types/exnref +page-type: webassembly-instruction +browser-compat: webassembly.types.exnref +sidebar: webassemblysidebar +--- + +The **`exnref`** value type represents a thrown exception in a Wasm module, allowing it to be rethrown. + +{{InteractiveExample("Wat Demo: exnref", "tabbed-taller")}} + +```wat interactive-example +(module + ;; Import error tag + (tag $my_error (import "env" "my_error") (param i32)) + + (func $try_and_rethrow (param $value i32) + ;; Define a variable to store an exnref + (local $err exnref) + + (block $handler (result i32 exnref) + (try_table (catch_ref $my_error $handler) + (call $might_throw (local.get $value)) + ) + (return) + ) + + ;; catch_ref returns error value and exnref + ;; Stack is now: i32, exnref (exnref on top) + (local.set $err) ;; pop exnref + (drop) ;; drop the i32 payload + (local.get $err) ;; push exnref back + (throw_ref) + ) + + ;; Function that throws an error of type $my_error + ;; when its parameter is less than 0 + (func $might_throw (param $value i32) + (local.get $value) + (i32.const 0) + (i32.lt_s) + (if + (then + (i32.const 42) + (throw $my_error) + ) + ) + ) + + (export "try_and_rethrow" (func $try_and_rethrow)) +) +``` + +```js interactive-example +// Define error tag in JS +const myErrorTag = new WebAssembly.Tag({ parameters: ["i32"] }); + +// Import the tag into the module +const env = { + my_error: myErrorTag, +}; + +WebAssembly.instantiateStreaming(fetch("{%wasm-url%}"), { env }).then( + (result) => { + try { + // Negative value causes function to throw + result.instance.exports.try_and_rethrow(-1); + } catch (e) { + if (e instanceof WebAssembly.Exception && e.is(myErrorTag)) { + // 0 is the first payload value, which is equal to 42 + const errorCode = e.getArg(myErrorTag, 0); + console.log("Error code:", errorCode); + } else { + // Throw other errors + throw e; + } + } + }, +); +``` + +## Syntax + +```wat +;; Define variable to hold exnref +(local $err exnref) +``` + +## Description + +The `exnref` type represents a thrown exception in a Wasm module. This value type is returned by the [`catch_ref`](/en-US/docs/WebAssembly/Reference/Exception_handling/try_table/catch_ref) and [`catch_all_ref`](/en-US/docs/WebAssembly/Reference/Exception_handling/try_table/catch_all_ref) clauses, providing a reference to the exception that was just thrown, and allowing it to be rethrown if required using the [`throw_ref`](/en-US/docs/WebAssembly/Reference/Exception_handling/throw_ref) instruction. + +The [`WebAssembly.Exception`](/en-US/docs/WebAssembly/Reference/JavaScript_interface/Exception) JavaScript interface represents a Wasm exception in the JavaScript host. + +> [!NOTE] +> You cannot call a Wasm function from JavaScript that has an `exnref` value as a parameter or result. Trying to do so will result in an error. + +## See also + +- [`throw_ref`](/en-US/docs/WebAssembly/Reference/Exception_handling/throw_ref) instruction +- [`try_table`](/en-US/docs/WebAssembly/Reference/Exception_handling/try_table) instruction + - [`catch_ref`](/en-US/docs/WebAssembly/Reference/Exception_handling/try_table/catch_ref) clause + - [`catch_all_ref`](/en-US/docs/WebAssembly/Reference/Exception_handling/try_table/catch_all_ref) clause +- [`tag`](/en-US/docs/WebAssembly/Reference/Definitions/tag) definition +- [`WebAssembly.Exception`](/en-US/docs/WebAssembly/Reference/JavaScript_interface/Exception) JavaScript interface diff --git a/files/en-us/webassembly/reference/value_types/externref/index.md b/files/en-us/webassembly/reference/value_types/externref/index.md index 2bc65e8010790e0..69aef5c16cad0a6 100644 --- a/files/en-us/webassembly/reference/value_types/externref/index.md +++ b/files/en-us/webassembly/reference/value_types/externref/index.md @@ -1,5 +1,5 @@ --- -title: "externref: Wasm type" +title: "externref: Wasm value type" short-title: externref slug: WebAssembly/Reference/Value_types/externref page-type: webassembly-instruction diff --git a/files/en-us/webassembly/reference/value_types/f32/index.md b/files/en-us/webassembly/reference/value_types/f32/index.md index 56f18187690d665..852d2acd38033aa 100644 --- a/files/en-us/webassembly/reference/value_types/f32/index.md +++ b/files/en-us/webassembly/reference/value_types/f32/index.md @@ -1,5 +1,5 @@ --- -title: "f32: Wasm type" +title: "f32: Wasm value type" short-title: f32 slug: WebAssembly/Reference/Value_types/f32 page-type: webassembly-instruction diff --git a/files/en-us/webassembly/reference/value_types/f64/index.md b/files/en-us/webassembly/reference/value_types/f64/index.md index 092823d765bafe3..b3ed7cef1b3c967 100644 --- a/files/en-us/webassembly/reference/value_types/f64/index.md +++ b/files/en-us/webassembly/reference/value_types/f64/index.md @@ -1,5 +1,5 @@ --- -title: "f64: Wasm type" +title: "f64: Wasm value type" short-title: f64 slug: WebAssembly/Reference/Value_types/f64 page-type: webassembly-instruction diff --git a/files/en-us/webassembly/reference/value_types/funcref/index.md b/files/en-us/webassembly/reference/value_types/funcref/index.md index 93e1754329a8b38..bac8e00ca0e9725 100644 --- a/files/en-us/webassembly/reference/value_types/funcref/index.md +++ b/files/en-us/webassembly/reference/value_types/funcref/index.md @@ -1,5 +1,5 @@ --- -title: "funcref: Wasm type" +title: "funcref: Wasm value type" short-title: funcref slug: WebAssembly/Reference/Value_types/funcref page-type: webassembly-instruction diff --git a/files/en-us/webassembly/reference/value_types/i32/index.md b/files/en-us/webassembly/reference/value_types/i32/index.md index 9ccc8334d530f6e..87c5757f28e9f25 100644 --- a/files/en-us/webassembly/reference/value_types/i32/index.md +++ b/files/en-us/webassembly/reference/value_types/i32/index.md @@ -1,5 +1,5 @@ --- -title: "i32: Wasm type" +title: "i32: Wasm value type" short-title: i32 slug: WebAssembly/Reference/Value_types/i32 page-type: webassembly-instruction diff --git a/files/en-us/webassembly/reference/value_types/i64/index.md b/files/en-us/webassembly/reference/value_types/i64/index.md index 0da006f818d092f..bd37b38e9be81fe 100644 --- a/files/en-us/webassembly/reference/value_types/i64/index.md +++ b/files/en-us/webassembly/reference/value_types/i64/index.md @@ -1,5 +1,5 @@ --- -title: "i64: Wasm type" +title: "i64: Wasm value type" short-title: i64 slug: WebAssembly/Reference/Value_types/i64 page-type: webassembly-instruction diff --git a/files/en-us/webassembly/reference/value_types/index.md b/files/en-us/webassembly/reference/value_types/index.md index 956b660f8eed3f3..c7e74d756a0380d 100644 --- a/files/en-us/webassembly/reference/value_types/index.md +++ b/files/en-us/webassembly/reference/value_types/index.md @@ -19,5 +19,7 @@ Value types classify the values used in computation. - : A 128-bit vector of packed integer or floating-point data, manipulated by [SIMD instructions](/en-US/docs/WebAssembly/Reference/SIMD). - [`funcref`](/en-US/docs/WebAssembly/Reference/Value_types/funcref) - : A reference to a function defined in Wasm, allowing higher-order functions to be called across the Wasm and JavaScript language boundaries. +- [`exnref`](/en-US/docs/WebAssembly/Reference/Value_types/exnref) + - : Represents a thrown exception in a Wasm module, allowing it to be rethrown. - [`externref`](/en-US/docs/WebAssembly/Reference/Value_types/externref) - : A reference to a host value (for example a JavaScript object), opaque to Wasm code. diff --git a/files/en-us/webassembly/reference/value_types/v128/index.md b/files/en-us/webassembly/reference/value_types/v128/index.md index 37590c83184e673..7f6158b40ef044c 100644 --- a/files/en-us/webassembly/reference/value_types/v128/index.md +++ b/files/en-us/webassembly/reference/value_types/v128/index.md @@ -1,5 +1,5 @@ --- -title: "v128: Wasm type" +title: "v128: Wasm value type" short-title: v128 slug: WebAssembly/Reference/Value_types/v128 page-type: webassembly-instruction diff --git a/files/sidebars/webassemblysidebar.yaml b/files/sidebars/webassemblysidebar.yaml index 9ec50970d6e0944..84bbe599ff38360 100644 --- a/files/sidebars/webassemblysidebar.yaml +++ b/files/sidebars/webassemblysidebar.yaml @@ -46,7 +46,9 @@ sidebar: children: - type: listSubPages path: /WebAssembly/Reference/JavaScript_interface - tags: webassembly-function + tags: + - webassembly-function + - unknown link: /WebAssembly/Reference/JavaScript_interface title: WebAssembly details: closed @@ -127,6 +129,8 @@ sidebar: title: v128 - link: /WebAssembly/Reference/Value_types/funcref title: funcref + - link: /WebAssembly/Reference/Value_types/exnref + title: exnref - link: /WebAssembly/Reference/Value_types/externref title: externref - link: /WebAssembly/Reference/Definitions @@ -142,6 +146,8 @@ sidebar: title: global - link: /WebAssembly/Reference/Definitions/table title: table + - link: /WebAssembly/Reference/Definitions/tag + title: tag - title: Instructions details: closed children: @@ -150,6 +156,19 @@ sidebar: link: /WebAssembly/Reference/Control_flow title: Control flow details: closed + - link: /WebAssembly/Reference/Exception_handling + title: Exception handling + details: closed + children: + - link: /WebAssembly/Reference/Exception_handling/throw + title: throw + - link: /WebAssembly/Reference/Exception_handling/throw_ref + title: throw_ref + - type: listSubPages + path: /WebAssembly/Reference/Exception_handling/try_table + link: /WebAssembly/Reference/Exception_handling/try_table + title: try_table + details: closed - type: listSubPages path: /WebAssembly/Reference/Memory link: /WebAssembly/Reference/Memory diff --git a/front-matter-config.json b/front-matter-config.json index 1a5830725b06d5e..f696fa8817f7922 100644 --- a/front-matter-config.json +++ b/front-matter-config.json @@ -354,6 +354,7 @@ "webassembly-instance-property", "webassembly-instance-method", "webassembly-static-method", + "webassembly-static-property", "webassembly-instruction" ] } diff --git a/package-lock.json b/package-lock.json index f6900a3df74ad4d..b34b58ea4d8d29c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,7 +10,7 @@ "license": "SEE LICENSE IN LICENSE.md", "devDependencies": { "@apideck/better-ajv-errors": "^0.3.7", - "@mdn/fred": "2.6.2", + "@mdn/fred": "2.6.4", "@octokit/rest": "^22.0.1", "ajv": "^8.20.0", "ajv-formats": "^3.0.1", @@ -1080,9 +1080,9 @@ "license": "MIT" }, "node_modules/@mdn/fred": { - "version": "2.6.2", - "resolved": "https://registry.npmjs.org/@mdn/fred/-/fred-2.6.2.tgz", - "integrity": "sha512-ftF4e08+eBlFOkXynFUtfM2959k2qYxigoVsltJ/jhxRw8v5EzNHgUCwSDIm9oznxnhh1IPCw2LAZ7RbxT3sGg==", + "version": "2.6.4", + "resolved": "https://registry.npmjs.org/@mdn/fred/-/fred-2.6.4.tgz", + "integrity": "sha512-OYa1dDzbsoQG9M/BfyiCnUZ3rTHCUMLkMSRF92bJEm1WvCB5ivGpNVYabog+zKr4D7rH8QpcOGqkUYsLfcOoaQ==", "dev": true, "license": "MPL-2.0", "dependencies": { @@ -1096,7 +1096,7 @@ "@lit-labs/ssr": "^4.1.0", "@lit-labs/ssr-client": "^1.1.8", "@lit/task": "^1.0.3", - "@mdn/rari": "0.2.23", + "@mdn/rari": "0.2.25", "@mdn/watify": "^1.1.9", "@mozilla/glean": "^5.0.8", "codemirror": "^6.0.1", @@ -1124,9 +1124,9 @@ } }, "node_modules/@mdn/rari": { - "version": "0.2.23", - "resolved": "https://registry.npmjs.org/@mdn/rari/-/rari-0.2.23.tgz", - "integrity": "sha512-zUX1kPn1Gyr6w/L06niTuewrzRVn0R2dGZSutBGLuwJNRilr1ycAzjuv1T+exiUjkfsLOaLnra6iHdUyHS1mUQ==", + "version": "0.2.25", + "resolved": "https://registry.npmjs.org/@mdn/rari/-/rari-0.2.25.tgz", + "integrity": "sha512-CxhOvB+qOqOdpdpXFlN9wlNNyvXB9Z8+LDVIXU1xO7WWMKJzem+clkhcqIUbcGzuYV/tiiu4MasGbVp6Jh/MQg==", "dev": true, "hasInstallScript": true, "license": "MPL-2.0", diff --git a/package.json b/package.json index e8bf8d046a3f996..16e99aa2216affb 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ }, "devDependencies": { "@apideck/better-ajv-errors": "^0.3.7", - "@mdn/fred": "2.6.2", + "@mdn/fred": "2.6.4", "@octokit/rest": "^22.0.1", "ajv": "^8.20.0", "ajv-formats": "^3.0.1",