Skip to content
This repository has been archived by the owner on Oct 15, 2020. It is now read-only.

Commit

Permalink
deps,src,test: fixing lint errors
Browse files Browse the repository at this point in the history
PR-URL: #465
Reviewed-By: Kyle Farnung <kfarnung@microsoft.com>
Reviewed-By: Seth Brenith <sethb@microsoft.com>
  • Loading branch information
MSLaguana committed Feb 14, 2018
1 parent 3785924 commit c057e77
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 34 deletions.
16 changes: 8 additions & 8 deletions deps/chakrashim/src/v8arraybuffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,15 @@ ArrayBuffer::Contents ArrayBuffer::GetContents() {
}

Contents contents;
if (buffer == nullptr)
{
if (buffer == nullptr) {
CHAKRA_ASSERT(bufferLength == 0);
// v8's version of ArrayBuffer will return a non-null pointer even in the case of
// an empty ArrayBuffer, and this behavior is relied upon by some of the i18n code.
// To support that, if we would otherwise return a null buffer, as long as the
// length is 0 we instead return a valid pointer to something, on the understanding
// that nobody will actually try to read it.
buffer = (BYTE*)this;
// v8's version of ArrayBuffer will return a non-null pointer even in the
// case of an empty ArrayBuffer, and this behavior is relied upon by some
// of the i18n code. To support that, if we would otherwise return a null
// buffer, as long as the length is 0 we instead return a valid pointer
// to something, on the understanding that nobody will actually try to
// read it.
buffer = reinterpret_cast<BYTE*>(this);
}
contents.data_ = buffer;
contents.byte_length_ = bufferLength;
Expand Down
12 changes: 9 additions & 3 deletions deps/chakrashim/src/v8promise.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,28 @@ Promise::Promise() { }

Local<Value> Promise::Result() {
JsValueRef value;
if (jsrt::GetProperty(this, jsrt::CachedPropertyIdRef::value, &value) != JsNoError) {
if (jsrt::GetProperty(
this,
jsrt::CachedPropertyIdRef::value,
&value) != JsNoError) {
return Local<Value>();
}
return Local<Value>::New(value);
}

Promise::PromiseState Promise::State() {
JsValueRef state;
if (jsrt::GetProperty(this, jsrt::CachedPropertyIdRef::state, &state) != JsNoError) {
if (jsrt::GetProperty(
this,
jsrt::CachedPropertyIdRef::state,
&state) != JsNoError) {
return PromiseState::kPending;
}
int stateNumber;
if (JsNumberToInt(state, &stateNumber) != JsNoError) {
return PromiseState::kPending;
}
switch(stateNumber) {
switch (stateNumber) {
case 1: return PromiseState::kFulfilled;
case 2: return PromiseState::kRejected;
default: return PromiseState::kPending;
Expand Down
73 changes: 56 additions & 17 deletions deps/chakrashim/src/v8resolver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,33 @@ namespace v8 {
return Local<Resolver>();
}

if (jsrt::SetProperty(resolver, jsrt::CachedPropertyIdRef::promise, promise) != JsNoError) {
if (jsrt::SetProperty(
resolver,
jsrt::CachedPropertyIdRef::promise,
promise) != JsNoError) {
return Local<Resolver>();
}

if (jsrt::SetProperty(resolver, jsrt::CachedPropertyIdRef::resolve, resolve) != JsNoError) {
if (jsrt::SetProperty(
resolver,
jsrt::CachedPropertyIdRef::resolve,
resolve) != JsNoError) {
return Local<Resolver>();
}

if (jsrt::SetProperty(resolver, jsrt::CachedPropertyIdRef::reject, reject) != JsNoError) {
if (jsrt::SetProperty(
resolver,
jsrt::CachedPropertyIdRef::reject,
reject) != JsNoError) {
return Local<Resolver>();
}

JsValueRef state;
jsrt::UintToValue(0, &state);
if (jsrt::SetProperty(promise, jsrt::CachedPropertyIdRef::value, state) != JsNoError) {
if (jsrt::SetProperty(
promise,
jsrt::CachedPropertyIdRef::value,
state) != JsNoError) {
return Local<Resolver>();
}

Expand All @@ -62,7 +74,10 @@ namespace v8 {

Local<Promise> Resolver::GetPromise() {
JsValueRef promise;
if (jsrt::GetProperty(this, jsrt::CachedPropertyIdRef::promise, &promise) != JsNoError) {
if (jsrt::GetProperty(
this,
jsrt::CachedPropertyIdRef::promise,
&promise) != JsNoError) {
return Local<Promise>();
}
return Local<Promise>::New(static_cast<Promise*>(promise));
Expand All @@ -74,28 +89,40 @@ namespace v8 {

Maybe<bool> Resolver::Resolve(Local<Context> context, Local<Value> value) {
JsValueRef resolve;
if (jsrt::GetProperty(this, jsrt::CachedPropertyIdRef::resolve, &resolve) != JsNoError) {
if (jsrt::GetProperty(
this,
jsrt::CachedPropertyIdRef::resolve,
&resolve) != JsNoError) {
return Nothing<bool>();
}

JsValueRef promise;
if (jsrt::GetProperty(this, jsrt::CachedPropertyIdRef::promise, &promise) != JsNoError) {
if (jsrt::GetProperty(
this,
jsrt::CachedPropertyIdRef::promise,
&promise) != JsNoError) {
return Nothing<bool>();
}

if (jsrt::SetProperty(promise, jsrt::CachedPropertyIdRef::value, *value) != JsNoError) {
if (jsrt::SetProperty(
promise,
jsrt::CachedPropertyIdRef::value,
*value) != JsNoError) {
return Nothing<bool>();
}

JsValueRef state;
jsrt::UintToValue(1, &state);
if (jsrt::SetProperty(promise, jsrt::CachedPropertyIdRef::value, state) != JsNoError) {
if (jsrt::SetProperty(
promise,
jsrt::CachedPropertyIdRef::value,
state) != JsNoError) {
return Nothing<bool>();
}

JsValueRef result;
JsValueRef args[2];
args[0] = this; // ? What is the "this" of the resolver here?
args[0] = this; // ? What is the "this" of the resolver here?
args[1] = reinterpret_cast<JsValueRef>(*value);

if (JsCallFunction(resolve, args, 2, &result) != JsNoError) {
Expand All @@ -112,28 +139,40 @@ namespace v8 {

Maybe<bool> Resolver::Reject(Local<Context> context, Local<Value> value) {
JsValueRef reject;
if (jsrt::GetProperty(this, jsrt::CachedPropertyIdRef::reject, &reject) != JsNoError) {
if (jsrt::GetProperty(
this,
jsrt::CachedPropertyIdRef::reject,
&reject) != JsNoError) {
return Nothing<bool>();
}

JsValueRef promise;
if (jsrt::GetProperty(this, jsrt::CachedPropertyIdRef::promise, &promise) != JsNoError) {
if (jsrt::GetProperty(
this,
jsrt::CachedPropertyIdRef::promise,
&promise) != JsNoError) {
return Nothing<bool>();
}

if (jsrt::SetProperty(promise, jsrt::CachedPropertyIdRef::value, *value) != JsNoError) {
if (jsrt::SetProperty(
promise,
jsrt::CachedPropertyIdRef::value,
*value) != JsNoError) {
return Nothing<bool>();
}

JsValueRef state;
jsrt::UintToValue(2, &state);
if (jsrt::SetProperty(promise, jsrt::CachedPropertyIdRef::value, state) != JsNoError) {
if (jsrt::SetProperty(
promise,
jsrt::CachedPropertyIdRef::value,
state) != JsNoError) {
return Nothing<bool>();
}

JsValueRef result;
JsValueRef args[2];
args[0] = this; // ? What is the "this" of the resolver here?
args[0] = this; // ? What is the "this" of the resolver here?
args[1] = reinterpret_cast<JsValueRef>(*value);

if (JsCallFunction(reject, args, 2, &result) != JsNoError) {
Expand Down
9 changes: 5 additions & 4 deletions src/node_api_jsrt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2119,15 +2119,16 @@ napi_status napi_open_callback_scope(napi_env env,
node::async_context* node_async_context =
reinterpret_cast<node::async_context*>(async_context_handle);

// TODO: It'd be nice if we could remove the dependency on v8::*
// TODO(MSLaguana): It'd be nice if we could remove the dependency on v8::*
// from here by changing node::CallbackScope's signature
v8::Local<v8::Object> resource =
v8impl::V8LocalValueFromJsValue(resource_object).As<v8::Object>();

*result = reinterpret_cast<napi_callback_scope>(
new node::InternalCallbackScope(node::Environment::GetCurrent(env->isolate),
resource,
*node_async_context));
new node::InternalCallbackScope(
node::Environment::GetCurrent(env->isolate),
resource,
*node_async_context));

napi_clear_last_error();
return napi_ok;
Expand Down
2 changes: 1 addition & 1 deletion src/node_contextify.cc
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ void ContextifyContext::PropertySetterCallback(

ctx->sandbox()->Set(property, value);
#else
bool is_declared =
bool is_declared =
ctx->global_proxy()->HasRealNamedProperty(ctx->context(),
property).FromJust();

Expand Down
3 changes: 2 additions & 1 deletion test/cctest/node_test_fixture.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ class EnvironmentTestFixture : public NodeTestFixture {
Env(const v8::HandleScope& handle_scope, const Argv& argv) {
auto isolate = handle_scope.GetIsolate();
#if ENABLE_TTD_NODE
context_ = node::NewContext(isolate, false); // TODO: should we support TTD in cctest?
// TODO(MSLaguana): should we support TTD in cctest?
context_ = node::NewContext(isolate, false);
#else
context_ = node::NewContext(isolate);
#endif
Expand Down

0 comments on commit c057e77

Please sign in to comment.