From a6c8329a685090dd7c00fa25be81b196d41b508b Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 31 Jul 2017 15:45:59 +0900 Subject: [PATCH 1/5] Remove unneeded heap allocation --- atom/common/api/atom_api_native_image.cc | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/atom/common/api/atom_api_native_image.cc b/atom/common/api/atom_api_native_image.cc index c15e47407b..4d5754ac97 100644 --- a/atom/common/api/atom_api_native_image.cc +++ b/atom/common/api/atom_api_native_image.cc @@ -268,11 +268,10 @@ v8::Local NativeImage::ToPNG(mate::Arguments* args) { const SkBitmap bitmap = image_.AsImageSkia().GetRepresentation(scale_factor).sk_bitmap(); - std::unique_ptr> encoded( - new std::vector()); - gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, false, encoded.get()); - const char* data = reinterpret_cast(encoded->data()); - size_t size = encoded->size(); + std::vector encoded; + gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, false, &encoded); + const char* data = reinterpret_cast(encoded.data()); + size_t size = encoded.size(); return node::Buffer::Copy(args->isolate(), data, size).ToLocalChecked(); } From 6ee95f952944f7903b90d4c4a6e27bae56c7c66f Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 31 Jul 2017 15:48:54 +0900 Subject: [PATCH 2/5] Fix crash when converting invalid image to JPEG --- atom/common/api/atom_api_native_image.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/atom/common/api/atom_api_native_image.cc b/atom/common/api/atom_api_native_image.cc index 4d5754ac97..4d30a88e0d 100644 --- a/atom/common/api/atom_api_native_image.cc +++ b/atom/common/api/atom_api_native_image.cc @@ -291,6 +291,8 @@ v8::Local NativeImage::ToBitmap(mate::Arguments* args) { v8::Local NativeImage::ToJPEG(v8::Isolate* isolate, int quality) { std::vector output; gfx::JPEG1xEncodedDataFromImage(image_, quality, &output); + if (output.empty()) + return node::Buffer::New(isolate, 0).ToLocalChecked(); return node::Buffer::Copy( isolate, reinterpret_cast(&output.front()), From 9ced85d8608a1f09d33d6ae25a92f748c10f037b Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 31 Jul 2017 16:24:23 +0900 Subject: [PATCH 3/5] Terminate tests when renderer process crashed --- spec/static/main.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/spec/static/main.js b/spec/static/main.js index b1af370654..faede549a1 100644 --- a/spec/static/main.js +++ b/spec/static/main.js @@ -141,6 +141,10 @@ app.on('ready', function () { }) if (chosen === 0) window.destroy() }) + window.webContents.on('crashed', function () { + console.error('Renderer process crashed') + process.exit(1) + }) // For session's download test, listen 'will-download' event in browser, and // reply the result to renderer for verifying From 4b46eca329c3fc019ef35b7dfc90bd0f5c28ae81 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 31 Jul 2017 16:36:52 +0900 Subject: [PATCH 4/5] spec: Always run crash-reporter at last So when a test crashed we can always see the stack trace. --- spec/static/index.html | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/spec/static/index.html b/spec/static/index.html index c89fe55fea..74a9e6d278 100644 --- a/spec/static/index.html +++ b/spec/static/index.html @@ -62,16 +62,17 @@ if (query.invert) mocha.invert(); // Read all test files. - var walker = require('walkdir').walk(require('path').dirname(__dirname), { + var walker = require('walkdir').walk(path.dirname(__dirname), { no_recurse: true }); walker.on('file', function(file) { - if (/-spec\.js$/.test(file)) + if (/-spec\.js$/.test(file) && !file.includes('api-crash-reporter-spec.js')) mocha.addFile(file); }); walker.on('end', function() { + mocha.addFile(path.resolve(__dirname, '..', 'api-crash-reporter-spec.js')) var runner = mocha.run(function() { if (isCi && runner.hasOnly) { try { From 0ee2ab8a6e4e0200f5ef0fb709b04cdf2aaf7900 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 31 Jul 2017 16:47:14 +0900 Subject: [PATCH 5/5] Fix accessing empty vector in V8FunctionInvoker --- atom/common/native_mate_converters/callback.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/atom/common/native_mate_converters/callback.h b/atom/common/native_mate_converters/callback.h index 8073d00779..34c6e5d62d 100644 --- a/atom/common/native_mate_converters/callback.h +++ b/atom/common/native_mate_converters/callback.h @@ -56,7 +56,8 @@ struct V8FunctionInvoker(ArgTypes...)> { v8::Local context = holder->CreationContext(); v8::Context::Scope context_scope(context); std::vector> args { ConvertToV8(isolate, raw)... }; - v8::Local ret(holder->Call(holder, args.size(), &args.front())); + v8::Local ret(holder->Call( + holder, args.size(), args.empty() ? nullptr : &args.front())); return handle_scope.Escape(ret); } }; @@ -76,7 +77,8 @@ struct V8FunctionInvoker { v8::Local context = holder->CreationContext(); v8::Context::Scope context_scope(context); std::vector> args { ConvertToV8(isolate, raw)... }; - holder->Call(holder, args.size(), &args.front()); + holder->Call( + holder, args.size(), args.empty() ? nullptr : &args.front()); } }; @@ -97,8 +99,8 @@ struct V8FunctionInvoker { v8::Context::Scope context_scope(context); std::vector> args { ConvertToV8(isolate, raw)... }; v8::Local result; - auto maybe_result = - holder->Call(context, holder, args.size(), &args.front()); + auto maybe_result = holder->Call( + context, holder, args.size(), args.empty() ? nullptr : &args.front()); if (maybe_result.ToLocal(&result)) Converter::FromV8(isolate, result, &ret); return ret;