Skip to content

Commit

Permalink
add PropertyDescriptor check
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam Shull committed Aug 10, 2010
1 parent 4712d59 commit 9a38dcc
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
34 changes: 32 additions & 2 deletions src/node-proxy.cc
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -197,6 +197,36 @@ Handle<Value> NodeProxy::ValidateProxyHandler(Local<Object> handler) {
return True(); return True();
} }


/**
*
*
*/
Local<Value> NodeProxy::CorrectPropertyDescriptor(Local<Object> pd) {
HandleScope scope;
Local<Value> undef;

//pd->Set(NodeProxy::value, pd->Has(NodeProxy::value) ? pd->Get(NodeProxy::value) : undef);
pd->Set(NodeProxy::writable, pd->Has(NodeProxy::writable) ? pd->Get(NodeProxy::writable)->ToBoolean() : True());
pd->Set(NodeProxy::enumerable, pd->Has(NodeProxy::enumerable) ? pd->Get(NodeProxy::enumerable)->ToBoolean() : True());
pd->Set(NodeProxy::configurable, pd->Has(NodeProxy::configurable) ? pd->Get(NodeProxy::configurable)->ToBoolean() : True());

if (pd->Has(NodeProxy::get)) {
Local<Value> getter = pd->Get(NodeProxy::get);
pd->Set(NodeProxy::get, getter->IsFunction() ? getter : undef);
} else {
pd->Set(NodeProxy::get, undef);
}

if (pd->Has(NodeProxy::set)) {
Local<Value> setter = pd->Get(NodeProxy::set);
pd->Set(NodeProxy::set, setter->IsFunction() ? setter : undef);
} else {
pd->Set(NodeProxy::set, undef);
}

return pd;
}

/** /**
* Used for creating a shallow copy of an object * Used for creating a shallow copy of an object
* *
Expand Down Expand Up @@ -709,15 +739,15 @@ Handle<Value> NodeProxy::DefineProperty(const Arguments& args) {
Local<Object> desc = handler->Get(name)->ToObject(); Local<Object> desc = handler->Get(name)->ToObject();


if (desc->Get(NodeProxy::configurable)->BooleanValue()) { if (desc->Get(NodeProxy::configurable)->BooleanValue()) {
return Boolean::New(handler->Set(name, args[2])); return Boolean::New(handler->Set(name, CorrectPropertyDescriptor(args[2]->ToObject())));
} }


return False(); return False();
} }


Local<Function> def = Local<Function>::Cast(handler->Get(NodeProxy::defineProperty)); Local<Function> def = Local<Function>::Cast(handler->Get(NodeProxy::defineProperty));


Local<Value> argv[2] = {args[1], args[2]}; Local<Value> argv[2] = {args[1], CorrectPropertyDescriptor(args[2]->ToObject())};


return def->Call(obj, 2, argv)->ToBoolean(); return def->Call(obj, 2, argv)->ToBoolean();
} }
Expand Down
5 changes: 4 additions & 1 deletion src/node-proxy.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ class NodeProxy {
NodeProxy(); NodeProxy();


~NodeProxy(); ~NodeProxy();

static Handle<Integer> GetPropertyAttributeFromPropertyDescriptor(Local<Object> pd);

static Local<Value> CorrectPropertyDescriptor(Local<Object> pd);


static Handle<Value> ValidateProxyHandler(Local<Object> handler); static Handle<Value> ValidateProxyHandler(Local<Object> handler);


Expand Down Expand Up @@ -149,7 +153,6 @@ class NodeProxy {
static Handle<Boolean> QueryNamedProperty(Local<String> name, const AccessorInfo &info); static Handle<Boolean> QueryNamedProperty(Local<String> name, const AccessorInfo &info);


static Handle<Integer> QueryNamedPropertyInteger(Local<String> name, const AccessorInfo &info); static Handle<Integer> QueryNamedPropertyInteger(Local<String> name, const AccessorInfo &info);
static Handle<Integer> GetPropertyAttributeFromPropertyDescriptor(Local<Object> pd);


static Handle<Boolean> DeleteNamedProperty(Local<String> name, const AccessorInfo &info); static Handle<Boolean> DeleteNamedProperty(Local<String> name, const AccessorInfo &info);


Expand Down

0 comments on commit 9a38dcc

Please sign in to comment.