From f8b9a66ead386034e6cc60e83d4a024f2a749c1e Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 17 Mar 2016 21:55:02 +0900 Subject: [PATCH 1/2] docs: Make it clear image.getNativeHandle is OS X only --- docs/api/native-image.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/docs/api/native-image.md b/docs/api/native-image.md index c33f35c6fe51..e0c3ae466248 100644 --- a/docs/api/native-image.md +++ b/docs/api/native-image.md @@ -133,11 +133,14 @@ Returns a [Buffer][buffer] that contains the image's `JPEG` encoded data. Returns the data URL of the image. -### `image.getNativeHandle()` +### `image.getNativeHandle()` _OS X_ -Returns a pointer to an underlying native type (encoded as a [Buffer][buffer]) which can be used with native APIs. Note that in many cases, this pointer is a weak pointer to the underlying native image not a copy, so you _must_ ensure that the associated `nativeImage` instance is kept around. +Returns a [Buffer][buffer] that stores C pointer to underlying native handle of +the image. On OS X, a pointer to `NSImage` instance would be returned. -Returns a [Buffer][buffer] that represents a pointer to a native type - on OS X, this type is an NSImage object. +Notice that the returned pointer is a weak pointer to the underlying native +image instead of a copy, so you _must_ ensure that the associated +`nativeImage` instance is kept around. ### `image.isEmpty()` From 939d69df6e0a97ad67838f4f01888fb0f86e15de Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 17 Mar 2016 22:01:31 +0900 Subject: [PATCH 2/2] Throw error with message of "Not implemented". --- atom/common/api/atom_api_native_image.cc | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/atom/common/api/atom_api_native_image.cc b/atom/common/api/atom_api_native_image.cc index 81db35715bcd..3dda326f59fd 100644 --- a/atom/common/api/atom_api_native_image.cc +++ b/atom/common/api/atom_api_native_image.cc @@ -184,8 +184,7 @@ mate::ObjectTemplateBuilder NativeImage::GetObjectTemplateBuilder( template_.Reset(isolate, mate::ObjectTemplateBuilder(isolate) .SetMethod("toPng", &NativeImage::ToPNG) .SetMethod("toJpeg", &NativeImage::ToJPEG) - .SetMethod("getNativeHandle", - &NativeImage::GetNativeHandle) + .SetMethod("getNativeHandle", &NativeImage::GetNativeHandle) .SetMethod("toDataURL", &NativeImage::ToDataURL) .SetMethod("toDataUrl", &NativeImage::ToDataURL) // deprecated. .SetMethod("isEmpty", &NativeImage::IsEmpty) @@ -223,21 +222,18 @@ std::string NativeImage::ToDataURL() { return data_url; } -v8::Local NativeImage::GetNativeHandle( - v8::Isolate* isolate, - mate::Arguments* args) { -void* ptr = NULL; +v8::Local NativeImage::GetNativeHandle(v8::Isolate* isolate, + mate::Arguments* args) { #if defined(OS_MACOSX) - ptr = reinterpret_cast(image_.AsNSImage()); + NSImage* ptr = image_.AsNSImage(); + return node::Buffer::Copy( + isolate, + reinterpret_cast(ptr), + sizeof(void*)).ToLocalChecked(); #else - args->ThrowError(); + args->ThrowError("Not implemented"); return v8::Undefined(isolate); #endif - - return node::Buffer::Copy( - isolate, - reinterpret_cast(ptr), - sizeof(void*)).ToLocalChecked(); } bool NativeImage::IsEmpty() {