-
Notifications
You must be signed in to change notification settings - Fork 30.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
util: Detect whether the string is one byte representation or not.
References: #56090
- Loading branch information
1 parent
c4aa34a
commit 6f30b0e
Showing
5 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
test/parallel/test-v8-string-is-one-byte-representation.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Flags: --expose-internals | ||
'use strict'; | ||
require('../common'); | ||
const assert = require('assert'); | ||
const { isStringOneByteRepresentation } = require('v8'); | ||
|
||
[ | ||
undefined, | ||
null, | ||
false, | ||
5n, | ||
5, | ||
Symbol(), | ||
() => {}, | ||
{}, | ||
].forEach((value) => { | ||
assert.throws( | ||
() => { isStringOneByteRepresentation(value); }, | ||
/The "content" argument must be of type string/ | ||
); | ||
}); | ||
|
||
{ | ||
const latin1String = 'hello world!'; | ||
// Run this inside a for loop to trigger the fast API | ||
for (let i = 0; i < 10_000; i++) { | ||
assert.strictEqual(isStringOneByteRepresentation(latin1String), true); | ||
} | ||
} | ||
|
||
{ | ||
const utf16String = '你好😀😃'; | ||
// Run this inside a for loop to trigger the fast API | ||
for (let i = 0; i < 10_000; i++) { | ||
assert.strictEqual(isStringOneByteRepresentation(utf16String), false); | ||
} | ||
} |