Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

Commit

Permalink
More napi fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jasongin committed Mar 2, 2017
1 parent d8e4cf2 commit b663dcf
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"dependencies": {
"async-foreach": "^0.1.3",
"chalk": "^1.1.1",
"cross-spawn": "^3.0.0",
"cross-spawn": "^5.1.0",
"gaze": "^1.0.0",
"get-stdin": "^4.0.1",
"glob": "^7.0.3",
Expand Down
17 changes: 14 additions & 3 deletions src/binding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ union Sass_Value* sass_custom_function(const union Sass_Value* s_args, Sass_Func
}

int ExtractOptions(napi_env e, napi_value options, void* cptr, sass_context_wrapper* ctx_w, bool is_file, bool is_sync) {
Napi::HandleScope scope;
// TODO: Enable napi_close_handle_scope during a pending exception state.
//Napi::HandleScope scope;

struct Sass_Context* ctx;

Expand Down Expand Up @@ -102,18 +103,26 @@ int ExtractOptions(napi_env e, napi_value options, void* cptr, sass_context_wrap
CHECK_NAPI_RESULT(napi_property_name(e, "indentWidth", &nameIndentWidth));
napi_value propertyIndentWidth;
CHECK_NAPI_RESULT(napi_get_property(e, options, nameIndentWidth, &propertyIndentWidth));
CHECK_NAPI_RESULT(napi_coerce_to_number(e, propertyIndentWidth, &propertyIndentWidth));
int32_t indent_width_len;
CHECK_NAPI_RESULT(napi_get_value_int32(e, propertyIndentWidth, &indent_width_len));

// TODO: Fix napi_coerce_to_number to coerce undefined to 0?
if (indent_width_len < 0) indent_width_len = 0;

ctx_w->indent = (char*)malloc(indent_width_len + 1);

napi_propertyname nameIndentType;
CHECK_NAPI_RESULT(napi_property_name(e, "indentType", &nameIndentType));
napi_value propertyIndentType;
CHECK_NAPI_RESULT(napi_get_property(e, options, nameIndentType, &propertyIndentType));
CHECK_NAPI_RESULT(napi_coerce_to_number(e, propertyIndentType, &propertyIndentType));
int32_t indent_type_len;
CHECK_NAPI_RESULT(napi_get_value_int32(e, propertyIndentType, &indent_type_len));

// TODO: Fix napi_coerce_to_number to coerce undefined to 0?
if (indent_type_len < 0) indent_type_len = 0;

strcpy(ctx_w->indent, std::string(
indent_width_len,
indent_type_len == 1 ? '\t' : ' '
Expand Down Expand Up @@ -283,7 +292,8 @@ int ExtractOptions(napi_env e, napi_value options, void* cptr, sass_context_wrap
}

void GetStats(napi_env env, sass_context_wrapper* ctx_w, Sass_Context* ctx) {
Napi::HandleScope scope;
// TODO: Enable napi_close_handle_scope during a pending exception state.
//Napi::HandleScope scope;

char** included_files = sass_context_get_included_files(ctx);
napi_value arr;
Expand Down Expand Up @@ -320,7 +330,8 @@ void GetStats(napi_env env, sass_context_wrapper* ctx_w, Sass_Context* ctx) {
}

int GetResult(napi_env env, sass_context_wrapper* ctx_w, Sass_Context* ctx, bool is_sync = false) {
Napi::HandleScope scope;
// TODO: Enable napi_close_handle_scope during a pending exception state.
//Napi::HandleScope scope;

int status = sass_context_get_error_status(ctx);
napi_value result;
Expand Down

0 comments on commit b663dcf

Please sign in to comment.