Changeset 10084 in webkit for trunk/JavaScriptCore/bindings/objc/WebScriptObject.mm
- Timestamp:
- Aug 7, 2005, 9:07:46 PM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/bindings/objc/WebScriptObject.mm
r9549 r10084 50 50 #define LOG_EXCEPTION(exec) \ 51 51 if (Interpreter::shouldPrintExceptions()) \ 52 printf("%s:%d:[%d] JavaScript exception: %s\n", __FILE__, __LINE__, getpid(), exec->exception() .toObject(exec).get(exec, messagePropertyName).toString(exec).ascii());52 printf("%s:%d:[%d] JavaScript exception: %s\n", __FILE__, __LINE__, getpid(), exec->exception()->toObject(exec)->get(exec, messagePropertyName)->toString(exec).ascii()); 53 53 54 54 @implementation WebScriptObjectPrivate … … 63 63 KJSDidExecuteFunctionPtr func = Instance::didExecuteFunction(); 64 64 if (func) 65 func (exec, static_cast< KJS::ObjectImp*>([obj _executionContext]->rootObjectImp()));66 } 67 68 - (void)_initializeWithObjectImp:( KJS::ObjectImp *)imp originExecutionContext:(const Bindings::RootObject *)originExecutionContext executionContext:(const Bindings::RootObject *)executionContext65 func (exec, static_cast<ObjectImp*>([obj _executionContext]->rootObjectImp())); 66 } 67 68 - (void)_initializeWithObjectImp:(ObjectImp *)imp originExecutionContext:(const Bindings::RootObject *)originExecutionContext executionContext:(const Bindings::RootObject *)executionContext 69 69 { 70 70 _private->imp = imp; … … 75 75 } 76 76 77 - _initWithObjectImp:( KJS::ObjectImp *)imp originExecutionContext:(const Bindings::RootObject *)originExecutionContext executionContext:(const Bindings::RootObject *)executionContext77 - _initWithObjectImp:(ObjectImp *)imp originExecutionContext:(const Bindings::RootObject *)originExecutionContext executionContext:(const Bindings::RootObject *)executionContext 78 78 { 79 79 assert (imp != 0); … … 89 89 } 90 90 91 - ( KJS::ObjectImp *)_imp91 - (ObjectImp *)_imp 92 92 { 93 93 if (!_private->imp && _private->isCreatedByDOMWrapper) { … … 99 99 } 100 100 101 - (const KJS::Bindings::RootObject *)_executionContext101 - (const RootObject *)_executionContext 102 102 { 103 103 return _private->executionContext; 104 104 } 105 105 106 - (void)_setExecutionContext:(const KJS::Bindings::RootObject *)context106 - (void)_setExecutionContext:(const RootObject *)context 107 107 { 108 108 _private->executionContext = context; … … 110 110 111 111 112 - (const KJS::Bindings::RootObject *)_originExecutionContext112 - (const RootObject *)_originExecutionContext 113 113 { 114 114 return _private->originExecutionContext; 115 115 } 116 116 117 - (void)_setOriginExecutionContext:(const KJS::Bindings::RootObject *)originExecutionContext117 - (void)_setOriginExecutionContext:(const RootObject *)originExecutionContext 118 118 { 119 119 _private->originExecutionContext = originExecutionContext; … … 159 159 // If the interpreter has a context, we set the exception. 160 160 if (interp->context()) { 161 Object 161 ObjectImp *err = Error::create(exec, GeneralError, [exceptionMessage UTF8String]); 162 162 exec->setException (err); 163 163 return YES; … … 169 169 } 170 170 171 static KJS::List listFromNSArray(ExecState *exec, NSArray *array)171 static List listFromNSArray(ExecState *exec, NSArray *array) 172 172 { 173 173 long i, numObjects = array ? [array count] : 0; 174 KJS::List aList;174 List aList; 175 175 176 176 for (i = 0; i < numObjects; i++) { … … 194 194 Interpreter::lock(); 195 195 196 Value 197 Identifier identifier(v .toString(exec));198 Value 199 Interpreter::unlock(); 200 if ( func.isNull() || func.type() == UndefinedType) {196 ValueImp *v = convertObjcValueToValue(exec, &name, ObjcObjectType); 197 Identifier identifier(v->toString(exec)); 198 ValueImp *func = [self _imp]->get (exec, identifier); 199 Interpreter::unlock(); 200 if (!func || func->isUndefined()) { 201 201 // Maybe throw an exception here? 202 202 return 0; … … 205 205 // Call the function object. 206 206 Interpreter::lock(); 207 ObjectImp *funcImp = static_cast<ObjectImp*>(func .imp());208 Object thisObj = Object(const_cast<ObjectImp*>([self _imp]));207 ObjectImp *funcImp = static_cast<ObjectImp*>(func); 208 ObjectImp *thisObj = const_cast<ObjectImp*>([self _imp]); 209 209 List argList = listFromNSArray(exec, args); 210 Value 210 ValueImp *result = funcImp->call (exec, thisObj, argList); 211 211 Interpreter::unlock(); 212 212 … … 234 234 ExecState *exec = [self _executionContext]->interpreter()->globalExec(); 235 235 236 Object thisObj = Object(const_cast<ObjectImp*>([self _imp])); 237 Value result; 238 239 Interpreter::lock(); 240 241 Value v = convertObjcValueToValue(exec, &script, ObjcObjectType); 242 Completion completion = [self _executionContext]->interpreter()->evaluate(UString(), 0, v.toString(exec)); 236 ValueImp *result; 237 238 Interpreter::lock(); 239 240 ValueImp *v = convertObjcValueToValue(exec, &script, ObjcObjectType); 241 Completion completion = [self _executionContext]->interpreter()->evaluate(UString(), 0, v->toString(exec)); 243 242 ComplType type = completion.complType(); 244 243 245 244 if (type == Normal) { 246 245 result = completion.value(); 247 if ( result.isNull()) {246 if (!result) { 248 247 result = Undefined(); 249 248 } … … 277 276 278 277 Interpreter::lock(); 279 Value 280 [self _imp]->put (exec, Identifier (v .toString(exec)), (convertObjcValueToValue(exec, &value, ObjcObjectType)));278 ValueImp *v = convertObjcValueToValue(exec, &key, ObjcObjectType); 279 [self _imp]->put (exec, Identifier (v->toString(exec)), (convertObjcValueToValue(exec, &value, ObjcObjectType))); 281 280 Interpreter::unlock(); 282 281 … … 299 298 300 299 Interpreter::lock(); 301 Value 302 Value result = [self _imp]->get (exec, Identifier (v.toString(exec)));300 ValueImp *v = convertObjcValueToValue(exec, &key, ObjcObjectType); 301 ValueImp *result = [self _imp]->get (exec, Identifier (v->toString(exec))); 303 302 Interpreter::unlock(); 304 303 … … 326 325 327 326 Interpreter::lock(); 328 Value 329 [self _imp]->deleteProperty (exec, Identifier (v .toString(exec)));327 ValueImp *v = convertObjcValueToValue(exec, &key, ObjcObjectType); 328 [self _imp]->deleteProperty (exec, Identifier (v->toString(exec))); 330 329 Interpreter::unlock(); 331 330 … … 344 343 345 344 Interpreter::lock(); 346 Object thisObj = Object(const_cast<ObjectImp*>([self _imp]));345 ObjectImp *thisObj = const_cast<ObjectImp*>([self _imp]); 347 346 ExecState *exec = [self _executionContext]->interpreter()->globalExec(); 348 347 … … 368 367 ExecState *exec = [self _executionContext]->interpreter()->globalExec(); 369 368 Interpreter::lock(); 370 Value 369 ValueImp *result = [self _imp]->get (exec, (unsigned)index); 371 370 Interpreter::unlock(); 372 371 … … 409 408 410 409 ExecState *exec = [self _executionContext]->interpreter()->globalExec(); 411 Object 410 ObjectImp *err = Error::create(exec, GeneralError, [description UTF8String]); 412 411 exec->setException (err); 413 412 } 414 413 415 + (id)_convertValueToObjcValue:( KJS::Value)value originExecutionContext:(const Bindings::RootObject *)originExecutionContext executionContext:(const Bindings::RootObject *)executionContext414 + (id)_convertValueToObjcValue:(ValueImp *)value originExecutionContext:(const RootObject *)originExecutionContext executionContext:(const Bindings::RootObject *)executionContext 416 415 { 417 416 id result = 0; 418 417 419 418 // First see if we have a ObjC instance. 420 if (value .type() == KJS::ObjectType){421 ObjectImp *objectImp = static_cast<ObjectImp*>(value .imp());419 if (value->isObject()) { 420 ObjectImp *objectImp = static_cast<ObjectImp*>(value); 422 421 Interpreter *intepreter = executionContext->interpreter(); 423 422 ExecState *exec = intepreter->globalExec(); 424 423 Interpreter::lock(); 425 424 426 if (objectImp->classInfo() != & KJS::RuntimeObjectImp::info) {427 Value 428 if (!runtimeObject .isNull() && runtimeObject.type() == KJS::ObjectType)429 objectImp = static_cast<RuntimeObjectImp*>(runtimeObject .imp());425 if (objectImp->classInfo() != &RuntimeObjectImp::info) { 426 ValueImp *runtimeObject = objectImp->get(exec, "__apple_runtime_object"); 427 if (!runtimeObject && runtimeObject->isObject()) 428 objectImp = static_cast<RuntimeObjectImp*>(runtimeObject); 430 429 } 431 430 432 431 Interpreter::unlock(); 433 432 434 if (objectImp->classInfo() == & KJS::RuntimeObjectImp::info) {433 if (objectImp->classInfo() == &RuntimeObjectImp::info) { 435 434 RuntimeObjectImp *imp = static_cast<RuntimeObjectImp *>(objectImp); 436 435 ObjcInstance *instance = static_cast<ObjcInstance*>(imp->getInternalInstance()); … … 440 439 // Convert to a WebScriptObject 441 440 else { 442 result = (id)intepreter->createLanguageInstanceForValue (exec, Instance::ObjectiveCLanguage, value .toObject(exec), originExecutionContext, executionContext);441 result = (id)intepreter->createLanguageInstanceForValue (exec, Instance::ObjectiveCLanguage, value->toObject(exec), originExecutionContext, executionContext); 443 442 } 444 443 } 445 444 446 445 // Convert JavaScript String value to NSString? 447 else if (value .type() == KJS::StringType) {448 StringImp *s = static_cast< KJS::StringImp*>(value.imp());446 else if (value->isString()) { 447 StringImp *s = static_cast<StringImp*>(value); 449 448 UString u = s->value(); 450 449 … … 454 453 455 454 // Convert JavaScript Number value to NSNumber? 456 else if (value.type() == KJS::NumberType) { 457 Number n = Number::dynamicCast(value); 458 result = [NSNumber numberWithDouble:n.value()]; 459 } 460 461 else if (value.type() == KJS::BooleanType) { 462 KJS::BooleanImp *b = static_cast<KJS::BooleanImp*>(value.imp()); 455 else if (value->isNumber()) { 456 result = [NSNumber numberWithDouble:value->getNumber()]; 457 } 458 459 else if (value->isBoolean()) { 460 BooleanImp *b = static_cast<BooleanImp*>(value); 463 461 result = [NSNumber numberWithBool:b->value()]; 464 462 } 465 463 466 464 // Convert JavaScript Undefined types to WebUndefined 467 else if (value .type() == KJS::UndefinedType) {465 else if (value->isUndefined()) { 468 466 result = [WebUndefined undefined]; 469 467 }
Note:
See TracChangeset
for help on using the changeset viewer.