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

Commit

Permalink
chakrashim: fix ObjectTemplate callbacks compat
Browse files Browse the repository at this point in the history
Many ObjectTemplate property callback handlings are not fully
v8-compatible. Noteably when a callback does not intercept (returns empty
handle), chakrashim should fallback to default JS behaviro. However most
of the shim code did not or did incorrectly. This change fixes them.

Also fixed Object::Has and Object::Delete issue. They only accepted normal
name types -- String/Symbol. Changed to use GetPropertyIdFromValue so they
accept other types, e.g. an Integer.

PR-URL: #37
Reviewed-By: Sandeep Agarwal <Agarwal.Sandeep@microsoft.com>
Reviewed-By: Kunal Pathak <Kunal.Pathak@microsoft.com>
  • Loading branch information
Jianchun Xu committed Mar 15, 2016
1 parent 75ace7d commit 878b8fd
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 236 deletions.
3 changes: 1 addition & 2 deletions deps/chakrashim/src/v8chakra.h
Expand Up @@ -116,8 +116,7 @@ class Utils {

static JsValueRef HasPropertyHandler(
JsValueRef *arguments,
unsigned short argumentCount,
bool checkInPrototype);
unsigned short argumentCount);
static JsValueRef CALLBACK HasCallback(
JsValueRef callee,
bool isConstructCall,
Expand Down
18 changes: 14 additions & 4 deletions deps/chakrashim/src/v8object.cc
Expand Up @@ -239,8 +239,13 @@ Local<Value> Object::GetOwnPropertyDescriptor(Local<String> key) {
}

Maybe<bool> Object::Has(Local<Context> context, Local<Value> key) {
JsPropertyIdRef idRef;
if (GetPropertyIdFromValue((JsValueRef)*key, &idRef) != JsNoError) {
return Nothing<bool>();
}

bool result;
if (jsrt::HasProperty(this, *key, &result) != JsNoError) {
if (JsHasProperty(this, idRef, &result) != JsNoError) {
return Nothing<bool>();
}

Expand All @@ -252,12 +257,17 @@ bool Object::Has(Handle<Value> key) {
}

Maybe<bool> Object::Delete(Local<Context> context, Local<Value> key) {
JsValueRef resultRef;
if (jsrt::DeleteProperty(this, *key, &resultRef) != JsNoError) {
JsPropertyIdRef idRef;
if (GetPropertyIdFromValue((JsValueRef)*key, &idRef) != JsNoError) {
return Nothing<bool>();
}

JsValueRef result;
if (JsDeleteProperty(this, idRef, false, &result) != JsNoError) {
return Nothing<bool>();
}

return Just(Local<Value>(resultRef)->BooleanValue());
return Just(Local<Value>(result)->BooleanValue());
}

bool Object::Delete(Handle<Value> key) {
Expand Down

0 comments on commit 878b8fd

Please sign in to comment.