From d2a885bd2756ce73391dec3e3fb060fbe9597459 Mon Sep 17 00:00:00 2001 From: Bong Nguyen Date: Wed, 23 Nov 2022 20:55:03 +1100 Subject: [PATCH] Avoid crash when trying to throw exceptions twice --- .gitignore | 1 + src/bindings/marker-index-wrapper.cc | 9 ++++++--- test/js/text-buffer.test.js | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index bcbb4f61..f56d30f6 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ build emsdk-portable package-lock.json .vscode +/bin/ \ No newline at end of file diff --git a/src/bindings/marker-index-wrapper.cc b/src/bindings/marker-index-wrapper.cc index b133b796..2021a1f8 100644 --- a/src/bindings/marker-index-wrapper.cc +++ b/src/bindings/marker-index-wrapper.cc @@ -122,12 +122,15 @@ optional MarkerIndexWrapper::bool_from_js(Napi::Value value) { void MarkerIndexWrapper::insert(const CallbackInfo &info) { optional id = marker_id_from_js(info[0]); + if (!id) return; + optional start = PointWrapper::point_from_js(info[1]); + if (!start) return; + optional end = PointWrapper::point_from_js(info[2]); + if (!end) return; - if (id && start && end) { - this->marker_index->insert(*id, *start, *end); - } + this->marker_index->insert(*id, *start, *end); } void MarkerIndexWrapper::set_exclusive(const CallbackInfo &info) { diff --git a/test/js/text-buffer.test.js b/test/js/text-buffer.test.js index 3a091acb..fa79cdcc 100644 --- a/test/js/text-buffer.test.js +++ b/test/js/text-buffer.test.js @@ -1067,9 +1067,9 @@ describe('TextBuffer', () => { const generateSeed = Random.create() let seed = generateSeed(MAX_INT32) const random = new Random(seed) + console.log('Seed: ', seed); const testDocument = new TestDocument(seed) - console.log('Seed: ', seed); const buffer = new TextBuffer(testDocument.getText()) for (let j = 0; j < 10; j++) {