Skip to content

Commit 2d9db90

Browse files
authored
llv8-inl.h: Fix crash on sliced external strings (#123)
Sliced strings with an external string as a parent would use their offset and length values against the string "(external)" as support for external strings is not implemented yet. Fixes: #112 PR-URL: #123 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
1 parent c14adb4 commit 2d9db90

4 files changed

Lines changed: 30 additions & 0 deletions

File tree

src/llv8-inl.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,13 @@ inline std::string SlicedString::ToString(Error& err) {
318318
String parent = Parent(err);
319319
if (err.Fail()) return std::string();
320320

321+
// TODO - Remove when we add support for external strings
322+
// We can't use the offset and length safely if we get "(external)"
323+
// instead of the original parent string.
324+
if (parent.Representation(err) == v8()->string()->kExternalStringTag) {
325+
return parent.ToString(err);
326+
}
327+
321328
Smi offset = Offset(err);
322329
if (err.Fail()) return std::string();
323330

test/common.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ function Session(scenario) {
120120
'--',
121121
process.execPath,
122122
'--abort_on_uncaught_exception',
123+
'--expose_externalize_string',
123124
path.join(exports.fixturesDir, scenario)
124125
], {
125126
stdio: [ 'pipe', 'pipe', 'pipe' ],

test/fixtures/inspect-scenario.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,15 @@ function closure() {
3838
c.hashmap['internalized-string'] = 'foobar';
3939
// This thin string points to the previous 'foobar'.
4040
c.hashmap['thin-string'] = makeThin('foo', 'bar');
41+
// Create an externalized string and slice it.
42+
c.hashmap['externalized-string'] =
43+
'string that will be externalized and sliced';
44+
externalizeString(c.hashmap['externalized-string']);
45+
// Sliced strings need to be longer that SlicedString::kMinLength
46+
// which seems to be 13 so our string is 26.
47+
c.hashmap['sliced-externalized-string'] =
48+
c.hashmap['externalized-string'].substring(10,36);
49+
4150
c.hashmap['array'] = [true, 1, undefined, null, 'test', Class];
4251
c.hashmap['long-array'] = new Array(20).fill(5);
4352
c.hashmap['array-buffer'] = new Uint8Array(

test/inspect-test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ tape('v8 inspect', (t) => {
4848
let regexp = null;
4949
let cons = null;
5050
let thin = null;
51+
let ext = null;
52+
let extSliced = null;
5153
let arrowFunc = null;
5254
let array = null;
5355
let longArray = null;
@@ -118,6 +120,17 @@ tape('v8 inspect', (t) => {
118120
t.ok(thinMatch, '.thin-string ThinString property');
119121
thin = thinMatch[1];
120122

123+
const extMatch = lines.match(
124+
/.externalized-string=(0x[0-9a-f]+):<String: "\(external\)">/);
125+
t.ok(extMatch, '.externalized-string ExternalString property');
126+
ext = extMatch[1];
127+
128+
const extSlicedMatch = lines.match(
129+
/.sliced-externalized-string=(0x[0-9a-f]+):<String: "\(external\)">/);
130+
t.ok(extSlicedMatch,
131+
'.sliced-externalized-string Sliced ExternalString property');
132+
extSliced = extSlicedMatch[1];
133+
121134
sess.send(`v8 inspect ${regexp}`);
122135
sess.send(`v8 inspect -F ${cons}`);
123136
});

0 commit comments

Comments
 (0)