Merge pull request #10162 from electron/native-image-crashes

Fix crashes due to using Debug version of libc++
This commit is contained in:
Cheng Zhao 2017-07-31 17:11:28 +09:00 committed by GitHub
commit 761eca052a
4 changed files with 19 additions and 11 deletions

View file

@ -268,11 +268,10 @@ v8::Local<v8::Value> NativeImage::ToPNG(mate::Arguments* args) {
const SkBitmap bitmap = const SkBitmap bitmap =
image_.AsImageSkia().GetRepresentation(scale_factor).sk_bitmap(); image_.AsImageSkia().GetRepresentation(scale_factor).sk_bitmap();
std::unique_ptr<std::vector<unsigned char>> encoded( std::vector<unsigned char> encoded;
new std::vector<unsigned char>()); gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, false, &encoded);
gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, false, encoded.get()); const char* data = reinterpret_cast<char*>(encoded.data());
const char* data = reinterpret_cast<char*>(encoded->data()); size_t size = encoded.size();
size_t size = encoded->size();
return node::Buffer::Copy(args->isolate(), data, size).ToLocalChecked(); return node::Buffer::Copy(args->isolate(), data, size).ToLocalChecked();
} }
@ -292,6 +291,8 @@ v8::Local<v8::Value> NativeImage::ToBitmap(mate::Arguments* args) {
v8::Local<v8::Value> NativeImage::ToJPEG(v8::Isolate* isolate, int quality) { v8::Local<v8::Value> NativeImage::ToJPEG(v8::Isolate* isolate, int quality) {
std::vector<unsigned char> output; std::vector<unsigned char> output;
gfx::JPEG1xEncodedDataFromImage(image_, quality, &output); gfx::JPEG1xEncodedDataFromImage(image_, quality, &output);
if (output.empty())
return node::Buffer::New(isolate, 0).ToLocalChecked();
return node::Buffer::Copy( return node::Buffer::Copy(
isolate, isolate,
reinterpret_cast<const char*>(&output.front()), reinterpret_cast<const char*>(&output.front()),

View file

@ -56,7 +56,8 @@ struct V8FunctionInvoker<v8::Local<v8::Value>(ArgTypes...)> {
v8::Local<v8::Context> context = holder->CreationContext(); v8::Local<v8::Context> context = holder->CreationContext();
v8::Context::Scope context_scope(context); v8::Context::Scope context_scope(context);
std::vector<v8::Local<v8::Value>> args { ConvertToV8(isolate, raw)... }; std::vector<v8::Local<v8::Value>> args { ConvertToV8(isolate, raw)... };
v8::Local<v8::Value> ret(holder->Call(holder, args.size(), &args.front())); v8::Local<v8::Value> ret(holder->Call(
holder, args.size(), args.empty() ? nullptr : &args.front()));
return handle_scope.Escape(ret); return handle_scope.Escape(ret);
} }
}; };
@ -76,7 +77,8 @@ struct V8FunctionInvoker<void(ArgTypes...)> {
v8::Local<v8::Context> context = holder->CreationContext(); v8::Local<v8::Context> context = holder->CreationContext();
v8::Context::Scope context_scope(context); v8::Context::Scope context_scope(context);
std::vector<v8::Local<v8::Value>> args { ConvertToV8(isolate, raw)... }; std::vector<v8::Local<v8::Value>> 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<ReturnType(ArgTypes...)> {
v8::Context::Scope context_scope(context); v8::Context::Scope context_scope(context);
std::vector<v8::Local<v8::Value>> args { ConvertToV8(isolate, raw)... }; std::vector<v8::Local<v8::Value>> args { ConvertToV8(isolate, raw)... };
v8::Local<v8::Value> result; v8::Local<v8::Value> result;
auto maybe_result = auto maybe_result = holder->Call(
holder->Call(context, holder, args.size(), &args.front()); context, holder, args.size(), args.empty() ? nullptr : &args.front());
if (maybe_result.ToLocal(&result)) if (maybe_result.ToLocal(&result))
Converter<ReturnType>::FromV8(isolate, result, &ret); Converter<ReturnType>::FromV8(isolate, result, &ret);
return ret; return ret;

View file

@ -62,16 +62,17 @@
if (query.invert) mocha.invert(); if (query.invert) mocha.invert();
// Read all test files. // Read all test files.
var walker = require('walkdir').walk(require('path').dirname(__dirname), { var walker = require('walkdir').walk(path.dirname(__dirname), {
no_recurse: true no_recurse: true
}); });
walker.on('file', function(file) { 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); mocha.addFile(file);
}); });
walker.on('end', function() { walker.on('end', function() {
mocha.addFile(path.resolve(__dirname, '..', 'api-crash-reporter-spec.js'))
var runner = mocha.run(function() { var runner = mocha.run(function() {
if (isCi && runner.hasOnly) { if (isCi && runner.hasOnly) {
try { try {

View file

@ -141,6 +141,10 @@ app.on('ready', function () {
}) })
if (chosen === 0) window.destroy() 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 // For session's download test, listen 'will-download' event in browser, and
// reply the result to renderer for verifying // reply the result to renderer for verifying