summaryrefslogtreecommitdiff
path: root/src/node_modules/es-abstract/2020/UTF16DecodeString.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/node_modules/es-abstract/2020/UTF16DecodeString.js')
-rw-r--r--src/node_modules/es-abstract/2020/UTF16DecodeString.js29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/node_modules/es-abstract/2020/UTF16DecodeString.js b/src/node_modules/es-abstract/2020/UTF16DecodeString.js
new file mode 100644
index 0000000..48bfac1
--- /dev/null
+++ b/src/node_modules/es-abstract/2020/UTF16DecodeString.js
@@ -0,0 +1,29 @@
+'use strict';
+
+var GetIntrinsic = require('../GetIntrinsic');
+
+var $TypeError = GetIntrinsic('%TypeError%');
+
+var callBound = require('../helpers/callBound');
+
+var $push = callBound('Array.prototype.push');
+
+var CodePointAt = require('./CodePointAt');
+var Type = require('./Type');
+
+// https://tc39.es/ecma262/2020/#sec-utf16decodestring
+
+module.exports = function UTF16DecodeString(string) {
+ if (Type(string) !== 'String') {
+ throw new $TypeError('Assertion failed: `string` must be a String');
+ }
+ var codePoints = [];
+ var size = string.length;
+ var position = 0;
+ while (position < size) {
+ var cp = CodePointAt(string, position);
+ $push(codePoints, cp['[[CodePoint]]']);
+ position += cp['[[CodeUnitCount]]'];
+ }
+ return codePoints;
+};