This repository has been archived by the owner on Jul 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Update bindings for io.js 3.0.0 #1054
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
d96ad37
Update to io.js 3.0.0, use nan 2.0
saper acd67bf
Nan::ReturnValue.Set() needs no Nan::New on primitive types
saper e1191f5
Use NAN_MODULE_INIT for exports, use Nan::HandleScope
saper a139513
Remove unnecessary empty return;
saper 7d62f68
Use As<>() instead of Cast() where appropriate
saper 9cadef6
Robust check of provided JS options
saper 645ee72
Use Nan::NewInstance() for constructors
saper 9a8f905
No need for escapable scope in Boolean::get_js_object()
saper f129ff3
bridge operator() does not need escapable scope
saper 8420fd9
Add comments to indicate V8 context
saper 4ed4739
Add explicit Local<> scope for wrapper construction
saper bf9f6ec
Change obj->XxxValue() to Nan::To<xxx>() in binding.cpp
saper a130dae
Cast received values to <v8::Object> once type confirmed
saper c949452
Change obj->XxxValue() to Nan::To<xxx>() in sass_types
saper 0604223
Throw more specific exceptions
saper File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,12 +3,18 @@ | |
#include <string.h> | ||
#include "create_string.h" | ||
|
||
char* create_string(Local<Value> value) { | ||
if (value->IsNull() || !value->IsString()) { | ||
char* create_string(Nan::MaybeLocal<v8::Value> maybevalue) { | ||
v8::Local<v8::Value> value; | ||
|
||
if (maybevalue.ToLocal(&value)) { | ||
if (value->IsNull() || !value->IsString()) { | ||
return 0; | ||
} | ||
} else { | ||
return 0; | ||
} | ||
|
||
String::Utf8Value string(value); | ||
v8::String::Utf8Value string(value); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
char *str = (char *)malloc(string.length() + 1); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And it would be better if you made it return a pointer to a heap allocated |
||
strcpy(str, *string); | ||
return str; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could use the
Maybe
API instead of dangerous null pointers. This would bereturn Nan::Nothing();
, the other casereturn Nan::Just(str);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately we are leaving a nice V8 world here:
create_string() pointers are being directly fed into C structures.
In fact this function exists only because the libsass C API insists
that almost all (char *) pointers should be heap allocated, because it
says it frees them (I think this API is incorrect, but that's another story).
But ~Utf8String() may crash if someone free()'s that underlying string, am I correct?
And if the string fits n str_st_ it can't be free()d.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is correct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll revisit it later - we might need to review
create_string()
anyway to better comply with libsass API.For now I have more issues to worry than V8 sending me wrong UTF-8 :)