You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: README.md
+89-1
Original file line number
Diff line number
Diff line change
@@ -2619,4 +2619,92 @@ Most of these features already supported by some browsers and try out with babel
2619
2619
for (let x ofresult.get("senior")) {
2620
2620
console.log(x.name+""+x.age);
2621
2621
}
2622
-
```
2622
+
```
2623
+
2624
+
2. ### Temporal API
2625
+
2626
+
The Temporal API is a modern API for working with dates and times, used to supersede the original Date API. It provides a more comprehensive and user-friendly way to handle date and time manipulation.
2627
+
2628
+
3. ### Well formed unicode strings
2629
+
Unicode strings are mainly used for representing a wide range of characters from different languages and symbols. In UTF-16, strings which contain lone surrogates(16-bit Code Unit) are considered as "malformed" or "not well formatted". These lone surrogates can be of two types,
2630
+
2631
+
1. **Leading surrogates:** Range between `0XD800` to `0XDBFF`
2632
+
2. **Trailing Surrogate:** Range between `0XDC00` to `0XDFFF`
2633
+
2634
+
Well-Formed Unicode Strings feature introduced below two string methods to check and convert into wellformed strings.
2635
+
2636
+
1. **String.prototype.isWellFormed:**
2637
+
This method is used to check if the string contains lone surrogates or not. Returns `true`, if unicode string is not present. The following stings can be verified either as well-formed or not well-formed strigns,
2638
+
2639
+
```javascript
2640
+
conststr1="Hello World \uD815";
2641
+
conststr2="Welcome to ES2024";
2642
+
conststr3="Welcome to ES2024 😀";
2643
+
2644
+
console.log(str1.isWellFormed()); // false
2645
+
console.log(str2.isWellFormed()); // true
2646
+
console.log(str2.isWellFormed()); // true
2647
+
```
2648
+
2649
+
**Note:** Emojis are considered as well-formed unicode strings.
2650
+
2651
+
2. **String.prototype.toWellFormed:**
2652
+
This method is used to return a string by converting unpaired surrogate(i.e, leading and trailing surrogates) code points with `U+FFFD` Replacement characters.
2653
+
2654
+
```javascript
2655
+
conststr1="Hello World \uD815";
2656
+
conststr2="Welcome to ES2024";
2657
+
2658
+
console.log(str1.toWellFormed()); // Hello World �
2659
+
console.log(str2.toWellFormed()); // Welcome to ES2024
2660
+
```
2661
+
2662
+
These two methods are mainly helpful for developers to work with string encoding without any errors. For example, the below encoding process throws an error due to lone surrogates,
2663
+
2664
+
```javascript
2665
+
consturl="https://somedomain.com/query=\uD423";
2666
+
2667
+
try {
2668
+
console.log(encodeURI(url));
2669
+
} catch (e) {
2670
+
console.log('Error:', e.message); // Expected: URIError: URI malformed
2671
+
}
2672
+
```
2673
+
2674
+
After applying `toWellFormed()` method, the lone surrogate is replaced with the Unicode replacement character (U+FFFD). It make sure `encodeURI()` is processed without errors.
The `Atomics.waitAsync()` is a static method that waits asynchronously on a shared memory location and returns a Promise. It is non-blocking as compared to `Atomics.wait()` and can be used on the main thread. The syntax looks like below,
2681
+
2682
+
```javascript
2683
+
Atomics.waitAsync(typedArray, ind, val, timeOut);
2684
+
```
2685
+
If the promise is not fulfilled then it will lead to a 'time-out' status otherwise the status will always be 'ok' once the promise has been fulfilled.
2686
+
2687
+
Let's take a shared Int32Array. Here it waits asynchrously for position 0 and expects a result 0 waiting for 500ms.
After that, the notify method awakes the waiting agent(i.e, array) that are sleeping in waiting queue and the promise is fulfilled.
2698
+
2699
+
Remember that, SharedArrayBuffer have been disabled on most browsers unless you specify `Cross-Origin-Opener-Policy` and `Cross-Origin-Embedder-Policy` headers. For example,
2700
+
2701
+
`
2702
+
Cross-Origin-Opener-Policy: same-origin
2703
+
Cross-Origin-Embedder-Policy: require-corp
2704
+
`
2705
+
2706
+
**Note:** There will be a TypeError if typedArray is not an **Int32Array** or **BigInt64Array** that views a SharedArrayBuffer.
0 commit comments