Permalink
Browse files

add PropertyDescriptor check

  • Loading branch information...
samshull committed Aug 10, 2010
1 parent 4712d59 commit 9a38dcc9c3b9b004b9864e8d48b6baa7171394f6
Showing with 36 additions and 3 deletions.
  1. +32 −2 src/node-proxy.cc
  2. +4 −1 src/node-proxy.h
View
@@ -197,6 +197,36 @@ Handle<Value> NodeProxy::ValidateProxyHandler(Local<Object> handler) {
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
*
@@ -709,15 +739,15 @@ Handle<Value> NodeProxy::DefineProperty(const Arguments& args) {
Local<Object> desc = handler->Get(name)->ToObject();
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();
}
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();
}
View
@@ -115,6 +115,10 @@ class NodeProxy {
NodeProxy();
~NodeProxy();
+
+ static Handle<Integer> GetPropertyAttributeFromPropertyDescriptor(Local<Object> pd);
+
+ static Local<Value> CorrectPropertyDescriptor(Local<Object> pd);
static Handle<Value> ValidateProxyHandler(Local<Object> handler);
@@ -149,7 +153,6 @@ class NodeProxy {
static Handle<Boolean> QueryNamedProperty(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);

0 comments on commit 9a38dcc

Please sign in to comment.