Changeset 15473 in webkit for trunk/JavaScriptCore/API
- Timestamp:
- Jul 16, 2006, 6:48:27 PM (19 years ago)
- Location:
- trunk/JavaScriptCore/API
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/API/JSCallbackObject.cpp
r15469 r15473 108 108 109 109 if (__JSClass::StaticValuesTable* staticValues = jsClass->staticValues) { 110 if (StaticValueEntry* entry = staticValues->get(propertyName.ustring().rep())) { 111 if (entry->getProperty) { 112 slot.setCustom(this, staticValueGetter); 113 return true; 114 } 110 if (staticValues->contains(propertyName.ustring().rep())) { 111 slot.setCustom(this, staticValueGetter); 112 return true; 115 113 } 116 114 } … … 149 147 if (entry->attributes & kJSPropertyAttributeReadOnly) 150 148 return; 151 if (JSObjectSetPropertyCallback setProperty = entry->setProperty) {152 if (setProperty(context, thisRef, propertyNameRef, valueRef, toRef(exec->exceptionSlot())))153 return;154 }149 if (JSObjectSetPropertyCallback setProperty = entry->setProperty) 150 setProperty(context, thisRef, propertyNameRef, valueRef, toRef(exec->exceptionSlot())); 151 else 152 throwError(exec, ReferenceError, "Writable static value property defined with NULL setProperty callback."); 155 153 } 156 154 } … … 393 391 return toJS(value); 394 392 395 return jsUndefined();393 return throwError(exec, ReferenceError, "Static value property defined with NULL getProperty callback."); 396 394 } 397 395 … … 407 405 if (__JSClass::StaticFunctionsTable* staticFunctions = jsClass->staticFunctions) { 408 406 if (StaticFunctionEntry* entry = staticFunctions->get(propertyName.ustring().rep())) { 409 JSObject* o = new JSCallbackFunction(exec, entry->callAsFunction, propertyName); 410 thisObj->putDirect(propertyName, o, entry->attributes); 411 return o; 412 } 413 } 414 } 415 416 return jsUndefined(); 407 if (JSObjectCallAsFunctionCallback callAsFunction = entry->callAsFunction) { 408 JSObject* o = new JSCallbackFunction(exec, callAsFunction, propertyName); 409 thisObj->putDirect(propertyName, o, entry->attributes); 410 return o; 411 } 412 } 413 } 414 } 415 416 return throwError(exec, ReferenceError, "Static function property defined with NULL callAsFunction callback."); 417 417 } 418 418 … … 430 430 return toJS(value); 431 431 432 return jsUndefined();432 return throwError(exec, ReferenceError, "hasProperty callback returned true for a property that doesn't exist."); 433 433 } 434 434 -
trunk/JavaScriptCore/API/JSObjectRef.h
r15469 r15473 263 263 @field name A null-terminated UTF8 string containing the property's name. 264 264 @field getProperty A JSObjectGetPropertyCallback to invoke when getting the property's value. 265 @field setProperty A JSObjectSetPropertyCallback to invoke when setting the property's value. 265 @field setProperty A JSObjectSetPropertyCallback to invoke when setting the property's value. May be NULL if the ReadOnly attribute is set. 266 266 @field attributes A logically ORed set of JSPropertyAttributes to give to the property. 267 267 */ -
trunk/JavaScriptCore/API/minidom.js
r15133 r15473 166 166 } 167 167 168 function shouldBe(a, b) 169 { 170 var evalA; 171 try { 172 evalA = eval(a); 173 } catch(e) { 174 evalA = e; 175 } 176 177 if (evalA == b || isNaN(evalA) && typeof evalA == 'number' && isNaN(b) && typeof b == 'number') 178 print("PASS: " + a + " should be " + b + " and is.", "green"); 179 else 180 print("__FAIL__: " + a + " should be " + b + " but instead is " + evalA + ".", "red"); 181 } 182 168 183 function test() 169 184 { … … 222 237 print("caught: " + e); 223 238 } 239 240 oldNodeType = node.nodeType; 241 node.nodeType = 1; 242 shouldBe("node.nodeType", oldNodeType); 224 243 225 244 /* -
trunk/JavaScriptCore/API/testapi.c
r15469 r15473 115 115 if (JSStringIsEqualToUTF8CString(propertyName, "alwaysOne") 116 116 || JSStringIsEqualToUTF8CString(propertyName, "cantFind") 117 || JSStringIsEqualToUTF8CString(propertyName, "myPropertyName")) { 117 || JSStringIsEqualToUTF8CString(propertyName, "myPropertyName") 118 || JSStringIsEqualToUTF8CString(propertyName, "hasPropertyLie")) { 118 119 return true; 119 120 } … … 243 244 } 244 245 246 static JSStaticValue evilStaticValues[] = { 247 { "nullGetSet", 0, 0, kJSPropertyAttributeNone }, 248 { 0, 0, 0, 0 } 249 }; 250 251 static JSStaticFunction evilStaticFunctions[] = { 252 { "nullCall", 0, kJSPropertyAttributeNone }, 253 { 0, 0, 0 } 254 }; 255 245 256 JSClassDefinition MyObject_definition = { 246 257 0, … … 249 260 NULL, 250 261 251 NULL,252 NULL,262 evilStaticValues, 263 evilStaticFunctions, 253 264 254 265 MyObject_initialize, -
trunk/JavaScriptCore/API/testapi.js
r15462 r15473 40 40 } 41 41 42 function shouldThrow(a) 43 { 44 var result = "__FAIL__: " + a + " did not throw an exception."; 45 46 var evalA; 47 try { 48 eval(a); 49 } catch(e) { 50 result = "PASS: " + a + " threw: " + e; 51 } 52 53 print(result); 54 } 55 42 56 shouldBe("typeof MyObject", "function"); // our object implements 'call' 43 57 MyObject.cantFind = 1; … … 69 83 : "__FAIL__: MyObject.regularType was not enumerated"); 70 84 85 myObject = new MyObject(); 86 71 87 shouldBe("delete MyObject.regularType", true); 72 88 shouldBe("MyObject.regularType", undefined); 73 89 shouldBe("MyObject(0)", 1); 74 90 shouldBe("MyObject()", undefined); 75 shouldBe("typeof new MyObject()", "object");91 shouldBe("typeof myObject", "object"); 76 92 shouldBe("MyObject ? 1 : 0", true); // toBoolean 77 93 shouldBe("+MyObject", 1); // toNumber … … 83 99 shouldBe("typeof constructedObject", "object"); 84 100 shouldBe("constructedObject.value", 1); 85 shouldBe(" (new MyObject())instanceof MyObject", true);101 shouldBe("myObject instanceof MyObject", true); 86 102 shouldBe("(new Object()) instanceof MyObject", false); 103 104 shouldThrow("MyObject.nullGetSet = 1"); 105 shouldThrow("MyObject.nullGetSet"); 106 shouldThrow("MyObject.nullCall()"); 107 shouldThrow("MyObject.hasPropertyLie");
Note:
See TracChangeset
for help on using the changeset viewer.