Skip to content

Commit bfd2d23

Browse files
author
Bradley Meck
committed
readme fix
1 parent 650111c commit bfd2d23

File tree

2 files changed

+58
-28
lines changed

2 files changed

+58
-28
lines changed

README.TXT

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Code
2828
Output
2929

3030
hello
31-
world!
31+
world!
3232

3333
##uses
3434
1. Debugging - Show what is being accessed / set

overload.cc

Lines changed: 57 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ Handle<Value> WatchableNamedPropertySetter(
5252
) {
5353
HandleScope scope;
5454
//Grab the value of the property
55-
Handle<Object> holder=info.Holder();
55+
Handle<Object> holder = Handle<Object>::Cast(
56+
holder->GetInternalField(0)
57+
);
5658
Handle<Value> old_value;
5759
Handle<Value> had_value;
5860

@@ -71,7 +73,34 @@ Handle<Value> WatchableNamedPropertySetter(
7173
//Grab function and call (property,value)
7274
Handle<Value> data = holder->GetInternalField(2);
7375
Handle<Function> callback = Handle<Function>::Cast(data);
74-
Handle<Value> new_value = callback->Call(info.Holder(),4,values);
76+
Handle<Value> new_value = callback->Call(Holder,4,values);
77+
78+
holder->ForceSet(property,new_value);
79+
80+
//Return value is the return of the function call
81+
return scope.Close(new_value);
82+
}
83+
84+
Handle<Array> WatchableNamedPropertyEnumerator(
85+
const AccessorInfo& info
86+
) {
87+
HandleScope scope;
88+
//Grab the value of the property
89+
Handle<Object> holder = Handle<Object>::Cast(
90+
holder->GetInternalField(0)
91+
);
92+
Handle<Value> old_value;
93+
Handle<Value> had_value;
94+
95+
Handle<Array> names = holder->GetPropertyNames();
96+
97+
//Set up arguments
98+
Handle<Value> values[4] = {property,old_value,value,had_value};
99+
100+
//Grab function and call (property,value)
101+
Handle<Value> data = holder->GetInternalField(2);
102+
Handle<Function> callback = Handle<Function>::Cast(data);
103+
Handle<Value> new_value = callback->Call(holder,4,values);
75104

76105
holder->ForceSet(property,new_value);
77106

@@ -86,14 +115,15 @@ Handle<Value> WatchableIndexedPropertyGetter(
86115
HandleScope scope;
87116

88117
//Grab the value
89-
Handle<Object> holder=info.Holder();
118+
Handle<Object> holder = Handle<Object>::Cast(
119+
holder->GetInternalField(0)
120+
);
90121
Handle<Number> property = Number::New(index);
91122
Handle<Value> value;
92123
Handle<Value> had_value;
93124

94-
Handle<Object> indices = Handle<Object>::Cast(holder->GetInternalField(0));
95-
if( indices->Has(index) ) {
96-
value =indices->Get(index);
125+
if( holder->Has(index) ) {
126+
value = holder->Get(index);
97127
had_value = True();
98128
}
99129
else {
@@ -106,7 +136,7 @@ Handle<Value> WatchableIndexedPropertyGetter(
106136
//Grab function and call (property,value)
107137
Handle<Value> data = holder->GetInternalField(1);
108138
Handle<Function> callback = Handle<Function>::Cast(data);
109-
Handle<Value> new_value = callback->Call(info.Holder(),3,values);
139+
Handle<Value> new_value = callback->Call(holder,3,values);
110140

111141
//Return value is the return of the function call
112142
return scope.Close(new_value);
@@ -120,14 +150,15 @@ Handle<Value> WatchableIndexedPropertySetter(
120150
HandleScope scope;
121151

122152
//Grab the value
123-
Handle<Object> holder=info.Holder();
153+
Handle<Object> holder = Handle<Object>::Cast(
154+
holder->GetInternalField(0)
155+
);
124156
Handle<Number> property = Number::New(index);
125157
Handle<Value> had_value;
126158

127-
Handle<Object> indices = Handle<Object>::Cast(holder->GetInternalField(0));
128159
Handle<Value> old_value;
129-
if( indices->Has(index) ) {
130-
old_value = indices->Get(index);
160+
if( holder->Has(index) ) {
161+
old_value = holder->Get(index);
131162
had_value = True();
132163
}
133164
else {
@@ -141,15 +172,15 @@ Handle<Value> WatchableIndexedPropertySetter(
141172
//Grab function and call (property,value)
142173
Handle<Value> data = holder->GetInternalField(2);
143174
Handle<Function> callback = Handle<Function>::Cast(data);
144-
Handle<Value> new_value = callback->Call(info.Holder(),4,values);
175+
Handle<Value> new_value = callback->Call(holder,4,values);
145176

146-
indices->Set(index,new_value);
177+
holder->Set(index,new_value);
147178

148179
//Return value is the return of the function call
149180
return scope.Close(new_value);
150181
}
151182

152-
183+
Local<ObjectTemplate> object_template = ObjectTemplate::New();
153184
Handle<Value> Watchable(const Arguments& args) {
154185
HandleScope scope;
155186
Handle<Value> getter = args[0];
@@ -163,9 +194,18 @@ Handle<Value> Watchable(const Arguments& args) {
163194
else {
164195
return ThrowException(String::New("Getter callback must be a function"));
165196
}
197+
Handle<Object> watchable = object_template->NewInstance();
198+
watchable->SetInternalField(0,Object::New());
199+
watchable->SetInternalField(1,getter);
200+
watchable->SetInternalField(2,setter);
201+
return scope.Close(watchable);
202+
}
203+
204+
extern "C" void init (Handle<Object> target)
205+
{
206+
HandleScope scope;
166207
//Every one with a different callback needs a different template
167-
Local<ObjectTemplate> object_template = ObjectTemplate::New();
168-
//0 - Indices object
208+
//0 - Holder object - aka the real one
169209
//1 - Getter
170210
//2 - Setter
171211
//3 - Query
@@ -177,23 +217,13 @@ Handle<Value> Watchable(const Arguments& args) {
177217
,WatchableNamedPropertySetter
178218
// ,WatchableNamedPropertyQuery
179219
// ,WatchableNamedPropertyDeleter
180-
// ,WatchableNamedPropertyEnumerator
220+
,WatchableNamedPropertyEnumerator
181221
);
182222
object_template->SetIndexedPropertyHandler(
183223
WatchableIndexedPropertyGetter
184224
,WatchableIndexedPropertySetter
185225
,0,0,0
186226
);
187-
Handle<Object> watchable = object_template->NewInstance();
188-
watchable->SetInternalField(0,Object::New());
189-
watchable->SetInternalField(1,getter);
190-
watchable->SetInternalField(2,setter);
191-
return scope.Close(watchable);
192-
}
193-
194-
extern "C" void init (Handle<Object> target)
195-
{
196-
HandleScope scope;
197227
Local<FunctionTemplate> watchable_template = FunctionTemplate::New(Watchable);
198228
Local<Function> watchable = watchable_template->GetFunction();
199229
//Export

0 commit comments

Comments
 (0)