Changeset 10084 in webkit for trunk/JavaScriptCore
- Timestamp:
- Aug 7, 2005, 9:07:46 PM (20 years ago)
- Location:
- trunk/JavaScriptCore
- Files:
-
- 90 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/ChangeLog
r10076 r10084 1 2005-08-07 Darin Adler <[email protected]> 2 3 Rubber stamped by Maciej. 4 5 - fixed http://bugzilla.opendarwin.org/show_bug.cgi?id=4313 6 eliminate KJS::Value and KJS::Object smart pointer wrappers (for simplicity and speed) 7 8 * JavaScriptCore.xcodeproj/project.pbxproj: Removed object_wrapper.h. 9 10 Global replaces and other wonderful stuff. 11 12 * bindings/NP_jsobject.cpp: 13 (_NPN_Invoke): 14 (_NPN_Evaluate): 15 (_NPN_GetProperty): 16 (_NPN_SetProperty): 17 (_NPN_HasMethod): 18 (_NPN_SetException): 19 * bindings/c/c_instance.cpp: 20 (KJS::Bindings::CInstance::CInstance): 21 (KJS::Bindings::CInstance::invokeMethod): 22 (KJS::Bindings::CInstance::invokeDefaultMethod): 23 (KJS::Bindings::CInstance::defaultValue): 24 (KJS::Bindings::CInstance::stringValue): 25 (KJS::Bindings::CInstance::numberValue): 26 (KJS::Bindings::CInstance::booleanValue): 27 (KJS::Bindings::CInstance::valueOf): 28 * bindings/c/c_instance.h: 29 * bindings/c/c_runtime.cpp: 30 (CField::valueFromInstance): 31 (CField::setValueToInstance): 32 * bindings/c/c_runtime.h: 33 * bindings/c/c_utility.cpp: 34 (convertNPStringToUTF16): 35 (convertUTF8ToUTF16): 36 (coerceValueToNPVariantStringType): 37 (convertValueToNPVariant): 38 (convertNPVariantToValue): 39 * bindings/c/c_utility.h: 40 * bindings/jni/jni_instance.cpp: 41 (JavaInstance::stringValue): 42 (JavaInstance::numberValue): 43 (JavaInstance::booleanValue): 44 (JavaInstance::invokeMethod): 45 (JavaInstance::invokeDefaultMethod): 46 (JavaInstance::defaultValue): 47 (JavaInstance::valueOf): 48 * bindings/jni/jni_instance.h: 49 * bindings/jni/jni_jsobject.cpp: 50 (JSObject::invoke): 51 (JSObject::call): 52 (JSObject::eval): 53 (JSObject::getMember): 54 (JSObject::getSlot): 55 (JSObject::toString): 56 (JSObject::convertValueToJObject): 57 (JSObject::convertJObjectToValue): 58 (JSObject::listFromJArray): 59 * bindings/jni/jni_jsobject.h: 60 * bindings/jni/jni_objc.mm: 61 (KJS::Bindings::dispatchJNICall): 62 * bindings/jni/jni_runtime.cpp: 63 (JavaArray::convertJObjectToArray): 64 (JavaField::dispatchValueFromInstance): 65 (JavaField::valueFromInstance): 66 (JavaField::dispatchSetValueToInstance): 67 (JavaField::setValueToInstance): 68 (JavaArray::setValueAt): 69 (JavaArray::valueAt): 70 * bindings/jni/jni_runtime.h: 71 (KJS::Bindings::JavaString::ustring): 72 * bindings/jni/jni_utility.cpp: 73 (KJS::Bindings::getJavaVM): 74 (KJS::Bindings::getJNIEnv): 75 (KJS::Bindings::getMethodID): 76 (KJS::Bindings::callJNIVoidMethod): 77 (KJS::Bindings::callJNIObjectMethod): 78 (KJS::Bindings::callJNIBooleanMethod): 79 (KJS::Bindings::callJNIStaticBooleanMethod): 80 (KJS::Bindings::callJNIByteMethod): 81 (KJS::Bindings::callJNICharMethod): 82 (KJS::Bindings::callJNIShortMethod): 83 (KJS::Bindings::callJNIIntMethod): 84 (KJS::Bindings::callJNILongMethod): 85 (KJS::Bindings::callJNIFloatMethod): 86 (KJS::Bindings::callJNIDoubleMethod): 87 (KJS::Bindings::callJNIVoidMethodA): 88 (KJS::Bindings::callJNIObjectMethodA): 89 (KJS::Bindings::callJNIByteMethodA): 90 (KJS::Bindings::callJNICharMethodA): 91 (KJS::Bindings::callJNIShortMethodA): 92 (KJS::Bindings::callJNIIntMethodA): 93 (KJS::Bindings::callJNILongMethodA): 94 (KJS::Bindings::callJNIFloatMethodA): 95 (KJS::Bindings::callJNIDoubleMethodA): 96 (KJS::Bindings::callJNIBooleanMethodA): 97 (KJS::Bindings::callJNIVoidMethodIDA): 98 (KJS::Bindings::callJNIObjectMethodIDA): 99 (KJS::Bindings::callJNIByteMethodIDA): 100 (KJS::Bindings::callJNICharMethodIDA): 101 (KJS::Bindings::callJNIShortMethodIDA): 102 (KJS::Bindings::callJNIIntMethodIDA): 103 (KJS::Bindings::callJNILongMethodIDA): 104 (KJS::Bindings::callJNIFloatMethodIDA): 105 (KJS::Bindings::callJNIDoubleMethodIDA): 106 (KJS::Bindings::callJNIBooleanMethodIDA): 107 (KJS::Bindings::getCharactersFromJString): 108 (KJS::Bindings::releaseCharactersForJString): 109 (KJS::Bindings::getCharactersFromJStringInEnv): 110 (KJS::Bindings::releaseCharactersForJStringInEnv): 111 (KJS::Bindings::getUCharactersFromJStringInEnv): 112 (KJS::Bindings::releaseUCharactersForJStringInEnv): 113 (KJS::Bindings::JNITypeFromClassName): 114 (KJS::Bindings::signatureFromPrimitiveType): 115 (KJS::Bindings::JNITypeFromPrimitiveType): 116 (KJS::Bindings::getJNIField): 117 (KJS::Bindings::convertValueToJValue): 118 * bindings/jni/jni_utility.h: 119 * bindings/objc/WebScriptObject.mm: 120 (_didExecute): 121 (-[WebScriptObject _initializeWithObjectImp:originExecutionContext:Bindings::executionContext:Bindings::]): 122 (-[WebScriptObject _initWithObjectImp:originExecutionContext:Bindings::executionContext:Bindings::]): 123 (-[WebScriptObject _imp]): 124 (-[WebScriptObject _executionContext]): 125 (-[WebScriptObject _setExecutionContext:]): 126 (-[WebScriptObject _originExecutionContext]): 127 (-[WebScriptObject _setOriginExecutionContext:]): 128 (+[WebScriptObject throwException:]): 129 (listFromNSArray): 130 (-[WebScriptObject callWebScriptMethod:withArguments:]): 131 (-[WebScriptObject evaluateWebScript:]): 132 (-[WebScriptObject setValue:forKey:]): 133 (-[WebScriptObject valueForKey:]): 134 (-[WebScriptObject removeWebScriptKey:]): 135 (-[WebScriptObject stringRepresentation]): 136 (-[WebScriptObject webScriptValueAtIndex:]): 137 (-[WebScriptObject setException:]): 138 (+[WebScriptObject _convertValueToObjcValue:originExecutionContext:executionContext:Bindings::]): 139 * bindings/objc/WebScriptObjectPrivate.h: 140 * bindings/objc/objc_class.h: 141 * bindings/objc/objc_class.mm: 142 (KJS::Bindings::ObjcClass::fallbackObject): 143 * bindings/objc/objc_instance.h: 144 * bindings/objc/objc_instance.mm: 145 (ObjcInstance::invokeMethod): 146 (ObjcInstance::invokeDefaultMethod): 147 (ObjcInstance::setValueOfField): 148 (ObjcInstance::setValueOfUndefinedField): 149 (ObjcInstance::getValueOfField): 150 (ObjcInstance::getValueOfUndefinedField): 151 (ObjcInstance::defaultValue): 152 (ObjcInstance::stringValue): 153 (ObjcInstance::numberValue): 154 (ObjcInstance::booleanValue): 155 (ObjcInstance::valueOf): 156 * bindings/objc/objc_runtime.h: 157 * bindings/objc/objc_runtime.mm: 158 (ObjcField::valueFromInstance): 159 (convertValueToObjcObject): 160 (ObjcField::setValueToInstance): 161 (ObjcArray::setValueAt): 162 (ObjcArray::valueAt): 163 (ObjcFallbackObjectImp::put): 164 (ObjcFallbackObjectImp::callAsFunction): 165 (ObjcFallbackObjectImp::defaultValue): 166 * bindings/objc/objc_utility.h: 167 * bindings/objc/objc_utility.mm: 168 (Bindings::JSMethodNameToObjCMethodName): 169 (Bindings::convertValueToObjcValue): 170 (Bindings::convertNSStringToString): 171 (Bindings::convertObjcValueToValue): 172 (Bindings::objcValueTypeForType): 173 (Bindings::createObjcInstanceForValue): 174 * bindings/runtime.cpp: 175 (Instance::getValueOfField): 176 (Instance::setValueOfField): 177 (Instance::createRuntimeObject): 178 (Instance::createLanguageInstanceForValue): 179 * bindings/runtime.h: 180 (KJS::Bindings::Constructor::~Constructor): 181 (KJS::Bindings::Field::~Field): 182 (KJS::Bindings::MethodList::MethodList): 183 (KJS::Bindings::Class::fallbackObject): 184 (KJS::Bindings::Class::~Class): 185 (KJS::Bindings::Instance::Instance): 186 (KJS::Bindings::Instance::getValueOfUndefinedField): 187 (KJS::Bindings::Instance::supportsSetValueOfUndefinedField): 188 (KJS::Bindings::Instance::setValueOfUndefinedField): 189 (KJS::Bindings::Instance::valueOf): 190 (KJS::Bindings::Instance::setExecutionContext): 191 (KJS::Bindings::Instance::~Instance): 192 (KJS::Bindings::Array::~Array): 193 * bindings/runtime_array.cpp: 194 (RuntimeArrayImp::RuntimeArrayImp): 195 (RuntimeArrayImp::lengthGetter): 196 (RuntimeArrayImp::indexGetter): 197 (RuntimeArrayImp::put): 198 * bindings/runtime_array.h: 199 * bindings/runtime_method.cpp: 200 (RuntimeMethodImp::lengthGetter): 201 (RuntimeMethodImp::callAsFunction): 202 * bindings/runtime_method.h: 203 * bindings/runtime_object.cpp: 204 (RuntimeObjectImp::fallbackObjectGetter): 205 (RuntimeObjectImp::fieldGetter): 206 (RuntimeObjectImp::methodGetter): 207 (RuntimeObjectImp::getOwnPropertySlot): 208 (RuntimeObjectImp::put): 209 (RuntimeObjectImp::defaultValue): 210 (RuntimeObjectImp::callAsFunction): 211 * bindings/runtime_object.h: 212 * kjs/array_instance.h: 213 * kjs/array_object.cpp: 214 (ArrayInstanceImp::ArrayInstanceImp): 215 (ArrayInstanceImp::lengthGetter): 216 (ArrayInstanceImp::getOwnPropertySlot): 217 (ArrayInstanceImp::put): 218 (ArrayInstanceImp::propList): 219 (ArrayInstanceImp::setLength): 220 (compareByStringForQSort): 221 (compareWithCompareFunctionForQSort): 222 (ArrayInstanceImp::sort): 223 (ArrayInstanceImp::pushUndefinedObjectsToEnd): 224 (ArrayPrototypeImp::ArrayPrototypeImp): 225 (ArrayProtoFuncImp::ArrayProtoFuncImp): 226 (ArrayProtoFuncImp::callAsFunction): 227 (ArrayObjectImp::ArrayObjectImp): 228 (ArrayObjectImp::construct): 229 (ArrayObjectImp::callAsFunction): 230 * kjs/array_object.h: 231 * kjs/bool_object.cpp: 232 (BooleanPrototypeImp::BooleanPrototypeImp): 233 (BooleanProtoFuncImp::BooleanProtoFuncImp): 234 (BooleanProtoFuncImp::callAsFunction): 235 (BooleanObjectImp::BooleanObjectImp): 236 (BooleanObjectImp::construct): 237 (BooleanObjectImp::callAsFunction): 238 * kjs/bool_object.h: 239 * kjs/collector.cpp: 240 (KJS::Collector::markStackObjectsConservatively): 241 (KJS::Collector::collect): 242 (KJS::className): 243 * kjs/completion.h: 244 (KJS::Completion::Completion): 245 (KJS::Completion::value): 246 (KJS::Completion::isValueCompletion): 247 * kjs/context.h: 248 (KJS::ContextImp::variableObject): 249 (KJS::ContextImp::setVariableObject): 250 (KJS::ContextImp::thisValue): 251 (KJS::ContextImp::activationObject): 252 (KJS::ContextImp::pushScope): 253 * kjs/date_object.cpp: 254 (formatLocaleDate): 255 (KJS::timeFromArgs): 256 (KJS::DatePrototypeImp::DatePrototypeImp): 257 (KJS::DateProtoFuncImp::DateProtoFuncImp): 258 (KJS::DateProtoFuncImp::callAsFunction): 259 (KJS::DateObjectImp::DateObjectImp): 260 (KJS::DateObjectImp::construct): 261 (KJS::DateObjectImp::callAsFunction): 262 (KJS::DateObjectFuncImp::DateObjectFuncImp): 263 (KJS::DateObjectFuncImp::callAsFunction): 264 (KJS::parseDate): 265 (KJS::KRFCDate_parseDate): 266 (KJS::timeClip): 267 * kjs/date_object.h: 268 * kjs/debugger.cpp: 269 (Debugger::exception): 270 (Debugger::callEvent): 271 (Debugger::returnEvent): 272 * kjs/debugger.h: 273 * kjs/error_object.cpp: 274 (ErrorPrototypeImp::ErrorPrototypeImp): 275 (ErrorProtoFuncImp::ErrorProtoFuncImp): 276 (ErrorProtoFuncImp::callAsFunction): 277 (ErrorObjectImp::ErrorObjectImp): 278 (ErrorObjectImp::construct): 279 (ErrorObjectImp::callAsFunction): 280 (NativeErrorPrototypeImp::NativeErrorPrototypeImp): 281 (NativeErrorImp::NativeErrorImp): 282 (NativeErrorImp::construct): 283 (NativeErrorImp::callAsFunction): 284 * kjs/error_object.h: 285 * kjs/function.cpp: 286 (KJS::FunctionImp::FunctionImp): 287 (KJS::FunctionImp::callAsFunction): 288 (KJS::FunctionImp::processParameters): 289 (KJS::FunctionImp::argumentsGetter): 290 (KJS::FunctionImp::lengthGetter): 291 (KJS::FunctionImp::put): 292 (KJS::DeclaredFunctionImp::DeclaredFunctionImp): 293 (KJS::DeclaredFunctionImp::construct): 294 (KJS::ArgumentsImp::ArgumentsImp): 295 (KJS::ArgumentsImp::mappedIndexGetter): 296 (KJS::ArgumentsImp::put): 297 (KJS::ActivationImp::argumentsGetter): 298 (KJS::GlobalFuncImp::GlobalFuncImp): 299 (KJS::encode): 300 (KJS::decode): 301 (KJS::GlobalFuncImp::callAsFunction): 302 * kjs/function.h: 303 * kjs/function_object.cpp: 304 (FunctionPrototypeImp::FunctionPrototypeImp): 305 (FunctionPrototypeImp::callAsFunction): 306 (FunctionProtoFuncImp::FunctionProtoFuncImp): 307 (FunctionProtoFuncImp::callAsFunction): 308 (FunctionObjectImp::FunctionObjectImp): 309 (FunctionObjectImp::construct): 310 (FunctionObjectImp::callAsFunction): 311 * kjs/function_object.h: 312 * kjs/internal.cpp: 313 (KJS::UndefinedImp::toPrimitive): 314 (KJS::UndefinedImp::toObject): 315 (KJS::NullImp::toPrimitive): 316 (KJS::NullImp::toObject): 317 (KJS::BooleanImp::toPrimitive): 318 (KJS::BooleanImp::toObject): 319 (KJS::StringImp::toPrimitive): 320 (KJS::StringImp::toObject): 321 (KJS::NumberImp::toPrimitive): 322 (KJS::NumberImp::toObject): 323 (KJS::NumberImp::getUInt32): 324 (KJS::LabelStack::push): 325 (KJS::ContextImp::ContextImp): 326 (KJS::InterpreterImp::globalInit): 327 (KJS::InterpreterImp::globalClear): 328 (KJS::InterpreterImp::InterpreterImp): 329 (KJS::InterpreterImp::initGlobalObject): 330 (KJS::InterpreterImp::clear): 331 (KJS::InterpreterImp::mark): 332 (KJS::InterpreterImp::evaluate): 333 (KJS::InternalFunctionImp::hasInstance): 334 (KJS::roundValue): 335 (KJS::printInfo): 336 * kjs/internal.h: 337 (KJS::InterpreterImp::builtinObject): 338 (KJS::InterpreterImp::builtinFunction): 339 (KJS::InterpreterImp::builtinArray): 340 (KJS::InterpreterImp::builtinBoolean): 341 (KJS::InterpreterImp::builtinString): 342 (KJS::InterpreterImp::builtinNumber): 343 (KJS::InterpreterImp::builtinDate): 344 (KJS::InterpreterImp::builtinRegExp): 345 (KJS::InterpreterImp::builtinError): 346 (KJS::InterpreterImp::builtinObjectPrototype): 347 (KJS::InterpreterImp::builtinFunctionPrototype): 348 (KJS::InterpreterImp::builtinArrayPrototype): 349 (KJS::InterpreterImp::builtinBooleanPrototype): 350 (KJS::InterpreterImp::builtinStringPrototype): 351 (KJS::InterpreterImp::builtinNumberPrototype): 352 (KJS::InterpreterImp::builtinDatePrototype): 353 (KJS::InterpreterImp::builtinRegExpPrototype): 354 (KJS::InterpreterImp::builtinErrorPrototype): 355 (KJS::InterpreterImp::builtinEvalError): 356 (KJS::InterpreterImp::builtinRangeError): 357 (KJS::InterpreterImp::builtinReferenceError): 358 (KJS::InterpreterImp::builtinSyntaxError): 359 (KJS::InterpreterImp::builtinTypeError): 360 (KJS::InterpreterImp::builtinURIError): 361 (KJS::InterpreterImp::builtinEvalErrorPrototype): 362 (KJS::InterpreterImp::builtinRangeErrorPrototype): 363 (KJS::InterpreterImp::builtinReferenceErrorPrototype): 364 (KJS::InterpreterImp::builtinSyntaxErrorPrototype): 365 (KJS::InterpreterImp::builtinTypeErrorPrototype): 366 (KJS::InterpreterImp::builtinURIErrorPrototype): 367 * kjs/interpreter.cpp: 368 (Context::variableObject): 369 (Context::thisValue): 370 (Interpreter::Interpreter): 371 (Interpreter::globalObject): 372 (Interpreter::evaluate): 373 (Interpreter::builtinObject): 374 (Interpreter::builtinFunction): 375 (Interpreter::builtinArray): 376 (Interpreter::builtinBoolean): 377 (Interpreter::builtinString): 378 (Interpreter::builtinNumber): 379 (Interpreter::builtinDate): 380 (Interpreter::builtinRegExp): 381 (Interpreter::builtinError): 382 (Interpreter::builtinObjectPrototype): 383 (Interpreter::builtinFunctionPrototype): 384 (Interpreter::builtinArrayPrototype): 385 (Interpreter::builtinBooleanPrototype): 386 (Interpreter::builtinStringPrototype): 387 (Interpreter::builtinNumberPrototype): 388 (Interpreter::builtinDatePrototype): 389 (Interpreter::builtinRegExpPrototype): 390 (Interpreter::builtinErrorPrototype): 391 (Interpreter::builtinEvalError): 392 (Interpreter::builtinRangeError): 393 (Interpreter::builtinReferenceError): 394 (Interpreter::builtinSyntaxError): 395 (Interpreter::builtinTypeError): 396 (Interpreter::builtinURIError): 397 (Interpreter::builtinEvalErrorPrototype): 398 (Interpreter::builtinRangeErrorPrototype): 399 (Interpreter::builtinReferenceErrorPrototype): 400 (Interpreter::builtinSyntaxErrorPrototype): 401 (Interpreter::builtinTypeErrorPrototype): 402 (Interpreter::builtinURIErrorPrototype): 403 (Interpreter::createLanguageInstanceForValue): 404 * kjs/interpreter.h: 405 (KJS::Interpreter::isGlobalObject): 406 (KJS::ExecState::setException): 407 (KJS::ExecState::clearException): 408 (KJS::ExecState::exception): 409 (KJS::ExecState::hadException): 410 (KJS::ExecState::ExecState): 411 * kjs/list.cpp: 412 (KJS::List::at): 413 * kjs/list.h: 414 (KJS::List::operator[]): 415 (KJS::ListIterator::operator->): 416 (KJS::ListIterator::operator*): 417 (KJS::ListIterator::operator++): 418 (KJS::ListIterator::operator--): 419 * kjs/lookup.h: 420 (KJS::staticFunctionGetter): 421 (KJS::staticValueGetter): 422 (KJS::lookupPut): 423 (KJS::cacheGlobalObject): 424 * kjs/math_object.cpp: 425 (MathObjectImp::getValueProperty): 426 (MathFuncImp::MathFuncImp): 427 (MathFuncImp::callAsFunction): 428 * kjs/math_object.h: 429 * kjs/nodes.cpp: 430 (Node::evaluateReference): 431 (Node::throwError): 432 (Node::setExceptionDetailsIfNeeded): 433 (NullNode::evaluate): 434 (BooleanNode::evaluate): 435 (NumberNode::evaluate): 436 (StringNode::evaluate): 437 (RegExpNode::evaluate): 438 (ThisNode::evaluate): 439 (ResolveNode::evaluate): 440 (ResolveNode::evaluateReference): 441 (GroupNode::evaluate): 442 (ElementNode::evaluate): 443 (ArrayNode::evaluate): 444 (ObjectLiteralNode::evaluate): 445 (PropertyValueNode::evaluate): 446 (PropertyNode::evaluate): 447 (AccessorNode1::evaluate): 448 (AccessorNode1::evaluateReference): 449 (AccessorNode2::evaluate): 450 (AccessorNode2::evaluateReference): 451 (ArgumentListNode::evaluate): 452 (ArgumentListNode::evaluateList): 453 (ArgumentsNode::evaluate): 454 (NewExprNode::evaluate): 455 (FunctionCallNode::evaluate): 456 (PostfixNode::evaluate): 457 (DeleteNode::evaluate): 458 (VoidNode::evaluate): 459 (TypeOfNode::evaluate): 460 (PrefixNode::evaluate): 461 (UnaryPlusNode::evaluate): 462 (NegateNode::evaluate): 463 (BitwiseNotNode::evaluate): 464 (LogicalNotNode::evaluate): 465 (MultNode::evaluate): 466 (AddNode::evaluate): 467 (ShiftNode::evaluate): 468 (RelationalNode::evaluate): 469 (EqualNode::evaluate): 470 (BitOperNode::evaluate): 471 (BinaryLogicalNode::evaluate): 472 (ConditionalNode::evaluate): 473 (AssignNode::evaluate): 474 (CommaNode::evaluate): 475 (StatListNode::execute): 476 (AssignExprNode::evaluate): 477 (VarDeclNode::evaluate): 478 (VarDeclNode::processVarDecls): 479 (VarDeclListNode::evaluate): 480 (ExprStatementNode::execute): 481 (IfNode::execute): 482 (DoWhileNode::execute): 483 (WhileNode::execute): 484 (ForNode::execute): 485 (ForInNode::execute): 486 (ContinueNode::execute): 487 (BreakNode::execute): 488 (ReturnNode::execute): 489 (WithNode::execute): 490 (CaseClauseNode::evaluate): 491 (ClauseListNode::evaluate): 492 (CaseBlockNode::evaluate): 493 (CaseBlockNode::evalBlock): 494 (SwitchNode::execute): 495 (ThrowNode::execute): 496 (CatchNode::execute): 497 (TryNode::execute): 498 (ParameterNode::evaluate): 499 (FuncDeclNode::processFuncDecl): 500 (FuncExprNode::evaluate): 501 (SourceElementsNode::execute): 502 * kjs/nodes.h: 503 (KJS::StatementNode::evaluate): 504 * kjs/number_object.cpp: 505 (NumberPrototypeImp::NumberPrototypeImp): 506 (NumberProtoFuncImp::NumberProtoFuncImp): 507 (NumberProtoFuncImp::callAsFunction): 508 (NumberObjectImp::NumberObjectImp): 509 (NumberObjectImp::getValueProperty): 510 (NumberObjectImp::construct): 511 (NumberObjectImp::callAsFunction): 512 * kjs/number_object.h: 513 * kjs/object.cpp: 514 (KJS::ObjectImp::call): 515 (KJS::ObjectImp::mark): 516 (KJS::ObjectImp::classInfo): 517 (KJS::ObjectImp::get): 518 (KJS::ObjectImp::getProperty): 519 (KJS::ObjectImp::getPropertySlot): 520 (KJS::ObjectImp::put): 521 (KJS::ObjectImp::hasOwnProperty): 522 (KJS::ObjectImp::defaultValue): 523 (KJS::ObjectImp::findPropertyHashEntry): 524 (KJS::ObjectImp::construct): 525 (KJS::ObjectImp::callAsFunction): 526 (KJS::ObjectImp::hasInstance): 527 (KJS::ObjectImp::propList): 528 (KJS::ObjectImp::toPrimitive): 529 (KJS::ObjectImp::toNumber): 530 (KJS::ObjectImp::toString): 531 (KJS::ObjectImp::toObject): 532 (KJS::ObjectImp::putDirect): 533 (KJS::Error::create): 534 (KJS::error): 535 * kjs/object.h: 536 (KJS::): 537 (KJS::ObjectImp::getPropertySlot): 538 (KJS::AllocatedValueImp::isObject): 539 (KJS::ObjectImp::ObjectImp): 540 (KJS::ObjectImp::internalValue): 541 (KJS::ObjectImp::setInternalValue): 542 (KJS::ObjectImp::prototype): 543 (KJS::ObjectImp::setPrototype): 544 (KJS::ObjectImp::inherits): 545 * kjs/object_object.cpp: 546 (ObjectPrototypeImp::ObjectPrototypeImp): 547 (ObjectProtoFuncImp::ObjectProtoFuncImp): 548 (ObjectProtoFuncImp::callAsFunction): 549 (ObjectObjectImp::ObjectObjectImp): 550 (ObjectObjectImp::construct): 551 (ObjectObjectImp::callAsFunction): 552 * kjs/object_object.h: 553 * kjs/operations.cpp: 554 (KJS::equal): 555 (KJS::strictEqual): 556 (KJS::relation): 557 (KJS::add): 558 (KJS::mult): 559 * kjs/operations.h: 560 * kjs/property_map.cpp: 561 (KJS::PropertyMap::mark): 562 (KJS::PropertyMap::addEnumerablesToReferenceList): 563 (KJS::PropertyMap::addSparseArrayPropertiesToReferenceList): 564 (KJS::PropertyMap::save): 565 (KJS::PropertyMap::restore): 566 * kjs/property_map.h: 567 * kjs/property_slot.cpp: 568 (KJS::PropertySlot::undefinedGetter): 569 * kjs/property_slot.h: 570 (KJS::PropertySlot::getValue): 571 * kjs/protect.h: 572 (KJS::gcUnprotectNullTolerant): 573 (KJS::ProtectedValue::ProtectedValue): 574 (KJS::ProtectedValue::~ProtectedValue): 575 (KJS::ProtectedValue::operator=): 576 (KJS::ProtectedValue::operator ValueImp *): 577 (KJS::ProtectedValue::operator->): 578 * kjs/protected_object.h: 579 (KJS::ProtectedObject::ProtectedObject): 580 (KJS::ProtectedObject::operator=): 581 (KJS::ProtectedObject::operator ValueImp *): 582 (KJS::ProtectedObject::operator ObjectImp *): 583 (KJS::ProtectedObject::operator->): 584 (KJS::ProtectedReference::ProtectedReference): 585 (KJS::ProtectedReference::~ProtectedReference): 586 (KJS::ProtectedReference::operator=): 587 * kjs/protected_values.cpp: 588 (KJS::ProtectedValues::getProtectCount): 589 (KJS::ProtectedValues::increaseProtectCount): 590 (KJS::ProtectedValues::insert): 591 (KJS::ProtectedValues::decreaseProtectCount): 592 * kjs/protected_values.h: 593 * kjs/reference.cpp: 594 (KJS::Reference::Reference): 595 (KJS::Reference::makeValueReference): 596 (KJS::Reference::getBase): 597 (KJS::Reference::getValue): 598 (KJS::Reference::putValue): 599 (KJS::Reference::deleteValue): 600 * kjs/reference.h: 601 (KJS::Reference::baseIfMutable): 602 * kjs/regexp_object.cpp: 603 (RegExpPrototypeImp::RegExpPrototypeImp): 604 (RegExpProtoFuncImp::RegExpProtoFuncImp): 605 (RegExpProtoFuncImp::callAsFunction): 606 (RegExpObjectImp::RegExpObjectImp): 607 (RegExpObjectImp::arrayOfMatches): 608 (RegExpObjectImp::backrefGetter): 609 (RegExpObjectImp::construct): 610 (RegExpObjectImp::callAsFunction): 611 * kjs/regexp_object.h: 612 * kjs/string_object.cpp: 613 (StringInstanceImp::lengthGetter): 614 (StringInstanceImp::indexGetter): 615 (StringInstanceImp::getOwnPropertySlot): 616 (StringInstanceImp::put): 617 (StringPrototypeImp::StringPrototypeImp): 618 (StringProtoFuncImp::StringProtoFuncImp): 619 (regExpIsGlobal): 620 (replace): 621 (StringProtoFuncImp::callAsFunction): 622 (StringObjectImp::StringObjectImp): 623 (StringObjectImp::construct): 624 (StringObjectImp::callAsFunction): 625 (StringObjectFuncImp::StringObjectFuncImp): 626 (StringObjectFuncImp::callAsFunction): 627 * kjs/string_object.h: 628 * kjs/testkjs.cpp: 629 (TestFunctionImp::callAsFunction): 630 (VersionFunctionImp::callAsFunction): 631 (main): 632 * kjs/value.cpp: 633 (KJS::AllocatedValueImp::operator new): 634 (KJS::AllocatedValueImp::getUInt32): 635 (KJS::ValueImp::toInteger): 636 (KJS::ValueImp::toInt32): 637 (KJS::ValueImp::toUInt32): 638 (KJS::ValueImp::toUInt16): 639 (KJS::ValueImp::toObject): 640 (KJS::AllocatedValueImp::getBoolean): 641 (KJS::AllocatedValueImp::getNumber): 642 (KJS::AllocatedValueImp::getString): 643 (KJS::AllocatedValueImp::getObject): 644 (KJS::jsString): 645 (KJS::jsNumber): 646 (KJS::ConstantValues::init): 647 (KJS::ConstantValues::clear): 648 (KJS::ConstantValues::mark): 649 * kjs/value.h: 650 (KJS::): 651 (KJS::jsUndefined): 652 (KJS::jsNull): 653 (KJS::jsBoolean): 654 (KJS::jsNaN): 655 (KJS::ValueImp::ValueImp): 656 (KJS::ValueImp::~ValueImp): 657 (KJS::AllocatedValueImp::AllocatedValueImp): 658 (KJS::AllocatedValueImp::~AllocatedValueImp): 659 (KJS::AllocatedValueImp::isBoolean): 660 (KJS::AllocatedValueImp::isNumber): 661 (KJS::AllocatedValueImp::isString): 662 (KJS::AllocatedValueImp::isObject): 663 (KJS::AllocatedValueImp::marked): 664 (KJS::AllocatedValueImp::mark): 665 (KJS::ValueImp::downcast): 666 (KJS::ValueImp::isUndefined): 667 (KJS::ValueImp::isNull): 668 (KJS::ValueImp::isUndefinedOrNull): 669 (KJS::ValueImp::isBoolean): 670 (KJS::ValueImp::isNumber): 671 (KJS::ValueImp::isString): 672 (KJS::ValueImp::isObject): 673 (KJS::ValueImp::getBoolean): 674 (KJS::ValueImp::getNumber): 675 (KJS::ValueImp::getString): 676 (KJS::ValueImp::getObject): 677 (KJS::ValueImp::getUInt32): 678 (KJS::ValueImp::mark): 679 (KJS::ValueImp::marked): 680 (KJS::ValueImp::type): 681 (KJS::ValueImp::toPrimitive): 682 (KJS::ValueImp::toBoolean): 683 (KJS::ValueImp::toNumber): 684 (KJS::ValueImp::toString): 685 (KJS::jsZero): 686 (KJS::jsOne): 687 (KJS::jsTwo): 688 (KJS::Undefined): 689 (KJS::Null): 690 (KJS::Boolean): 691 (KJS::Number): 692 (KJS::String): 693 1 694 2005-08-06 Maciej Stachowiak <[email protected]> 2 695 -
trunk/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj
r10076 r10084 28 28 65305EAF08A58DDE00F31E73 /* protected_object.h in Headers */ = {isa = PBXBuildFile; fileRef = 65305EAE08A58DDE00F31E73 /* protected_object.h */; settings = {ATTRIBUTES = (Private, ); }; }; 29 29 65305EB008A58E0900F31E73 /* protected_object.h in Headers */ = {isa = PBXBuildFile; fileRef = 65305EAE08A58DDE00F31E73 /* protected_object.h */; settings = {ATTRIBUTES = (Private, ); }; }; 30 6539AACB08A3225A00223EE2 /* object_wrapper.h in Headers */ = {isa = PBXBuildFile; fileRef = 6539AACA08A3225A00223EE2 /* object_wrapper.h */; settings = {ATTRIBUTES = (Private, ); }; };31 30 65621E6D089E859700760F35 /* property_slot.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 65621E6B089E859700760F35 /* property_slot.cpp */; }; 32 31 65621E6E089E859700760F35 /* property_slot.h in Headers */ = {isa = PBXBuildFile; fileRef = 65621E6C089E859700760F35 /* property_slot.h */; settings = {ATTRIBUTES = (Private, ); }; }; 33 32 65621E6F089E85D300760F35 /* property_slot.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 65621E6B089E859700760F35 /* property_slot.cpp */; }; 34 33 65621E70089E85D300760F35 /* property_slot.h in Headers */ = {isa = PBXBuildFile; fileRef = 65621E6C089E859700760F35 /* property_slot.h */; settings = {ATTRIBUTES = (Private, ); }; }; 35 65BBAEE008A329B300357728 /* object_wrapper.h in Headers */ = {isa = PBXBuildFile; fileRef = 6539AACA08A3225A00223EE2 /* object_wrapper.h */; settings = {ATTRIBUTES = (Private, ); }; };36 34 932F5B400822A1C700736975 /* array_object.h in Headers */ = {isa = PBXBuildFile; fileRef = F692A84E0255597D01FF60F7 /* array_object.h */; settings = {ATTRIBUTES = (Private, ); }; }; 37 35 932F5B420822A1C700736975 /* collector.h in Headers */ = {isa = PBXBuildFile; fileRef = F692A8530255597D01FF60F7 /* collector.h */; settings = {ATTRIBUTES = (Private, ); }; }; … … 459 457 651F6413039D5B5F0078395C /* dtoa.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = dtoa.h; sourceTree = "<group>"; }; 460 458 65305EAE08A58DDE00F31E73 /* protected_object.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = protected_object.h; sourceTree = "<group>"; }; 461 6539AACA08A3225A00223EE2 /* object_wrapper.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = object_wrapper.h; sourceTree = "<group>"; };462 459 65417205039E02E70058BFEB /* get.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = get.c; path = pcre/get.c; sourceTree = "<group>"; }; 463 460 65417206039E02E70058BFEB /* maketables.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = maketables.c; path = pcre/maketables.c; sourceTree = "<group>"; }; … … 646 643 children = ( 647 644 65305EAE08A58DDE00F31E73 /* protected_object.h */, 648 6539AACA08A3225A00223EE2 /* object_wrapper.h */,649 645 65621E6B089E859700760F35 /* property_slot.cpp */, 650 646 65621E6C089E859700760F35 /* property_slot.h */, … … 919 915 932FC11D0824A6A3005B3C75 /* create_hash_table in Headers */, 920 916 65621E6E089E859700760F35 /* property_slot.h in Headers */, 921 6539AACB08A3225A00223EE2 /* object_wrapper.h in Headers */,922 917 ); 923 918 runOnlyForDeploymentPostprocessing = 0; … … 943 938 A85D8205087B2822006A9172 /* number_object.h in Headers */, 944 939 A85D8206087B2822006A9172 /* object_object.h in Headers */, 945 65BBAEE008A329B300357728 /* object_wrapper.h in Headers */,946 940 A85D8207087B2822006A9172 /* object.h in Headers */, 947 941 A85D8208087B2822006A9172 /* operations.h in Headers */, -
trunk/JavaScriptCore/bindings/NP_jsobject.cpp
r9061 r10084 150 150 ExecState *exec = obj->executionContext->interpreter()->globalExec(); 151 151 Interpreter::lock(); 152 Value 152 ValueImp *func = obj->imp->get (exec, identiferFromNPIdentifier(i->value.string)); 153 153 Interpreter::unlock(); 154 154 155 if (func .isNull()) {155 if (func->isNull()) { 156 156 NPN_InitializeVariantAsNull(result); 157 157 return false; 158 158 } 159 else if ( func.type() == UndefinedType) {159 else if (func->isUndefined()) { 160 160 NPN_InitializeVariantAsUndefined(result); 161 161 return false; … … 163 163 else { 164 164 // Call the function object. 165 ObjectImp *funcImp = static_cast<ObjectImp*>(func .imp());166 Object thisObj = Object(const_cast<ObjectImp*>(obj->imp));165 ObjectImp *funcImp = static_cast<ObjectImp*>(func); 166 ObjectImp *thisObj = const_cast<ObjectImp*>(obj->imp); 167 167 List argList = listFromVariantArgs(exec, args, argCount); 168 168 Interpreter::lock(); 169 Value 169 ValueImp *resultV = funcImp->call (exec, thisObj, argList); 170 170 Interpreter::unlock(); 171 171 … … 194 194 195 195 ExecState *exec = obj->executionContext->interpreter()->globalExec(); 196 Object thisObj = Object(const_cast<ObjectImp*>(obj->imp)); 197 Value result; 196 ValueImp *result; 198 197 199 198 Interpreter::lock(); … … 206 205 if (type == Normal) { 207 206 result = completion.value(); 208 if ( result.isNull()) {207 if (!result) { 209 208 result = Undefined(); 210 209 } … … 235 234 236 235 PrivateIdentifier *i = (PrivateIdentifier *)propertyName; 237 if (i->isString) { 238 if (!obj->imp->hasProperty (exec, identiferFromNPIdentifier(i->value.string))) { 239 NPN_InitializeVariantAsNull(variant); 240 return false; 241 } 242 } 243 else { 244 if (!obj->imp->hasProperty (exec, i->value.number)) { 245 NPN_InitializeVariantAsNull(variant); 246 return false; 247 } 248 } 249 250 Interpreter::lock(); 251 Value result; 236 237 Interpreter::lock(); 238 ValueImp *result; 252 239 if (i->isString) { 253 240 result = obj->imp->get (exec, identiferFromNPIdentifier(i->value.string)); … … 258 245 Interpreter::unlock(); 259 246 260 if (result .isNull()) {247 if (result->isNull()) { 261 248 NPN_InitializeVariantAsNull(variant); 262 249 return false; 263 250 } 264 else if (result .type() == UndefinedType) {251 else if (result->isUndefined()) { 265 252 NPN_InitializeVariantAsUndefined(variant); 266 253 return false; … … 293 280 ExecState *exec = obj->executionContext->interpreter()->globalExec(); 294 281 Interpreter::lock(); 295 Value result;296 282 PrivateIdentifier *i = (PrivateIdentifier *)propertyName; 297 283 if (i->isString) { … … 395 381 ExecState *exec = obj->executionContext->interpreter()->globalExec(); 396 382 Interpreter::lock(); 397 Value 398 Interpreter::unlock(); 399 400 if (func .isNull() || func.type() == UndefinedType) {383 ValueImp *func = obj->imp->get (exec, identiferFromNPIdentifier(i->value.string)); 384 Interpreter::unlock(); 385 386 if (func->isUndefined()) { 401 387 return false; 402 388 } … … 418 404 ExecState *exec = obj->executionContext->interpreter()->globalExec(); 419 405 Interpreter::lock(); 420 Object 406 ObjectImp *err = Error::create(exec, GeneralError, message); 421 407 exec->setException (err); 422 408 Interpreter::unlock(); -
trunk/JavaScriptCore/bindings/c/c_instance.cpp
r8384 r10084 40 40 #endif 41 41 42 using namespace KJS::Bindings; 43 using namespace KJS; 42 namespace KJS { 43 namespace Bindings { 44 44 45 45 CInstance::CInstance (NPObject *o) … … 48 48 _class = 0; 49 49 setExecutionContext (0); 50 } ;50 } 51 51 52 52 CInstance::~CInstance () … … 95 95 } 96 96 97 Value CInstance::invokeMethod (KJS::ExecState *exec, const MethodList &methodList, const List &args)98 { 99 Value 97 ValueImp *CInstance::invokeMethod (ExecState *exec, const MethodList &methodList, const List &args) 98 { 99 ValueImp *resultValue; 100 100 101 101 // Overloading methods are not allowed by NPObjects. Should only be one … … 147 147 148 148 149 Value CInstance::invokeDefaultMethod (KJS::ExecState *exec, const List &args)150 { 151 Value 149 ValueImp *CInstance::invokeDefaultMethod (ExecState *exec, const List &args) 150 { 151 ValueImp *resultValue; 152 152 153 153 if (_object->_class->invokeDefault) { … … 189 189 190 190 191 KJS::Value CInstance::defaultValue (KJS::Type hint) const192 { 193 if (hint == KJS::StringType) {191 ValueImp *CInstance::defaultValue (Type hint) const 192 { 193 if (hint == StringType) { 194 194 return stringValue(); 195 195 } 196 else if (hint == KJS::NumberType) {196 else if (hint == NumberType) { 197 197 return numberValue(); 198 198 } 199 else if (hint == KJS::BooleanType) {199 else if (hint == BooleanType) { 200 200 return booleanValue(); 201 201 } … … 204 204 } 205 205 206 KJS::ValueCInstance::stringValue() const206 ValueImp *CInstance::stringValue() const 207 207 { 208 208 char buf[1024]; 209 snprintf (buf, 1024, "NPObject %p, NPClass %p", _object, _object->_class); 210 KJS::String v(buf); 211 return v; 212 } 213 214 KJS::Value CInstance::numberValue() const 209 snprintf(buf, 1024, "NPObject %p, NPClass %p", _object, _object->_class); 210 return jsString(buf); 211 } 212 213 ValueImp *CInstance::numberValue() const 215 214 { 216 215 // FIXME: Implement something sensible 217 KJS::Number v(0); 218 return v; 219 } 220 221 KJS::Value CInstance::booleanValue() const 216 return jsNumber(0); 217 } 218 219 ValueImp *CInstance::booleanValue() const 222 220 { 223 221 // FIXME: Implement something sensible 224 KJS::Boolean v((bool)0); 225 return v; 226 } 227 228 KJS::Value CInstance::valueOf() const 222 return jsBoolean(false); 223 } 224 225 ValueImp *CInstance::valueOf() const 229 226 { 230 227 return stringValue(); 231 }; 228 } 229 230 } 231 } -
trunk/JavaScriptCore/bindings/c/c_instance.h
r8384 r10084 52 52 virtual void end(); 53 53 54 virtual Value 55 virtual Value 54 virtual ValueImp *valueOf() const; 55 virtual ValueImp *defaultValue (KJS::Type hint) const; 56 56 57 virtual Value 58 virtual Value 57 virtual ValueImp *invokeMethod (ExecState *exec, const MethodList &method, const List &args); 58 virtual ValueImp *invokeDefaultMethod (ExecState *exec, const List &args); 59 59 60 Value 61 Value 62 Value 60 ValueImp *stringValue() const; 61 ValueImp *numberValue() const; 62 ValueImp *booleanValue() const; 63 63 64 64 NPObject *getObject() const { return _object; } -
trunk/JavaScriptCore/bindings/c/c_runtime.cpp
r7927 r10084 42 42 // ---------------------- CField ---------------------- 43 43 44 Value CField::valueFromInstance(KJS::ExecState *exec, const Instance *inst) const44 ValueImp *CField::valueFromInstance(ExecState *exec, const Instance *inst) const 45 45 { 46 46 const CInstance *instance = static_cast<const CInstance*>(inst); 47 47 NPObject *obj = instance->getObject(); 48 Value 48 ValueImp *aValue; 49 49 NPVariant property; 50 50 VOID_TO_NPVARIANT(property); … … 59 59 } 60 60 61 void CField::setValueToInstance( KJS::ExecState *exec, const Instance *inst, const KJS::Value &aValue) const61 void CField::setValueToInstance(ExecState *exec, const Instance *inst, ValueImp *aValue) const 62 62 { 63 63 const CInstance *instance = static_cast<const CInstance*>(inst); -
trunk/JavaScriptCore/bindings/c/c_runtime.h
r7733 r10084 36 36 namespace KJS 37 37 { 38 class Value;39 38 40 39 namespace Bindings … … 50 49 }; 51 50 52 virtual KJS::Value valueFromInstance(KJS::ExecState *exec, const Instance *instance) const;53 virtual void setValueToInstance( KJS::ExecState *exec, const Instance *instance, const KJS::Value &aValue) const;51 virtual ValueImp *valueFromInstance(ExecState *exec, const Instance *instance) const; 52 virtual void setValueToInstance(ExecState *exec, const Instance *instance, ValueImp *aValue) const; 54 53 55 54 virtual const char *name() const { return _NPN_UTF8FromIdentifier(_fieldIdentifier); } … … 86 85 CArray &operator=(const CArray &other); 87 86 88 virtual void setValueAt( KJS::ExecState *exec, unsigned int index, const KJS::Value &aValue) const;89 virtual KJS::Value valueAt(KJS::ExecState *exec, unsigned int index) const;87 virtual void setValueAt(ExecState *exec, unsigned int index, ValueImp *aValue) const; 88 virtual ValueImp *valueAt(ExecState *exec, unsigned int index) const; 90 89 virtual unsigned int getLength() const; 91 90 -
trunk/JavaScriptCore/bindings/c/c_utility.cpp
r8585 r10084 38 38 39 39 // Requires free() of returned UTF16Chars. 40 void convertNPStringToUTF16 40 void convertNPStringToUTF16(const NPString *string, NPUTF16 **UTF16Chars, unsigned int *UTF16Length) 41 41 { 42 convertUTF8ToUTF16 42 convertUTF8ToUTF16(string->UTF8Characters, string->UTF8Length, UTF16Chars, UTF16Length); 43 43 } 44 44 45 45 // Requires free() of returned UTF16Chars. 46 void convertUTF8ToUTF16 46 void convertUTF8ToUTF16(const NPUTF8 *UTF8Chars, int UTF8Length, NPUTF16 **UTF16Chars, unsigned int *UTF16Length) 47 47 { 48 assert 48 assert(UTF8Chars); 49 49 50 50 if (UTF8Length == -1) 51 51 UTF8Length = strlen(UTF8Chars); 52 52 53 CFStringRef stringRef = CFStringCreateWithBytes 53 CFStringRef stringRef = CFStringCreateWithBytes(NULL, (const UInt8*)UTF8Chars, (CFIndex)UTF8Length, kCFStringEncodingUTF8, false); 54 54 55 *UTF16Length = (unsigned int)CFStringGetLength 56 *UTF16Chars = (NPUTF16 *)malloc 55 *UTF16Length = (unsigned int)CFStringGetLength(stringRef); 56 *UTF16Chars = (NPUTF16 *)malloc(sizeof(NPUTF16) * (*UTF16Length)); 57 57 58 58 // Convert the string to UTF16. 59 59 CFRange range = { 0, *UTF16Length }; 60 CFStringGetCharacters 61 CFRelease 60 CFStringGetCharacters(stringRef, range, (UniChar *)*UTF16Chars); 61 CFRelease(stringRef); 62 62 } 63 63 64 64 // Variant value must be released with NPReleaseVariantValue() 65 void coerceValueToNPVariantStringType (KJS::ExecState *exec, const KJS::Value &value, NPVariant *result)65 void coerceValueToNPVariantStringType(ExecState *exec, ValueImp *value, NPVariant *result) 66 66 { 67 UString ustring = value .toString(exec);67 UString ustring = value->toString(exec); 68 68 CString cstring = ustring.UTF8String(); 69 69 NPString string = { (const NPUTF8 *)cstring.c_str(), cstring.size() }; 70 NPN_InitializeVariantWithStringCopy 70 NPN_InitializeVariantWithStringCopy(result, &string); 71 71 } 72 72 73 73 // Variant value must be released with NPReleaseVariantValue() 74 void convertValueToNPVariant (KJS::ExecState *exec, const KJS::Value &value, NPVariant *result)74 void convertValueToNPVariant(ExecState *exec, ValueImp *value, NPVariant *result) 75 75 { 76 Type type = value .type();76 Type type = value->type(); 77 77 78 78 if (type == StringType) { 79 UString ustring = value .toString(exec);79 UString ustring = value->toString(exec); 80 80 CString cstring = ustring.UTF8String(); 81 81 NPString string = { (const NPUTF8 *)cstring.c_str(), cstring.size() }; 82 NPN_InitializeVariantWithStringCopy 82 NPN_InitializeVariantWithStringCopy(result, &string ); 83 83 } 84 84 else if (type == NumberType) { 85 NPN_InitializeVariantWithDouble (result, value.toNumber(exec));85 NPN_InitializeVariantWithDouble(result, value->toNumber(exec)); 86 86 } 87 87 else if (type == BooleanType) { 88 NPN_InitializeVariantWithBool (result, value.toBoolean(exec));88 NPN_InitializeVariantWithBool(result, value->toBoolean(exec)); 89 89 } 90 90 else if (type == UnspecifiedType) { … … 95 95 } 96 96 else if (type == ObjectType) { 97 KJS::ObjectImp *objectImp = static_cast<KJS::ObjectImp*>(value.imp());98 if (objectImp->classInfo() == & KJS::RuntimeObjectImp::info) {99 KJS::RuntimeObjectImp *imp = static_cast<KJS::RuntimeObjectImp *>(value.imp());97 ObjectImp *objectImp = static_cast<ObjectImp*>(value); 98 if (objectImp->classInfo() == &RuntimeObjectImp::info) { 99 RuntimeObjectImp *imp = static_cast<RuntimeObjectImp *>(value); 100 100 CInstance *instance = static_cast<CInstance*>(imp->getInternalInstance()); 101 NPN_InitializeVariantWithObject 101 NPN_InitializeVariantWithObject(result, instance->getObject()); 102 102 } 103 103 else { 104 104 105 KJS::Interpreter *originInterpreter = exec->interpreter();105 Interpreter *originInterpreter = exec->interpreter(); 106 106 const Bindings::RootObject *originExecutionContext = rootForInterpreter(originInterpreter); 107 107 108 KJS::Interpreter *interpreter = 0;108 Interpreter *interpreter = 0; 109 109 if (originInterpreter->isGlobalObject(value)) { 110 interpreter = originInterpreter->interpreterForGlobalObject (value.imp());110 interpreter = originInterpreter->interpreterForGlobalObject(value); 111 111 } 112 112 … … 116 116 const Bindings::RootObject *executionContext = rootForInterpreter(interpreter); 117 117 if (!executionContext) { 118 Bindings::RootObject *newExecutionContext = new KJS::Bindings::RootObject(0);119 newExecutionContext->setInterpreter 118 Bindings::RootObject *newExecutionContext = new Bindings::RootObject(0); 119 newExecutionContext->setInterpreter(interpreter); 120 120 executionContext = newExecutionContext; 121 121 } 122 122 123 NPObject *obj = (NPObject *)exec->interpreter()->createLanguageInstanceForValue (exec, Instance::CLanguage, value.toObject(exec), originExecutionContext, executionContext);124 NPN_InitializeVariantWithObject 125 _NPN_ReleaseObject 123 NPObject *obj = (NPObject *)exec->interpreter()->createLanguageInstanceForValue(exec, Instance::CLanguage, value->toObject(exec), originExecutionContext, executionContext); 124 NPN_InitializeVariantWithObject(result, obj); 125 _NPN_ReleaseObject(obj); 126 126 } 127 127 } … … 130 130 } 131 131 132 Value convertNPVariantToValue (KJS::ExecState *exec, const NPVariant *variant)132 ValueImp *convertNPVariantToValue(ExecState *exec, const NPVariant *variant) 133 133 { 134 134 NPVariantType type = variant->type; … … 136 136 if (type == NPVariantType_Bool) { 137 137 NPBool aBool; 138 if (NPN_VariantToBool 139 return KJS::Boolean(aBool);140 return KJS::Boolean(false);138 if (NPN_VariantToBool(variant, &aBool)) 139 return jsBoolean(aBool); 140 return jsBoolean(false); 141 141 } 142 142 else if (type == NPVariantType_Null) { … … 148 148 else if (type == NPVariantType_Int32) { 149 149 int32_t anInt; 150 if (NPN_VariantToInt32 151 return Number 152 return Number 150 if (NPN_VariantToInt32(variant, &anInt)) 151 return Number(anInt); 152 return Number(0); 153 153 } 154 154 else if (type == NPVariantType_Double) { 155 155 double aDouble; 156 if (NPN_VariantToDouble 157 return Number 158 return Number 156 if (NPN_VariantToDouble(variant, &aDouble)) 157 return Number(aDouble); 158 return Number(0); 159 159 } 160 160 else if (type == NPVariantType_String) { 161 161 NPUTF16 *stringValue; 162 162 unsigned int UTF16Length; 163 convertNPStringToUTF16 164 String resultString(UString((const UChar *)stringValue,UTF16Length));165 free 166 return resultString;163 convertNPStringToUTF16(&variant->value.stringValue, &stringValue, &UTF16Length); // requires free() of returned memory. 164 UString resultString((const UChar *)stringValue,UTF16Length); 165 free(stringValue); 166 return jsString(resultString); 167 167 } 168 168 else if (type == NPVariantType_Object) { … … 172 172 // Get ObjectImp from NP_JavaScriptObject. 173 173 JavaScriptObject *o = (JavaScriptObject *)obj; 174 return Object(const_cast<ObjectImp*>(o->imp));174 return const_cast<ObjectImp*>(o->imp); 175 175 } 176 176 else { -
trunk/JavaScriptCore/bindings/c/c_utility.h
r6909 r10084 46 46 } NP_ValueType; 47 47 48 49 extern void convertNPStringToUTF16 (const NPString *string, NPUTF16 **UTF16Chars, unsigned int *UTF16Length); 50 extern void convertUTF8ToUTF16 (const NPUTF8 *UTF8Chars, int UTF8Length, NPUTF16 **UTF16Chars, unsigned int *UTF16Length); 51 extern void coerceValueToNPVariantStringType (KJS::ExecState *exec, const KJS::Value &value, NPVariant *result); 52 extern void convertValueToNPVariant (KJS::ExecState *exec, const KJS::Value &value, NPVariant *result); 53 extern KJS::Value convertNPVariantToValue (KJS::ExecState *exec, const NPVariant *variant); 48 void convertNPStringToUTF16(const NPString *string, NPUTF16 **UTF16Chars, unsigned int *UTF16Length); 49 void convertUTF8ToUTF16(const NPUTF8 *UTF8Chars, int UTF8Length, NPUTF16 **UTF16Chars, unsigned int *UTF16Length); 50 void coerceValueToNPVariantStringType(KJS::ExecState *exec, KJS::ValueImp *value, NPVariant *result); 51 void convertValueToNPVariant(KJS::ExecState *exec, KJS::ValueImp *value, NPVariant *result); 52 KJS::ValueImp *convertNPVariantToValue(KJS::ExecState *exec, const NPVariant *variant); 54 53 55 54 typedef struct -
trunk/JavaScriptCore/bindings/jni/jni_instance.cpp
r8585 r10084 82 82 } 83 83 84 KJS::ValueJavaInstance::stringValue() const84 ValueImp *JavaInstance::stringValue() const 85 85 { 86 86 jstring stringValue = (jstring)callJNIObjectMethod (_instance->_instance, "toString", "()Ljava/lang/String;"); 87 87 JNIEnv *env = getJNIEnv(); 88 const UChar *c = (const UChar *)getUCharactersFromJStringInEnv (env, stringValue); 89 UString u(c, (int)env->GetStringLength(stringValue)); 90 String v(u); 91 releaseUCharactersForJStringInEnv (env, stringValue, (const jchar *)c); 92 return v; 93 } 94 95 KJS::Value JavaInstance::numberValue() const 88 const jchar *c = getUCharactersFromJStringInEnv(env, stringValue); 89 UString u((const UChar *)c, (int)env->GetStringLength(stringValue)); 90 releaseUCharactersForJStringInEnv(env, stringValue, c); 91 return jsString(u); 92 } 93 94 ValueImp *JavaInstance::numberValue() const 96 95 { 97 96 jdouble doubleValue = callJNIDoubleMethod (_instance->_instance, "doubleValue", "()D"); 98 KJS::Number v(doubleValue); 99 return v; 100 } 101 102 KJS::Value JavaInstance::booleanValue() const 97 return jsNumber(doubleValue); 98 } 99 100 ValueImp *JavaInstance::booleanValue() const 103 101 { 104 102 jboolean booleanValue = callJNIBooleanMethod (_instance->_instance, "booleanValue", "()Z"); 105 KJS::Boolean v(booleanValue); 106 return v; 107 } 108 109 Value JavaInstance::invokeMethod (KJS::ExecState *exec, const MethodList &methodList, const List &args) 103 return jsBoolean(booleanValue); 104 } 105 106 ValueImp *JavaInstance::invokeMethod (ExecState *exec, const MethodList &methodList, const List &args) 110 107 { 111 108 int i, count = args.size(); 112 109 jvalue *jArgs; 113 Value 110 ValueImp *resultValue; 114 111 Method *method = 0; 115 112 unsigned int numMethods = methodList.length(); … … 146 143 JavaParameter *aParameter = static_cast<JavaParameter *>(jMethod->parameterAt(i)); 147 144 jArgs[i] = convertValueToJValue (exec, args.at(i), aParameter->getJNIType(), aParameter->type()); 148 JS_LOG("arg[%d] = %s\n", i, args.at(i) .toString(exec).ascii());145 JS_LOG("arg[%d] = %s\n", i, args.at(i)->toString(exec).ascii()); 149 146 } 150 147 … … 159 156 if (execContext && execContext->nativeHandle()) { 160 157 jobject obj = _instance->_instance; 161 Value 158 ValueImp *exceptionDescription; 162 159 const char *callingURL = 0; // FIXME, need to propagate calling URL to Java 163 160 handled = dispatchJNICall (execContext->nativeHandle(), obj, jMethod->isStatic(), jMethod->JNIReturnType(), jMethod->methodID(obj), jArgs, result, callingURL, exceptionDescription); 164 if (!exceptionDescription.isNull()) { 165 Object error = Error::create(exec, GeneralError, exceptionDescription.toString(exec).UTF8String().c_str()); 166 161 if (exceptionDescription) { 162 ObjectImp *error = Error::create(exec, GeneralError, exceptionDescription->toString(exec).UTF8String().c_str()); 167 163 exec->setException(error); 168 164 … … 257 253 258 254 case boolean_type: { 259 resultValue = KJS::Boolean(result.z);255 resultValue = Boolean(result.z); 260 256 } 261 257 break; … … 308 304 } 309 305 310 KJS::Value JavaInstance::invokeDefaultMethod (KJS::ExecState *exec, const KJS::List &args)306 ValueImp *JavaInstance::invokeDefaultMethod (ExecState *exec, const List &args) 311 307 { 312 308 return Undefined(); … … 314 310 315 311 316 KJS::Value JavaInstance::defaultValue (KJS::Type hint) const312 ValueImp *JavaInstance::defaultValue (Type hint) const 317 313 { 318 314 if (hint == StringType) { … … 341 337 } 342 338 343 KJS::ValueJavaInstance::valueOf() const339 ValueImp *JavaInstance::valueOf() const 344 340 { 345 341 return stringValue(); -
trunk/JavaScriptCore/bindings/jni/jni_instance.h
r8384 r10084 91 91 virtual void end(); 92 92 93 virtual Value 94 virtual Value 93 virtual ValueImp *valueOf() const; 94 virtual ValueImp *defaultValue (Type hint) const; 95 95 96 virtual Value 97 virtual Value 96 virtual ValueImp *invokeMethod (ExecState *exec, const MethodList &method, const List &args); 97 virtual ValueImp *invokeDefaultMethod (ExecState *exec, const List &args); 98 98 99 99 jobject javaInstance() const { return _instance->_instance; } 100 100 101 Value 102 Value 103 Value 101 ValueImp *stringValue() const; 102 ValueImp *numberValue() const; 103 ValueImp *booleanValue() const; 104 104 105 105 private: -
trunk/JavaScriptCore/bindings/jni/jni_jsobject.cpp
r9078 r10084 78 78 } 79 79 else { 80 KJS::ObjectImp *imp = jlong_to_impptr(nativeHandle);80 ObjectImp *imp = jlong_to_impptr(nativeHandle); 81 81 if (!rootForImp(imp)) { 82 82 fprintf (stderr, "%s:%d: Attempt to access JavaScript from destroyed applet, type %d.\n", __FILE__, __LINE__, context->type); … … 174 174 175 175 Identifier identifier(JavaString(methodName).ustring()); 176 Value 177 Interpreter::unlock(); 178 if (func .isNull() || func.type() == UndefinedType) {176 ValueImp *func = _imp->get (exec, identifier); 177 Interpreter::unlock(); 178 if (func->isUndefinedOrNull()) { 179 179 // Maybe throw an exception here? 180 180 return 0; … … 182 182 183 183 // Call the function object. 184 ObjectImp *funcImp = static_cast<ObjectImp*>(func .imp());185 Object thisObj = Object(const_cast<ObjectImp*>(_imp));184 ObjectImp *funcImp = static_cast<ObjectImp*>(func); 185 ObjectImp *thisObj = const_cast<ObjectImp*>(_imp); 186 186 List argList = listFromJArray(args); 187 187 Interpreter::lock(); 188 Value 188 ValueImp *result = funcImp->call (exec, thisObj, argList); 189 189 Interpreter::unlock(); 190 190 … … 197 197 JS_LOG ("script = %s\n", JavaString(script).UTF8String()); 198 198 199 Object thisObj = Object(const_cast<ObjectImp*>(_imp));200 Value 199 ObjectImp *thisObj = const_cast<ObjectImp*>(_imp); 200 ValueImp *result; 201 201 202 202 Interpreter::lock(); … … 207 207 if (type == Normal) { 208 208 result = completion.value(); 209 if ( result.isNull()) {209 if (!result) { 210 210 result = Undefined(); 211 211 } … … 226 226 227 227 Interpreter::lock(); 228 Value 228 ValueImp *result = _imp->get (exec, Identifier (JavaString(memberName).ustring())); 229 229 Interpreter::unlock(); 230 230 … … 259 259 ExecState *exec = _root->interpreter()->globalExec(); 260 260 Interpreter::lock(); 261 Value 261 ValueImp *result = _imp->get (exec, (unsigned)index); 262 262 Interpreter::unlock(); 263 263 … … 282 282 283 283 Interpreter::lock(); 284 Object thisObj = Object(const_cast<ObjectImp*>(_imp));284 ObjectImp *thisObj = const_cast<ObjectImp*>(_imp); 285 285 ExecState *exec = _root->interpreter()->globalExec(); 286 286 … … 329 329 } 330 330 331 jobject JSObject::convertValueToJObject ( KJS::Valuevalue) const331 jobject JSObject::convertValueToJObject (ValueImp *value) const 332 332 { 333 333 ExecState *exec = _root->interpreter()->globalExec(); … … 343 343 // Everything else -> JSObject 344 344 345 KJS::Type type = value.type();346 if (type == KJS::NumberType) {345 Type type = value->type(); 346 if (type == NumberType) { 347 347 jclass JSObjectClass = env->FindClass ("java/lang/Double"); 348 348 jmethodID constructorID = env->GetMethodID (JSObjectClass, "<init>", "(D)V"); 349 349 if (constructorID != NULL) { 350 result = env->NewObject (JSObjectClass, constructorID, (jdouble)value .toNumber(exec));351 } 352 } 353 else if (type == KJS::StringType) {354 KJS::UString stringValue = value.toString(exec);350 result = env->NewObject (JSObjectClass, constructorID, (jdouble)value->toNumber(exec)); 351 } 352 } 353 else if (type == StringType) { 354 UString stringValue = value->toString(exec); 355 355 JNIEnv *env = getJNIEnv(); 356 356 result = env->NewString ((const jchar *)stringValue.data(), stringValue.size()); 357 357 } 358 else if (type == KJS::BooleanType) {358 else if (type == BooleanType) { 359 359 jclass JSObjectClass = env->FindClass ("java/lang/Boolean"); 360 360 jmethodID constructorID = env->GetMethodID (JSObjectClass, "<init>", "(Z)V"); 361 361 if (constructorID != NULL) { 362 result = env->NewObject (JSObjectClass, constructorID, (jboolean)value .toBoolean(exec));362 result = env->NewObject (JSObjectClass, constructorID, (jboolean)value->toBoolean(exec)); 363 363 } 364 364 } … … 367 367 jlong nativeHandle; 368 368 369 if (type == KJS::ObjectType){370 KJS::ObjectImp *imp = static_cast<KJS::ObjectImp*>(value.imp());369 if (type == ObjectType){ 370 ObjectImp *imp = static_cast<ObjectImp*>(value); 371 371 372 372 // We either have a wrapper around a Java instance or a JavaScript … … 375 375 // as it's nativeHandle. 376 376 if (imp->classInfo() && strcmp(imp->classInfo()->className, "RuntimeObject") == 0) { 377 KJS::RuntimeObjectImp *runtimeImp = static_cast<KJS::RuntimeObjectImp*>(value.imp());377 RuntimeObjectImp *runtimeImp = static_cast<RuntimeObjectImp*>(value); 378 378 Bindings::JavaInstance *runtimeInstance = static_cast<Bindings::JavaInstance *>(runtimeImp->getInternalInstance()); 379 379 return runtimeInstance->javaInstance(); … … 412 412 } 413 413 414 KJS::ValueJSObject::convertJObjectToValue (jobject theObject) const414 ValueImp *JSObject::convertJObjectToValue (jobject theObject) const 415 415 { 416 416 // Instances of netscape.javascript.JSObject get converted back to … … 428 428 jfieldID fieldID = env->GetFieldID((jclass)classOfInstance, "nativeJSObject", "long"); 429 429 if (fieldID == NULL) { 430 return KJS::Undefined();430 return Undefined(); 431 431 } 432 432 jlong nativeHandle = env->GetLongField(theObject, fieldID); 433 433 if (nativeHandle == UndefinedHandle) { 434 return KJS::Undefined();435 } 436 KJS::ObjectImp *imp = static_cast<KJS::ObjectImp*>(jlong_to_impptr(nativeHandle));437 return KJS::Object(const_cast<KJS::ObjectImp*>(imp));438 } 439 440 Interpreter::lock(); 441 KJS::RuntimeObjectImp *newImp = new KJS::RuntimeObjectImp(new Bindings::JavaInstance (theObject, _root));442 Interpreter::unlock(); 443 444 return KJS::Object(newImp);445 } 446 447 KJS::List JSObject::listFromJArray(jobjectArray jArray) const434 return Undefined(); 435 } 436 ObjectImp *imp = static_cast<ObjectImp*>(jlong_to_impptr(nativeHandle)); 437 return imp; 438 } 439 440 Interpreter::lock(); 441 RuntimeObjectImp *newImp = new RuntimeObjectImp(new Bindings::JavaInstance (theObject, _root)); 442 Interpreter::unlock(); 443 444 return newImp; 445 } 446 447 List JSObject::listFromJArray(jobjectArray jArray) const 448 448 { 449 449 JNIEnv *env = getJNIEnv(); 450 450 long i, numObjects = jArray ? env->GetArrayLength (jArray) : 0; 451 KJS::List aList;451 List aList; 452 452 453 453 for (i = 0; i < numObjects; i++) { -
trunk/JavaScriptCore/bindings/jni/jni_jsobject.h
r6637 r10084 89 89 static jvalue invoke (JSObjectCallContext *context); 90 90 91 jobject convertValueToJObject ( KJS::Valuevalue) const;92 KJS::ValueconvertJObjectToValue (jobject theObject) const;93 KJS::List listFromJArray(jobjectArray jArray) const;91 jobject convertValueToJObject (ValueImp *value) const; 92 ValueImp *convertJObjectToValue (jobject theObject) const; 93 List listFromJArray(jobjectArray jArray) const; 94 94 95 95 private: 96 const Bindings::RootObject *_root;97 KJS::ObjectImp *_imp;96 const RootObject *_root; 97 ObjectImp *_imp; 98 98 }; 99 99 … … 117 117 jstring KJS_JSObject_JSObjectToString (JNIEnv *env, jclass clazz, jlong nativeJSObject); 118 118 119 } // namespace Bindings119 } 120 120 121 121 #endif -
trunk/JavaScriptCore/bindings/jni/jni_objc.mm
r8213 r10084 44 44 @end 45 45 46 bool KJS::Bindings::dispatchJNICall (const void *targetAppletView, jobject obj, bool isStatic, JNIType returnType, jmethodID methodID, jvalue *args, jvalue &result, const char *callingURL, Value 46 bool KJS::Bindings::dispatchJNICall (const void *targetAppletView, jobject obj, bool isStatic, JNIType returnType, jmethodID methodID, jvalue *args, jvalue &result, const char *callingURL, ValueImp *&exceptionDescription) 47 47 { 48 48 id view = (id)targetAppletView; -
trunk/JavaScriptCore/bindings/jni/jni_runtime.cpp
r9102 r10084 68 68 } 69 69 70 KJS::Value JavaArray::convertJObjectToArray (KJS::ExecState *exec, jobject anObject, const char *type, const RootObject *r)70 ValueImp *JavaArray::convertJObjectToArray (ExecState *exec, jobject anObject, const char *type, const RootObject *r) 71 71 { 72 72 if (type[0] != '[') 73 73 return Undefined(); 74 74 75 return KJS::Object(new RuntimeArrayImp(exec, new JavaArray ((jobject)anObject, type, r)));76 } 77 78 jvalue JavaField::dispatchValueFromInstance( KJS::ExecState *exec, const JavaInstance *instance, const char *name, const char *sig, JNIType returnType) const75 return new RuntimeArrayImp(exec, new JavaArray((jobject)anObject, type, r)); 76 } 77 78 jvalue JavaField::dispatchValueFromInstance(ExecState *exec, const JavaInstance *instance, const char *name, const char *sig, JNIType returnType) const 79 79 { 80 80 jobject jinstance = instance->javaInstance(); … … 91 91 const RootObject *execContext = instance->executionContext(); 92 92 if (execContext && execContext->nativeHandle()) { 93 Value 93 ValueImp *exceptionDescription; 94 94 jvalue args[1]; 95 95 96 96 args[0].l = jinstance; 97 97 dispatchJNICall (execContext->nativeHandle(), fieldJInstance, false, returnType, mid, args, result, 0, exceptionDescription); 98 if ( !exceptionDescription.isNull()) {99 Object error = Error::create(exec, GeneralError, exceptionDescription.toString(exec).UTF8String().c_str());98 if (exceptionDescription) { 99 ObjectImp *error = Error::create(exec, GeneralError, exceptionDescription->toString(exec).UTF8String().c_str()); 100 100 exec->setException(error); 101 101 } … … 106 106 } 107 107 108 KJS::Value JavaField::valueFromInstance(KJS::ExecState *exec, const Instance *i) const108 ValueImp *JavaField::valueFromInstance(ExecState *exec, const Instance *i) const 109 109 { 110 110 const JavaInstance *instance = static_cast<const JavaInstance *>(i); 111 111 112 Value 112 ValueImp *jsresult = Undefined(); 113 113 114 114 switch (_JNIType) { … … 130 130 jvalue result = dispatchValueFromInstance (exec, instance, "getBoolean", "(Ljava/lang/Object;)Z", boolean_type); 131 131 jboolean value = result.z; 132 jsresult = KJS::Boolean((bool)value);132 jsresult = Boolean((bool)value); 133 133 } 134 134 break; … … 159 159 } 160 160 161 JS_LOG ("getting %s = %s\n", name(), jsresult .toString(exec).ascii());161 JS_LOG ("getting %s = %s\n", name(), jsresult->toString(exec).ascii()); 162 162 163 163 return jsresult; 164 164 } 165 165 166 void JavaField::dispatchSetValueToInstance( KJS::ExecState *exec, const JavaInstance *instance, jvalue javaValue, const char *name, const char *sig) const166 void JavaField::dispatchSetValueToInstance(ExecState *exec, const JavaInstance *instance, jvalue javaValue, const char *name, const char *sig) const 167 167 { 168 168 jobject jinstance = instance->javaInstance(); … … 177 177 const RootObject *execContext = instance->executionContext(); 178 178 if (execContext && execContext->nativeHandle()) { 179 Value 179 ValueImp *exceptionDescription; 180 180 jvalue args[2]; 181 181 jvalue result; … … 184 184 args[1] = javaValue; 185 185 dispatchJNICall (execContext->nativeHandle(), fieldJInstance, false, void_type, mid, args, result, 0, exceptionDescription); 186 if ( !exceptionDescription.isNull()) {187 Object error = Error::create(exec, GeneralError, exceptionDescription.toString(exec).UTF8String().c_str());186 if (exceptionDescription) { 187 ObjectImp *error = Error::create(exec, GeneralError, exceptionDescription->toString(exec).UTF8String().c_str()); 188 188 exec->setException(error); 189 189 } … … 193 193 } 194 194 195 void JavaField::setValueToInstance( KJS::ExecState *exec, const Instance *i, const KJS::Value &aValue) const195 void JavaField::setValueToInstance(ExecState *exec, const Instance *i, ValueImp *aValue) const 196 196 { 197 197 const JavaInstance *instance = static_cast<const JavaInstance *>(i); 198 198 jvalue javaValue = convertValueToJValue (exec, aValue, _JNIType, type()); 199 199 200 JS_LOG ("setting value %s to %s\n", name(), aValue .toString(exec).ascii());200 JS_LOG ("setting value %s to %s\n", name(), aValue->toString(exec).ascii()); 201 201 202 202 switch (_JNIType) { … … 395 395 }; 396 396 397 void JavaArray::setValueAt( KJS::ExecState *exec, unsigned int index, const KJS::Value &aValue) const397 void JavaArray::setValueAt(ExecState *exec, unsigned int index, ValueImp *aValue) const 398 398 { 399 399 JNIEnv *env = getJNIEnv(); … … 463 463 464 464 465 KJS::Value JavaArray::valueAt(KJS::ExecState *exec, unsigned int index) const465 ValueImp *JavaArray::valueAt(ExecState *exec, unsigned int index) const 466 466 { 467 467 JNIEnv *env = getJNIEnv(); … … 490 490 jboolean aBoolean; 491 491 env->GetBooleanArrayRegion(booleanArray, index, 1, &aBoolean); 492 return KJS::Boolean (aBoolean);492 return Boolean (aBoolean); 493 493 } 494 494 -
trunk/JavaScriptCore/bindings/jni/jni_runtime.h
r8344 r10084 36 36 namespace KJS 37 37 { 38 class Value;39 38 40 39 namespace Bindings … … 69 68 const jchar *uchars() const { return (const jchar *)_ustring.data(); } 70 69 int length() const { return _ustring.size(); } 71 KJS::UString ustring() const { return _ustring; }70 UString ustring() const { return _ustring; } 72 71 73 72 private: … … 183 182 } 184 183 185 virtual KJS::Value valueFromInstance(KJS::ExecState *exec, const Instance *instance) const;186 virtual void setValueToInstance( KJS::ExecState *exec, const Instance *instance, const KJS::Value &aValue) const;184 virtual ValueImp *valueFromInstance(ExecState *exec, const Instance *instance) const; 185 virtual void setValueToInstance(ExecState *exec, const Instance *instance, ValueImp *aValue) const; 187 186 188 187 virtual const char *name() const { return _name.UTF8String(); } … … 192 191 193 192 private: 194 void JavaField::dispatchSetValueToInstance( KJS::ExecState *exec, const JavaInstance *instance, jvalue javaValue, const char *name, const char *sig) const;195 jvalue JavaField::dispatchValueFromInstance( KJS::ExecState *exec, const JavaInstance *instance, const char *name, const char *sig, JNIType returnType) const;193 void JavaField::dispatchSetValueToInstance(ExecState *exec, const JavaInstance *instance, jvalue javaValue, const char *name, const char *sig) const; 194 jvalue JavaField::dispatchValueFromInstance(ExecState *exec, const JavaInstance *instance, const char *name, const char *sig, JNIType returnType) const; 196 195 197 196 JavaString _name; … … 262 261 long _numParameters; 263 262 JavaString _name; 264 mutable KJS::UString *_signature;263 mutable UString *_signature; 265 264 JavaString _returnType; 266 265 JNIType _JNIReturnType; … … 292 291 }; 293 292 294 virtual void setValueAt( KJS::ExecState *exec, unsigned int index, const KJS::Value &aValue) const;295 virtual KJS::Value valueAt(KJS::ExecState *exec, unsigned int index) const;293 virtual void setValueAt(ExecState *exec, unsigned int index, ValueImp *aValue) const; 294 virtual ValueImp *valueAt(ExecState *exec, unsigned int index) const; 296 295 virtual unsigned int getLength() const; 297 296 … … 300 299 jobject javaArray() const { return _array->_instance; } 301 300 302 static KJS::Value convertJObjectToArray (KJS::ExecState *exec, jobject anObject, const char *type, const RootObject *r);301 static ValueImp *convertJObjectToArray (ExecState *exec, jobject anObject, const char *type, const RootObject *r); 303 302 304 303 const RootObject *executionContext() const { return _root; } -
trunk/JavaScriptCore/bindings/jni/jni_utility.cpp
r9078 r10084 31 31 #include "runtime_object.h" 32 32 33 using namespace KJS::Bindings; 33 namespace KJS { 34 35 namespace Bindings { 34 36 35 37 static JavaVM *jvm = 0; 36 38 37 JavaVM * KJS::Bindings::getJavaVM()39 JavaVM *getJavaVM() 38 40 { 39 41 if (jvm) … … 56 58 } 57 59 58 JNIEnv * KJS::Bindings::getJNIEnv()60 JNIEnv *getJNIEnv() 59 61 { 60 62 JNIEnv *env; … … 271 273 } 272 274 273 jmethodID KJS::Bindings::getMethodID (jobject obj, const char *name, const char *sig)275 jmethodID getMethodID (jobject obj, const char *name, const char *sig) 274 276 { 275 277 JNIEnv *env = getJNIEnv(); … … 310 312 va_end (args); 311 313 312 void KJS::Bindings::callJNIVoidMethod (jobject obj, const char *name, const char *sig, ... )314 void callJNIVoidMethod (jobject obj, const char *name, const char *sig, ... ) 313 315 { 314 316 CALL_JNI_METHOD (void_type, obj, name, sig); 315 317 } 316 318 317 jobject KJS::Bindings::callJNIObjectMethod (jobject obj, const char *name, const char *sig, ... )319 jobject callJNIObjectMethod (jobject obj, const char *name, const char *sig, ... ) 318 320 { 319 321 CALL_JNI_METHOD (object_type, obj, name, sig); … … 321 323 } 322 324 323 jboolean KJS::Bindings::callJNIBooleanMethod( jobject obj, const char *name, const char *sig, ... )325 jboolean callJNIBooleanMethod( jobject obj, const char *name, const char *sig, ... ) 324 326 { 325 327 CALL_JNI_METHOD (boolean_type, obj, name, sig); … … 327 329 } 328 330 329 jboolean KJS::Bindings::callJNIStaticBooleanMethod (jclass cls, const char *name, const char *sig, ... )331 jboolean callJNIStaticBooleanMethod (jclass cls, const char *name, const char *sig, ... ) 330 332 { 331 333 CALL_JNI_STATIC_METHOD (boolean_type, cls, name, sig); … … 333 335 } 334 336 335 jbyte KJS::Bindings::callJNIByteMethod( jobject obj, const char *name, const char *sig, ... )337 jbyte callJNIByteMethod( jobject obj, const char *name, const char *sig, ... ) 336 338 { 337 339 CALL_JNI_METHOD (byte_type, obj, name, sig); … … 339 341 } 340 342 341 jchar KJS::Bindings::callJNICharMethod (jobject obj, const char *name, const char *sig, ... )343 jchar callJNICharMethod (jobject obj, const char *name, const char *sig, ... ) 342 344 { 343 345 CALL_JNI_METHOD (char_type, obj, name, sig); … … 345 347 } 346 348 347 jshort KJS::Bindings::callJNIShortMethod (jobject obj, const char *name, const char *sig, ... )349 jshort callJNIShortMethod (jobject obj, const char *name, const char *sig, ... ) 348 350 { 349 351 CALL_JNI_METHOD (short_type, obj, name, sig); … … 351 353 } 352 354 353 jint KJS::Bindings::callJNIIntMethod (jobject obj, const char *name, const char *sig, ... )355 jint callJNIIntMethod (jobject obj, const char *name, const char *sig, ... ) 354 356 { 355 357 CALL_JNI_METHOD (int_type, obj, name, sig); … … 357 359 } 358 360 359 jlong KJS::Bindings::callJNILongMethod (jobject obj, const char *name, const char *sig, ... )361 jlong callJNILongMethod (jobject obj, const char *name, const char *sig, ... ) 360 362 { 361 363 CALL_JNI_METHOD (long_type, obj, name, sig); … … 363 365 } 364 366 365 jfloat KJS::Bindings::callJNIFloatMethod (jobject obj, const char *name, const char *sig, ... )367 jfloat callJNIFloatMethod (jobject obj, const char *name, const char *sig, ... ) 366 368 { 367 369 CALL_JNI_METHOD (float_type, obj, name, sig); … … 369 371 } 370 372 371 jdouble KJS::Bindings::callJNIDoubleMethod (jobject obj, const char *name, const char *sig, ... )373 jdouble callJNIDoubleMethod (jobject obj, const char *name, const char *sig, ... ) 372 374 { 373 375 CALL_JNI_METHOD (double_type, obj, name, sig); … … 375 377 } 376 378 377 void KJS::Bindings::callJNIVoidMethodA (jobject obj, const char *name, const char *sig, jvalue *args)379 void callJNIVoidMethodA (jobject obj, const char *name, const char *sig, jvalue *args) 378 380 { 379 381 jvalue result = callJNIMethodA (void_type, obj, name, sig, args); 380 382 } 381 383 382 jobject KJS::Bindings::callJNIObjectMethodA (jobject obj, const char *name, const char *sig, jvalue *args)384 jobject callJNIObjectMethodA (jobject obj, const char *name, const char *sig, jvalue *args) 383 385 { 384 386 jvalue result = callJNIMethodA (object_type, obj, name, sig, args); … … 386 388 } 387 389 388 jbyte KJS::Bindings::callJNIByteMethodA ( jobject obj, const char *name, const char *sig, jvalue *args)390 jbyte callJNIByteMethodA ( jobject obj, const char *name, const char *sig, jvalue *args) 389 391 { 390 392 jvalue result = callJNIMethodA (byte_type, obj, name, sig, args); … … 392 394 } 393 395 394 jchar KJS::Bindings::callJNICharMethodA (jobject obj, const char *name, const char *sig, jvalue *args)396 jchar callJNICharMethodA (jobject obj, const char *name, const char *sig, jvalue *args) 395 397 { 396 398 jvalue result = callJNIMethodA (char_type, obj, name, sig, args); … … 398 400 } 399 401 400 jshort KJS::Bindings::callJNIShortMethodA (jobject obj, const char *name, const char *sig, jvalue *args)402 jshort callJNIShortMethodA (jobject obj, const char *name, const char *sig, jvalue *args) 401 403 { 402 404 jvalue result = callJNIMethodA (short_type, obj, name, sig, args); … … 404 406 } 405 407 406 jint KJS::Bindings::callJNIIntMethodA (jobject obj, const char *name, const char *sig, jvalue *args)408 jint callJNIIntMethodA (jobject obj, const char *name, const char *sig, jvalue *args) 407 409 { 408 410 jvalue result = callJNIMethodA (int_type, obj, name, sig, args); … … 410 412 } 411 413 412 jlong KJS::Bindings::callJNILongMethodA (jobject obj, const char *name, const char *sig, jvalue *args)414 jlong callJNILongMethodA (jobject obj, const char *name, const char *sig, jvalue *args) 413 415 { 414 416 jvalue result = callJNIMethodA (long_type, obj, name, sig, args); … … 416 418 } 417 419 418 jfloat KJS::Bindings::callJNIFloatMethodA (jobject obj, const char *name, const char *sig, jvalue *args)420 jfloat callJNIFloatMethodA (jobject obj, const char *name, const char *sig, jvalue *args) 419 421 { 420 422 jvalue result = callJNIMethodA (float_type, obj, name, sig, args); … … 422 424 } 423 425 424 jdouble KJS::Bindings::callJNIDoubleMethodA (jobject obj, const char *name, const char *sig, jvalue *args)426 jdouble callJNIDoubleMethodA (jobject obj, const char *name, const char *sig, jvalue *args) 425 427 { 426 428 jvalue result = callJNIMethodA (double_type, obj, name, sig, args); … … 428 430 } 429 431 430 jboolean KJS::Bindings::callJNIBooleanMethodA (jobject obj, const char *name, const char *sig, jvalue *args)432 jboolean callJNIBooleanMethodA (jobject obj, const char *name, const char *sig, jvalue *args) 431 433 { 432 434 jvalue result = callJNIMethodA (boolean_type, obj, name, sig, args); … … 434 436 } 435 437 436 void KJS::Bindings::callJNIVoidMethodIDA (jobject obj, jmethodID methodID, jvalue *args)438 void callJNIVoidMethodIDA (jobject obj, jmethodID methodID, jvalue *args) 437 439 { 438 440 jvalue result = callJNIMethodIDA (void_type, obj, methodID, args); 439 441 } 440 442 441 jobject KJS::Bindings::callJNIObjectMethodIDA (jobject obj, jmethodID methodID, jvalue *args)443 jobject callJNIObjectMethodIDA (jobject obj, jmethodID methodID, jvalue *args) 442 444 { 443 445 jvalue result = callJNIMethodIDA (object_type, obj, methodID, args); … … 445 447 } 446 448 447 jbyte KJS::Bindings::callJNIByteMethodIDA ( jobject obj, jmethodID methodID, jvalue *args)449 jbyte callJNIByteMethodIDA ( jobject obj, jmethodID methodID, jvalue *args) 448 450 { 449 451 jvalue result = callJNIMethodIDA (byte_type, obj, methodID, args); … … 451 453 } 452 454 453 jchar KJS::Bindings::callJNICharMethodIDA (jobject obj, jmethodID methodID, jvalue *args)455 jchar callJNICharMethodIDA (jobject obj, jmethodID methodID, jvalue *args) 454 456 { 455 457 jvalue result = callJNIMethodIDA (char_type, obj, methodID, args); … … 457 459 } 458 460 459 jshort KJS::Bindings::callJNIShortMethodIDA (jobject obj, jmethodID methodID, jvalue *args)461 jshort callJNIShortMethodIDA (jobject obj, jmethodID methodID, jvalue *args) 460 462 { 461 463 jvalue result = callJNIMethodIDA (short_type, obj, methodID, args); … … 463 465 } 464 466 465 jint KJS::Bindings::callJNIIntMethodIDA (jobject obj, jmethodID methodID, jvalue *args)467 jint callJNIIntMethodIDA (jobject obj, jmethodID methodID, jvalue *args) 466 468 { 467 469 jvalue result = callJNIMethodIDA (int_type, obj, methodID, args); … … 469 471 } 470 472 471 jlong KJS::Bindings::callJNILongMethodIDA (jobject obj, jmethodID methodID, jvalue *args)473 jlong callJNILongMethodIDA (jobject obj, jmethodID methodID, jvalue *args) 472 474 { 473 475 jvalue result = callJNIMethodIDA (long_type, obj, methodID, args); … … 475 477 } 476 478 477 jfloat KJS::Bindings::callJNIFloatMethodIDA (jobject obj, jmethodID methodID, jvalue *args)479 jfloat callJNIFloatMethodIDA (jobject obj, jmethodID methodID, jvalue *args) 478 480 { 479 481 jvalue result = callJNIMethodIDA (float_type, obj, methodID, args); … … 481 483 } 482 484 483 jdouble KJS::Bindings::callJNIDoubleMethodIDA (jobject obj, jmethodID methodID, jvalue *args)485 jdouble callJNIDoubleMethodIDA (jobject obj, jmethodID methodID, jvalue *args) 484 486 { 485 487 jvalue result = callJNIMethodIDA (double_type, obj, methodID, args); … … 487 489 } 488 490 489 jboolean KJS::Bindings::callJNIBooleanMethodIDA (jobject obj, jmethodID methodID, jvalue *args)491 jboolean callJNIBooleanMethodIDA (jobject obj, jmethodID methodID, jvalue *args) 490 492 { 491 493 jvalue result = callJNIMethodIDA (boolean_type, obj, methodID, args); … … 493 495 } 494 496 495 const char * KJS::Bindings::getCharactersFromJString (jstring aJString)497 const char *getCharactersFromJString (jstring aJString) 496 498 { 497 499 return getCharactersFromJStringInEnv (getJNIEnv(), aJString); 498 500 } 499 501 500 void KJS::Bindings::releaseCharactersForJString (jstring aJString, const char *s)502 void releaseCharactersForJString (jstring aJString, const char *s) 501 503 { 502 504 releaseCharactersForJStringInEnv (getJNIEnv(), aJString, s); 503 505 } 504 506 505 const char * KJS::Bindings::getCharactersFromJStringInEnv (JNIEnv *env, jstring aJString)507 const char *getCharactersFromJStringInEnv (JNIEnv *env, jstring aJString) 506 508 { 507 509 jboolean isCopy; … … 515 517 } 516 518 517 void KJS::Bindings::releaseCharactersForJStringInEnv (JNIEnv *env, jstring aJString, const char *s)519 void releaseCharactersForJStringInEnv (JNIEnv *env, jstring aJString, const char *s) 518 520 { 519 521 env->ReleaseStringUTFChars (aJString, s); 520 522 } 521 523 522 const jchar * KJS::Bindings::getUCharactersFromJStringInEnv (JNIEnv *env, jstring aJString)524 const jchar *getUCharactersFromJStringInEnv (JNIEnv *env, jstring aJString) 523 525 { 524 526 jboolean isCopy; … … 532 534 } 533 535 534 void KJS::Bindings::releaseUCharactersForJStringInEnv (JNIEnv *env, jstring aJString, const jchar *s)536 void releaseUCharactersForJStringInEnv (JNIEnv *env, jstring aJString, const jchar *s) 535 537 { 536 538 env->ReleaseStringChars (aJString, s); 537 539 } 538 540 539 JNIType KJS::Bindings::JNITypeFromClassName(const char *name)541 JNIType JNITypeFromClassName(const char *name) 540 542 { 541 543 JNIType type; … … 565 567 } 566 568 567 const char * KJS::Bindings::signatureFromPrimitiveType(JNIType type)569 const char *signatureFromPrimitiveType(JNIType type) 568 570 { 569 571 switch (type){ … … 605 607 } 606 608 607 JNIType KJS::Bindings::JNITypeFromPrimitiveType(char type)609 JNIType JNITypeFromPrimitiveType(char type) 608 610 { 609 611 switch (type){ … … 645 647 } 646 648 647 jvalue KJS::Bindings::getJNIField( jobject obj, JNIType type, const char *name, const char *signature)649 jvalue getJNIField( jobject obj, JNIType type, const char *name, const char *signature) 648 650 { 649 651 JavaVM *jvm = getJavaVM(); … … 707 709 } 708 710 709 jvalue KJS::Bindings::convertValueToJValue (KJS::ExecState *exec, KJS::Valuevalue, JNIType _JNIType, const char *javaClassName)711 jvalue convertValueToJValue (ExecState *exec, ValueImp *value, JNIType _JNIType, const char *javaClassName) 710 712 { 711 713 jvalue result; … … 716 718 717 719 // First see if we have a Java instance. 718 if (value .type() == KJS::ObjectType){719 KJS::ObjectImp *objectImp = static_cast<KJS::ObjectImp*>(value.imp());720 if (objectImp->classInfo() == & KJS::RuntimeObjectImp::info) {721 KJS::RuntimeObjectImp *imp = static_cast<KJS::RuntimeObjectImp *>(value.imp());720 if (value->isObject()){ 721 ObjectImp *objectImp = static_cast<ObjectImp*>(value); 722 if (objectImp->classInfo() == &RuntimeObjectImp::info) { 723 RuntimeObjectImp *imp = static_cast<RuntimeObjectImp *>(value); 722 724 JavaInstance *instance = static_cast<JavaInstance*>(imp->getInternalInstance()); 723 725 result.l = instance->javaInstance(); 724 726 } 725 else if (objectImp->classInfo() == & KJS::RuntimeArrayImp::info) {726 KJS::RuntimeArrayImp *imp = static_cast<KJS::RuntimeArrayImp *>(value.imp());727 else if (objectImp->classInfo() == &RuntimeArrayImp::info) { 728 RuntimeArrayImp *imp = static_cast<RuntimeArrayImp *>(value); 727 729 JavaArray *array = static_cast<JavaArray*>(imp->getConcreteArray()); 728 730 result.l = array->javaArray(); … … 734 736 if (result.l == 0 && strcmp(javaClassName, "java.lang.String") == 0) { 735 737 #if CONVERT_NULL_TO_EMPTY_STRING 736 if (value .type() == KJS::NullType) {738 if (value->isNull()) { 737 739 JNIEnv *env = getJNIEnv(); 738 740 jchar buf[2]; … … 742 744 else 743 745 #else 744 if ( value.type() != KJS::NullType)746 if (!value->isNull()) 745 747 #endif 746 748 { 747 KJS::UString stringValue = value.toString(exec);749 UString stringValue = value->toString(exec); 748 750 JNIEnv *env = getJNIEnv(); 749 751 jobject javaString = env->functions->NewString (env, (const jchar *)stringValue.data(), stringValue.size()); … … 755 757 756 758 case boolean_type: { 757 result.z = (jboolean)value .toNumber(exec);759 result.z = (jboolean)value->toNumber(exec); 758 760 } 759 761 break; 760 762 761 763 case byte_type: { 762 result.b = (jbyte)value .toNumber(exec);764 result.b = (jbyte)value->toNumber(exec); 763 765 } 764 766 break; 765 767 766 768 case char_type: { 767 result.c = (jchar)value .toNumber(exec);769 result.c = (jchar)value->toNumber(exec); 768 770 } 769 771 break; 770 772 771 773 case short_type: { 772 result.s = (jshort)value .toNumber(exec);774 result.s = (jshort)value->toNumber(exec); 773 775 } 774 776 break; 775 777 776 778 case int_type: { 777 result.i = (jint)value .toNumber(exec);779 result.i = (jint)value->toNumber(exec); 778 780 } 779 781 break; 780 782 781 783 case long_type: { 782 result.j = (jlong)value .toNumber(exec);784 result.j = (jlong)value->toNumber(exec); 783 785 } 784 786 break; 785 787 786 788 case float_type: { 787 result.f = (jfloat)value .toNumber(exec);789 result.f = (jfloat)value->toNumber(exec); 788 790 } 789 791 break; 790 792 791 793 case double_type: { 792 result.d = (jdouble)value .toNumber(exec);794 result.d = (jdouble)value->toNumber(exec); 793 795 } 794 796 break; … … 806 808 } 807 809 810 } 811 812 } -
trunk/JavaScriptCore/bindings/jni/jni_utility.h
r8201 r10084 52 52 class JavaParameter; 53 53 54 const char *getCharactersFromJString 55 void releaseCharactersForJString 54 const char *getCharactersFromJString(jstring aJString); 55 void releaseCharactersForJString(jstring aJString, const char *s); 56 56 57 const char *getCharactersFromJStringInEnv 58 void releaseCharactersForJStringInEnv 59 const jchar *getUCharactersFromJStringInEnv 60 void releaseUCharactersForJStringInEnv 57 const char *getCharactersFromJStringInEnv(JNIEnv *env, jstring aJString); 58 void releaseCharactersForJStringInEnv(JNIEnv *env, jstring aJString, const char *s); 59 const jchar *getUCharactersFromJStringInEnv(JNIEnv *env, jstring aJString); 60 void releaseUCharactersForJStringInEnv(JNIEnv *env, jstring aJString, const jchar *s); 61 61 62 62 JNIType JNITypeFromClassName(const char *name); … … 64 64 const char *signatureFromPrimitiveType(JNIType type); 65 65 66 jvalue convertValueToJValue (KJS::ExecState *exec, KJS::Valuevalue, JNIType _JNIType, const char *javaClassName);66 jvalue convertValueToJValue(ExecState *exec, ValueImp *value, JNIType _JNIType, const char *javaClassName); 67 67 68 jvalue getJNIField 68 jvalue getJNIField(jobject obj, JNIType type, const char *name, const char *signature); 69 69 70 jmethodID getMethodID 70 jmethodID getMethodID(jobject obj, const char *name, const char *sig); 71 71 72 jobject callJNIObjectMethod 73 void callJNIVoidMethod 74 jboolean callJNIBooleanMethod 75 jboolean callJNIStaticBooleanMethod 76 jbyte callJNIByteMethod 77 jchar callJNICharMethod 78 jshort callJNIShortMethod 79 jint callJNIIntMethod 80 jlong callJNILongMethod 81 jfloat callJNIFloatMethod 82 jdouble callJNIDoubleMethod 72 jobject callJNIObjectMethod(jobject obj, const char *name, const char *sig, ... ); 73 void callJNIVoidMethod(jobject obj, const char *name, const char *sig, ... ); 74 jboolean callJNIBooleanMethod(jobject obj, const char *name, const char *sig, ... ); 75 jboolean callJNIStaticBooleanMethod(jclass cls, const char *name, const char *sig, ... ); 76 jbyte callJNIByteMethod(jobject obj, const char *name, const char *sig, ... ); 77 jchar callJNICharMethod(jobject obj, const char *name, const char *sig, ... ); 78 jshort callJNIShortMethod(jobject obj, const char *name, const char *sig, ... ); 79 jint callJNIIntMethod(jobject obj, const char *name, const char *sig, ... ); 80 jlong callJNILongMethod(jobject obj, const char *name, const char *sig, ... ); 81 jfloat callJNIFloatMethod(jobject obj, const char *name, const char *sig, ... ); 82 jdouble callJNIDoubleMethod(jobject obj, const char *name, const char *sig, ... ); 83 83 84 jobject callJNIObjectMethodA 85 void callJNIVoidMethodA 86 jboolean callJNIBooleanMethodA 87 jbyte callJNIByteMethodA 88 jchar callJNICharMethodA 89 jshort callJNIShortMethodA 90 jint callJNIIntMethodA 91 jlong callJNILongMethodA 92 jfloat callJNIFloatMethodA 93 jdouble callJNIDoubleMethodA 84 jobject callJNIObjectMethodA(jobject obj, const char *name, const char *sig, jvalue *args); 85 void callJNIVoidMethodA(jobject obj, const char *name, const char *sig, jvalue *args); 86 jboolean callJNIBooleanMethodA(jobject obj, const char *name, const char *sig, jvalue *args); 87 jbyte callJNIByteMethodA(jobject obj, const char *name, const char *sig, jvalue *args); 88 jchar callJNICharMethodA(jobject obj, const char *name, const char *sig, jvalue *args); 89 jshort callJNIShortMethodA(jobject obj, const char *name, const char *sig, jvalue *args); 90 jint callJNIIntMethodA(jobject obj, const char *name, const char *sig, jvalue *args); 91 jlong callJNILongMethodA(jobject obj, const char *name, const char *sig, jvalue *args); 92 jfloat callJNIFloatMethodA(jobject obj, const char *name, const char *sig, jvalue *args); 93 jdouble callJNIDoubleMethodA(jobject obj, const char *name, const char *sig, jvalue *args); 94 94 95 jobject callJNIObjectMethodIDA 96 void callJNIVoidMethodIDA 97 jboolean callJNIBooleanMethodIDA 98 jbyte callJNIByteMethodIDA 99 jchar callJNICharMethodIDA 100 jshort callJNIShortMethodIDA 101 jint callJNIIntMethodIDA 102 jlong callJNILongMethodIDA 103 jfloat callJNIFloatMethodIDA 104 jdouble callJNIDoubleMethodIDA 95 jobject callJNIObjectMethodIDA(jobject obj, jmethodID methodID, jvalue *args); 96 void callJNIVoidMethodIDA(jobject obj, jmethodID methodID, jvalue *args); 97 jboolean callJNIBooleanMethodIDA(jobject obj, jmethodID methodID, jvalue *args); 98 jbyte callJNIByteMethodIDA(jobject obj, jmethodID methodID, jvalue *args); 99 jchar callJNICharMethodIDA(jobject obj, jmethodID methodID, jvalue *args); 100 jshort callJNIShortMethodIDA(jobject obj, jmethodID methodID, jvalue *args); 101 jint callJNIIntMethodIDA(jobject obj, jmethodID methodID, jvalue *args); 102 jlong callJNILongMethodIDA(jobject obj, jmethodID methodID, jvalue *args); 103 jfloat callJNIFloatMethodIDA(jobject obj, jmethodID methodID, jvalue *args); 104 jdouble callJNIDoubleMethodIDA(jobject obj, jmethodID methodID, jvalue *args); 105 105 106 106 JavaVM *getJavaVM(); 107 107 JNIEnv *getJNIEnv(); 108 108 109 bool dispatchJNICall (const void *targetAppletView, jobject obj, bool isStatic, JNIType returnType, jmethodID methodID, jvalue *args, jvalue &result, const char *callingURL, Value&exceptionDescription);109 bool dispatchJNICall(const void *targetAppletView, jobject obj, bool isStatic, JNIType returnType, jmethodID methodID, jvalue *args, jvalue &result, const char *callingURL, ValueImp *&exceptionDescription); 110 110 111 111 } // namespace Bindings -
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 } -
trunk/JavaScriptCore/bindings/objc/WebScriptObjectPrivate.h
r8585 r10084 14 14 15 15 @interface WebScriptObject (Private) 16 + (id)_convertValueToObjcValue:(KJS::Value )value originExecutionContext:(const KJS::Bindings::RootObject *)originExecutionContext executionContext:(const KJS::Bindings::RootObject *)executionContext;16 + (id)_convertValueToObjcValue:(KJS::ValueImp *)value originExecutionContext:(const KJS::Bindings::RootObject *)originExecutionContext executionContext:(const KJS::Bindings::RootObject *)executionContext; 17 17 - _init; 18 18 - _initWithObjectImp:(KJS::ObjectImp *)imp originExecutionContext:(const KJS::Bindings::RootObject *)originExecutionContext executionContext:(const KJS::Bindings::RootObject *)executionContext ; -
trunk/JavaScriptCore/bindings/objc/objc_class.h
r7742 r10084 78 78 virtual Field *fieldNamed(const char *name, Instance *instance) const; 79 79 80 virtual Value 80 virtual ValueImp *fallbackObject(ExecState *exec, Instance *instance, const Identifier &propertyName); 81 81 82 82 virtual Constructor *constructorAt(long i) const { -
trunk/JavaScriptCore/bindings/objc/objc_class.mm
r10028 r10084 31 31 #include <WebScriptObject.h> 32 32 33 using namespace KJS::Bindings; 33 namespace KJS { 34 namespace Bindings { 34 35 35 36 void ObjcClass::_commonDelete() { … … 233 234 } 234 235 235 KJS::Value ObjcClass::fallbackObject (ExecState *exec, Instance *instance, const Identifier &propertyName) 236 { 237 return Object (new ObjcFallbackObjectImp(static_cast<ObjcInstance*>(instance), propertyName)); 238 } 236 ValueImp *ObjcClass::fallbackObject (ExecState *exec, Instance *instance, const Identifier &propertyName) 237 { 238 return new ObjcFallbackObjectImp(static_cast<ObjcInstance*>(instance), propertyName); 239 } 240 241 } 242 } -
trunk/JavaScriptCore/bindings/objc/objc_instance.h
r8400 r10084 54 54 virtual void end(); 55 55 56 virtual Value 57 virtual Value 56 virtual ValueImp *valueOf() const; 57 virtual ValueImp *defaultValue (Type hint) const; 58 58 59 virtual Value 60 virtual Value 59 virtual ValueImp *invokeMethod (ExecState *exec, const MethodList &method, const List &args); 60 virtual ValueImp *invokeDefaultMethod (ExecState *exec, const List &args); 61 61 62 virtual void setValueOfField (ExecState *exec, const Field *aField, const Value &aValue) const;62 virtual void setValueOfField (ExecState *exec, const Field *aField, ValueImp *aValue) const; 63 63 virtual bool supportsSetValueOfUndefinedField (); 64 virtual void setValueOfUndefinedField (ExecState *exec, const Identifier &property, const Value &aValue);64 virtual void setValueOfUndefinedField (ExecState *exec, const Identifier &property, ValueImp *aValue); 65 65 66 virtual Value 67 virtual Value 66 virtual ValueImp *ObjcInstance::getValueOfField (ExecState *exec, const Field *aField) const; 67 virtual ValueImp *getValueOfUndefinedField (ExecState *exec, const Identifier &property, Type hint) const; 68 68 69 69 ObjectStructPtr getObject() const { return _instance; } 70 70 71 Value 72 Value 73 Value 71 ValueImp *stringValue() const; 72 ValueImp *numberValue() const; 73 ValueImp *booleanValue() const; 74 74 75 75 private: -
trunk/JavaScriptCore/bindings/objc/objc_instance.mm
r8400 r10084 123 123 } 124 124 125 Value ObjcInstance::invokeMethod (KJS::ExecState *exec, const MethodList &methodList, const List &args)126 { 127 Value 125 ValueImp *ObjcInstance::invokeMethod (ExecState *exec, const MethodList &methodList, const List &args) 126 { 127 ValueImp *resultValue; 128 128 129 129 // Overloading methods is not allowed in ObjectiveC. Should only be one … … 222 222 assert (objcValueType != ObjcInvalidType); 223 223 224 // Get the return value and convert it to a KJS::Value.Length224 // Get the return value and convert it to a JavaScript value. Length 225 225 // of return value will never exceed the size of largest scalar 226 226 // or a pointer. … … 245 245 } 246 246 247 Value ObjcInstance::invokeDefaultMethod (KJS::ExecState *exec, const List &args)248 { 249 Value 247 ValueImp *ObjcInstance::invokeDefaultMethod (ExecState *exec, const List &args) 248 { 249 ValueImp *resultValue; 250 250 251 251 NS_DURING … … 282 282 ObjcValueType objcValueType = objcValueTypeForType (type); 283 283 284 // Get the return value and convert it to a KJS::Value.Length284 // Get the return value and convert it to a JavaScript value. Length 285 285 // of return value will never exceed the size of a pointer, so we're 286 // OK w e32 here.286 // OK with 32 here. 287 287 char buffer[32]; 288 288 [invocation getReturnValue:buffer]; … … 298 298 } 299 299 300 void ObjcInstance::setValueOfField ( KJS::ExecState *exec, const Field *aField, const KJS::Value &aValue) const300 void ObjcInstance::setValueOfField (ExecState *exec, const Field *aField, ValueImp *aValue) const 301 301 { 302 302 aField->setValueToInstance (exec, this, aValue); … … 313 313 } 314 314 315 void ObjcInstance::setValueOfUndefinedField ( KJS::ExecState *exec, const KJS::Identifier &property, const KJS::Value &aValue)315 void ObjcInstance::setValueOfUndefinedField (ExecState *exec, const Identifier &property, ValueImp *aValue) 316 316 { 317 317 id targetObject = getObject(); … … 336 336 } 337 337 338 Value ObjcInstance::getValueOfField (KJS::ExecState *exec, const Field *aField) const {338 ValueImp *ObjcInstance::getValueOfField (ExecState *exec, const Field *aField) const { 339 339 return aField->valueFromInstance (exec, this); 340 340 } 341 341 342 KJS::Value ObjcInstance::getValueOfUndefinedField (KJS::ExecState *exec, const KJS::Identifier &property, KJS::Type hint) const343 { 344 Value result = Undefined();342 ValueImp *ObjcInstance::getValueOfUndefinedField (ExecState *exec, const Identifier &property, Type hint) const 343 { 344 ValueImp *volatile result = Undefined(); 345 345 346 346 id targetObject = getObject(); … … 368 368 } 369 369 370 KJS::Value ObjcInstance::defaultValue (KJS::Type hint) const371 { 372 if (hint == KJS::StringType) {370 ValueImp *ObjcInstance::defaultValue (Type hint) const 371 { 372 if (hint == StringType) { 373 373 return stringValue(); 374 374 } 375 else if (hint == KJS::NumberType) {375 else if (hint == NumberType) { 376 376 return numberValue(); 377 377 } 378 else if (hint == KJS::BooleanType) {378 else if (hint == BooleanType) { 379 379 return booleanValue(); 380 380 } 381 else if (hint == KJS::UnspecifiedType) {381 else if (hint == UnspecifiedType) { 382 382 if ([_instance isKindOfClass:[NSString class]]) { 383 383 return stringValue(); … … 394 394 } 395 395 396 KJS::ValueObjcInstance::stringValue() const396 ValueImp *ObjcInstance::stringValue() const 397 397 { 398 398 return convertNSStringToString ([getObject() description]); 399 399 } 400 400 401 KJS::ValueObjcInstance::numberValue() const401 ValueImp *ObjcInstance::numberValue() const 402 402 { 403 403 // FIXME: Implement something sensible 404 KJS::Number v(0); 405 return v; 406 } 407 408 KJS::Value ObjcInstance::booleanValue() const 404 return jsNumber(0); 405 } 406 407 ValueImp *ObjcInstance::booleanValue() const 409 408 { 410 409 // FIXME: Implement something sensible 411 KJS::Boolean v((bool)0); 412 return v; 413 } 414 415 KJS::Value ObjcInstance::valueOf() const 410 return jsBoolean(false); 411 } 412 413 ValueImp *ObjcInstance::valueOf() const 416 414 { 417 415 return stringValue(); -
trunk/JavaScriptCore/bindings/objc/objc_runtime.h
r10076 r10084 35 35 namespace KJS 36 36 { 37 class Value;38 37 39 38 namespace Bindings … … 85 84 }; 86 85 87 virtual KJS::Value valueFromInstance(KJS::ExecState *exec, const Instance *instance) const;88 virtual void setValueToInstance( KJS::ExecState *exec, const Instance *instance, const KJS::Value &aValue) const;86 virtual ValueImp *valueFromInstance(ExecState *exec, const Instance *instance) const; 87 virtual void setValueToInstance(ExecState *exec, const Instance *instance, ValueImp *aValue) const; 89 88 90 89 virtual const char *name() const; … … 148 147 ObjcArray &operator=(const ObjcArray &other); 149 148 150 virtual void setValueAt( KJS::ExecState *exec, unsigned int index, const KJS::Value &aValue) const;151 virtual KJS::Value valueAt(KJS::ExecState *exec, unsigned int index) const;149 virtual void setValueAt(ExecState *exec, unsigned int index, ValueImp *aValue) const; 150 virtual ValueImp *valueAt(ExecState *exec, unsigned int index) const; 152 151 virtual unsigned int getLength() const; 153 152 … … 156 155 ObjectStructPtr getObjcArray() const { return _array; } 157 156 158 static KJS::Value convertObjcArrayToArray (KJS::ExecState *exec, ObjectStructPtr anObject);157 static ValueImp *convertObjcArrayToArray (ExecState *exec, ObjectStructPtr anObject); 159 158 160 159 private: … … 162 161 }; 163 162 164 class ObjcFallbackObjectImp : public KJS::ObjectImp {163 class ObjcFallbackObjectImp : public ObjectImp { 165 164 public: 166 165 ObjcFallbackObjectImp(ObjectImp *proto); 167 166 168 ObjcFallbackObjectImp(ObjcInstance *i, const KJS::Identifier propertyName);167 ObjcFallbackObjectImp(ObjcInstance *i, const Identifier propertyName); 169 168 170 169 const ClassInfo *classInfo() const { return &info; } … … 173 172 174 173 virtual void put(ExecState *exec, const Identifier &propertyName, 175 const Value &value, int attr = None);174 ValueImp *value, int attr = None); 176 175 177 176 virtual bool canPut(ExecState *exec, const Identifier &propertyName) const; 178 177 179 178 virtual bool implementsCall() const; 180 virtual Value call(ExecState *exec, Object &thisObj, const List &args);179 virtual ValueImp *callAsFunction(ExecState *exec, ObjectImp *thisObj, const List &args); 181 180 182 181 virtual bool deleteProperty(ExecState *exec, const Identifier &propertyName); 183 182 184 virtual Value 183 virtual ValueImp *defaultValue(ExecState *exec, Type hint) const; 185 184 186 185 virtual Type type() const; … … 191 190 192 191 ObjcInstance *_instance; 193 KJS::Identifier _item;192 Identifier _item; 194 193 }; 195 194 -
trunk/JavaScriptCore/bindings/objc/objc_runtime.mm
r10076 r10084 103 103 } 104 104 105 Value ObjcField::valueFromInstance(KJS::ExecState *exec, const Instance *instance) const106 { 107 Value 105 ValueImp *ObjcField::valueFromInstance(ExecState *exec, const Instance *instance) const 106 { 107 ValueImp *aValue; 108 108 id targetObject = (static_cast<const ObjcInstance*>(instance))->getObject(); 109 109 id objcValue = nil; … … 116 116 NS_HANDLER 117 117 118 Value 118 ValueImp *exceptionValue = Error::create(exec, GeneralError, [[localException reason] lossyCString]); 119 119 exec->setException(exceptionValue); 120 120 … … 129 129 } 130 130 131 static id convertValueToObjcObject ( KJS::ExecState *exec, const KJS::Value &value)131 static id convertValueToObjcObject (ExecState *exec, ValueImp *value) 132 132 { 133 133 const Bindings::RootObject *root = rootForInterpreter(exec->interpreter()); 134 134 if (!root) { 135 Bindings::RootObject *newRoot = new KJS::Bindings::RootObject(0);135 Bindings::RootObject *newRoot = new Bindings::RootObject(0); 136 136 newRoot->setInterpreter (exec->interpreter()); 137 137 root = newRoot; … … 141 141 142 142 143 void ObjcField::setValueToInstance( KJS::ExecState *exec, const Instance *instance, const KJS::Value &aValue) const143 void ObjcField::setValueToInstance(ExecState *exec, const Instance *instance, ValueImp *aValue) const 144 144 { 145 145 id targetObject = (static_cast<const ObjcInstance*>(instance))->getObject(); … … 153 153 NS_HANDLER 154 154 155 Value 155 ValueImp *aValue = Error::create(exec, GeneralError, [[localException reason] lossyCString]); 156 156 exec->setException(aValue); 157 157 … … 187 187 } 188 188 189 void ObjcArray::setValueAt( KJS::ExecState *exec, unsigned int index, const KJS::Value &aValue) const189 void ObjcArray::setValueAt(ExecState *exec, unsigned int index, ValueImp *aValue) const 190 190 { 191 191 if (![_array respondsToSelector:@selector(insertObject:atIndex:)]) { 192 Object 192 ObjectImp *error = Error::create(exec, TypeError, "Array is not mutable."); 193 193 exec->setException(error); 194 194 return; … … 196 196 197 197 if (index > [_array count]) { 198 Object 198 ObjectImp *error = Error::create(exec, RangeError, "Index exceeds array size."); 199 199 exec->setException(error); 200 200 return; … … 211 211 NS_HANDLER 212 212 213 Object 213 ObjectImp *error = Error::create(exec, GeneralError, "ObjectiveC exception."); 214 214 exec->setException(error); 215 215 … … 218 218 219 219 220 KJS::Value ObjcArray::valueAt(KJS::ExecState *exec, unsigned int index) const 221 { 222 ObjectStructPtr obj = 0; 223 Object error; 224 volatile bool haveError = false; 225 220 ValueImp *ObjcArray::valueAt(ExecState *exec, unsigned int index) const 221 { 226 222 if (index > [_array count]) { 227 Object 223 ObjectImp *error = Error::create(exec, RangeError, "Index exceeds array size."); 228 224 exec->setException(error); 229 225 return error; 230 226 } 231 227 228 ObjectStructPtr obj = 0; 229 ObjectImp * volatile error; 230 volatile bool haveError = false; 231 232 232 NS_DURING 233 233 … … 236 236 NS_HANDLER 237 237 238 Objecterror = Error::create(exec, GeneralError, "ObjectiveC exception.");238 error = Error::create(exec, GeneralError, "ObjectiveC exception."); 239 239 exec->setException(error); 240 240 haveError = true; … … 276 276 277 277 void ObjcFallbackObjectImp::put(ExecState *exec, const Identifier &propertyName, 278 const Value &value, int attr)278 ValueImp *value, int attr) 279 279 { 280 280 } … … 306 306 } 307 307 308 Value ObjcFallbackObjectImp::call(ExecState *exec, Object &thisObj, const List &args)309 { 310 Value 311 312 RuntimeObjectImp *imp = static_cast<RuntimeObjectImp*>(thisObj .imp());308 ValueImp *ObjcFallbackObjectImp::callAsFunction(ExecState *exec, ObjectImp *thisObj, const List &args) 309 { 310 ValueImp *result = Undefined(); 311 312 RuntimeObjectImp *imp = static_cast<RuntimeObjectImp*>(thisObj); 313 313 if (imp) { 314 314 Instance *instance = imp->getInternalInstance(); … … 341 341 } 342 342 343 Value 343 ValueImp *ObjcFallbackObjectImp::defaultValue(ExecState *exec, Type hint) const 344 344 { 345 345 return _instance->getValueOfUndefinedField(exec, _item, hint); -
trunk/JavaScriptCore/bindings/objc/objc_utility.h
r8585 r10084 69 69 class RootObject; 70 70 71 ObjcValue convertValueToObjcValue (KJS::ExecState *exec, const KJS::Value &value, ObjcValueType type);72 Value 73 Value convertObjcValueToValue (KJS::ExecState *exec, void *buffer, ObjcValueType type);74 ObjcValueType objcValueTypeForType 71 ObjcValue convertValueToObjcValue(ExecState *exec, ValueImp *value, ObjcValueType type); 72 ValueImp *convertNSStringToString(NSString *nsstring); 73 ValueImp *convertObjcValueToValue(ExecState *exec, void *buffer, ObjcValueType type); 74 ObjcValueType objcValueTypeForType(const char *type); 75 75 76 76 void JSMethodNameToObjCMethodName(const char *name, char *name, unsigned int length); 77 77 78 void *createObjcInstanceForValue (const Object &value, const RootObject *origin, const RootObject *current);78 void *createObjcInstanceForValue(ObjectImp *value, const RootObject *origin, const RootObject *current); 79 79 80 80 } // namespace Bindings -
trunk/JavaScriptCore/bindings/objc/objc_utility.mm
r9078 r10084 51 51 @result Returns the name to be used to represent the specificed selector in the 52 52 */ 53 void KJS::Bindings::JSMethodNameToObjCMethodName(const char *name, char *buffer, unsigned int len)53 void Bindings::JSMethodNameToObjCMethodName(const char *name, char *buffer, unsigned int len) 54 54 { 55 55 const char *np = name; … … 88 88 89 89 */ 90 ObjcValue KJS::Bindings::convertValueToObjcValue (KJS::ExecState *exec, const KJS::Value &value, ObjcValueType type)90 ObjcValue Bindings::convertValueToObjcValue (ExecState *exec, ValueImp *value, ObjcValueType type) 91 91 { 92 92 ObjcValue result; 93 93 double d = 0; 94 95 if (value .type() == NumberType || value.type() == StringType || value.type() == BooleanType)96 d = value .toNumber(exec);94 95 if (value->isNumber() || value->isString() || value->isBoolean()) 96 d = value->toNumber(exec); 97 97 98 98 switch (type){ 99 99 case ObjcObjectType: { 100 KJS::Interpreter *originInterpreter = exec->interpreter();100 Interpreter *originInterpreter = exec->interpreter(); 101 101 const Bindings::RootObject *originExecutionContext = rootForInterpreter(originInterpreter); 102 102 103 KJS::Interpreter *interpreter = 0;103 Interpreter *interpreter = 0; 104 104 if (originInterpreter->isGlobalObject(value)) { 105 interpreter = originInterpreter->interpreterForGlobalObject (value .imp());105 interpreter = originInterpreter->interpreterForGlobalObject (value); 106 106 } 107 107 … … 111 111 const Bindings::RootObject *executionContext = rootForInterpreter(interpreter); 112 112 if (!executionContext) { 113 Bindings::RootObject *newExecutionContext = new KJS::Bindings::RootObject(0);113 Bindings::RootObject *newExecutionContext = new Bindings::RootObject(0); 114 114 newExecutionContext->setInterpreter (interpreter); 115 115 executionContext = newExecutionContext; … … 165 165 } 166 166 167 Value KJS::Bindings::convertNSStringToString(NSString *nsstring)167 ValueImp *Bindings::convertNSStringToString(NSString *nsstring) 168 168 { 169 169 unichar *chars; … … 171 171 chars = (unichar *)malloc(sizeof(unichar)*length); 172 172 [nsstring getCharacters:chars]; 173 UString u((const KJS::UChar*)chars, length);174 Value 173 UString u((const UChar*)chars, length); 174 ValueImp *aValue = String (u); 175 175 free((void *)chars); 176 176 return aValue; … … 193 193 194 194 */ 195 Value KJS::Bindings::convertObjcValueToValue (KJS::ExecState *exec, void *buffer, ObjcValueType type)196 { 197 Value aValue;195 ValueImp *Bindings::convertObjcValueToValue (ExecState *exec, void *buffer, ObjcValueType type) 196 { 197 ValueImp *aValue = NULL; 198 198 199 199 switch (type) { … … 225 225 } 226 226 else if ([*obj isKindOfClass:[NSArray class]]) { 227 aValue = Object(new RuntimeArrayImp(exec, new ObjcArray (*obj)));227 aValue = new RuntimeArrayImp(exec, new ObjcArray (*obj)); 228 228 } 229 229 else if ([*obj isKindOfClass:[WebScriptObject class]]) { 230 230 WebScriptObject *jsobject = (WebScriptObject *)*obj; 231 aValue = Object([jsobject _imp]);231 aValue = [jsobject _imp]; 232 232 } 233 233 else if (*obj == 0) { … … 287 287 288 288 289 ObjcValueType KJS::Bindings::objcValueTypeForType (const char *type)289 ObjcValueType Bindings::objcValueTypeForType (const char *type) 290 290 { 291 291 int typeLength = strlen(type); … … 333 333 334 334 335 void * KJS::Bindings::createObjcInstanceForValue (const Object &value, const RootObject *origin, const RootObject *current)336 { 337 if ( value.type() != ObjectType)335 void *Bindings::createObjcInstanceForValue (ObjectImp *value, const RootObject *origin, const RootObject *current) 336 { 337 if (!value->isObject()) 338 338 return 0; 339 339 340 ObjectImp *imp = static_cast<ObjectImp*>(value .imp());340 ObjectImp *imp = static_cast<ObjectImp*>(value); 341 341 342 342 return [[[WebScriptObject alloc] _initWithObjectImp:imp originExecutionContext:origin executionContext:current] autorelease]; -
trunk/JavaScriptCore/bindings/runtime.cpp
r8585 r10084 92 92 KJSDidExecuteFunctionPtr Instance::didExecuteFunction () { return _DidExecuteFunction; } 93 93 94 Value 94 ValueImp *Instance::getValueOfField (KJS::ExecState *exec, const Field *aField) const { 95 95 return aField->valueFromInstance (exec, this); 96 96 } 97 97 98 void Instance::setValueOfField (KJS::ExecState *exec, const Field *aField, const Value &aValue) const {98 void Instance::setValueOfField (KJS::ExecState *exec, const Field *aField, ValueImp *aValue) const { 99 99 aField->setValueToInstance (exec, this, aValue); 100 100 } … … 127 127 } 128 128 129 Object 129 ObjectImp *Instance::createRuntimeObject (BindingLanguage language, void *nativeInstance, const RootObject *executionContext) 130 130 { 131 131 Instance *interfaceObject = Instance::createBindingForLanguageInstance (language, (void *)nativeInstance, executionContext); 132 132 133 133 Interpreter::lock(); 134 Object 134 ObjectImp *theObject(new RuntimeObjectImp(interfaceObject,true)); 135 135 Interpreter::unlock(); 136 136 … … 138 138 } 139 139 140 void *Instance::createLanguageInstanceForValue (ExecState *exec, BindingLanguage language, const Object &value, const RootObject *origin, const RootObject *current)140 void *Instance::createLanguageInstanceForValue (ExecState *exec, BindingLanguage language, ObjectImp *value, const RootObject *origin, const RootObject *current) 141 141 { 142 142 void *result = 0; 143 143 144 if ( value.type() != ObjectType)144 if (!value->isObject()) 145 145 return 0; 146 146 147 ObjectImp *imp = static_cast<ObjectImp*>(value .imp());147 ObjectImp *imp = static_cast<ObjectImp*>(value); 148 148 149 149 switch (language) { -
trunk/JavaScriptCore/bindings/runtime.h
r8585 r10084 60 60 virtual long numParameters() const = 0; 61 61 62 virtual ~Constructor() {} ;62 virtual ~Constructor() {} 63 63 }; 64 64 … … 69 69 virtual RuntimeType type() const = 0; 70 70 71 virtual KJS::Value valueFromInstance(ExecState *exec, const Instance *instance) const = 0;72 virtual void setValueToInstance(ExecState * exec, const Instance *instance, const Value &aValue) const = 0;71 virtual ValueImp *valueFromInstance(ExecState *, const Instance *) const = 0; 72 virtual void setValueToInstance(ExecState *, const Instance *, ValueImp *) const = 0; 73 73 74 virtual ~Field() {} ;74 virtual ~Field() {} 75 75 }; 76 76 … … 79 79 { 80 80 public: 81 MethodList() : _methods(0), _length(0) {} ;81 MethodList() : _methods(0), _length(0) {} 82 82 83 void addMethod 83 void addMethod(Method *aMethod); 84 84 unsigned int length() const; 85 Method *methodAt 85 Method *methodAt(unsigned int index) const; 86 86 87 87 ~MethodList(); 88 88 89 MethodList 89 MethodList(const MethodList &other); 90 90 MethodList &operator=(const MethodList &other); 91 91 … … 118 118 virtual Field *fieldNamed(const char *name, Instance *instance) const = 0; 119 119 120 virtual Value fallbackObject(ExecState *exec, Bindings::Instance *instance, const Identifier &propertyName) { return Undefined(); }120 virtual ValueImp *fallbackObject(ExecState *, Instance *, const Identifier &) { return Undefined(); } 121 121 122 virtual ~Class() {} ;122 virtual ~Class() {} 123 123 }; 124 124 … … 134 134 } BindingLanguage; 135 135 136 static void setDidExecuteFunction 137 static KJSDidExecuteFunctionPtr didExecuteFunction 136 static void setDidExecuteFunction(KJSDidExecuteFunctionPtr func); 137 static KJSDidExecuteFunctionPtr didExecuteFunction(); 138 138 139 static Instance *createBindingForLanguageInstance 140 static void *createLanguageInstanceForValue (ExecState *exec, BindingLanguage language, const Object &value, const RootObject *origin, const RootObject *current);141 static Object createRuntimeObject(BindingLanguage language, void *nativeInstance, const RootObject *r = 0);139 static Instance *createBindingForLanguageInstance(BindingLanguage language, void *nativeInstance, const RootObject *r = 0); 140 static void *createLanguageInstanceForValue(ExecState *exec, BindingLanguage language, ObjectImp *value, const RootObject *origin, const RootObject *current); 141 static ObjectImp *createRuntimeObject(BindingLanguage language, void *nativeInstance, const RootObject *r = 0); 142 142 143 Instance 143 Instance() : _executionContext(0) {}; 144 144 145 Instance 145 Instance(const Instance &other); 146 146 147 147 Instance &operator=(const Instance &other); … … 155 155 virtual Class *getClass() const = 0; 156 156 157 virtual Value getValueOfField(ExecState *exec, const Field *aField) const;158 virtual Value getValueOfUndefinedField(ExecState *exec, const Identifier &property, Type hint) const { return Undefined(); };159 virtual void setValueOfField (ExecState *exec, const Field *aField, const Value &aValue) const;160 virtual bool supportsSetValueOfUndefinedField 161 virtual void setValueOfUndefinedField (ExecState *exec, const Identifier &property, const Value &aValue) {};157 virtual ValueImp *getValueOfField(ExecState *exec, const Field *aField) const; 158 virtual ValueImp *getValueOfUndefinedField(ExecState *exec, const Identifier &property, Type hint) const { return Undefined(); }; 159 virtual void setValueOfField(ExecState *exec, const Field *aField, ValueImp *aValue) const; 160 virtual bool supportsSetValueOfUndefinedField() { return false; }; 161 virtual void setValueOfUndefinedField(ExecState *exec, const Identifier &property, ValueImp *aValue) {}; 162 162 163 virtual Value invokeMethod(ExecState *exec, const MethodList &method, const List &args) = 0;164 virtual Value invokeDefaultMethod(ExecState *exec, const List &args) = 0;163 virtual ValueImp *invokeMethod(ExecState *exec, const MethodList &method, const List &args) = 0; 164 virtual ValueImp *invokeDefaultMethod(ExecState *exec, const List &args) = 0; 165 165 166 virtual Value defaultValue(Type hint) const = 0;166 virtual ValueImp *defaultValue(Type hint) const = 0; 167 167 168 virtual Value 168 virtual ValueImp *valueOf() const { return String(getClass()->name()); }; 169 169 170 void setExecutionContext 170 void setExecutionContext(const RootObject *r) { _executionContext = r; } 171 171 const RootObject *executionContext() const { return _executionContext; } 172 172 173 virtual ~Instance() {} ;173 virtual ~Instance() {} 174 174 175 175 protected: … … 180 180 { 181 181 public: 182 virtual void setValueAt(ExecState * exec, unsigned int index, const Value &aValue) const = 0;183 virtual Value valueAt(ExecState *exec, unsigned intindex) const = 0;182 virtual void setValueAt(ExecState *, unsigned index, ValueImp *) const = 0; 183 virtual ValueImp *valueAt(ExecState *, unsigned index) const = 0; 184 184 virtual unsigned int getLength() const = 0; 185 virtual ~Array() {} ;185 virtual ~Array() {} 186 186 }; 187 187 188 const char *signatureForParameters(const KJS::List &aList);188 const char *signatureForParameters(const List &aList); 189 189 190 190 } // namespace Bindings -
trunk/JavaScriptCore/bindings/runtime_array.cpp
r10076 r10084 33 33 34 34 RuntimeArrayImp::RuntimeArrayImp(ExecState *exec, Bindings::Array *a) 35 : ArrayInstanceImp (exec->lexicalInterpreter()->builtinArrayPrototype().imp(), a->getLength())35 : ArrayInstanceImp(exec->lexicalInterpreter()->builtinArrayPrototype(), a->getLength()) 36 36 { 37 37 // Always takes ownership of concrete array. … … 44 44 } 45 45 46 Value 46 ValueImp *RuntimeArrayImp::lengthGetter(ExecState *exec, const Identifier& propertyName, const PropertySlot& slot) 47 47 { 48 48 RuntimeArrayImp *thisObj = static_cast<RuntimeArrayImp *>(slot.slotBase()); … … 50 50 } 51 51 52 Value 52 ValueImp *RuntimeArrayImp::indexGetter(ExecState *exec, const Identifier& propertyName, const PropertySlot& slot) 53 53 { 54 54 RuntimeArrayImp *thisObj = static_cast<RuntimeArrayImp *>(slot.slotBase()); … … 85 85 } 86 86 87 void RuntimeArrayImp::put(ExecState *exec, const Identifier &propertyName, const Value &value, int attr)87 void RuntimeArrayImp::put(ExecState *exec, const Identifier &propertyName, ValueImp *value, int attr) 88 88 { 89 89 if (propertyName == lengthPropertyName) { 90 Object 90 ObjectImp *err = Error::create(exec,RangeError); 91 91 exec->setException(err); 92 92 return; … … 103 103 } 104 104 105 void RuntimeArrayImp::put(ExecState *exec, unsigned index, const Value &value, int attr)105 void RuntimeArrayImp::put(ExecState *exec, unsigned index, ValueImp *value, int attr) 106 106 { 107 107 if (index >= getLength()) { 108 Object 108 ObjectImp *err = Error::create(exec,RangeError); 109 109 exec->setException(err); 110 110 return; -
trunk/JavaScriptCore/bindings/runtime_array.h
r10076 r10084 40 40 virtual bool getOwnPropertySlot(ExecState *, const Identifier&, PropertySlot&); 41 41 virtual bool getOwnPropertySlot(ExecState *, unsigned, PropertySlot&); 42 virtual void put(ExecState *exec, const Identifier &propertyName, const Value &value, int attr = None);43 virtual void put(ExecState *exec, unsigned propertyName, const Value &value, int attr = None);42 virtual void put(ExecState *exec, const Identifier &propertyName, ValueImp *value, int attr = None); 43 virtual void put(ExecState *exec, unsigned propertyName, ValueImp *value, int attr = None); 44 44 45 45 virtual bool deleteProperty(ExecState *exec, const Identifier &propertyName); … … 55 55 56 56 private: 57 static Value 58 static Value 57 static ValueImp *lengthGetter(ExecState *, const Identifier&, const PropertySlot&); 58 static ValueImp *indexGetter(ExecState *, const Identifier&, const PropertySlot&); 59 59 60 60 Bindings::Array *_array; -
trunk/JavaScriptCore/bindings/runtime_method.cpp
r10076 r10084 41 41 } 42 42 43 Value 43 ValueImp *RuntimeMethodImp::lengthGetter(ExecState *exec, const Identifier& propertyName, const PropertySlot& slot) 44 44 { 45 45 RuntimeMethodImp *thisObj = static_cast<RuntimeMethodImp *>(slot.slotBase()); … … 69 69 } 70 70 71 Value RuntimeMethodImp::call(ExecState *exec, Object &thisObj, const List &args)71 ValueImp *RuntimeMethodImp::callAsFunction(ExecState *exec, ObjectImp *thisObj, const List &args) 72 72 { 73 73 if (_methodList.length() > 0) { … … 76 76 // If thisObj is the DOM object for a plugin, get the corresponding 77 77 // runtime object from the DOM object. 78 if (thisObj .classInfo() != &KJS::RuntimeObjectImp::info) {79 Value runtimeObject = thisObj.get(exec, "__apple_runtime_object");80 imp = static_cast<RuntimeObjectImp*>(runtimeObject .imp());78 if (thisObj->classInfo() != &KJS::RuntimeObjectImp::info) { 79 ValueImp *runtimeObject = thisObj->get(exec, "__apple_runtime_object"); 80 imp = static_cast<RuntimeObjectImp*>(runtimeObject); 81 81 } 82 82 else { 83 imp = static_cast<RuntimeObjectImp*>(thisObj .imp());83 imp = static_cast<RuntimeObjectImp*>(thisObj); 84 84 } 85 85 if (imp) { … … 88 88 instance->begin(); 89 89 90 Value 90 ValueImp *aValue = instance->invokeMethod(exec, _methodList, args); 91 91 92 92 instance->end(); -
trunk/JavaScriptCore/bindings/runtime_method.h
r10076 r10084 42 42 43 43 virtual bool implementsCall() const; 44 virtual Value call(ExecState *exec, Object &thisObj, const List &args);44 virtual ValueImp *callAsFunction(ExecState *exec, ObjectImp *thisObj, const List &args); 45 45 46 46 virtual CodeType codeType() const; … … 49 49 50 50 private: 51 static Value 51 static ValueImp *lengthGetter(ExecState *, const Identifier&, const PropertySlot&); 52 52 53 53 Bindings::MethodList _methodList; -
trunk/JavaScriptCore/bindings/runtime_object.cpp
r10076 r10084 61 61 } 62 62 63 Value 63 ValueImp *RuntimeObjectImp::fallbackObjectGetter(ExecState *exec, const Identifier& propertyName, const PropertySlot& slot) 64 64 { 65 65 RuntimeObjectImp *thisObj = static_cast<RuntimeObjectImp *>(slot.slotBase()); … … 69 69 70 70 Class *aClass = instance->getClass(); 71 Value 71 ValueImp *result = aClass->fallbackObject(exec, instance, propertyName); 72 72 73 73 instance->end(); … … 76 76 } 77 77 78 Value 78 ValueImp *RuntimeObjectImp::fieldGetter(ExecState *exec, const Identifier& propertyName, const PropertySlot& slot) 79 79 { 80 80 RuntimeObjectImp *thisObj = static_cast<RuntimeObjectImp *>(slot.slotBase()); … … 85 85 Class *aClass = instance->getClass(); 86 86 Field *aField = aClass->fieldNamed(propertyName.ascii(), instance); 87 Value 87 ValueImp *result = instance->getValueOfField(exec, aField); 88 88 89 89 instance->end(); … … 92 92 } 93 93 94 Value 94 ValueImp *RuntimeObjectImp::methodGetter(ExecState *exec, const Identifier& propertyName, const PropertySlot& slot) 95 95 { 96 96 RuntimeObjectImp *thisObj = static_cast<RuntimeObjectImp *>(slot.slotBase()); … … 101 101 Class *aClass = instance->getClass(); 102 102 MethodList methodList = aClass->methodsNamed(propertyName.ascii(), instance); 103 Value result = Object(new RuntimeMethodImp(exec, propertyName, methodList));103 ValueImp *result = new RuntimeMethodImp(exec, propertyName, methodList); 104 104 105 105 instance->end(); … … 133 133 134 134 // Try a fallback object. 135 if (!aClass->fallbackObject(exec, instance, propertyName) .type() != UndefinedType) {135 if (!aClass->fallbackObject(exec, instance, propertyName)->isUndefined()) { 136 136 slot.setCustom(this, fallbackObjectGetter); 137 137 instance->end(); … … 147 147 148 148 void RuntimeObjectImp::put(ExecState *exec, const Identifier &propertyName, 149 const Value &value, int attr)149 ValueImp *value, int attr) 150 150 { 151 151 instance->begin(); … … 188 188 } 189 189 190 Value 191 { 192 Value 190 ValueImp *RuntimeObjectImp::defaultValue(ExecState *exec, Type hint) const 191 { 192 ValueImp *result; 193 193 194 194 instance->begin(); … … 207 207 } 208 208 209 Value RuntimeObjectImp::call(ExecState *exec, Object &thisObj, const List &args)210 { 211 instance->begin(); 212 213 Value 209 ValueImp *RuntimeObjectImp::callAsFunction(ExecState *exec, ObjectImp *thisObj, const List &args) 210 { 211 instance->begin(); 212 213 ValueImp *aValue = getInternalInstance()->invokeDefaultMethod(exec, args); 214 214 215 215 instance->end(); -
trunk/JavaScriptCore/bindings/runtime_object.h
r10076 r10084 45 45 46 46 virtual void put(ExecState *exec, const Identifier &propertyName, 47 const Value &value, int attr = None);47 ValueImp *value, int attr = None); 48 48 49 49 virtual bool canPut(ExecState *exec, const Identifier &propertyName) const; … … 52 52 const Identifier &propertyName); 53 53 54 virtual Value 54 virtual ValueImp *defaultValue(ExecState *exec, Type hint) const; 55 55 56 56 void setInternalInstance (Bindings::Instance *i) { instance = i; } … … 58 58 59 59 virtual bool implementsCall() const; 60 virtual Value call(ExecState *exec, Object &thisObj, const List &args);60 virtual ValueImp *callAsFunction(ExecState *exec, ObjectImp *thisObj, const List &args); 61 61 62 62 static const ClassInfo info; 63 63 64 64 private: 65 static Value 66 static Value 67 static Value 65 static ValueImp *fallbackObjectGetter(ExecState *, const Identifier&, const PropertySlot&); 66 static ValueImp *fieldGetter(ExecState *, const Identifier&, const PropertySlot&); 67 static ValueImp *methodGetter(ExecState *, const Identifier&, const PropertySlot&); 68 68 69 69 Bindings::Instance *instance; -
trunk/JavaScriptCore/kjs/array_instance.h
r10076 r10084 36 36 virtual bool getOwnPropertySlot(ExecState *, const Identifier&, PropertySlot&); 37 37 virtual bool getOwnPropertySlot(ExecState *, unsigned, PropertySlot&); 38 virtual void put(ExecState *exec, const Identifier &propertyName, const Value &value, int attr = None);39 virtual void put(ExecState *exec, unsigned propertyName, const Value &value, int attr = None);38 virtual void put(ExecState *exec, const Identifier &propertyName, ValueImp *value, int attr = None); 39 virtual void put(ExecState *exec, unsigned propertyName, ValueImp *value, int attr = None); 40 40 virtual bool deleteProperty(ExecState *exec, const Identifier &propertyName); 41 41 virtual bool deleteProperty(ExecState *exec, unsigned propertyName); … … 50 50 51 51 void sort(ExecState *exec); 52 void sort(ExecState *exec, Object &compareFunction);52 void sort(ExecState *exec, ObjectImp *compareFunction); 53 53 54 54 private: 55 static Value 55 static ValueImp *lengthGetter(ExecState *, const Identifier&, const PropertySlot&); 56 56 57 57 void setLength(unsigned newLength, ExecState *exec); -
trunk/JavaScriptCore/kjs/array_object.cpp
r10076 r10084 21 21 */ 22 22 23 #include "array_object.h" 24 25 #include "error_object.h" 26 #include "internal.h" 27 #include "interpreter.h" 28 #include "object.h" 29 #include "operations.h" 30 #include "reference_list.h" 31 #include "types.h" 23 32 #include "value.h" 24 #include "object.h"25 #include "types.h"26 #include "interpreter.h"27 #include "operations.h"28 #include "array_object.h"29 #include "internal.h"30 #include "error_object.h"31 33 32 34 #include "array_object.lut.h" … … 62 64 unsigned l = length; 63 65 for (unsigned i = 0; i < l; ++i) { 64 storage[i] = (it++).imp();66 storage[i] = it++; 65 67 } 66 68 } … … 71 73 } 72 74 73 Value 75 ValueImp *ArrayInstanceImp::lengthGetter(ExecState *exec, const Identifier& propertyName, const PropertySlot& slot) 74 76 { 75 77 return Number(static_cast<ArrayInstanceImp *>(slot.slotBase())->length); … … 90 92 if (index < storageLength) { 91 93 ValueImp *v = storage[index]; 92 if (!v || v == UndefinedImp::staticUndefined) 93 return false; 94 94 if (!v || v->isUndefined()) 95 return false; 95 96 slot.setValueSlot(this, &storage[index]); 96 97 return true; … … 107 108 if (index < storageLength) { 108 109 ValueImp *v = storage[index]; 109 if (!v || v == UndefinedImp::staticUndefined)110 if (!v || v->isUndefined()) 110 111 return false; 111 112 112 slot.setValueSlot(this, &storage[index]); 113 113 return true; … … 118 118 119 119 // Special implementation of [[Put]] - see ECMA 15.4.5.1 120 void ArrayInstanceImp::put(ExecState *exec, const Identifier &propertyName, const Value &value, int attr)120 void ArrayInstanceImp::put(ExecState *exec, const Identifier &propertyName, ValueImp *value, int attr) 121 121 { 122 122 if (propertyName == lengthPropertyName) { 123 setLength(value .toUInt32(exec), exec);123 setLength(value->toUInt32(exec), exec); 124 124 return; 125 125 } … … 135 135 } 136 136 137 void ArrayInstanceImp::put(ExecState *exec, unsigned index, const Value &value, int attr)137 void ArrayInstanceImp::put(ExecState *exec, unsigned index, ValueImp *value, int attr) 138 138 { 139 139 if (index < sparseArrayCutoff && index >= storageLength) { … … 146 146 147 147 if (index < storageLength) { 148 storage[index] = value .imp();148 storage[index] = value; 149 149 return; 150 150 } … … 190 190 191 191 // avoid fetching this every time through the loop 192 ValueImp *undefined = UndefinedImp::staticUndefined;192 ValueImp *undefined = jsUndefined(); 193 193 194 194 for (unsigned i = 0; i < storageLength; ++i) { … … 232 232 ReferenceList sparseProperties; 233 233 234 _prop.addSparseArrayPropertiesToReferenceList(sparseProperties, Object(this));234 _prop.addSparseArrayPropertiesToReferenceList(sparseProperties, this); 235 235 236 236 ReferenceListIterator it = sparseProperties.begin(); … … 266 266 ValueImp *va = *(ValueImp **)a; 267 267 ValueImp *vb = *(ValueImp **)b; 268 if (va-> dispatchType() == UndefinedType) {269 return vb-> dispatchType() == UndefinedType? 0 : 1;270 } 271 if (vb-> dispatchType() == UndefinedType) {268 if (va->isUndefined()) { 269 return vb->isUndefined() ? 0 : 1; 270 } 271 if (vb->isUndefined()) { 272 272 return -1; 273 273 } 274 return compare(va-> dispatchToString(exec), vb->dispatchToString(exec));274 return compare(va->toString(exec), vb->toString(exec)); 275 275 } 276 276 … … 297 297 ObjectImp *compareFunction; 298 298 List arguments; 299 Object 299 ObjectImp *globalObject; 300 300 }; 301 301 … … 308 308 ValueImp *va = *(ValueImp **)a; 309 309 ValueImp *vb = *(ValueImp **)b; 310 if (va-> dispatchType() == UndefinedType) {311 return vb-> dispatchType() == UndefinedType? 0 : 1;312 } 313 if (vb-> dispatchType() == UndefinedType) {310 if (va->isUndefined()) { 311 return vb->isUndefined() ? 0 : 1; 312 } 313 if (vb->isUndefined()) { 314 314 return -1; 315 315 } … … 319 319 args->arguments.append(vb); 320 320 double compareResult = args->compareFunction->call 321 (args->exec, args->globalObject, args->arguments) .toNumber(args->exec);321 (args->exec, args->globalObject, args->arguments)->toNumber(args->exec); 322 322 return compareResult < 0 ? -1 : compareResult > 0 ? 1 : 0; 323 323 } 324 324 325 void ArrayInstanceImp::sort(ExecState *exec, Object &compareFunction)325 void ArrayInstanceImp::sort(ExecState *exec, ObjectImp *compareFunction) 326 326 { 327 327 int lengthNotIncludingUndefined = pushUndefinedObjectsToEnd(exec); 328 328 329 CompareWithCompareFunctionArguments args(exec, compareFunction .imp());329 CompareWithCompareFunctionArguments args(exec, compareFunction); 330 330 compareWithCompareFunctionArguments = &args; 331 331 qsort(storage, lengthNotIncludingUndefined, sizeof(ValueImp *), compareWithCompareFunctionForQSort); … … 335 335 unsigned ArrayInstanceImp::pushUndefinedObjectsToEnd(ExecState *exec) 336 336 { 337 ValueImp *undefined = UndefinedImp::staticUndefined;337 ValueImp *undefined = jsUndefined(); 338 338 339 339 unsigned o = 0; … … 349 349 350 350 ReferenceList sparseProperties; 351 _prop.addSparseArrayPropertiesToReferenceList(sparseProperties, Object(this));351 _prop.addSparseArrayPropertiesToReferenceList(sparseProperties, this); 352 352 unsigned newLength = o + sparseProperties.length(); 353 353 … … 359 359 while (it != sparseProperties.end()) { 360 360 Reference ref = it++; 361 storage[o] = ref.getValue(exec) .imp();361 storage[o] = ref.getValue(exec); 362 362 ObjectImp::deleteProperty(exec, ref.getPropertyName(exec)); 363 363 o++; … … 399 399 : ArrayInstanceImp(objProto, 0) 400 400 { 401 Value protect(this);402 401 setInternalValue(Null()); 403 402 } … … 412 411 ArrayProtoFuncImp::ArrayProtoFuncImp(ExecState *exec, int i, int len) 413 412 : InternalFunctionImp( 414 static_cast<FunctionPrototypeImp*>(exec->lexicalInterpreter()->builtinFunctionPrototype() .imp())413 static_cast<FunctionPrototypeImp*>(exec->lexicalInterpreter()->builtinFunctionPrototype()) 415 414 ), id(i) 416 415 { 417 Value protect(this);418 416 put(exec,lengthPropertyName,Number(len),DontDelete|ReadOnly|DontEnum); 419 417 } … … 425 423 426 424 // ECMA 15.4.4 427 Value ArrayProtoFuncImp::call(ExecState *exec, Object &thisObj, const List &args) 428 { 429 unsigned int length = thisObj.get(exec,lengthPropertyName).toUInt32(exec); 430 ObjectImp *thisImp = thisObj.imp(); 431 432 Value result; 425 ValueImp *ArrayProtoFuncImp::callAsFunction(ExecState *exec, ObjectImp *thisObj, const List &args) 426 { 427 unsigned length = thisObj->get(exec,lengthPropertyName)->toUInt32(exec); 428 429 ValueImp *result; 433 430 434 431 switch (id) { … … 436 433 case ToString: 437 434 438 if (!thisObj .inherits(&ArrayInstanceImp::info)) {439 Object 435 if (!thisObj->inherits(&ArrayInstanceImp::info)) { 436 ObjectImp *err = Error::create(exec,TypeError); 440 437 exec->setException(err); 441 438 return err; … … 447 444 UString str = ""; 448 445 449 if ( args[0].type() != UndefinedType)450 separator = args[0] .toString(exec);446 if (!args[0]->isUndefined()) 447 separator = args[0]->toString(exec); 451 448 for (unsigned int k = 0; k < length; k++) { 452 449 if (k >= 1) 453 450 str += separator; 454 451 455 Value element = thisObj.get(exec, k);456 if (element .type() == UndefinedType || element.type() == NullType)452 ValueImp *element = thisObj->get(exec, k); 453 if (element->isUndefinedOrNull()) 457 454 continue; 458 455 459 456 bool fallback = false; 460 457 if (id == ToLocaleString) { 461 Object o = element.toObject(exec); 462 Object conversionFunction = 463 Object::dynamicCast(o.get(exec, toLocaleStringPropertyName)); 464 if (conversionFunction.isValid() && 465 conversionFunction.implementsCall()) { 466 str += conversionFunction.call(exec, o, List()).toString(exec); 458 ObjectImp *o = element->toObject(exec); 459 ValueImp *conversionFunction = o->get(exec, toLocaleStringPropertyName); 460 if (conversionFunction->isObject() && static_cast<ObjectImp *>(conversionFunction)->implementsCall()) { 461 str += static_cast<ObjectImp *>(conversionFunction)->call(exec, o, List())->toString(exec); 467 462 } else { 468 463 // try toString() fallback … … 472 467 473 468 if (id == ToString || id == Join || fallback) { 474 if (element.type() == ObjectType) { 475 Object o = Object::dynamicCast(element); 476 Object conversionFunction = 477 Object::dynamicCast(o.get(exec, toStringPropertyName)); 478 if (conversionFunction.isValid() && 479 conversionFunction.implementsCall()) { 480 str += conversionFunction.call(exec, o, List()).toString(exec); 469 if (element->isObject()) { 470 ObjectImp *o = static_cast<ObjectImp *>(element); 471 ValueImp *conversionFunction = o->get(exec, toStringPropertyName); 472 if (conversionFunction->isObject() && static_cast<ObjectImp *>(conversionFunction)->implementsCall()) { 473 str += static_cast<ObjectImp *>(conversionFunction)->call(exec, o, List())->toString(exec); 481 474 } else { 482 UString msg = "Can't convert " + o.className() + 483 " object to string"; 484 Object error = Error::create(exec, RangeError, 485 msg.cstring().c_str()); 475 UString msg = "Can't convert " + o->className() + " object to string"; 476 ObjectImp *error = Error::create(exec, RangeError, msg.cstring().c_str()); 486 477 exec->setException(error); 487 478 return error; 488 479 } 489 480 } else { 490 str += element .toString(exec);481 str += element->toString(exec); 491 482 } 492 483 } … … 499 490 } 500 491 case Concat: { 501 Object arr = Object::dynamicCast(exec->lexicalInterpreter()->builtinArray().construct(exec,List::empty()));492 ObjectImp *arr = static_cast<ObjectImp *>(exec->lexicalInterpreter()->builtinArray()->construct(exec,List::empty())); 502 493 int n = 0; 503 Value 504 Object curObj = Object::dynamicCast(thisObj);494 ValueImp *curArg = thisObj; 495 ObjectImp *curObj = static_cast<ObjectImp *>(thisObj); 505 496 ListIterator it = args.begin(); 506 497 for (;;) { 507 if (curArg .type() == ObjectType&&508 curObj .inherits(&ArrayInstanceImp::info)) {498 if (curArg->isObject() && 499 curObj->inherits(&ArrayInstanceImp::info)) { 509 500 unsigned int k = 0; 510 501 // Older versions tried to optimize out getting the length of thisObj 511 502 // by checking for n != 0, but that doesn't work if thisObj is an empty array. 512 length = curObj .get(exec,lengthPropertyName).toUInt32(exec);503 length = curObj->get(exec,lengthPropertyName)->toUInt32(exec); 513 504 while (k < length) { 514 Value 515 if (curObj .imp()->getProperty(exec, k, v))516 arr .put(exec, n, v);505 ValueImp *v; 506 if (curObj->getProperty(exec, k, v)) 507 arr->put(exec, n, v); 517 508 n++; 518 509 k++; 519 510 } 520 511 } else { 521 arr .put(exec, n, curArg);512 arr->put(exec, n, curArg); 522 513 n++; 523 514 } … … 525 516 break; 526 517 curArg = *it; 527 curObj = Object::dynamicCast(it++); // may be 0528 } 529 arr .put(exec,lengthPropertyName, Number(n), DontEnum | DontDelete);518 curObj = static_cast<ObjectImp *>(it++); // may be 0 519 } 520 arr->put(exec,lengthPropertyName, Number(n), DontEnum | DontDelete); 530 521 531 522 result = arr; … … 534 525 case Pop:{ 535 526 if (length == 0) { 536 thisObj .put(exec, lengthPropertyName, Number(length), DontEnum | DontDelete);527 thisObj->put(exec, lengthPropertyName, Number(length), DontEnum | DontDelete); 537 528 result = Undefined(); 538 529 } else { 539 result = thisObj .get(exec, length - 1);540 thisObj .put(exec, lengthPropertyName, Number(length - 1), DontEnum | DontDelete);530 result = thisObj->get(exec, length - 1); 531 thisObj->put(exec, lengthPropertyName, Number(length - 1), DontEnum | DontDelete); 541 532 } 542 533 break; … … 544 535 case Push: { 545 536 for (int n = 0; n < args.size(); n++) 546 thisObj .put(exec, length + n, args[n]);537 thisObj->put(exec, length + n, args[n]); 547 538 length += args.size(); 548 thisObj .put(exec,lengthPropertyName, Number(length), DontEnum | DontDelete);539 thisObj->put(exec,lengthPropertyName, Number(length), DontEnum | DontDelete); 549 540 result = Number(length); 550 541 break; … … 556 547 for (unsigned int k = 0; k < middle; k++) { 557 548 unsigned lk1 = length - k - 1; 558 Value 559 Value 560 bool has2 = this Imp->getProperty(exec, lk1, obj2);561 bool has1 = this Imp->getProperty(exec, k, obj);549 ValueImp *obj; 550 ValueImp *obj2; 551 bool has2 = thisObj->getProperty(exec, lk1, obj2); 552 bool has1 = thisObj->getProperty(exec, k, obj); 562 553 563 554 if (has2) 564 thisObj .put(exec, k, obj2);555 thisObj->put(exec, k, obj2); 565 556 else 566 thisObj .deleteProperty(exec, k);557 thisObj->deleteProperty(exec, k); 567 558 568 559 if (has1) 569 thisObj .put(exec, lk1, obj);560 thisObj->put(exec, lk1, obj); 570 561 else 571 thisObj .deleteProperty(exec, lk1);562 thisObj->deleteProperty(exec, lk1); 572 563 } 573 564 result = thisObj; … … 576 567 case Shift: { 577 568 if (length == 0) { 578 thisObj .put(exec, lengthPropertyName, Number(length), DontEnum | DontDelete);569 thisObj->put(exec, lengthPropertyName, Number(length), DontEnum | DontDelete); 579 570 result = Undefined(); 580 571 } else { 581 result = thisObj .get(exec, 0);572 result = thisObj->get(exec, 0); 582 573 for(unsigned int k = 1; k < length; k++) { 583 Value 584 if (this Imp->getProperty(exec, k, obj))585 thisObj .put(exec, k-1, obj);574 ValueImp *obj; 575 if (thisObj->getProperty(exec, k, obj)) 576 thisObj->put(exec, k-1, obj); 586 577 else 587 thisObj .deleteProperty(exec, k-1);588 } 589 thisObj .deleteProperty(exec, length - 1);590 thisObj .put(exec, lengthPropertyName, Number(length - 1), DontEnum | DontDelete);578 thisObj->deleteProperty(exec, k-1); 579 } 580 thisObj->deleteProperty(exec, length - 1); 581 thisObj->put(exec, lengthPropertyName, Number(length - 1), DontEnum | DontDelete); 591 582 } 592 583 break; … … 596 587 597 588 // We return a new array 598 Object resObj = Object::dynamicCast(exec->lexicalInterpreter()->builtinArray().construct(exec,List::empty()));589 ObjectImp *resObj = static_cast<ObjectImp *>(exec->lexicalInterpreter()->builtinArray()->construct(exec,List::empty())); 599 590 result = resObj; 600 591 double begin = 0; 601 if ( args[0].type() != UndefinedType) {602 begin = args[0] .toInteger(exec);592 if (!args[0]->isUndefined()) { 593 begin = args[0]->toInteger(exec); 603 594 if (begin >= 0) { // false for NaN 604 595 if (begin > length) … … 611 602 } 612 603 double end = length; 613 if ( args[1].type() != UndefinedType) {614 end = args[1] .toInteger(exec);604 if (!args[1]->isUndefined()) { 605 end = args[1]->toInteger(exec); 615 606 if (end < 0) { // false for NaN 616 607 end += length; … … 628 619 int e = static_cast<int>(end); 629 620 for(int k = b; k < e; k++, n++) { 630 Value 631 if (this Imp->getProperty(exec, k, obj))632 resObj .put(exec, n, obj);633 } 634 resObj .put(exec, lengthPropertyName, Number(n), DontEnum | DontDelete);621 ValueImp *obj; 622 if (thisObj->getProperty(exec, k, obj)) 623 resObj->put(exec, n, obj); 624 } 625 resObj->put(exec, lengthPropertyName, Number(n), DontEnum | DontDelete); 635 626 break; 636 627 } … … 639 630 printf("KJS Array::Sort length=%d\n", length); 640 631 for ( unsigned int i = 0 ; i<length ; ++i ) 641 printf("KJS Array::Sort: %d: %s\n", i, thisObj .get(exec, i).toString(exec).ascii() );632 printf("KJS Array::Sort: %d: %s\n", i, thisObj->get(exec, i)->toString(exec).ascii() ); 642 633 #endif 643 Object sortFunction; 644 bool useSortFunction = (args[0].type() != UndefinedType); 645 if (useSortFunction) 634 ObjectImp *sortFunction = NULL; 635 if (!args[0]->isUndefined()) 646 636 { 647 sortFunction = args[0] .toObject(exec);648 if (!sortFunction .implementsCall())649 useSortFunction = false;650 } 651 652 if (this Imp->classInfo() == &ArrayInstanceImp::info) {653 if ( useSortFunction)654 ((ArrayInstanceImp *)this Imp)->sort(exec, sortFunction);637 sortFunction = args[0]->toObject(exec); 638 if (!sortFunction->implementsCall()) 639 sortFunction = NULL; 640 } 641 642 if (thisObj->classInfo() == &ArrayInstanceImp::info) { 643 if (sortFunction) 644 ((ArrayInstanceImp *)thisObj)->sort(exec, sortFunction); 655 645 else 656 ((ArrayInstanceImp *)this Imp)->sort(exec);646 ((ArrayInstanceImp *)thisObj)->sort(exec); 657 647 result = thisObj; 658 648 break; … … 660 650 661 651 if (length == 0) { 662 thisObj .put(exec, lengthPropertyName, Number(0), DontEnum | DontDelete);652 thisObj->put(exec, lengthPropertyName, Number(0), DontEnum | DontDelete); 663 653 result = thisObj; 664 654 break; … … 669 659 for ( unsigned int i = 0 ; i<length-1 ; ++i ) 670 660 { 671 Value iObj = thisObj.get(exec,i);661 ValueImp *iObj = thisObj->get(exec,i); 672 662 unsigned int themin = i; 673 Value 663 ValueImp *minObj = iObj; 674 664 for ( unsigned int j = i+1 ; j<length ; ++j ) 675 665 { 676 Value jObj = thisObj.get(exec,j);666 ValueImp *jObj = thisObj->get(exec,j); 677 667 double cmp; 678 if (jObj .type() == UndefinedType) {668 if (jObj->isUndefined()) { 679 669 cmp = 1; // don't check minObj because there's no need to differentiate == (0) from > (1) 680 } else if (minObj .type() == UndefinedType) {670 } else if (minObj->isUndefined()) { 681 671 cmp = -1; 682 } else if ( useSortFunction) {672 } else if (sortFunction) { 683 673 List l; 684 674 l.append(jObj); 685 675 l.append(minObj); 686 cmp = sortFunction .call(exec, exec->dynamicInterpreter()->globalObject(), l).toNumber(exec);676 cmp = sortFunction->call(exec, exec->dynamicInterpreter()->globalObject(), l)->toNumber(exec); 687 677 } else { 688 cmp = (jObj .toString(exec) < minObj.toString(exec)) ? -1 : 1;678 cmp = (jObj->toString(exec) < minObj->toString(exec)) ? -1 : 1; 689 679 } 690 680 if ( cmp < 0 ) … … 698 688 { 699 689 //printf("KJS Array::Sort: swapping %d and %d\n", i, themin ); 700 thisObj .put( exec, i, minObj );701 thisObj .put( exec, themin, iObj );690 thisObj->put( exec, i, minObj ); 691 thisObj->put( exec, themin, iObj ); 702 692 } 703 693 } … … 705 695 printf("KJS Array::Sort -- Resulting array:\n"); 706 696 for ( unsigned int i = 0 ; i<length ; ++i ) 707 printf("KJS Array::Sort: %d: %s\n", i, thisObj .get(exec, i).toString(exec).ascii() );697 printf("KJS Array::Sort: %d: %s\n", i, thisObj->get(exec, i)->toString(exec).ascii() ); 708 698 #endif 709 699 result = thisObj; … … 712 702 case Splice: { 713 703 // 15.4.4.12 - oh boy this is huge 714 Object resObj = Object::dynamicCast(exec->lexicalInterpreter()->builtinArray().construct(exec,List::empty()));704 ObjectImp *resObj = static_cast<ObjectImp *>(exec->lexicalInterpreter()->builtinArray()->construct(exec,List::empty())); 715 705 result = resObj; 716 int begin = args[0] .toUInt32(exec);706 int begin = args[0]->toUInt32(exec); 717 707 if ( begin < 0 ) 718 708 begin = maxInt( begin + length, 0 ); 719 709 else 720 710 begin = minInt( begin, length ); 721 unsigned int deleteCount = minInt( maxInt( args[1] .toUInt32(exec), 0 ), length - begin );711 unsigned int deleteCount = minInt( maxInt( args[1]->toUInt32(exec), 0 ), length - begin ); 722 712 723 713 //printf( "Splicing from %d, deleteCount=%d \n", begin, deleteCount ); 724 714 for(unsigned int k = 0; k < deleteCount; k++) { 725 Value 726 if (this Imp->getProperty(exec, k+begin, obj))727 resObj .put(exec, k, obj);728 } 729 resObj .put(exec, lengthPropertyName, Number(deleteCount), DontEnum | DontDelete);715 ValueImp *obj; 716 if (thisObj->getProperty(exec, k+begin, obj)) 717 resObj->put(exec, k, obj); 718 } 719 resObj->put(exec, lengthPropertyName, Number(deleteCount), DontEnum | DontDelete); 730 720 731 721 unsigned int additionalArgs = maxInt( args.size() - 2, 0 ); … … 736 726 for ( unsigned int k = begin; k < length - deleteCount; ++k ) 737 727 { 738 Value 739 if (this Imp->getProperty(exec, k+deleteCount, obj))740 thisObj .put(exec, k+additionalArgs, obj);728 ValueImp *obj; 729 if (thisObj->getProperty(exec, k+deleteCount, obj)) 730 thisObj->put(exec, k+additionalArgs, obj); 741 731 else 742 thisObj .deleteProperty(exec, k+additionalArgs);732 thisObj->deleteProperty(exec, k+additionalArgs); 743 733 } 744 734 for ( unsigned int k = length ; k > length - deleteCount + additionalArgs; --k ) 745 thisObj .deleteProperty(exec, k-1);735 thisObj->deleteProperty(exec, k-1); 746 736 } 747 737 else … … 749 739 for ( unsigned int k = length - deleteCount; (int)k > begin; --k ) 750 740 { 751 Value 752 if (this Imp->getProperty(exec, k + deleteCount - 1, obj))753 thisObj .put(exec, k + additionalArgs - 1, obj);741 ValueImp *obj; 742 if (thisObj->getProperty(exec, k + deleteCount - 1, obj)) 743 thisObj->put(exec, k + additionalArgs - 1, obj); 754 744 else 755 thisObj .deleteProperty(exec, k+additionalArgs-1);745 thisObj->deleteProperty(exec, k+additionalArgs-1); 756 746 } 757 747 } … … 759 749 for ( unsigned int k = 0; k < additionalArgs; ++k ) 760 750 { 761 thisObj .put(exec, k+begin, args[k+2]);762 } 763 thisObj .put(exec, lengthPropertyName, Number(length - deleteCount + additionalArgs), DontEnum | DontDelete);751 thisObj->put(exec, k+begin, args[k+2]); 752 } 753 thisObj->put(exec, lengthPropertyName, Number(length - deleteCount + additionalArgs), DontEnum | DontDelete); 764 754 break; 765 755 } … … 768 758 for ( unsigned int k = length; k > 0; --k ) 769 759 { 770 Value 771 if (this Imp->getProperty(exec, k - 1, obj))772 thisObj .put(exec, k+nrArgs-1, obj);760 ValueImp *obj; 761 if (thisObj->getProperty(exec, k - 1, obj)) 762 thisObj->put(exec, k+nrArgs-1, obj); 773 763 else 774 thisObj .deleteProperty(exec, k+nrArgs-1);764 thisObj->deleteProperty(exec, k+nrArgs-1); 775 765 } 776 766 for ( unsigned int k = 0; k < nrArgs; ++k ) 777 thisObj .put(exec, k, args[k]);767 thisObj->put(exec, k, args[k]); 778 768 result = Number(length + nrArgs); 779 thisObj .put(exec, lengthPropertyName, result, DontEnum | DontDelete);769 thisObj->put(exec, lengthPropertyName, result, DontEnum | DontDelete); 780 770 break; 781 771 } … … 788 778 //http://developer-test.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Objects:Array:some 789 779 790 Object eachFunction = args[0].toObject(exec);791 792 if (!eachFunction .implementsCall()) {793 Object 780 ObjectImp *eachFunction = args[0]->toObject(exec); 781 782 if (!eachFunction->implementsCall()) { 783 ObjectImp *err = Error::create(exec,TypeError); 794 784 exec->setException(err); 795 785 return err; 796 786 } 797 787 798 Object applyThis = args[1].imp()->isUndefinedOrNull() ? exec->dynamicInterpreter()->globalObject() : args[1].toObject(exec);788 ObjectImp *applyThis = args[1]->isUndefinedOrNull() ? exec->dynamicInterpreter()->globalObject() : args[1]->toObject(exec); 799 789 800 790 if (id == Some || id == Every) … … 807 797 List eachArguments; 808 798 809 eachArguments.append(thisObj .get(exec, k));799 eachArguments.append(thisObj->get(exec, k)); 810 800 eachArguments.append(Number(k)); 811 801 eachArguments.append(thisObj); 812 802 813 bool predicateResult = eachFunction .call(exec, applyThis, eachArguments).toBoolean(exec);803 bool predicateResult = eachFunction->call(exec, applyThis, eachArguments)->toBoolean(exec); 814 804 815 805 if (id == Every && !predicateResult) { … … 827 817 default: 828 818 assert(0); 819 result = 0; 829 820 break; 830 821 } … … 839 830 : InternalFunctionImp(funcProto) 840 831 { 841 Value protect(this);842 832 // ECMA 15.4.3.1 Array.prototype 843 put(exec,prototypePropertyName, Object(arrayProto), DontEnum|DontDelete|ReadOnly);833 put(exec,prototypePropertyName, arrayProto, DontEnum|DontDelete|ReadOnly); 844 834 845 835 // no. of arguments for constructor … … 853 843 854 844 // ECMA 15.4.2 855 Object 845 ObjectImp *ArrayObjectImp::construct(ExecState *exec, const List &args) 856 846 { 857 847 // a single numeric argument denotes the array size (!) 858 if (args.size() == 1 && args[0] .type() == NumberType) {859 uint32_t n = args[0] .toUInt32(exec);860 if (n != args[0] .toNumber(exec)) {861 Object 848 if (args.size() == 1 && args[0]->isNumber()) { 849 uint32_t n = args[0]->toUInt32(exec); 850 if (n != args[0]->toNumber(exec)) { 851 ObjectImp *error = Error::create(exec, RangeError, "Array size is not a small enough positive integer."); 862 852 exec->setException(error); 863 853 return error; 864 854 } 865 return Object(new ArrayInstanceImp(exec->lexicalInterpreter()->builtinArrayPrototype().imp(), n));855 return new ArrayInstanceImp(exec->lexicalInterpreter()->builtinArrayPrototype(), n); 866 856 } 867 857 868 858 // otherwise the array is constructed with the arguments in it 869 return Object(new ArrayInstanceImp(exec->lexicalInterpreter()->builtinArrayPrototype().imp(), args));859 return new ArrayInstanceImp(exec->lexicalInterpreter()->builtinArrayPrototype(), args); 870 860 } 871 861 … … 876 866 877 867 // ECMA 15.6.1 878 Value ArrayObjectImp::call(ExecState *exec, Object &/*thisObj*/, const List &args)868 ValueImp *ArrayObjectImp::callAsFunction(ExecState *exec, ObjectImp */*thisObj*/, const List &args) 879 869 { 880 870 // equivalent to 'new Array(....)' -
trunk/JavaScriptCore/kjs/array_object.h
r10076 r10084 42 42 43 43 virtual bool implementsCall() const; 44 virtual Value call(ExecState *exec, Object &thisObj, const List &args);44 virtual ValueImp *callAsFunction(ExecState *exec, ObjectImp *thisObj, const List &args); 45 45 46 46 enum { ToString, ToLocaleString, Concat, Join, Pop, Push, … … 58 58 59 59 virtual bool implementsConstruct() const; 60 virtual Object 60 virtual ObjectImp *construct(ExecState *exec, const List &args); 61 61 virtual bool implementsCall() const; 62 virtual Value call(ExecState *exec, Object &thisObj, const List &args);62 virtual ValueImp *callAsFunction(ExecState *exec, ObjectImp *thisObj, const List &args); 63 63 64 64 }; -
trunk/JavaScriptCore/kjs/bool_object.cpp
r9768 r10084 51 51 : BooleanInstanceImp(objectProto) 52 52 { 53 Value protect(this);54 53 // The constructor will be added later by InterpreterImp::InterpreterImp() 55 54 … … 66 65 : InternalFunctionImp(funcProto), id(i) 67 66 { 68 Value protect(this);69 67 putDirect(lengthPropertyName, len, DontDelete|ReadOnly|DontEnum); 70 68 } … … 78 76 79 77 // ECMA 15.6.4.2 + 15.6.4.3 80 Value BooleanProtoFuncImp::call(ExecState *exec, Object &thisObj, const List &/*args*/)78 ValueImp *BooleanProtoFuncImp::callAsFunction(ExecState *exec, ObjectImp *thisObj, const List &/*args*/) 81 79 { 82 80 // no generic function. "this" has to be a Boolean object 83 if (!thisObj .inherits(&BooleanInstanceImp::info)) {84 Object 81 if (!thisObj->inherits(&BooleanInstanceImp::info)) { 82 ObjectImp *err = Error::create(exec,TypeError); 85 83 exec->setException(err); 86 84 return err; … … 89 87 // execute "toString()" or "valueOf()", respectively 90 88 91 Value v = thisObj.internalValue();92 assert( !v.isNull());89 ValueImp *v = thisObj->internalValue(); 90 assert(v); 93 91 94 92 if (id == ToString) 95 return String(v .toString(exec));96 return Boolean(v .toBoolean(exec)); /* TODO: optimize for bool case */93 return String(v->toString(exec)); 94 return Boolean(v->toBoolean(exec)); /* TODO: optimize for bool case */ 97 95 } 98 96 … … 104 102 : InternalFunctionImp(funcProto) 105 103 { 106 Value protect(this);107 104 putDirect(prototypePropertyName, booleanProto, DontEnum|DontDelete|ReadOnly); 108 105 109 106 // no. of arguments for constructor 110 putDirect(lengthPropertyName, NumberImp::one(), ReadOnly|DontDelete|DontEnum);107 putDirect(lengthPropertyName, jsOne(), ReadOnly|DontDelete|DontEnum); 111 108 } 112 109 … … 118 115 119 116 // ECMA 15.6.2 120 Object 117 ObjectImp *BooleanObjectImp::construct(ExecState *exec, const List &args) 121 118 { 122 Object obj(new BooleanInstanceImp(exec->lexicalInterpreter()->builtinBooleanPrototype().imp()));119 ObjectImp *obj(new BooleanInstanceImp(exec->lexicalInterpreter()->builtinBooleanPrototype())); 123 120 124 Booleanb;121 bool b; 125 122 if (args.size() > 0) 126 b = args.begin()-> dispatchToBoolean(exec);123 b = args.begin()->toBoolean(exec); 127 124 else 128 b = Boolean(false);125 b = false; 129 126 130 obj .setInternalValue(b);127 obj->setInternalValue(jsBoolean(b)); 131 128 132 129 return obj; … … 139 136 140 137 // ECMA 15.6.1 141 Value BooleanObjectImp::call(ExecState *exec, Object &/*thisObj*/, const List &args)138 ValueImp *BooleanObjectImp::callAsFunction(ExecState *exec, ObjectImp */*thisObj*/, const List &args) 142 139 { 143 140 if (args.isEmpty()) 144 141 return Boolean(false); 145 142 else 146 return Boolean(args[0] .toBoolean(exec)); /* TODO: optimize for bool case */143 return Boolean(args[0]->toBoolean(exec)); /* TODO: optimize for bool case */ 147 144 } 148 145 -
trunk/JavaScriptCore/kjs/bool_object.h
r9768 r10084 61 61 62 62 virtual bool implementsCall() const; 63 virtual Value call(ExecState *exec, Object &thisObj, const List &args);63 virtual ValueImp *callAsFunction(ExecState *exec, ObjectImp *thisObj, const List &args); 64 64 65 65 enum { ToString, ValueOf }; … … 80 80 81 81 virtual bool implementsConstruct() const; 82 virtual Object 82 virtual ObjectImp *construct(ExecState *exec, const List &args); 83 83 84 84 virtual bool implementsCall() const; 85 virtual Value call(ExecState *exec, Object &thisObj, const List &args);85 virtual ValueImp *callAsFunction(ExecState *exec, ObjectImp *thisObj, const List &args); 86 86 }; 87 87 -
trunk/JavaScriptCore/kjs/collector.cpp
r9992 r10084 252 252 253 253 if (good && ((CollectorCell *)x)->u.freeCell.zeroIfFree != 0) { 254 ValueImp *imp = (ValueImp *)x;254 AllocatedValueImp *imp = (AllocatedValueImp *)x; 255 255 if (!imp->marked()) 256 256 imp->mark(); … … 371 371 372 372 CollectorCell *cell = curBlock->cells + i; 373 ValueImp *imp = reinterpret_cast<ValueImp *>(cell);373 AllocatedValueImp *imp = reinterpret_cast<AllocatedValueImp *>(cell); 374 374 375 375 if (cell->u.freeCell.zeroIfFree != 0) { 376 if (!imp-> _marked)376 if (!imp->m_marked) 377 377 { 378 //fprintf(stderr, "Collector::deleting ValueImp %p (%s)\n", imp, className(imp));378 //fprintf(stderr, "Collector::deleting AllocatedValueImp %p (%s)\n", imp, className(imp)); 379 379 // emulate destructing part of 'operator delete()' 380 imp->~ ValueImp();380 imp->~AllocatedValueImp(); 381 381 curBlock->usedCells--; 382 382 numLiveObjects--; … … 389 389 390 390 } else { 391 imp-> _marked = false;391 imp->m_marked = false; 392 392 } 393 393 } else { … … 423 423 int cell = 0; 424 424 while (cell < heap.usedOversizeCells) { 425 ValueImp *imp = (ValueImp *)heap.oversizeCells[cell];425 AllocatedValueImp *imp = (AllocatedValueImp *)heap.oversizeCells[cell]; 426 426 427 if (!imp-> _marked) {428 imp->~ ValueImp();427 if (!imp->m_marked) { 428 imp->~AllocatedValueImp(); 429 429 #if DEBUG_COLLECTOR 430 430 heap.oversizeCells[cell]->u.freeCell.zeroIfFree = 0; … … 446 446 447 447 } else { 448 imp-> _marked = false;448 imp->m_marked = false; 449 449 cell++; 450 450 } … … 509 509 { 510 510 const char *name = "???"; 511 switch (val-> dispatchType()) {511 switch (val->type()) { 512 512 case UnspecifiedType: 513 513 break; -
trunk/JavaScriptCore/kjs/completion.h
r9768 r10084 48 48 class Completion { 49 49 public: 50 Completion(ComplType c = Normal, const Value& v = Value(), 51 const Identifier &t = Identifier::null()) 50 Completion(ComplType c = Normal, ValueImp *v = NULL, const Identifier &t = Identifier::null()) 52 51 : comp(c), val(v), tar(t) { } 53 52 54 53 ComplType complType() const { return comp; } 55 Value 54 ValueImp *value() const { return val; } 56 55 Identifier target() const { return tar; } 57 bool isValueCompletion() const { return !val.isNull(); }56 bool isValueCompletion() const { return val; } 58 57 private: 59 58 ComplType comp; 60 Value 59 ValueImp *val; 61 60 Identifier tar; 62 61 }; -
trunk/JavaScriptCore/kjs/context.h
r9768 r10084 36 36 class ContextImp { 37 37 public: 38 ContextImp(Object &glob, InterpreterImp *, Object &thisV, CodeType type = GlobalCode,38 ContextImp(ObjectImp *glob, InterpreterImp *, ObjectImp *thisV, CodeType type = GlobalCode, 39 39 ContextImp *callingContext = 0, FunctionImp *functiion = 0, const List *args = 0); 40 40 ~ContextImp(); … … 42 42 const ScopeChain &scopeChain() const { return scope; } 43 43 CodeType codeType() { return m_codeType; } 44 Object 45 void setVariableObject( const Object &v) { variable = v; }46 Object 44 ObjectImp *variableObject() const { return variable; } 45 void setVariableObject(ObjectImp *v) { variable = v; } 46 ObjectImp *thisValue() const { return thisVal; } 47 47 ContextImp *callingContext() { return _callingContext; } 48 ObjectImp *activationObject() { return activation .imp(); }48 ObjectImp *activationObject() { return activation; } 49 49 FunctionImp *function() const { return _function; } 50 50 const List *arguments() const { return _arguments; } 51 51 52 void pushScope( const Object &s) { scope.push(s.imp()); }52 void pushScope(ObjectImp *s) { scope.push(s); } 53 53 void popScope() { scope.pop(); } 54 54 LabelStack *seenLabels() { return &ls; } … … 64 64 // there is no need to protect various pointers from conservative 65 65 // GC since they will be caught by the conservative sweep anyway! 66 Object 66 ObjectImp *activation; 67 67 68 68 ScopeChain scope; 69 Object 70 Object 69 ObjectImp *variable; 70 ObjectImp *thisVal; 71 71 72 72 LabelStack ls; -
trunk/JavaScriptCore/kjs/date_object.cpp
r10076 r10084 270 270 bool useCustomFormat = false; 271 271 UString customFormatString; 272 arg0String = args[0] .toString(exec);272 arg0String = args[0]->toString(exec); 273 273 if ((arg0String == "custom") && (argCount >= 2)) { 274 274 useCustomFormat = true; 275 customFormatString = args[1] .toString(exec);275 customFormatString = args[1]->toString(exec); 276 276 } else if (includeDate && includeTime && (argCount >= 2)) { 277 arg1String = args[1] .toString(exec);277 arg1String = args[1]->toString(exec); 278 278 dateStyle = styleFromArgString(arg0String,dateStyle); 279 279 timeStyle = styleFromArgString(arg1String,timeStyle); … … 309 309 #endif // APPLE_CHANGES 310 310 311 using namespace KJS; 311 namespace KJS { 312 312 313 313 static int day(double t) … … 400 400 if (maxArgs >= 4 && idx < numArgs) { 401 401 t->tm_hour = 0; 402 result = args[idx++] .toInt32(exec) * msPerHour;402 result = args[idx++]->toInt32(exec) * msPerHour; 403 403 } 404 404 // minutes 405 405 if (maxArgs >= 3 && idx < numArgs) { 406 406 t->tm_min = 0; 407 result += args[idx++] .toInt32(exec) * msPerMinute;407 result += args[idx++]->toInt32(exec) * msPerMinute; 408 408 } 409 409 // seconds 410 410 if (maxArgs >= 2 && idx < numArgs) { 411 411 t->tm_sec = 0; 412 result += args[idx++] .toInt32(exec) * msPerSecond;412 result += args[idx++]->toInt32(exec) * msPerSecond; 413 413 } 414 414 // read ms from args if present or add the old value … … 486 486 : DateInstanceImp(objectProto) 487 487 { 488 Value protect(this); 489 setInternalValue(NumberImp::create(NaN)); 488 setInternalValue(jsNaN()); 490 489 // The constructor will be added later, after DateObjectImp has been built 491 490 } … … 500 499 DateProtoFuncImp::DateProtoFuncImp(ExecState *exec, int i, int len) 501 500 : InternalFunctionImp( 502 static_cast<FunctionPrototypeImp*>(exec->lexicalInterpreter()->builtinFunctionPrototype() .imp())501 static_cast<FunctionPrototypeImp*>(exec->lexicalInterpreter()->builtinFunctionPrototype()) 503 502 ), id(abs(i)), utc(i<0) 504 503 // We use a negative ID to denote the "UTC" variant. 505 504 { 506 Value protect(this);507 505 putDirect(lengthPropertyName, len, DontDelete|ReadOnly|DontEnum); 508 506 } … … 513 511 } 514 512 515 Value DateProtoFuncImp::call(ExecState *exec, Object &thisObj, const List &args)513 ValueImp *DateProtoFuncImp::callAsFunction(ExecState *exec, ObjectImp *thisObj, const List &args) 516 514 { 517 515 if ((id == ToString || id == ValueOf || id == GetTime || id == SetTime) && 518 !thisObj .inherits(&DateInstanceImp::info)) {516 !thisObj->inherits(&DateInstanceImp::info)) { 519 517 // non-generic function called on non-date object 520 518 521 519 // ToString and ValueOf are generic according to the spec, but the mozilla 522 520 // tests suggest otherwise... 523 Object 521 ObjectImp *err = Error::create(exec,TypeError); 524 522 exec->setException(err); 525 523 return err; … … 527 525 528 526 529 Value result;527 ValueImp *result = NULL; 530 528 UString s; 531 529 #if !APPLE_CHANGES … … 536 534 oldlocale = setlocale(LC_ALL, NULL); 537 535 #endif 538 Value v = thisObj.internalValue();539 double milli = v .toNumber(exec);536 ValueImp *v = thisObj->internalValue(); 537 double milli = v->toNumber(exec); 540 538 541 539 if (isNaN(milli)) { … … 562 560 case GetMilliSeconds: 563 561 case GetTimezoneOffset: 564 return Number(NaN);562 return jsNaN(); 565 563 } 566 564 } … … 708 706 milli = roundValue(exec, args[0]); 709 707 result = Number(milli); 710 thisObj .setInternalValue(result);708 thisObj->setInternalValue(result); 711 709 break; 712 710 case SetMilliSeconds: … … 724 722 case SetDate: 725 723 t->tm_mday = 0; 726 ms += args[0] .toInt32(exec) * msPerDay;724 ms += args[0]->toInt32(exec) * msPerDay; 727 725 break; 728 726 case SetMonth: 729 t->tm_mon = args[0] .toInt32(exec);727 t->tm_mon = args[0]->toInt32(exec); 730 728 if (args.size() >= 2) 731 t->tm_mday = args[1] .toInt32(exec);729 t->tm_mday = args[1]->toInt32(exec); 732 730 break; 733 731 case SetFullYear: 734 t->tm_year = args[0] .toInt32(exec) - 1900;732 t->tm_year = args[0]->toInt32(exec) - 1900; 735 733 if (args.size() >= 2) 736 t->tm_mon = args[1] .toInt32(exec);734 t->tm_mon = args[1]->toInt32(exec); 737 735 if (args.size() >= 3) 738 t->tm_mday = args[2] .toInt32(exec);736 t->tm_mday = args[2]->toInt32(exec); 739 737 break; 740 738 case SetYear: 741 t->tm_year = args[0] .toInt32(exec) >= 1900 ? args[0].toInt32(exec) - 1900 : args[0].toInt32(exec);739 t->tm_year = args[0]->toInt32(exec) >= 1900 ? args[0]->toInt32(exec) - 1900 : args[0]->toInt32(exec); 742 740 break; 743 741 } … … 747 745 id == SetMonth || id == SetFullYear ) { 748 746 result = Number(makeTime(t, ms, utc)); 749 thisObj .setInternalValue(result);747 thisObj->setInternalValue(result); 750 748 } 751 749 … … 762 760 : InternalFunctionImp(funcProto) 763 761 { 764 Value protect(this);765 766 762 // ECMA 15.9.4.1 Date.prototype 767 763 putDirect(prototypePropertyName, dateProto, DontEnum|DontDelete|ReadOnly); … … 782 778 783 779 // ECMA 15.9.3 784 Object 780 ObjectImp *DateObjectImp::construct(ExecState *exec, const List &args) 785 781 { 786 782 int numArgs = args.size(); … … 808 804 value = utc; 809 805 } else if (numArgs == 1) { 810 if (args[0] .type() == StringType)811 value = parseDate(args[0] .toString(exec));806 if (args[0]->isString()) 807 value = parseDate(args[0]->toString(exec)); 812 808 else 813 value = args[0] .toPrimitive(exec).toNumber(exec);809 value = args[0]->toPrimitive(exec)->toNumber(exec); 814 810 } else { 815 811 struct tm t; 816 812 memset(&t, 0, sizeof(t)); 817 if (isNaN(args[0] .toNumber(exec))818 || isNaN(args[1] .toNumber(exec))819 || (numArgs >= 3 && isNaN(args[2] .toNumber(exec)))820 || (numArgs >= 4 && isNaN(args[3] .toNumber(exec)))821 || (numArgs >= 5 && isNaN(args[4] .toNumber(exec)))822 || (numArgs >= 6 && isNaN(args[5] .toNumber(exec)))823 || (numArgs >= 7 && isNaN(args[6] .toNumber(exec)))) {813 if (isNaN(args[0]->toNumber(exec)) 814 || isNaN(args[1]->toNumber(exec)) 815 || (numArgs >= 3 && isNaN(args[2]->toNumber(exec))) 816 || (numArgs >= 4 && isNaN(args[3]->toNumber(exec))) 817 || (numArgs >= 5 && isNaN(args[4]->toNumber(exec))) 818 || (numArgs >= 6 && isNaN(args[5]->toNumber(exec))) 819 || (numArgs >= 7 && isNaN(args[6]->toNumber(exec)))) { 824 820 value = NaN; 825 821 } else { 826 int year = args[0] .toInt32(exec);822 int year = args[0]->toInt32(exec); 827 823 t.tm_year = (year >= 0 && year <= 99) ? year : year - 1900; 828 t.tm_mon = args[1] .toInt32(exec);829 t.tm_mday = (numArgs >= 3) ? args[2] .toInt32(exec) : 1;830 t.tm_hour = (numArgs >= 4) ? args[3] .toInt32(exec) : 0;831 t.tm_min = (numArgs >= 5) ? args[4] .toInt32(exec) : 0;832 t.tm_sec = (numArgs >= 6) ? args[5] .toInt32(exec) : 0;824 t.tm_mon = args[1]->toInt32(exec); 825 t.tm_mday = (numArgs >= 3) ? args[2]->toInt32(exec) : 1; 826 t.tm_hour = (numArgs >= 4) ? args[3]->toInt32(exec) : 0; 827 t.tm_min = (numArgs >= 5) ? args[4]->toInt32(exec) : 0; 828 t.tm_sec = (numArgs >= 6) ? args[5]->toInt32(exec) : 0; 833 829 t.tm_isdst = -1; 834 830 double ms = (numArgs >= 7) ? roundValue(exec, args[6]) : 0; … … 837 833 } 838 834 839 Object proto = exec->lexicalInterpreter()->builtinDatePrototype(); 840 Object ret(new DateInstanceImp(proto.imp())); 841 ret.setInternalValue(Number(timeClip(value))); 835 DateInstanceImp *ret = new DateInstanceImp(exec->lexicalInterpreter()->builtinDatePrototype()); 836 ret->setInternalValue(Number(timeClip(value))); 842 837 return ret; 843 838 } … … 849 844 850 845 // ECMA 15.9.2 851 Value DateObjectImp::call(ExecState */*exec*/, Object &/*thisObj*/, const List &/*args*/) 852 { 853 #ifdef KJS_VERBOSE 854 fprintf(stderr,"DateObjectImp::call - current time\n"); 855 #endif 846 ValueImp *DateObjectImp::callAsFunction(ExecState */*exec*/, ObjectImp */*thisObj*/, const List &/*args*/) 847 { 856 848 time_t t = time(0L); 857 849 #if APPLE_CHANGES … … 872 864 : InternalFunctionImp(funcProto), id(i) 873 865 { 874 Value protect(this);875 866 putDirect(lengthPropertyName, len, DontDelete|ReadOnly|DontEnum); 876 867 } … … 882 873 883 874 // ECMA 15.9.4.2 - 3 884 Value DateObjectFuncImp::call(ExecState *exec, Object &/*thisObj*/, const List &args)875 ValueImp *DateObjectFuncImp::callAsFunction(ExecState *exec, ObjectImp *thisObj, const List &args) 885 876 { 886 877 if (id == Parse) { 887 return Number(parseDate(args[0] .toString(exec)));878 return Number(parseDate(args[0]->toString(exec))); 888 879 } 889 880 else { // UTC … … 891 882 memset(&t, 0, sizeof(t)); 892 883 int n = args.size(); 893 if (isNaN(args[0] .toNumber(exec))894 || isNaN(args[1] .toNumber(exec))895 || (n >= 3 && isNaN(args[2] .toNumber(exec)))896 || (n >= 4 && isNaN(args[3] .toNumber(exec)))897 || (n >= 5 && isNaN(args[4] .toNumber(exec)))898 || (n >= 6 && isNaN(args[5] .toNumber(exec)))899 || (n >= 7 && isNaN(args[6] .toNumber(exec)))) {884 if (isNaN(args[0]->toNumber(exec)) 885 || isNaN(args[1]->toNumber(exec)) 886 || (n >= 3 && isNaN(args[2]->toNumber(exec))) 887 || (n >= 4 && isNaN(args[3]->toNumber(exec))) 888 || (n >= 5 && isNaN(args[4]->toNumber(exec))) 889 || (n >= 6 && isNaN(args[5]->toNumber(exec))) 890 || (n >= 7 && isNaN(args[6]->toNumber(exec)))) { 900 891 return Number(NaN); 901 892 } 902 int year = args[0] .toInt32(exec);893 int year = args[0]->toInt32(exec); 903 894 t.tm_year = (year >= 0 && year <= 99) ? year : year - 1900; 904 t.tm_mon = args[1] .toInt32(exec);905 t.tm_mday = (n >= 3) ? args[2] .toInt32(exec) : 1;906 t.tm_hour = (n >= 4) ? args[3] .toInt32(exec) : 0;907 t.tm_min = (n >= 5) ? args[4] .toInt32(exec) : 0;908 t.tm_sec = (n >= 6) ? args[5] .toInt32(exec) : 0;895 t.tm_mon = args[1]->toInt32(exec); 896 t.tm_mday = (n >= 3) ? args[2]->toInt32(exec) : 1; 897 t.tm_hour = (n >= 4) ? args[3]->toInt32(exec) : 0; 898 t.tm_min = (n >= 5) ? args[4]->toInt32(exec) : 0; 899 t.tm_sec = (n >= 6) ? args[5]->toInt32(exec) : 0; 909 900 double ms = (n >= 7) ? roundValue(exec, args[6]) : 0; 910 901 return Number(makeTime(&t, ms, true)); … … 915 906 916 907 917 double KJS::parseDate(const UString &u)908 double parseDate(const UString &u) 918 909 { 919 910 #ifdef KJS_VERBOSE … … 1028 1019 } 1029 1020 1030 double K JS::KRFCDate_parseDate(const UString &_date)1021 double KRFCDate_parseDate(const UString &_date) 1031 1022 { 1032 1023 // This parse a date in the form: … … 1345 1336 1346 1337 1347 double KJS::timeClip(double t)1338 double timeClip(double t) 1348 1339 { 1349 1340 if (!isfinite(t)) … … 1354 1345 return copysign(floor(at), t); 1355 1346 } 1347 1348 } -
trunk/JavaScriptCore/kjs/date_object.h
r10076 r10084 63 63 64 64 virtual bool implementsCall() const; 65 virtual Value call(ExecState *exec, Object &thisObj, const List &args);65 virtual ValueImp *callAsFunction(ExecState *exec, ObjectImp *thisObj, const List &args); 66 66 67 67 … … 92 92 93 93 virtual bool implementsConstruct() const; 94 virtual Object 94 virtual ObjectImp *construct(ExecState *exec, const List &args); 95 95 virtual bool implementsCall() const; 96 virtual Value call(ExecState *exec, Object &thisObj, const List &args);96 virtual ValueImp *callAsFunction(ExecState *exec, ObjectImp *thisObj, const List &args); 97 97 98 98 Completion execute(const List &); 99 Object 99 ObjectImp *construct(const List &); 100 100 }; 101 101 … … 112 112 113 113 virtual bool implementsCall() const; 114 virtual Value call(ExecState *exec, Object &thisObj, const List &args);114 virtual ValueImp *callAsFunction(ExecState *exec, ObjectImp *thisObj, const List &args); 115 115 116 116 enum { Parse, UTC }; -
trunk/JavaScriptCore/kjs/debugger.cpp
r9929 r10084 100 100 101 101 bool Debugger::exception(ExecState */*exec*/, int /*sourceId*/, int /*lineno*/, 102 Object &/*exceptionObj*/)102 ObjectImp */*exceptionObj*/) 103 103 { 104 104 return true; … … 112 112 113 113 bool Debugger::callEvent(ExecState */*exec*/, int /*sourceId*/, int /*lineno*/, 114 Object &/*function*/, const List &/*args*/)114 ObjectImp */*function*/, const List &/*args*/) 115 115 { 116 116 return true; … … 118 118 119 119 bool Debugger::returnEvent(ExecState */*exec*/, int /*sourceId*/, int /*lineno*/, 120 Object &/*function*/)120 ObjectImp */*function*/) 121 121 { 122 122 return true; -
trunk/JavaScriptCore/kjs/debugger.h
r9929 r10084 29 29 class Interpreter; 30 30 class ExecState; 31 class Object ;31 class ObjectImp; 32 32 class UString; 33 33 class List; … … 142 142 */ 143 143 virtual bool exception(ExecState *exec, int sourceId, int lineno, 144 Object &exceptionObj);144 ObjectImp *exceptionObj); 145 145 146 146 /** … … 182 182 */ 183 183 virtual bool callEvent(ExecState *exec, int sourceId, int lineno, 184 Object &function, const List &args);184 ObjectImp *function, const List &args); 185 185 186 186 /** … … 203 203 */ 204 204 virtual bool returnEvent(ExecState *exec, int sourceId, int lineno, 205 Object &function);205 ObjectImp *function); 206 206 207 207 private: -
trunk/JavaScriptCore/kjs/error_object.cpp
r9819 r10084 48 48 : ObjectImp(objectProto) 49 49 { 50 Value protect(this);51 50 setInternalValue(Undefined()); 52 51 // The constructor will be added later in ErrorObjectImp's constructor … … 62 61 : InternalFunctionImp(funcProto) 63 62 { 64 Value protect(this); 65 putDirect(lengthPropertyName, NumberImp::zero(), DontDelete|ReadOnly|DontEnum); 63 putDirect(lengthPropertyName, jsZero(), DontDelete|ReadOnly|DontEnum); 66 64 } 67 65 … … 71 69 } 72 70 73 Value ErrorProtoFuncImp::call(ExecState *exec, Object &thisObj, const List &/*args*/)71 ValueImp *ErrorProtoFuncImp::callAsFunction(ExecState *exec, ObjectImp *thisObj, const List &/*args*/) 74 72 { 75 73 // toString() 76 74 UString s = "Error"; 77 75 78 Value v = thisObj.get(exec, namePropertyName);79 if ( v.type() != UndefinedType) {80 s = v .toString(exec);76 ValueImp *v = thisObj->get(exec, namePropertyName); 77 if (!v->isUndefined()) { 78 s = v->toString(exec); 81 79 } 82 80 83 v = thisObj .get(exec, messagePropertyName);84 if ( v.type() != UndefinedType) {85 s += ": " + v .toString(exec); // Mozilla compatible format81 v = thisObj->get(exec, messagePropertyName); 82 if (!v->isUndefined()) { 83 s += ": " + v->toString(exec); // Mozilla compatible format 86 84 } 87 85 … … 95 93 : InternalFunctionImp(funcProto) 96 94 { 97 Value protect(this);98 95 // ECMA 15.11.3.1 Error.prototype 99 96 putDirect(prototypePropertyName, errorProto, DontEnum|DontDelete|ReadOnly); 100 putDirect(lengthPropertyName, NumberImp::one(), DontDelete|ReadOnly|DontEnum);97 putDirect(lengthPropertyName, jsOne(), DontDelete|ReadOnly|DontEnum); 101 98 //putDirect(namePropertyName, String(n)); 102 99 } … … 108 105 109 106 // ECMA 15.9.3 110 Object 107 ObjectImp *ErrorObjectImp::construct(ExecState *exec, const List &args) 111 108 { 112 Object proto = Object::dynamicCast(exec->lexicalInterpreter()->builtinErrorPrototype());113 ObjectImp *imp = new ErrorInstanceImp(proto .imp());114 Object 109 ObjectImp *proto = static_cast<ObjectImp *>(exec->lexicalInterpreter()->builtinErrorPrototype()); 110 ObjectImp *imp = new ErrorInstanceImp(proto); 111 ObjectImp *obj(imp); 115 112 116 if (!args.isEmpty() && args[0].type() != UndefinedType) { 117 imp->putDirect(messagePropertyName, new StringImp(args[0].toString(exec))); 118 } 113 if (!args[0]->isUndefined()) 114 imp->putDirect(messagePropertyName, jsString(args[0]->toString(exec))); 119 115 120 116 return obj; … … 127 123 128 124 // ECMA 15.9.2 129 Value ErrorObjectImp::call(ExecState *exec, Object &/*thisObj*/, const List &args)125 ValueImp *ErrorObjectImp::callAsFunction(ExecState *exec, ObjectImp */*thisObj*/, const List &args) 130 126 { 131 127 // "Error()" gives the sames result as "new Error()" … … 139 135 : ObjectImp(errorProto) 140 136 { 141 Value protect(this);142 137 errType = et; 143 putDirect(namePropertyName, new StringImp(name), 0);144 putDirect(messagePropertyName, new StringImp(message), 0);138 putDirect(namePropertyName, jsString(name), 0); 139 putDirect(messagePropertyName, jsString(message), 0); 145 140 } 146 141 … … 150 145 151 146 NativeErrorImp::NativeErrorImp(ExecState *exec, FunctionPrototypeImp *funcProto, 152 const Object &prot)147 ObjectImp *prot) 153 148 : InternalFunctionImp(funcProto), proto(0) 154 149 { 155 Value protect(this); 156 proto = static_cast<ObjectImp*>(prot.imp()); 150 proto = static_cast<ObjectImp*>(prot); 157 151 158 putDirect(lengthPropertyName, NumberImp::one(), DontDelete|ReadOnly|DontEnum); // ECMA 15.11.7.5152 putDirect(lengthPropertyName, jsOne(), DontDelete|ReadOnly|DontEnum); // ECMA 15.11.7.5 159 153 putDirect(prototypePropertyName, proto, DontDelete|ReadOnly|DontEnum); 160 154 } … … 165 159 } 166 160 167 Object 161 ObjectImp *NativeErrorImp::construct(ExecState *exec, const List &args) 168 162 { 169 163 ObjectImp *imp = new ErrorInstanceImp(proto); 170 Object 171 if ( args[0].type() != UndefinedType)172 imp->putDirect(messagePropertyName, new StringImp(args[0].toString(exec)));164 ObjectImp *obj(imp); 165 if (!args[0]->isUndefined()) 166 imp->putDirect(messagePropertyName, jsString(args[0]->toString(exec))); 173 167 return obj; 174 168 } … … 179 173 } 180 174 181 Value NativeErrorImp::call(ExecState *exec, Object &/*thisObj*/, const List &args)175 ValueImp *NativeErrorImp::callAsFunction(ExecState *exec, ObjectImp */*thisObj*/, const List &args) 182 176 { 183 177 return construct(exec,args); -
trunk/JavaScriptCore/kjs/error_object.h
r9795 r10084 47 47 ErrorProtoFuncImp(ExecState *exec, FunctionPrototypeImp *funcProto); 48 48 virtual bool implementsCall() const; 49 virtual Value call(ExecState *exec, Object &thisObj, const List &args);49 virtual ValueImp *callAsFunction(ExecState *exec, ObjectImp *thisObj, const List &args); 50 50 }; 51 51 … … 56 56 57 57 virtual bool implementsConstruct() const; 58 virtual Object 58 virtual ObjectImp *construct(ExecState *exec, const List &args); 59 59 60 60 virtual bool implementsCall() const; 61 virtual Value call(ExecState *exec, Object &thisObj, const List &args);61 virtual ValueImp *callAsFunction(ExecState *exec, ObjectImp *thisObj, const List &args); 62 62 }; 63 63 … … 73 73 public: 74 74 NativeErrorImp(ExecState *exec, FunctionPrototypeImp *funcProto, 75 const Object &prot);75 ObjectImp *prot); 76 76 77 77 virtual bool implementsConstruct() const; 78 virtual Object 78 virtual ObjectImp *construct(ExecState *exec, const List &args); 79 79 virtual bool implementsCall() const; 80 virtual Value call(ExecState *exec, Object &thisObj, const List &args);80 virtual ValueImp *callAsFunction(ExecState *exec, ObjectImp *thisObj, const List &args); 81 81 82 82 virtual void mark(); -
trunk/JavaScriptCore/kjs/function.cpp
r10076 r10084 59 59 FunctionImp::FunctionImp(ExecState *exec, const Identifier &n) 60 60 : InternalFunctionImp( 61 static_cast<FunctionPrototypeImp*>(exec->lexicalInterpreter()->builtinFunctionPrototype() .imp())61 static_cast<FunctionPrototypeImp*>(exec->lexicalInterpreter()->builtinFunctionPrototype()) 62 62 ), param(0L), ident(n) 63 63 { … … 74 74 } 75 75 76 Value FunctionImp::call(ExecState *exec, Object &thisObj, const List &args)77 { 78 Object &globalObj = exec->dynamicInterpreter()->globalObject();76 ValueImp *FunctionImp::callAsFunction(ExecState *exec, ObjectImp *thisObj, const List &args) 77 { 78 ObjectImp *globalObj = exec->dynamicInterpreter()->globalObject(); 79 79 80 80 // enter a new execution context … … 98 98 } 99 99 100 Object func(this); 101 bool cont = dbg->callEvent(&newExec,sid,lineno,func,args); 100 bool cont = dbg->callEvent(&newExec,sid,lineno,this,args); 102 101 if (!cont) { 103 102 dbg->imp()->abort(); … … 128 127 newExec.setException(comp.value()); 129 128 130 Object func(this); 131 int cont = dbg->returnEvent(&newExec,sid,lineno,func); 129 int cont = dbg->returnEvent(&newExec,sid,lineno,this); 132 130 if (!cont) { 133 131 dbg->imp()->abort(); … … 173 171 void FunctionImp::processParameters(ExecState *exec, const List &args) 174 172 { 175 Object 173 ObjectImp *variable = exec->context().imp()->variableObject(); 176 174 177 175 #ifdef KJS_VERBOSE … … 190 188 printInfo(exec,"to", *it); 191 189 #endif 192 variable .put(exec, p->name, *it);190 variable->put(exec, p->name, *it); 193 191 it++; 194 192 } else 195 variable .put(exec, p->name, Undefined());193 variable->put(exec, p->name, Undefined()); 196 194 p = p->next; 197 195 } … … 209 207 } 210 208 211 Value 209 ValueImp *FunctionImp::argumentsGetter(ExecState *exec, const Identifier& propertyName, const PropertySlot& slot) 212 210 { 213 211 FunctionImp *thisObj = static_cast<FunctionImp *>(slot.slotBase()); … … 222 220 } 223 221 224 Value 222 ValueImp *FunctionImp::lengthGetter(ExecState *exec, const Identifier& propertyName, const PropertySlot& slot) 225 223 { 226 224 FunctionImp *thisObj = static_cast<FunctionImp *>(slot.slotBase()); … … 251 249 } 252 250 253 void FunctionImp::put(ExecState *exec, const Identifier &propertyName, const Value &value, int attr)251 void FunctionImp::put(ExecState *exec, const Identifier &propertyName, ValueImp *value, int attr) 254 252 { 255 253 if (propertyName == exec->dynamicInterpreter()->argumentsIdentifier() || propertyName == lengthPropertyName) … … 306 304 : FunctionImp(exec,n), body(b) 307 305 { 308 Value protect(this);309 306 body->ref(); 310 307 setScope(sc); … … 323 320 324 321 // ECMA 13.2.2 [[Construct]] 325 Object 326 { 327 Object 328 Value 329 if (p .type() == ObjectType)330 proto = Object(static_cast<ObjectImp*>(p.imp()));322 ObjectImp *DeclaredFunctionImp::construct(ExecState *exec, const List &args) 323 { 324 ObjectImp *proto; 325 ValueImp *p = get(exec,prototypePropertyName); 326 if (p->isObject()) 327 proto = static_cast<ObjectImp*>(p); 331 328 else 332 329 proto = exec->lexicalInterpreter()->builtinObjectPrototype(); 333 330 334 Object 335 336 Value 337 338 if (res .type() == ObjectType)339 return Object::dynamicCast(res);331 ObjectImp *obj(new ObjectImp(proto)); 332 333 ValueImp *res = call(exec,obj,args); 334 335 if (res->isObject()) 336 return static_cast<ObjectImp *>(res); 340 337 else 341 338 return obj; … … 434 431 indexToNameMap(func, args) 435 432 { 436 Value protect(this);437 433 putDirect(calleePropertyName, func, DontEnum); 438 434 putDirect(lengthPropertyName, args.size(), DontEnum); … … 454 450 } 455 451 456 Value 452 ValueImp *ArgumentsImp::mappedIndexGetter(ExecState *exec, const Identifier& propertyName, const PropertySlot& slot) 457 453 { 458 454 ArgumentsImp *thisObj = static_cast<ArgumentsImp *>(slot.slotBase()); … … 470 466 } 471 467 472 void ArgumentsImp::put(ExecState *exec, const Identifier &propertyName, const Value &value, int attr)468 void ArgumentsImp::put(ExecState *exec, const Identifier &propertyName, ValueImp *value, int attr) 473 469 { 474 470 if (indexToNameMap.isMapped(propertyName)) { … … 501 497 } 502 498 503 Value 499 ValueImp *ActivationImp::argumentsGetter(ExecState *exec, const Identifier& propertyName, const PropertySlot& slot) 504 500 { 505 501 ActivationImp *thisObj = static_cast<ActivationImp *>(slot.slotBase()); … … 509 505 thisObj->createArgumentsObject(exec); 510 506 511 return Value(thisObj->_argumentsObject);507 return thisObj->_argumentsObject; 512 508 } 513 509 … … 559 555 : InternalFunctionImp(funcProto), id(i) 560 556 { 561 Value protect(this);562 557 putDirect(lengthPropertyName, len, DontDelete|ReadOnly|DontEnum); 563 558 } … … 573 568 } 574 569 575 static Value 576 { 577 UString r = "", s, str = args[0] .toString(exec);570 static ValueImp *encode(ExecState *exec, const List &args, const char *do_not_escape) 571 { 572 UString r = "", s, str = args[0]->toString(exec); 578 573 CString cstr = str.UTF8String(); 579 574 const char *p = cstr.c_str(); … … 591 586 } 592 587 593 static Value 594 { 595 UString s = "", str = args[0] .toString(exec);588 static ValueImp *decode(ExecState *exec, const List &args, const char *do_not_unescape, bool strict) 589 { 590 UString s = "", str = args[0]->toString(exec); 596 591 int k = 0, len = str.size(); 597 592 const UChar *d = str.data(); … … 635 630 if (charLen == 0) { 636 631 if (strict) { 637 Object 632 ObjectImp *error = Error::create(exec, URIError); 638 633 exec->setException(error); 639 634 return error; … … 768 763 } 769 764 770 Value GlobalFuncImp::call(ExecState *exec, Object &/*thisObj*/, const List &args)771 { 772 Value res;765 ValueImp *GlobalFuncImp::callAsFunction(ExecState *exec, ObjectImp */*thisObj*/, const List &args) 766 { 767 ValueImp *res = jsUndefined(); 773 768 774 769 static const char do_not_escape[] = … … 793 788 switch (id) { 794 789 case Eval: { // eval() 795 Value 796 if ( x.type() != StringType)790 ValueImp *x = args[0]; 791 if (!x->isString()) 797 792 return x; 798 793 else { 799 UString s = x .toString(exec);794 UString s = x->toString(exec); 800 795 801 796 int sid; … … 813 808 // no program node means a syntax occurred 814 809 if (!progNode) { 815 Object 816 err .put(exec,"sid",Number(sid));810 ObjectImp *err = Error::create(exec,SyntaxError,errMsg.ascii(),errLine); 811 err->put(exec,"sid",Number(sid)); 817 812 exec->setException(err); 818 813 return err; … … 822 817 823 818 // enter a new execution context 824 Object thisVal(Object::dynamicCast(exec->context().thisValue()));819 ObjectImp *thisVal = static_cast<ObjectImp *>(exec->context().thisValue()); 825 820 ContextImp ctx(exec->dynamicInterpreter()->globalObject(), 826 821 exec->dynamicInterpreter()->imp(), … … 852 847 } 853 848 case ParseInt: 854 res = Number(parseInt(args[0] .toString(exec), args[1].toInt32(exec)));849 res = Number(parseInt(args[0]->toString(exec), args[1]->toInt32(exec))); 855 850 break; 856 851 case ParseFloat: 857 res = Number(parseFloat(args[0] .toString(exec)));852 res = Number(parseFloat(args[0]->toString(exec))); 858 853 break; 859 854 case IsNaN: 860 res = Boolean(isNaN(args[0] .toNumber(exec)));855 res = Boolean(isNaN(args[0]->toNumber(exec))); 861 856 break; 862 857 case IsFinite: { 863 double n = args[0] .toNumber(exec);858 double n = args[0]->toNumber(exec); 864 859 res = Boolean(!isNaN(n) && !isInf(n)); 865 860 break; … … 879 874 case Escape: 880 875 { 881 UString r = "", s, str = args[0] .toString(exec);876 UString r = "", s, str = args[0]->toString(exec); 882 877 const UChar *c = str.data(); 883 878 for (int k = 0; k < str.size(); k++, c++) { … … 901 896 case UnEscape: 902 897 { 903 UString s = "", str = args[0] .toString(exec);898 UString s = "", str = args[0]->toString(exec); 904 899 int k = 0, len = str.size(); 905 900 while (k < len) { … … 928 923 #ifndef NDEBUG 929 924 case KJSPrint: 930 puts(args[0] .toString(exec).ascii());925 puts(args[0]->toString(exec).ascii()); 931 926 break; 932 927 #endif -
trunk/JavaScriptCore/kjs/function.h
r10076 r10084 44 44 45 45 virtual bool getOwnPropertySlot(ExecState *, const Identifier &, PropertySlot&); 46 virtual void put(ExecState *exec, const Identifier &propertyName, const Value &value, int attr = None);46 virtual void put(ExecState *exec, const Identifier &propertyName, ValueImp *value, int attr = None); 47 47 virtual bool deleteProperty(ExecState *exec, const Identifier &propertyName); 48 48 49 49 virtual bool implementsCall() const; 50 virtual Value call(ExecState *exec, Object &thisObj, const List &args);50 virtual ValueImp *callAsFunction(ExecState *exec, ObjectImp *thisObj, const List &args); 51 51 52 52 void addParameter(const Identifier &n); … … 66 66 67 67 private: 68 static Value 69 static Value 68 static ValueImp *argumentsGetter(ExecState *, const Identifier &, const PropertySlot&); 69 static ValueImp *lengthGetter(ExecState *, const Identifier &, const PropertySlot&); 70 70 71 71 void processParameters(ExecState *exec, const List &); … … 80 80 81 81 bool implementsConstruct() const; 82 Object 82 ObjectImp *construct(ExecState *exec, const List &args); 83 83 84 84 virtual Completion execute(ExecState *exec); … … 113 113 virtual void mark(); 114 114 virtual bool getOwnPropertySlot(ExecState *, const Identifier &, PropertySlot&); 115 virtual void put(ExecState *exec, const Identifier &propertyName, 116 const Value &value, int attr = None); 115 virtual void put(ExecState *exec, const Identifier &propertyName, ValueImp *value, int attr = None); 117 116 virtual bool deleteProperty(ExecState *exec, const Identifier &propertyName); 118 117 virtual const ClassInfo *classInfo() const { return &info; } 119 118 static const ClassInfo info; 120 119 private: 121 static Value 120 static ValueImp *mappedIndexGetter(ExecState *exec, const Identifier &, const PropertySlot& slot); 122 121 123 122 ActivationImp *_activationObject; … … 139 138 private: 140 139 static PropertySlot::GetValueFunc getArgumentsGetter(); 141 static Value 140 static ValueImp *argumentsGetter(ExecState *exec, const Identifier &, const PropertySlot& slot); 142 141 void createArgumentsObject(ExecState *exec) const; 143 142 … … 151 150 GlobalFuncImp(ExecState *exec, FunctionPrototypeImp *funcProto, int i, int len); 152 151 virtual bool implementsCall() const; 153 virtual Value call(ExecState *exec, Object &thisObj, const List &args);152 virtual ValueImp *callAsFunction(ExecState *exec, ObjectImp *thisObj, const List &args); 154 153 virtual CodeType codeType() const; 155 154 enum { Eval, ParseInt, ParseFloat, IsNaN, IsFinite, Escape, UnEscape, -
trunk/JavaScriptCore/kjs/function_object.cpp
r9929 r10084 41 41 : InternalFunctionImp(0) 42 42 { 43 Value protect(this); 44 putDirect(lengthPropertyName, NumberImp::zero(), DontDelete|ReadOnly|DontEnum); 43 putDirect(lengthPropertyName, jsZero(), DontDelete|ReadOnly|DontEnum); 45 44 putDirect(toStringPropertyName, new FunctionProtoFuncImp(exec, this, FunctionProtoFuncImp::ToString, 0), DontEnum); 46 45 static const Identifier applyPropertyName("apply"); … … 60 59 61 60 // ECMA 15.3.4 62 Value FunctionPrototypeImp::call(ExecState */*exec*/, Object &/*thisObj*/, const List &/*args*/)61 ValueImp *FunctionPrototypeImp::callAsFunction(ExecState */*exec*/, ObjectImp */*thisObj*/, const List &/*args*/) 63 62 { 64 63 return Undefined(); … … 71 70 : InternalFunctionImp(funcProto), id(i) 72 71 { 73 Value protect(this);74 72 putDirect(lengthPropertyName, len, DontDelete|ReadOnly|DontEnum); 75 73 } … … 81 79 } 82 80 83 Value FunctionProtoFuncImp::call(ExecState *exec, Object &thisObj, const List &args)84 { 85 Value result;81 ValueImp *FunctionProtoFuncImp::callAsFunction(ExecState *exec, ObjectImp *thisObj, const List &args) 82 { 83 ValueImp *result = NULL; 86 84 87 85 switch (id) { 88 86 case ToString: { 89 87 // ### also make this work for internal functions 90 if ( thisObj.isNull() || !thisObj.inherits(&InternalFunctionImp::info)) {88 if (!thisObj || !thisObj->inherits(&InternalFunctionImp::info)) { 91 89 #ifndef NDEBUG 92 90 fprintf(stderr,"attempted toString() call on null or non-function object\n"); 93 91 #endif 94 Object 92 ObjectImp *err = Error::create(exec,TypeError); 95 93 exec->setException(err); 96 94 return err; 97 95 } 98 if (thisObj .inherits(&DeclaredFunctionImp::info)) {96 if (thisObj->inherits(&DeclaredFunctionImp::info)) { 99 97 DeclaredFunctionImp *fi = static_cast<DeclaredFunctionImp*> 100 (thisObj .imp());98 (thisObj); 101 99 return String("function " + fi->name().ustring() + "(" + 102 100 fi->parameterString() + ") " + fi->body->toString()); 103 } else if (thisObj .inherits(&FunctionImp::info) &&104 !static_cast<FunctionImp*>(thisObj .imp())->name().isNull()) {105 result = String("function " + static_cast<FunctionImp*>(thisObj .imp())->name().ustring() + "()");101 } else if (thisObj->inherits(&FunctionImp::info) && 102 !static_cast<FunctionImp*>(thisObj)->name().isNull()) { 103 result = String("function " + static_cast<FunctionImp*>(thisObj)->name().ustring() + "()"); 106 104 } 107 105 else { … … 111 109 break; 112 110 case Apply: { 113 Value 114 Value 115 Object 116 117 if (!func .implementsCall()) {118 Object 111 ValueImp *thisArg = args[0]; 112 ValueImp *argArray = args[1]; 113 ObjectImp *func = thisObj; 114 115 if (!func->implementsCall()) { 116 ObjectImp *err = Error::create(exec,TypeError); 119 117 exec->setException(err); 120 118 return err; 121 119 } 122 120 123 Object 124 if (thisArg .isA(NullType) || thisArg.isA(UndefinedType))121 ObjectImp *applyThis; 122 if (thisArg->isUndefinedOrNull()) 125 123 applyThis = exec->dynamicInterpreter()->globalObject(); 126 124 else 127 applyThis = thisArg .toObject(exec);125 applyThis = thisArg->toObject(exec); 128 126 129 127 List applyArgs; 130 if (!argArray .isA(NullType) && !argArray.isA(UndefinedType)) {131 if (argArray .isA(ObjectType) &&132 ( Object::dynamicCast(argArray).inherits(&ArrayInstanceImp::info) ||133 Object::dynamicCast(argArray).inherits(&ArgumentsImp::info))) {134 135 Object argArrayObj = Object::dynamicCast(argArray);136 unsigned int length = argArrayObj .get(exec,lengthPropertyName).toUInt32(exec);128 if (!argArray->isUndefinedOrNull()) { 129 if (argArray->isObject() && 130 (static_cast<ObjectImp *>(argArray)->inherits(&ArrayInstanceImp::info) || 131 static_cast<ObjectImp *>(argArray)->inherits(&ArgumentsImp::info))) { 132 133 ObjectImp *argArrayObj = static_cast<ObjectImp *>(argArray); 134 unsigned int length = argArrayObj->get(exec,lengthPropertyName)->toUInt32(exec); 137 135 for (unsigned int i = 0; i < length; i++) 138 applyArgs.append(argArrayObj .get(exec,i));136 applyArgs.append(argArrayObj->get(exec,i)); 139 137 } 140 138 else { 141 Object 139 ObjectImp *err = Error::create(exec,TypeError); 142 140 exec->setException(err); 143 141 return err; 144 142 } 145 143 } 146 result = func .call(exec,applyThis,applyArgs);144 result = func->call(exec,applyThis,applyArgs); 147 145 } 148 146 break; 149 147 case Call: { 150 Value 151 Object 152 153 if (!func .implementsCall()) {154 Object 148 ValueImp *thisArg = args[0]; 149 ObjectImp *func = thisObj; 150 151 if (!func->implementsCall()) { 152 ObjectImp *err = Error::create(exec,TypeError); 155 153 exec->setException(err); 156 154 return err; 157 155 } 158 156 159 Object 160 if (thisArg .isA(NullType) || thisArg.isA(UndefinedType))157 ObjectImp *callThis; 158 if (thisArg->isUndefinedOrNull()) 161 159 callThis = exec->dynamicInterpreter()->globalObject(); 162 160 else 163 callThis = thisArg .toObject(exec);164 165 result = func .call(exec,callThis,args.copyTail());161 callThis = thisArg->toObject(exec); 162 163 result = func->call(exec,callThis,args.copyTail()); 166 164 } 167 165 break; … … 176 174 : InternalFunctionImp(funcProto) 177 175 { 178 Value protect(this);179 176 putDirect(prototypePropertyName, funcProto, DontEnum|DontDelete|ReadOnly); 180 177 181 178 // no. of arguments for constructor 182 putDirect(lengthPropertyName, NumberImp::one(), ReadOnly|DontDelete|DontEnum);179 putDirect(lengthPropertyName, jsOne(), ReadOnly|DontDelete|DontEnum); 183 180 } 184 181 … … 193 190 194 191 // ECMA 15.3.2 The Function Constructor 195 Object 192 ObjectImp *FunctionObjectImp::construct(ExecState *exec, const List &args, const UString &sourceURL, int lineNumber) 196 193 { 197 194 UString p(""); … … 201 198 body = ""; 202 199 } else if (argsSize == 1) { 203 body = args[0] .toString(exec);200 body = args[0]->toString(exec); 204 201 } else { 205 p = args[0] .toString(exec);202 p = args[0]->toString(exec); 206 203 for (int k = 1; k < argsSize - 1; k++) 207 p += "," + args[k] .toString(exec);208 body = args[argsSize-1] .toString(exec);204 p += "," + args[k]->toString(exec); 205 body = args[argsSize-1]->toString(exec); 209 206 } 210 207 … … 222 219 if (!cont) { 223 220 dbg->imp()->abort(); 224 return Object(new ObjectImp());221 return new ObjectImp(); 225 222 } 226 223 } … … 228 225 // no program node == syntax error - throw a syntax error 229 226 if (!progNode) { 230 Object 227 ObjectImp *err = Error::create(exec,SyntaxError,errMsg.ascii(),errLine); 231 228 // we can't return a Completion(Throw) here, so just set the exception 232 229 // and return it … … 236 233 237 234 ScopeChain scopeChain; 238 scopeChain.push(exec->dynamicInterpreter()->globalObject() .imp());235 scopeChain.push(exec->dynamicInterpreter()->globalObject()); 239 236 FunctionBodyNode *bodyNode = progNode; 240 237 241 238 FunctionImp *fimp = new DeclaredFunctionImp(exec, Identifier::null(), bodyNode, 242 239 scopeChain); 243 Object ret(fimp); // protect from GC244 240 245 241 // parse parameter list. throw syntax error on illegal identifiers … … 272 268 } // else error 273 269 } 274 Object 270 ObjectImp *err = Error::create(exec,SyntaxError, 275 271 I18N_NOOP("Syntax error in parameter list"), 276 272 -1); … … 281 277 List consArgs; 282 278 283 Object 284 Object prototype = objCons.construct(exec,List::empty());285 prototype .put(exec, constructorPropertyName, Value(fimp), DontEnum|DontDelete|ReadOnly);279 ObjectImp *objCons = exec->lexicalInterpreter()->builtinObject(); 280 ObjectImp *prototype = objCons->construct(exec,List::empty()); 281 prototype->put(exec, constructorPropertyName, fimp, DontEnum|DontDelete|ReadOnly); 286 282 fimp->put(exec, prototypePropertyName, prototype, DontEnum|DontDelete|ReadOnly); 287 return ret;283 return fimp; 288 284 } 289 285 290 286 // ECMA 15.3.2 The Function Constructor 291 Object 287 ObjectImp *FunctionObjectImp::construct(ExecState *exec, const List &args) 292 288 { 293 289 return FunctionObjectImp::construct(exec, args, UString(), 0); … … 301 297 302 298 // ECMA 15.3.1 The Function Constructor Called as a Function 303 Value FunctionObjectImp::call(ExecState *exec, Object &/*thisObj*/, const List &args)299 ValueImp *FunctionObjectImp::callAsFunction(ExecState *exec, ObjectImp */*thisObj*/, const List &args) 304 300 { 305 301 return construct(exec,args); -
trunk/JavaScriptCore/kjs/function_object.h
r9768 r10084 41 41 42 42 virtual bool implementsCall() const; 43 virtual Value call(ExecState *exec, Object &thisObj, const List &args);43 virtual ValueImp *callAsFunction(ExecState *exec, ObjectImp *thisObj, const List &args); 44 44 }; 45 45 … … 56 56 57 57 virtual bool implementsCall() const; 58 virtual Value call(ExecState *exec, Object &thisObj, const List &args);58 virtual ValueImp *callAsFunction(ExecState *exec, ObjectImp *thisObj, const List &args); 59 59 60 60 enum { ToString, Apply, Call }; … … 74 74 75 75 virtual bool implementsConstruct() const; 76 virtual Object 77 virtual Object 76 virtual ObjectImp *construct(ExecState *exec, const List &args, const UString &sourceURL, int lineNumber); 77 virtual ObjectImp *construct(ExecState *exec, const List &args); 78 78 virtual bool implementsCall() const; 79 virtual Value call(ExecState *exec, Object &thisObj, const List &args);79 virtual ValueImp *callAsFunction(ExecState *exec, ObjectImp *thisObj, const List &args); 80 80 }; 81 81 -
trunk/JavaScriptCore/kjs/internal.cpp
r10076 r10084 54 54 extern int kjsyyparse(); 55 55 56 using namespace KJS; 56 namespace KJS { 57 57 58 58 #if !APPLE_CHANGES 59 59 60 namespace KJS {61 60 #ifdef WORDS_BIGENDIAN 62 61 const unsigned char NaN_Bytes[] = { 0x7f, 0xf8, 0, 0, 0, 0, 0, 0 }; … … 72 71 const double NaN = *(const double*) NaN_Bytes; 73 72 const double Inf = *(const double*) Inf_Bytes; 74 };75 73 76 74 #endif // APPLE_CHANGES … … 108 106 // ------------------------------ UndefinedImp --------------------------------- 109 107 110 UndefinedImp *UndefinedImp::staticUndefined = 0; 111 112 Value UndefinedImp::toPrimitive(ExecState */*exec*/, Type) const 113 { 114 return Value((ValueImp*)this); 108 ValueImp *UndefinedImp::toPrimitive(ExecState */*exec*/, Type) const 109 { 110 return const_cast<UndefinedImp *>(this); 115 111 } 116 112 … … 130 126 } 131 127 132 Object 133 { 134 Object 128 ObjectImp *UndefinedImp::toObject(ExecState *exec) const 129 { 130 ObjectImp *err = Error::create(exec, TypeError, I18N_NOOP("Undefined value")); 135 131 exec->setException(err); 136 132 return err; … … 139 135 // ------------------------------ NullImp -------------------------------------- 140 136 141 NullImp *NullImp::staticNull = 0; 142 143 Value NullImp::toPrimitive(ExecState */*exec*/, Type) const 144 { 145 return Value((ValueImp*)this); 137 ValueImp *NullImp::toPrimitive(ExecState */*exec*/, Type) const 138 { 139 return const_cast<NullImp *>(this); 146 140 } 147 141 … … 161 155 } 162 156 163 Object 164 { 165 Object 157 ObjectImp *NullImp::toObject(ExecState *exec) const 158 { 159 ObjectImp *err = Error::create(exec, TypeError, I18N_NOOP("Null value")); 166 160 exec->setException(err); 167 161 return err; … … 170 164 // ------------------------------ BooleanImp ----------------------------------- 171 165 172 BooleanImp* BooleanImp::staticTrue = 0; 173 BooleanImp* BooleanImp::staticFalse = 0; 174 175 Value BooleanImp::toPrimitive(ExecState */*exec*/, Type) const 176 { 177 return Value((ValueImp*)this); 166 ValueImp *BooleanImp::toPrimitive(ExecState */*exec*/, Type) const 167 { 168 return const_cast<BooleanImp *>(this); 178 169 } 179 170 … … 193 184 } 194 185 195 Object 186 ObjectImp *BooleanImp::toObject(ExecState *exec) const 196 187 { 197 188 List args; 198 189 args.append(const_cast<BooleanImp*>(this)); 199 return Object::dynamicCast(exec->lexicalInterpreter()->builtinBoolean().construct(exec,args));190 return static_cast<ObjectImp *>(exec->lexicalInterpreter()->builtinBoolean()->construct(exec,args)); 200 191 } 201 192 202 193 // ------------------------------ StringImp ------------------------------------ 203 194 204 Value 205 { 206 return Value((ValueImp*)this);195 ValueImp *StringImp::toPrimitive(ExecState */*exec*/, Type) const 196 { 197 return const_cast<StringImp *>(this); 207 198 } 208 199 … … 222 213 } 223 214 224 Object 215 ObjectImp *StringImp::toObject(ExecState *exec) const 225 216 { 226 217 List args; 227 218 args.append(const_cast<StringImp*>(this)); 228 return Object(static_cast<ObjectImp *>(exec->lexicalInterpreter()->builtinString().construct(exec, args).imp()));219 return static_cast<ObjectImp *>(exec->lexicalInterpreter()->builtinString()->construct(exec, args)); 229 220 } 230 221 231 222 // ------------------------------ NumberImp ------------------------------------ 232 223 233 NumberImp *NumberImp::staticNaN; 234 235 ValueImp *NumberImp::create(int i) 236 { 237 if (SimpleNumber::fits(i)) 238 return SimpleNumber::make(i); 239 return new NumberImp(static_cast<double>(i)); 240 } 241 242 ValueImp *NumberImp::create(double d) 243 { 244 if (SimpleNumber::fits(d)) 245 return SimpleNumber::make((int)d); 246 if (isNaN(d)) 247 return staticNaN; 248 return new NumberImp(d); 249 } 250 251 Value NumberImp::toPrimitive(ExecState *, Type) const 252 { 253 return Number((NumberImp*)this); 224 ValueImp *NumberImp::toPrimitive(ExecState *, Type) const 225 { 226 return const_cast<NumberImp *>(this); 254 227 } 255 228 … … 271 244 } 272 245 273 Object 246 ObjectImp *NumberImp::toObject(ExecState *exec) const 274 247 { 275 248 List args; 276 249 args.append(const_cast<NumberImp*>(this)); 277 return Object::dynamicCast(exec->lexicalInterpreter()->builtinNumber().construct(exec,args));278 } 279 280 bool NumberImp:: toUInt32(unsigned& uint32) const281 { 282 uint32 = (u nsigned)val;250 return static_cast<ObjectImp *>(exec->lexicalInterpreter()->builtinNumber()->construct(exec,args)); 251 } 252 253 bool NumberImp::getUInt32(uint32_t& uint32) const 254 { 255 uint32 = (uint32_t)val; 283 256 return (double)uint32 == val; 284 257 } … … 316 289 bool LabelStack::push(const Identifier &id) 317 290 { 318 if ( id.isEmpty() ||contains(id))291 if (contains(id)) 319 292 return false; 320 293 … … 366 339 367 340 // ECMA 10.2 368 ContextImp::ContextImp(Object &glob, InterpreterImp *interpreter, Object &thisV, CodeType type,341 ContextImp::ContextImp(ObjectImp *glob, InterpreterImp *interpreter, ObjectImp *thisV, CodeType type, 369 342 ContextImp *callingCon, FunctionImp *func, const List *args) 370 343 : _interpreter(interpreter), _function(func), _arguments(args) … … 375 348 // create and initialize activation object (ECMA 10.1.6) 376 349 if (type == FunctionCode || type == AnonymousCode ) { 377 activation = Object(new ActivationImp(func, *args));350 activation = new ActivationImp(func, *args); 378 351 variable = activation; 379 352 } else { 380 activation = Object();353 activation = NULL; 381 354 variable = glob; 382 355 } … … 393 366 case GlobalCode: 394 367 scope.clear(); 395 scope.push(glob .imp());396 thisVal = Object(static_cast<ObjectImp*>(glob.imp()));368 scope.push(glob); 369 thisVal = static_cast<ObjectImp*>(glob); 397 370 break; 398 371 case FunctionCode: … … 400 373 if (type == FunctionCode) { 401 374 scope = func->scope(); 402 scope.push(activation .imp());375 scope.push(activation); 403 376 } else { 404 377 scope.clear(); 405 scope.push(glob .imp());406 scope.push(activation .imp());378 scope.push(glob); 379 scope.push(activation); 407 380 } 408 381 variable = activation; // TODO: DontDelete ? (ECMA 10.2.3) … … 479 452 void InterpreterImp::globalInit() 480 453 { 481 //fprintf( stderr, "InterpreterImp::globalInit()\n" ); 482 UndefinedImp::staticUndefined = new UndefinedImp(); 483 NullImp::staticNull = new NullImp(); 484 BooleanImp::staticTrue = new BooleanImp(true); 485 BooleanImp::staticFalse = new BooleanImp(false); 486 NumberImp::staticNaN = new NumberImp(NaN); 454 ConstantValues::init(); 487 455 } 488 456 489 457 void InterpreterImp::globalClear() 490 458 { 491 //fprintf( stderr, "InterpreterImp::globalClear()\n" ); 492 UndefinedImp::staticUndefined = 0; 493 NullImp::staticNull = 0; 494 BooleanImp::staticTrue = 0; 495 BooleanImp::staticFalse = 0; 496 NumberImp::staticNaN = 0; 497 } 498 499 InterpreterImp::InterpreterImp(Interpreter *interp, const Object &glob) 500 : globExec(interp, 0) 501 , _context(0) 459 ConstantValues::clear(); 460 } 461 462 InterpreterImp::InterpreterImp(Interpreter *interp, ObjectImp *glob) 463 : globExec(interp, 0) 464 , _context(0) 502 465 { 503 466 // add this interpreter to the global chain … … 516 479 } 517 480 518 InterpreterMap::setInterpreterForGlobalObject(this, glob .imp());481 InterpreterMap::setInterpreterForGlobalObject(this, glob); 519 482 520 483 global = glob; … … 551 514 552 515 FunctionPrototypeImp *funcProto = new FunctionPrototypeImp(&globExec); 553 b_FunctionPrototype = Object(funcProto);516 b_FunctionPrototype = funcProto; 554 517 ObjectPrototypeImp *objProto = new ObjectPrototypeImp(&globExec, funcProto); 555 b_ObjectPrototype = Object(objProto);518 b_ObjectPrototype = objProto; 556 519 funcProto->setPrototype(b_ObjectPrototype); 557 520 558 521 ArrayPrototypeImp *arrayProto = new ArrayPrototypeImp(&globExec, objProto); 559 b_ArrayPrototype = Object(arrayProto);522 b_ArrayPrototype = arrayProto; 560 523 StringPrototypeImp *stringProto = new StringPrototypeImp(&globExec, objProto); 561 b_StringPrototype = Object(stringProto);524 b_StringPrototype = stringProto; 562 525 BooleanPrototypeImp *booleanProto = new BooleanPrototypeImp(&globExec, objProto, funcProto); 563 b_BooleanPrototype = Object(booleanProto);526 b_BooleanPrototype = booleanProto; 564 527 NumberPrototypeImp *numberProto = new NumberPrototypeImp(&globExec, objProto, funcProto); 565 b_NumberPrototype = Object(numberProto);528 b_NumberPrototype = numberProto; 566 529 DatePrototypeImp *dateProto = new DatePrototypeImp(&globExec, objProto); 567 b_DatePrototype = Object(dateProto);530 b_DatePrototype = dateProto; 568 531 RegExpPrototypeImp *regexpProto = new RegExpPrototypeImp(&globExec, objProto, funcProto); 569 b_RegExpPrototype = Object(regexpProto);532 b_RegExpPrototype = regexpProto; 570 533 ErrorPrototypeImp *errorProto = new ErrorPrototypeImp(&globExec, objProto, funcProto); 571 b_ErrorPrototype = Object(errorProto);572 573 static_cast<ObjectImp*>(global .imp())->setPrototype(b_ObjectPrototype);534 b_ErrorPrototype = errorProto; 535 536 static_cast<ObjectImp*>(global)->setPrototype(b_ObjectPrototype); 574 537 575 538 // Constructors (Object, Array, etc.) 576 b_Object = Object(new ObjectObjectImp(&globExec, objProto, funcProto));577 b_Function = Object(new FunctionObjectImp(&globExec, funcProto));578 b_Array = Object(new ArrayObjectImp(&globExec, funcProto, arrayProto));579 b_String = Object(new StringObjectImp(&globExec, funcProto, stringProto));580 b_Boolean = Object(new BooleanObjectImp(&globExec, funcProto, booleanProto));581 b_Number = Object(new NumberObjectImp(&globExec, funcProto, numberProto));582 b_Date = Object(new DateObjectImp(&globExec, funcProto, dateProto));583 b_RegExp = Object(new RegExpObjectImp(&globExec, funcProto, regexpProto));584 b_Error = Object(new ErrorObjectImp(&globExec, funcProto, errorProto));539 b_Object = new ObjectObjectImp(&globExec, objProto, funcProto); 540 b_Function = new FunctionObjectImp(&globExec, funcProto); 541 b_Array = new ArrayObjectImp(&globExec, funcProto, arrayProto); 542 b_String = new StringObjectImp(&globExec, funcProto, stringProto); 543 b_Boolean = new BooleanObjectImp(&globExec, funcProto, booleanProto); 544 b_Number = new NumberObjectImp(&globExec, funcProto, numberProto); 545 b_Date = new DateObjectImp(&globExec, funcProto, dateProto); 546 b_RegExp = new RegExpObjectImp(&globExec, funcProto, regexpProto); 547 b_Error = new ErrorObjectImp(&globExec, funcProto, errorProto); 585 548 586 549 // Error object prototypes 587 b_evalErrorPrototype = Object(new NativeErrorPrototypeImp(&globExec, errorProto, EvalError, 588 "EvalError", "EvalError")); 589 b_rangeErrorPrototype = Object(new NativeErrorPrototypeImp(&globExec, errorProto, RangeError, 590 "RangeError", "RangeError")); 591 b_referenceErrorPrototype = Object(new NativeErrorPrototypeImp(&globExec, errorProto, ReferenceError, 592 "ReferenceError", "ReferenceError")); 593 b_syntaxErrorPrototype = Object(new NativeErrorPrototypeImp(&globExec, errorProto, SyntaxError, 594 "SyntaxError", "SyntaxError")); 595 b_typeErrorPrototype = Object(new NativeErrorPrototypeImp(&globExec, errorProto, TypeError, 596 "TypeError", "TypeError")); 597 b_uriErrorPrototype = Object(new NativeErrorPrototypeImp(&globExec, errorProto, URIError, 598 "URIError", "URIError")); 550 b_evalErrorPrototype = new NativeErrorPrototypeImp(&globExec, errorProto, EvalError, "EvalError", "EvalError"); 551 b_rangeErrorPrototype = new NativeErrorPrototypeImp(&globExec, errorProto, RangeError, "RangeError", "RangeError"); 552 b_referenceErrorPrototype = new NativeErrorPrototypeImp(&globExec, errorProto, ReferenceError, "ReferenceError", "ReferenceError"); 553 b_syntaxErrorPrototype = new NativeErrorPrototypeImp(&globExec, errorProto, SyntaxError, "SyntaxError", "SyntaxError"); 554 b_typeErrorPrototype = new NativeErrorPrototypeImp(&globExec, errorProto, TypeError, "TypeError", "TypeError"); 555 b_uriErrorPrototype = new NativeErrorPrototypeImp(&globExec, errorProto, URIError, "URIError", "URIError"); 599 556 600 557 // Error objects 601 b_evalError = Object(new NativeErrorImp(&globExec, funcProto, b_evalErrorPrototype));602 b_rangeError = Object(new NativeErrorImp(&globExec, funcProto, b_rangeErrorPrototype));603 b_referenceError = Object(new NativeErrorImp(&globExec, funcProto, b_referenceErrorPrototype));604 b_syntaxError = Object(new NativeErrorImp(&globExec, funcProto, b_syntaxErrorPrototype));605 b_typeError = Object(new NativeErrorImp(&globExec, funcProto, b_typeErrorPrototype));606 b_uriError = Object(new NativeErrorImp(&globExec, funcProto, b_uriErrorPrototype));558 b_evalError = new NativeErrorImp(&globExec, funcProto, b_evalErrorPrototype); 559 b_rangeError = new NativeErrorImp(&globExec, funcProto, b_rangeErrorPrototype); 560 b_referenceError = new NativeErrorImp(&globExec, funcProto, b_referenceErrorPrototype); 561 b_syntaxError = new NativeErrorImp(&globExec, funcProto, b_syntaxErrorPrototype); 562 b_typeError = new NativeErrorImp(&globExec, funcProto, b_typeErrorPrototype); 563 b_uriError = new NativeErrorImp(&globExec, funcProto, b_uriErrorPrototype); 607 564 608 565 // ECMA 15.3.4.1 609 566 funcProto->put(&globExec, "constructor", b_Function, DontEnum); 610 567 611 global .put(&globExec, "Object", b_Object, DontEnum);612 global .put(&globExec, "Function", b_Function, DontEnum);613 global .put(&globExec, "Array", b_Array, DontEnum);614 global .put(&globExec, "Boolean", b_Boolean, DontEnum);615 global .put(&globExec, "String", b_String, DontEnum);616 global .put(&globExec, "Number", b_Number, DontEnum);617 global .put(&globExec, "Date", b_Date, DontEnum);618 global .put(&globExec, "RegExp", b_RegExp, DontEnum);619 global .put(&globExec, "Error", b_Error, DontEnum);568 global->put(&globExec, "Object", b_Object, DontEnum); 569 global->put(&globExec, "Function", b_Function, DontEnum); 570 global->put(&globExec, "Array", b_Array, DontEnum); 571 global->put(&globExec, "Boolean", b_Boolean, DontEnum); 572 global->put(&globExec, "String", b_String, DontEnum); 573 global->put(&globExec, "Number", b_Number, DontEnum); 574 global->put(&globExec, "Date", b_Date, DontEnum); 575 global->put(&globExec, "RegExp", b_RegExp, DontEnum); 576 global->put(&globExec, "Error", b_Error, DontEnum); 620 577 // Using Internal for those to have something != 0 621 578 // (see kjs_window). Maybe DontEnum would be ok too ? 622 global .put(&globExec, "EvalError",b_evalError, Internal);623 global .put(&globExec, "RangeError",b_rangeError, Internal);624 global .put(&globExec, "ReferenceError",b_referenceError, Internal);625 global .put(&globExec, "SyntaxError",b_syntaxError, Internal);626 global .put(&globExec, "TypeError",b_typeError, Internal);627 global .put(&globExec, "URIError",b_uriError, Internal);579 global->put(&globExec, "EvalError",b_evalError, Internal); 580 global->put(&globExec, "RangeError",b_rangeError, Internal); 581 global->put(&globExec, "ReferenceError",b_referenceError, Internal); 582 global->put(&globExec, "SyntaxError",b_syntaxError, Internal); 583 global->put(&globExec, "TypeError",b_typeError, Internal); 584 global->put(&globExec, "URIError",b_uriError, Internal); 628 585 629 586 // Set the "constructor" property of all builtin constructors … … 637 594 regexpProto->put(&globExec, "constructor", b_RegExp, DontEnum | DontDelete | ReadOnly); 638 595 errorProto->put(&globExec, "constructor", b_Error, DontEnum | DontDelete | ReadOnly); 639 b_evalErrorPrototype .put(&globExec, "constructor", b_evalError, DontEnum | DontDelete | ReadOnly);640 b_rangeErrorPrototype .put(&globExec, "constructor", b_rangeError, DontEnum | DontDelete | ReadOnly);641 b_referenceErrorPrototype .put(&globExec, "constructor", b_referenceError, DontEnum | DontDelete | ReadOnly);642 b_syntaxErrorPrototype .put(&globExec, "constructor", b_syntaxError, DontEnum | DontDelete | ReadOnly);643 b_typeErrorPrototype .put(&globExec, "constructor", b_typeError, DontEnum | DontDelete | ReadOnly);644 b_uriErrorPrototype .put(&globExec, "constructor", b_uriError, DontEnum | DontDelete | ReadOnly);596 b_evalErrorPrototype->put(&globExec, "constructor", b_evalError, DontEnum | DontDelete | ReadOnly); 597 b_rangeErrorPrototype->put(&globExec, "constructor", b_rangeError, DontEnum | DontDelete | ReadOnly); 598 b_referenceErrorPrototype->put(&globExec, "constructor", b_referenceError, DontEnum | DontDelete | ReadOnly); 599 b_syntaxErrorPrototype->put(&globExec, "constructor", b_syntaxError, DontEnum | DontDelete | ReadOnly); 600 b_typeErrorPrototype->put(&globExec, "constructor", b_typeError, DontEnum | DontDelete | ReadOnly); 601 b_uriErrorPrototype->put(&globExec, "constructor", b_uriError, DontEnum | DontDelete | ReadOnly); 645 602 646 603 // built-in values 647 global .put(&globExec, "NaN", Number(NaN), DontEnum|DontDelete);648 global .put(&globExec, "Infinity", Number(Inf), DontEnum|DontDelete);649 global .put(&globExec, "undefined", Undefined(), DontEnum|DontDelete);604 global->put(&globExec, "NaN", jsNaN(), DontEnum|DontDelete); 605 global->put(&globExec, "Infinity", Number(Inf), DontEnum|DontDelete); 606 global->put(&globExec, "undefined", Undefined(), DontEnum|DontDelete); 650 607 651 608 // built-in functions 652 global .put(&globExec, "eval", Object(new GlobalFuncImp(&globExec, funcProto, GlobalFuncImp::Eval, 1)), DontEnum);653 global .put(&globExec, "parseInt", Object(new GlobalFuncImp(&globExec, funcProto, GlobalFuncImp::ParseInt, 2)), DontEnum);654 global .put(&globExec, "parseFloat", Object(new GlobalFuncImp(&globExec, funcProto, GlobalFuncImp::ParseFloat, 1)), DontEnum);655 global .put(&globExec, "isNaN", Object(new GlobalFuncImp(&globExec, funcProto, GlobalFuncImp::IsNaN, 1)), DontEnum);656 global .put(&globExec, "isFinite", Object(new GlobalFuncImp(&globExec, funcProto, GlobalFuncImp::IsFinite, 1)), DontEnum);657 global .put(&globExec, "escape", Object(new GlobalFuncImp(&globExec, funcProto, GlobalFuncImp::Escape, 1)), DontEnum);658 global .put(&globExec, "unescape", Object(new GlobalFuncImp(&globExec, funcProto, GlobalFuncImp::UnEscape, 1)), DontEnum);659 global .put(&globExec, "decodeURI", Object(new GlobalFuncImp(&globExec, funcProto, GlobalFuncImp::DecodeURI, 1)), DontEnum);660 global .put(&globExec, "decodeURIComponent", Object(new GlobalFuncImp(&globExec, funcProto, GlobalFuncImp::DecodeURIComponent, 1)), DontEnum);661 global .put(&globExec, "encodeURI", Object(new GlobalFuncImp(&globExec, funcProto, GlobalFuncImp::EncodeURI, 1)), DontEnum);662 global .put(&globExec, "encodeURIComponent", Object(new GlobalFuncImp(&globExec, funcProto, GlobalFuncImp::EncodeURIComponent, 1)), DontEnum);609 global->put(&globExec, "eval", new GlobalFuncImp(&globExec, funcProto, GlobalFuncImp::Eval, 1), DontEnum); 610 global->put(&globExec, "parseInt", new GlobalFuncImp(&globExec, funcProto, GlobalFuncImp::ParseInt, 2), DontEnum); 611 global->put(&globExec, "parseFloat", new GlobalFuncImp(&globExec, funcProto, GlobalFuncImp::ParseFloat, 1), DontEnum); 612 global->put(&globExec, "isNaN", new GlobalFuncImp(&globExec, funcProto, GlobalFuncImp::IsNaN, 1), DontEnum); 613 global->put(&globExec, "isFinite", new GlobalFuncImp(&globExec, funcProto, GlobalFuncImp::IsFinite, 1), DontEnum); 614 global->put(&globExec, "escape", new GlobalFuncImp(&globExec, funcProto, GlobalFuncImp::Escape, 1), DontEnum); 615 global->put(&globExec, "unescape", new GlobalFuncImp(&globExec, funcProto, GlobalFuncImp::UnEscape, 1), DontEnum); 616 global->put(&globExec, "decodeURI", new GlobalFuncImp(&globExec, funcProto, GlobalFuncImp::DecodeURI, 1), DontEnum); 617 global->put(&globExec, "decodeURIComponent", new GlobalFuncImp(&globExec, funcProto, GlobalFuncImp::DecodeURIComponent, 1), DontEnum); 618 global->put(&globExec, "encodeURI", new GlobalFuncImp(&globExec, funcProto, GlobalFuncImp::EncodeURI, 1), DontEnum); 619 global->put(&globExec, "encodeURIComponent", new GlobalFuncImp(&globExec, funcProto, GlobalFuncImp::EncodeURIComponent, 1), DontEnum); 663 620 #ifndef NDEBUG 664 global .put(&globExec, "kjsprint", Object(new GlobalFuncImp(&globExec, funcProto, GlobalFuncImp::KJSPrint, 1)), DontEnum);621 global->put(&globExec, "kjsprint", new GlobalFuncImp(&globExec, funcProto, GlobalFuncImp::KJSPrint, 1), DontEnum); 665 622 #endif 666 623 667 624 // built-in objects 668 global .put(&globExec, "Math", Object(new MathObjectImp(&globExec, objProto)), DontEnum);625 global->put(&globExec, "Math", new MathObjectImp(&globExec, objProto), DontEnum); 669 626 } 670 627 … … 692 649 globalClear(); 693 650 } 694 InterpreterMap::removeInterpreterForGlobalObject(global .imp());651 InterpreterMap::removeInterpreterForGlobalObject(global); 695 652 696 653 #if APPLE_CHANGES … … 701 658 void InterpreterImp::mark() 702 659 { 703 //if (exVal && !exVal->marked()) 704 // exVal->mark(); 705 //if (retVal && !retVal->marked()) 706 // retVal->mark(); 707 if (UndefinedImp::staticUndefined && !UndefinedImp::staticUndefined->marked()) 708 UndefinedImp::staticUndefined->mark(); 709 if (NullImp::staticNull && !NullImp::staticNull->marked()) 710 NullImp::staticNull->mark(); 711 if (NumberImp::staticNaN && !NumberImp::staticNaN->marked()) 712 NumberImp::staticNaN->mark(); 713 if (BooleanImp::staticTrue && !BooleanImp::staticTrue->marked()) 714 BooleanImp::staticTrue->mark(); 715 if (BooleanImp::staticFalse && !BooleanImp::staticFalse->marked()) 716 BooleanImp::staticFalse->mark(); 717 //fprintf( stderr, "InterpreterImp::mark this=%p global.imp()=%p\n", this, global.imp() ); 660 ConstantValues::mark(); 718 661 if (m_interpreter) 719 662 m_interpreter->mark(); … … 736 679 } 737 680 738 Completion InterpreterImp::evaluate(const UString &code, const Value &thisV, const UString &sourceURL, int startingLineNumber)681 Completion InterpreterImp::evaluate(const UString &code, ValueImp *thisV, const UString &sourceURL, int startingLineNumber) 739 682 { 740 683 #if APPLE_CHANGES … … 774 717 // no program node means a syntax error occurred 775 718 if (!progNode) { 776 Object 777 err .put(&globExec, "sid", Number(sid));719 ObjectImp *err = Error::create(&globExec, SyntaxError, errMsg.ascii(), errLine, -1, &sourceURL); 720 err->put(&globExec, "sid", Number(sid)); 778 721 #if APPLE_CHANGES 779 722 unlockInterpreter(); … … 787 730 progNode->ref(); 788 731 789 Object &globalObj = globalObject();790 Object 791 792 if ( !thisV.isNull()) {732 ObjectImp *globalObj = globalObject(); 733 ObjectImp *thisObj = globalObject(); 734 735 if (thisV) { 793 736 // "this" must be an object... use same rules as Function.prototype.apply() 794 if (thisV .isA(NullType) || thisV.isA(UndefinedType))737 if (thisV->isUndefinedOrNull()) 795 738 thisObj = globalObject(); 796 739 else { 797 thisObj = thisV .toObject(&globExec);740 thisObj = thisV->toObject(&globExec); 798 741 } 799 742 } … … 801 744 Completion res; 802 745 if (globExec.hadException()) { 803 // the thisArg .toObject() conversion above might have thrown an exception - if so,746 // the thisArg->toObject() conversion above might have thrown an exception - if so, 804 747 // propagate it back 805 748 res = Completion(Throw, globExec.exception()); … … 925 868 } 926 869 927 Boolean InternalFunctionImp::hasInstance(ExecState *exec, const Value &value)928 { 929 if ( value.type() != ObjectType)930 return Boolean(false);931 932 Value 933 if ( prot.type() != ObjectType && prot.type() != NullType) {934 Object 870 bool InternalFunctionImp::hasInstance(ExecState *exec, ValueImp *value) 871 { 872 if (!value->isObject()) 873 return false; 874 875 ValueImp *prot = get(exec,prototypePropertyName); 876 if (!prot->isObject() && !prot->isNull()) { 877 ObjectImp *err = Error::create(exec, TypeError, "Invalid prototype encountered " 935 878 "in instanceof operation."); 936 879 exec->setException(err); 937 return Boolean(false);938 } 939 940 Object v = Object(static_cast<ObjectImp*>(value.imp()));941 while ((v = Object::dynamicCast(v.prototype())).imp()) {942 if (v .imp() == prot.imp())943 return Boolean(true);944 } 945 return Boolean(false);880 return false; 881 } 882 883 ObjectImp *v = static_cast<ObjectImp *>(value); 884 while ((v = v->prototype()->getObject())) { 885 if (v == prot) 886 return true; 887 } 888 return false; 946 889 } 947 890 948 891 // ------------------------------ global functions ----------------------------- 949 892 950 double KJS::roundValue(ExecState *exec, const Value &v) 951 { 952 Number n = v.toNumber(exec); 953 double d = n.value(); 893 double roundValue(ExecState *exec, ValueImp *v) 894 { 895 double d = v->toNumber(exec); 954 896 double ad = fabs(d); 955 897 if (ad == 0 || isNaN(d) || isInf(d)) … … 960 902 #ifndef NDEBUG 961 903 #include <stdio.h> 962 void KJS::printInfo(ExecState *exec, const char *s, const Value &o, int lineno)963 { 964 if ( o.isNull())904 void printInfo(ExecState *exec, const char *s, ValueImp *o, int lineno) 905 { 906 if (!o) 965 907 fprintf(stderr, "KJS: %s: (null)", s); 966 908 else { 967 Value 909 ValueImp *v = o; 968 910 969 911 UString name; 970 switch ( v.type()) {912 switch (v->type()) { 971 913 case UnspecifiedType: 972 914 name = "Unspecified"; … … 988 930 break; 989 931 case ObjectType: 990 name = Object::dynamicCast(v).className();932 name = static_cast<ObjectImp *>(v)->className(); 991 933 if (name.isNull()) 992 934 name = "(unknown class)"; 993 935 break; 994 936 } 995 UString vString = v .toString(exec);937 UString vString = v->toString(exec); 996 938 if ( vString.size() > 50 ) 997 939 vString = vString.substr( 0, 50 ) + "..."; … … 1000 942 1001 943 fprintf(stderr, "KJS: %s: %s : %s (%p)", 1002 s, tempString.c_str(), name.ascii(), (void*)v .imp());944 s, tempString.c_str(), name.ascii(), (void*)v); 1003 945 1004 946 if (lineno >= 0) … … 1009 951 } 1010 952 #endif 953 954 } -
trunk/JavaScriptCore/kjs/internal.h
r10076 r10084 23 23 */ 24 24 25 #ifndef _INTERNAL_H_26 #define _INTERNAL_H_25 #ifndef INTERNAL_H 26 #define INTERNAL_H 27 27 28 28 #include "ustring.h" … … 38 38 namespace KJS { 39 39 40 static const double D16 = 65536.0;41 static const double D32 = 4294967296.0;42 43 40 class ProgramNode; 44 41 class FunctionBodyNode; … … 51 48 // --------------------------------------------------------------------------- 52 49 53 class UndefinedImp : public ValueImp {50 class UndefinedImp : public AllocatedValueImp { 54 51 public: 55 52 Type type() const { return UndefinedType; } 56 53 57 Value 54 ValueImp *toPrimitive(ExecState *exec, Type preferred = UnspecifiedType) const; 58 55 bool toBoolean(ExecState *exec) const; 59 56 double toNumber(ExecState *exec) const; 60 57 UString toString(ExecState *exec) const; 61 Object toObject(ExecState *exec) const; 62 63 static UndefinedImp *staticUndefined; 64 }; 65 66 inline Undefined::Undefined(UndefinedImp *imp) : Value(imp) { } 67 68 class NullImp : public ValueImp { 58 ObjectImp *toObject(ExecState *exec) const; 59 }; 60 61 class NullImp : public AllocatedValueImp { 69 62 public: 70 63 Type type() const { return NullType; } 71 64 72 Value 65 ValueImp *toPrimitive(ExecState *exec, Type preferred = UnspecifiedType) const; 73 66 bool toBoolean(ExecState *exec) const; 74 67 double toNumber(ExecState *exec) const; 75 68 UString toString(ExecState *exec) const; 76 Object toObject(ExecState *exec) const; 77 78 static NullImp *staticNull; 79 }; 80 81 inline Null::Null(NullImp *imp) : Value(imp) { } 82 83 class BooleanImp : public ValueImp { 69 ObjectImp *toObject(ExecState *exec) const; 70 }; 71 72 class BooleanImp : public AllocatedValueImp { 84 73 public: 85 74 BooleanImp(bool v = false) : val(v) { } … … 88 77 Type type() const { return BooleanType; } 89 78 90 Value 79 ValueImp *toPrimitive(ExecState *exec, Type preferred = UnspecifiedType) const; 91 80 bool toBoolean(ExecState *exec) const; 92 81 double toNumber(ExecState *exec) const; 93 82 UString toString(ExecState *exec) const; 94 Object toObject(ExecState *exec) const; 95 96 static BooleanImp *staticTrue; 97 static BooleanImp *staticFalse; 83 ObjectImp *toObject(ExecState *exec) const; 84 98 85 private: 99 86 bool val; 100 87 }; 101 88 102 inline Boolean::Boolean(BooleanImp *imp) : Value(imp) { } 103 104 class StringImp : public ValueImp { 89 class StringImp : public AllocatedValueImp { 105 90 public: 106 91 StringImp(const UString& v) : val(v) { } … … 109 94 Type type() const { return StringType; } 110 95 111 Value 96 ValueImp *toPrimitive(ExecState *exec, Type preferred = UnspecifiedType) const; 112 97 bool toBoolean(ExecState *exec) const; 113 98 double toNumber(ExecState *exec) const; 114 99 UString toString(ExecState *exec) const; 115 Object 100 ObjectImp *toObject(ExecState *exec) const; 116 101 117 102 private: … … 119 104 }; 120 105 121 inline String::String(StringImp *imp) : Value(imp) { } 122 123 class NumberImp : public ValueImp { 124 friend class Value; 125 friend class Number; 106 class NumberImp : public AllocatedValueImp { 107 friend class ConstantValues; 126 108 friend class InterpreterImp; 127 friend ValueImp *number(int); 128 friend ValueImp *number(unsigned); 129 friend ValueImp *number(long); 130 friend ValueImp *number(unsigned long); 131 friend ValueImp *number(double); 132 friend ValueImp *number(double, bool); 133 public: 134 static ValueImp *create(int); 135 static ValueImp *create(double); 136 static ValueImp *zero() { return SimpleNumber::make(0); } 137 static ValueImp *one() { return SimpleNumber::make(1); } 138 static ValueImp *two() { return SimpleNumber::make(2); } 139 109 friend ValueImp *jsNumber(int); 110 friend ValueImp *jsNumber(unsigned); 111 friend ValueImp *jsNumber(long); 112 friend ValueImp *jsNumber(unsigned long); 113 friend ValueImp *jsNumber(double); 114 friend ValueImp *jsNumber(double, bool); 115 public: 140 116 double value() const { return val; } 141 117 142 118 Type type() const { return NumberType; } 143 119 144 Value 120 ValueImp *toPrimitive(ExecState *exec, Type preferred = UnspecifiedType) const; 145 121 bool toBoolean(ExecState *exec) const; 146 122 double toNumber(ExecState *exec) const; 147 123 UString toString(ExecState *exec) const; 148 Object toObject(ExecState *exec) const; 149 150 static NumberImp *staticNaN; 124 ObjectImp *toObject(ExecState *exec) const; 151 125 152 126 private: 153 127 NumberImp(double v) : val(v) { } 154 128 155 virtual bool toUInt32(unsigned&) const;129 virtual bool getUInt32(uint32_t&) const; 156 130 157 131 double val; 158 132 }; 159 160 inline Number::Number(NumberImp *imp) : Value(imp) { }161 133 162 134 /** … … 207 179 208 180 // --------------------------------------------------------------------------- 209 // Parsing & evaluat eion181 // Parsing & evaluation 210 182 // --------------------------------------------------------------------------- 211 183 … … 276 248 static void globalClear(); 277 249 278 InterpreterImp(Interpreter *interp, const Object &glob);250 InterpreterImp(Interpreter *interp, ObjectImp *glob); 279 251 ~InterpreterImp(); 280 252 … … 291 263 ExecState *globalExec() { return &globExec; } 292 264 bool checkSyntax(const UString &code); 293 Completion evaluate(const UString &code, const Value &thisV, const UString &sourceURL, int startingLineNumber);265 Completion evaluate(const UString &code, ValueImp *thisV, const UString &sourceURL, int startingLineNumber); 294 266 Debugger *debugger() const { return dbg; } 295 267 void setDebugger(Debugger *d) { dbg = d; } 296 268 297 Object 298 Object 299 Object 300 Object 301 Object 302 Object 303 Object 304 Object 305 Object 306 307 Object 308 Object 309 Object 310 Object 311 Object 312 Object 313 Object 314 Object 315 Object 316 317 Object 318 Object 319 Object 320 Object 321 Object 322 Object 323 324 Object 325 Object 326 Object 327 Object 328 Object 329 Object 269 ObjectImp *builtinObject() const { return b_Object; } 270 ObjectImp *builtinFunction() const { return b_Function; } 271 ObjectImp *builtinArray() const { return b_Array; } 272 ObjectImp *builtinBoolean() const { return b_Boolean; } 273 ObjectImp *builtinString() const { return b_String; } 274 ObjectImp *builtinNumber() const { return b_Number; } 275 ObjectImp *builtinDate() const { return b_Date; } 276 ObjectImp *builtinRegExp() const { return b_RegExp; } 277 ObjectImp *builtinError() const { return b_Error; } 278 279 ObjectImp *builtinObjectPrototype() const { return b_ObjectPrototype; } 280 ObjectImp *builtinFunctionPrototype() const { return b_FunctionPrototype; } 281 ObjectImp *builtinArrayPrototype() const { return b_ArrayPrototype; } 282 ObjectImp *builtinBooleanPrototype() const { return b_BooleanPrototype; } 283 ObjectImp *builtinStringPrototype() const { return b_StringPrototype; } 284 ObjectImp *builtinNumberPrototype() const { return b_NumberPrototype; } 285 ObjectImp *builtinDatePrototype() const { return b_DatePrototype; } 286 ObjectImp *builtinRegExpPrototype() const { return b_RegExpPrototype; } 287 ObjectImp *builtinErrorPrototype() const { return b_ErrorPrototype; } 288 289 ObjectImp *builtinEvalError() const { return b_evalError; } 290 ObjectImp *builtinRangeError() const { return b_rangeError; } 291 ObjectImp *builtinReferenceError() const { return b_referenceError; } 292 ObjectImp *builtinSyntaxError() const { return b_syntaxError; } 293 ObjectImp *builtinTypeError() const { return b_typeError; } 294 ObjectImp *builtinURIError() const { return b_uriError; } 295 296 ObjectImp *builtinEvalErrorPrototype() const { return b_evalErrorPrototype; } 297 ObjectImp *builtinRangeErrorPrototype() const { return b_rangeErrorPrototype; } 298 ObjectImp *builtinReferenceErrorPrototype() const { return b_referenceErrorPrototype; } 299 ObjectImp *builtinSyntaxErrorPrototype() const { return b_syntaxErrorPrototype; } 300 ObjectImp *builtinTypeErrorPrototype() const { return b_typeErrorPrototype; } 301 ObjectImp *builtinURIErrorPrototype() const { return b_uriErrorPrototype; } 330 302 331 303 void setCompatMode(Interpreter::CompatMode mode) { m_compatMode = mode; } … … 423 395 InternalFunctionImp(FunctionPrototypeImp *funcProto); 424 396 bool implementsHasInstance() const; 425 Boolean hasInstance(ExecState *exec, const Value &value);397 bool hasInstance(ExecState *exec, ValueImp *value); 426 398 427 399 virtual const ClassInfo *classInfo() const { return &info; } … … 430 402 431 403 // helper function for toInteger, toInt32, toUInt32 and toUInt16 432 double roundValue(ExecState * exec, const Value &v);404 double roundValue(ExecState *, ValueImp *); 433 405 434 406 #ifndef NDEBUG 435 void printInfo(ExecState *exec, const char *s, const Value &o, int lineno = -1);407 void printInfo(ExecState *exec, const char *s, ValueImp *, int lineno = -1); 436 408 #endif 437 409 438 410 } // namespace 439 411 440 441 #endif // _INTERNAL_H_ 412 #endif // INTERNAL_H -
trunk/JavaScriptCore/kjs/interpreter.cpp
r10076 r10084 51 51 } 52 52 53 Object 53 ObjectImp *Context::variableObject() const 54 54 { 55 55 return rep->variableObject(); 56 56 } 57 57 58 Object 58 ObjectImp *Context::thisValue() const 59 59 { 60 60 return rep->thisValue(); … … 68 68 // ------------------------------ Interpreter ---------------------------------- 69 69 70 Interpreter::Interpreter( const Object &global)70 Interpreter::Interpreter(ObjectImp *global) 71 71 : rep(0) 72 72 , m_argumentsPropertyName(&argumentsPropertyName) 73 73 , m_specialPrototypePropertyName(&specialPrototypePropertyName) 74 74 { 75 rep = new InterpreterImp(this, global);75 rep = new InterpreterImp(this, global); 76 76 } 77 77 … … 81 81 , m_specialPrototypePropertyName(&specialPrototypePropertyName) 82 82 { 83 Object global(new ObjectImp()); 84 rep = new InterpreterImp(this,global); 83 rep = new InterpreterImp(this, new ObjectImp); 85 84 } 86 85 … … 90 89 } 91 90 92 Object &Interpreter::globalObject() const91 ObjectImp *Interpreter::globalObject() const 93 92 { 94 93 return rep->globalObject(); … … 125 124 } 126 125 127 Completion Interpreter::evaluate(const UString &code, const Value &thisV, const UString &)126 Completion Interpreter::evaluate(const UString &code, ValueImp *thisV, const UString &) 128 127 { 129 128 return evaluate(UString(), 0, code, thisV); 130 129 } 131 130 132 Completion Interpreter::evaluate(const UString &sourceURL, int startingLineNumber, const UString &code, const Value &thisV)131 Completion Interpreter::evaluate(const UString &sourceURL, int startingLineNumber, const UString &code, ValueImp *thisV) 133 132 { 134 133 Completion comp = rep->evaluate(code,thisV, sourceURL, startingLineNumber); … … 139 138 ExecState *exec = rep->globalExec(); 140 139 char *f = strdup(sourceURL.ascii()); 141 const char *message = comp.value() .toObject(exec).toString(exec).ascii();140 const char *message = comp.value()->toObject(exec)->toString(exec).ascii(); 142 141 printf("[%d] %s:%s\n", getpid(), f, message); 143 142 … … 150 149 } 151 150 152 Object 151 ObjectImp *Interpreter::builtinObject() const 153 152 { 154 153 return rep->builtinObject(); 155 154 } 156 155 157 Object 156 ObjectImp *Interpreter::builtinFunction() const 158 157 { 159 158 return rep->builtinFunction(); 160 159 } 161 160 162 Object 161 ObjectImp *Interpreter::builtinArray() const 163 162 { 164 163 return rep->builtinArray(); 165 164 } 166 165 167 Object 166 ObjectImp *Interpreter::builtinBoolean() const 168 167 { 169 168 return rep->builtinBoolean(); 170 169 } 171 170 172 Object 171 ObjectImp *Interpreter::builtinString() const 173 172 { 174 173 return rep->builtinString(); 175 174 } 176 175 177 Object 176 ObjectImp *Interpreter::builtinNumber() const 178 177 { 179 178 return rep->builtinNumber(); 180 179 } 181 180 182 Object 181 ObjectImp *Interpreter::builtinDate() const 183 182 { 184 183 return rep->builtinDate(); 185 184 } 186 185 187 Object 186 ObjectImp *Interpreter::builtinRegExp() const 188 187 { 189 188 return rep->builtinRegExp(); 190 189 } 191 190 192 Object 191 ObjectImp *Interpreter::builtinError() const 193 192 { 194 193 return rep->builtinError(); 195 194 } 196 195 197 Object 196 ObjectImp *Interpreter::builtinObjectPrototype() const 198 197 { 199 198 return rep->builtinObjectPrototype(); 200 199 } 201 200 202 Object 201 ObjectImp *Interpreter::builtinFunctionPrototype() const 203 202 { 204 203 return rep->builtinFunctionPrototype(); 205 204 } 206 205 207 Object 206 ObjectImp *Interpreter::builtinArrayPrototype() const 208 207 { 209 208 return rep->builtinArrayPrototype(); 210 209 } 211 210 212 Object 211 ObjectImp *Interpreter::builtinBooleanPrototype() const 213 212 { 214 213 return rep->builtinBooleanPrototype(); 215 214 } 216 215 217 Object 216 ObjectImp *Interpreter::builtinStringPrototype() const 218 217 { 219 218 return rep->builtinStringPrototype(); 220 219 } 221 220 222 Object 221 ObjectImp *Interpreter::builtinNumberPrototype() const 223 222 { 224 223 return rep->builtinNumberPrototype(); 225 224 } 226 225 227 Object 226 ObjectImp *Interpreter::builtinDatePrototype() const 228 227 { 229 228 return rep->builtinDatePrototype(); 230 229 } 231 230 232 Object 231 ObjectImp *Interpreter::builtinRegExpPrototype() const 233 232 { 234 233 return rep->builtinRegExpPrototype(); 235 234 } 236 235 237 Object 236 ObjectImp *Interpreter::builtinErrorPrototype() const 238 237 { 239 238 return rep->builtinErrorPrototype(); 240 239 } 241 240 242 Object 241 ObjectImp *Interpreter::builtinEvalError() const 243 242 { 244 243 return rep->builtinEvalError(); 245 244 } 246 245 247 Object 246 ObjectImp *Interpreter::builtinRangeError() const 248 247 { 249 248 return rep->builtinRangeError(); 250 249 } 251 250 252 Object 251 ObjectImp *Interpreter::builtinReferenceError() const 253 252 { 254 253 return rep->builtinReferenceError(); 255 254 } 256 255 257 Object 256 ObjectImp *Interpreter::builtinSyntaxError() const 258 257 { 259 258 return rep->builtinSyntaxError(); 260 259 } 261 260 262 Object 261 ObjectImp *Interpreter::builtinTypeError() const 263 262 { 264 263 return rep->builtinTypeError(); 265 264 } 266 265 267 Object 266 ObjectImp *Interpreter::builtinURIError() const 268 267 { 269 268 return rep->builtinURIError(); 270 269 } 271 270 272 Object 271 ObjectImp *Interpreter::builtinEvalErrorPrototype() const 273 272 { 274 273 return rep->builtinEvalErrorPrototype(); 275 274 } 276 275 277 Object 276 ObjectImp *Interpreter::builtinRangeErrorPrototype() const 278 277 { 279 278 return rep->builtinRangeErrorPrototype(); 280 279 } 281 280 282 Object 281 ObjectImp *Interpreter::builtinReferenceErrorPrototype() const 283 282 { 284 283 return rep->builtinReferenceErrorPrototype(); 285 284 } 286 285 287 Object 286 ObjectImp *Interpreter::builtinSyntaxErrorPrototype() const 288 287 { 289 288 return rep->builtinSyntaxErrorPrototype(); 290 289 } 291 290 292 Object 291 ObjectImp *Interpreter::builtinTypeErrorPrototype() const 293 292 { 294 293 return rep->builtinTypeErrorPrototype(); 295 294 } 296 295 297 Object 296 ObjectImp *Interpreter::builtinURIErrorPrototype() const 298 297 { 299 298 return rep->builtinURIErrorPrototype(); … … 338 337 339 338 340 void *Interpreter::createLanguageInstanceForValue (ExecState *exec, int language, const Object &value, const Bindings::RootObject *origin, const Bindings::RootObject *current)339 void *Interpreter::createLanguageInstanceForValue(ExecState *exec, int language, ObjectImp *value, const Bindings::RootObject *origin, const Bindings::RootObject *current) 341 340 { 342 341 return Bindings::Instance::createLanguageInstanceForValue (exec, (Bindings::Instance::BindingLanguage)language, value, origin, current); -
trunk/JavaScriptCore/kjs/interpreter.h
r10076 r10084 26 26 #define _KJS_INTERPRETER_H_ 27 27 28 #include "object_wrapper.h"29 28 #include "value.h" 30 29 #include "types.h" … … 35 34 class InterpreterImp; 36 35 class RuntimeMethodImp; 36 class ScopeChain; 37 37 38 38 namespace Bindings { … … 79 79 * @return The execution context's variable object 80 80 */ 81 Object 81 ObjectImp *variableObject() const; 82 82 83 83 /** … … 96 96 * @return The execution context's "this" value 97 97 */ 98 Object 98 ObjectImp *thisValue() const; 99 99 100 100 /** … … 153 153 * @param global The object to use as the global object for this interpreter 154 154 */ 155 Interpreter( const Object &global);155 Interpreter(ObjectImp *global); 156 156 /** 157 157 * Creates a new interpreter. A global object will be created and … … 165 165 * execution performed by this interpreter 166 166 */ 167 Object &globalObject() const;167 ObjectImp *globalObject() const; 168 168 169 169 void initGlobalObject(); … … 209 209 * @return A completion object representing the result of the execution. 210 210 */ 211 Completion evaluate(const UString &sourceURL, int startingLineNumber, const UString &code, const Value &thisV = Value());211 Completion evaluate(const UString &sourceURL, int startingLineNumber, const UString &code, ValueImp *thisV = NULL); 212 212 213 213 // Overload of evaluate to keep JavaScriptGlue both source and binary compatible. 214 Completion evaluate(const UString &code, const Value &thisV = Value(), const UString &sourceFilename = UString());214 Completion evaluate(const UString &code, ValueImp *thisV = NULL, const UString &sourceFilename = UString()); 215 215 216 216 /** … … 230 230 * @return The builtin "Object" object 231 231 */ 232 Object 232 ObjectImp *builtinObject() const; 233 233 234 234 /** 235 235 * Returns the builtin "Function" object. 236 236 */ 237 Object 237 ObjectImp *builtinFunction() const; 238 238 239 239 /** 240 240 * Returns the builtin "Array" object. 241 241 */ 242 Object 242 ObjectImp *builtinArray() const; 243 243 244 244 /** 245 245 * Returns the builtin "Boolean" object. 246 246 */ 247 Object 247 ObjectImp *builtinBoolean() const; 248 248 249 249 /** 250 250 * Returns the builtin "String" object. 251 251 */ 252 Object 252 ObjectImp *builtinString() const; 253 253 254 254 /** 255 255 * Returns the builtin "Number" object. 256 256 */ 257 Object 257 ObjectImp *builtinNumber() const; 258 258 259 259 /** 260 260 * Returns the builtin "Date" object. 261 261 */ 262 Object 262 ObjectImp *builtinDate() const; 263 263 264 264 /** 265 265 * Returns the builtin "RegExp" object. 266 266 */ 267 Object 267 ObjectImp *builtinRegExp() const; 268 268 269 269 /** 270 270 * Returns the builtin "Error" object. 271 271 */ 272 Object 272 ObjectImp *builtinError() const; 273 273 274 274 /** 275 275 * Returns the builtin "Object.prototype" object. 276 276 */ 277 Object 277 ObjectImp *builtinObjectPrototype() const; 278 278 279 279 /** 280 280 * Returns the builtin "Function.prototype" object. 281 281 */ 282 Object 282 ObjectImp *builtinFunctionPrototype() const; 283 283 284 284 /** 285 285 * Returns the builtin "Array.prototype" object. 286 286 */ 287 Object 287 ObjectImp *builtinArrayPrototype() const; 288 288 289 289 /** 290 290 * Returns the builtin "Boolean.prototype" object. 291 291 */ 292 Object 292 ObjectImp *builtinBooleanPrototype() const; 293 293 294 294 /** 295 295 * Returns the builtin "String.prototype" object. 296 296 */ 297 Object 297 ObjectImp *builtinStringPrototype() const; 298 298 299 299 /** 300 300 * Returns the builtin "Number.prototype" object. 301 301 */ 302 Object 302 ObjectImp *builtinNumberPrototype() const; 303 303 304 304 /** 305 305 * Returns the builtin "Date.prototype" object. 306 306 */ 307 Object 307 ObjectImp *builtinDatePrototype() const; 308 308 309 309 /** 310 310 * Returns the builtin "RegExp.prototype" object. 311 311 */ 312 Object 312 ObjectImp *builtinRegExpPrototype() const; 313 313 314 314 /** 315 315 * Returns the builtin "Error.prototype" object. 316 316 */ 317 Object 317 ObjectImp *builtinErrorPrototype() const; 318 318 319 319 /** 320 320 * The initial value of "Error" global property 321 321 */ 322 Object 323 Object 324 Object 325 Object 326 Object 327 Object 328 329 Object 330 Object 331 Object 332 Object 333 Object 334 Object 322 ObjectImp *builtinEvalError() const; 323 ObjectImp *builtinRangeError() const; 324 ObjectImp *builtinReferenceError() const; 325 ObjectImp *builtinSyntaxError() const; 326 ObjectImp *builtinTypeError() const; 327 ObjectImp *builtinURIError() const; 328 329 ObjectImp *builtinEvalErrorPrototype() const; 330 ObjectImp *builtinRangeErrorPrototype() const; 331 ObjectImp *builtinReferenceErrorPrototype() const; 332 ObjectImp *builtinSyntaxErrorPrototype() const; 333 ObjectImp *builtinTypeErrorPrototype() const; 334 ObjectImp *builtinURIErrorPrototype() const; 335 335 336 336 enum CompatMode { NativeMode, IECompat, NetscapeCompat }; … … 381 381 * security checks. 382 382 */ 383 virtual bool isGlobalObject( const Value &v) { return false; }383 virtual bool isGlobalObject(ValueImp *v) { return false; } 384 384 385 385 /** … … 400 400 virtual bool isSafeScript (const Interpreter *target) { return true; } 401 401 402 virtual void *createLanguageInstanceForValue (ExecState *exec, int language, const Object &value, const Bindings::RootObject *origin, const Bindings::RootObject *current);402 virtual void *createLanguageInstanceForValue (ExecState *exec, int language, ObjectImp *value, const Bindings::RootObject *origin, const Bindings::RootObject *current); 403 403 #endif 404 404 … … 471 471 Context context() const { return _context; } 472 472 473 void setException( const Value &e) { _exception = e; }474 void clearException() { _exception = Value(); }475 Value 476 bool hadException() const { return !_exception.isNull(); }473 void setException(ValueImp *e) { _exception = e; } 474 void clearException() { _exception = NULL; } 475 ValueImp *exception() const { return _exception; } 476 bool hadException() const { return _exception; } 477 477 478 478 private: 479 479 ExecState(Interpreter *interp, ContextImp *con) 480 : _interpreter(interp), _context(con) { }480 : _interpreter(interp), _context(con), _exception(NULL) { } 481 481 Interpreter *_interpreter; 482 482 ContextImp *_context; 483 Value 483 ValueImp *_exception; 484 484 }; 485 485 -
trunk/JavaScriptCore/kjs/list.cpp
r9768 r10084 234 234 } 235 235 236 ValueImp *List:: impAt(int i) const236 ValueImp *List::at(int i) const 237 237 { 238 238 ListImp *imp = static_cast<ListImp *>(_impBase); 239 239 if ((unsigned)i >= (unsigned)imp->size) 240 return UndefinedImp::staticUndefined;240 return jsUndefined(); 241 241 if (i < inlineValuesSize) 242 242 return imp->values[i]; -
trunk/JavaScriptCore/kjs/list.h
r9768 r10084 63 63 * @param val Pointer to object. 64 64 */ 65 void append(const Value& val) { append(val.imp()); }66 65 void append(ValueImp *val); 67 66 /** … … 105 104 * index is out of range. 106 105 */ 107 Value at(int i) const { return Value(impAt(i)); }106 ValueImp *at(int i) const; 108 107 /** 109 108 * Equivalent to at. 110 109 */ 111 Value operator[](int i) const { return Value(impAt(i)); } 112 113 ValueImp *impAt(int i) const; 110 ValueImp *operator[](int i) const { return at(i); } 114 111 115 112 /** … … 147 144 * @return A pointer to the element the iterator operates on. 148 145 */ 149 ValueImp *operator->() const { return _list-> impAt(_i); }150 Value operator*() const { return Value(_list->impAt(_i)); }146 ValueImp *operator->() const { return _list->at(_i); } 147 ValueImp *operator*() const { return _list->at(_i); } 151 148 /** 152 149 * Prefix increment operator. 153 150 * @return The element after the increment. 154 151 */ 155 Value operator++() { return Value(_list->impAt(++_i)); }152 ValueImp *operator++() { return _list->at(++_i); } 156 153 /** 157 154 * Postfix increment operator. 158 155 */ 159 Value operator++(int) { return Value(_list->impAt(_i++)); }156 ValueImp *operator++(int) { return _list->at(_i++); } 160 157 /** 161 158 * Prefix decrement operator. 162 159 */ 163 Value operator--() { return Value(_list->impAt(--_i)); }160 ValueImp *operator--() { return _list->at(--_i); } 164 161 /** 165 162 * Postfix decrement operator. 166 163 */ 167 Value operator--(int) { return Value(_list->impAt(_i--)); }164 ValueImp *operator--(int) { return _list->at(_i--); } 168 165 /** 169 166 * Compare the iterator with another one. -
trunk/JavaScriptCore/kjs/lookup.h
r10076 r10084 128 128 */ 129 129 template <class FuncImp> 130 inline Value 130 inline ValueImp *staticFunctionGetter(ExecState *exec, const Identifier& propertyName, const PropertySlot& slot) 131 131 { 132 132 // Look for cached value in dynamic map of properties (in ObjectImp) … … 134 134 ValueImp *cachedVal = thisObj->getDirect(propertyName); 135 135 if (cachedVal) 136 return Value(cachedVal);136 return cachedVal; 137 137 138 138 const HashEntry *entry = slot.staticEntry(); 139 Value val = Value(new FuncImp(exec, entry->value, entry->params));140 thisObj->putDirect(propertyName, val .imp(), entry->attr);139 ValueImp *val = new FuncImp(exec, entry->value, entry->params); 140 thisObj->putDirect(propertyName, val, entry->attr); 141 141 return val; 142 142 } … … 147 147 */ 148 148 template <class ThisImp> 149 inline Value 149 inline ValueImp *staticValueGetter(ExecState *exec, const Identifier&, const PropertySlot& slot) 150 150 { 151 151 ThisImp *thisObj = static_cast<ThisImp *>(slot.slotBase()); … … 236 236 template <class ThisImp, class ParentImp> 237 237 inline void lookupPut(ExecState *exec, const Identifier &propertyName, 238 const Value&value, int attr,238 ValueImp *value, int attr, 239 239 const HashTable* table, ThisImp* thisObj) 240 240 { … … 265 265 inline ObjectImp *cacheGlobalObject(ExecState *exec, const Identifier &propertyName) 266 266 { 267 ObjectImp *globalObject = static_cast<ObjectImp *>(exec->lexicalInterpreter()->globalObject() .imp());267 ObjectImp *globalObject = static_cast<ObjectImp *>(exec->lexicalInterpreter()->globalObject()); 268 268 ValueImp *obj = globalObject->getDirect(propertyName); 269 269 if (obj) { … … 272 272 } 273 273 ObjectImp *newObject = new ClassCtor(exec); 274 globalObject->put(exec, propertyName, Value(newObject), Internal);274 globalObject->put(exec, propertyName, newObject, Internal); 275 275 return newObject; 276 276 } … … 298 298 static ObjectImp *self(ExecState *exec) \ 299 299 { \ 300 return cacheGlobalObject<ClassProto>( exec, "[[" ClassName ".prototype]]"); \300 return cacheGlobalObject<ClassProto>(exec, "[[" ClassName ".prototype]]"); \ 301 301 } \ 302 302 protected: \ … … 332 332 put(exec, lengthPropertyName, Number(len), DontDelete|ReadOnly|DontEnum); \ 333 333 } \ 334 /* Macro user needs to implement the call function. */ \335 virtual Value call(ExecState *exec, Object &thisObj, const List &args); \334 /* Macro user needs to implement the callAsFunction function. */ \ 335 virtual ValueImp *callAsFunction(ExecState *exec, ObjectImp *thisObj, const List &args); \ 336 336 private: \ 337 337 int id; \ -
trunk/JavaScriptCore/kjs/math_object.cpp
r10076 r10084 87 87 } 88 88 89 Value 89 ValueImp *MathObjectImp::getValueProperty(ExecState *, int token) const 90 90 { 91 91 double d = -42; // ;) … … 126 126 MathFuncImp::MathFuncImp(ExecState *exec, int i, int l) 127 127 : InternalFunctionImp( 128 static_cast<FunctionPrototypeImp*>(exec->lexicalInterpreter()->builtinFunctionPrototype() .imp())128 static_cast<FunctionPrototypeImp*>(exec->lexicalInterpreter()->builtinFunctionPrototype()) 129 129 ), id(i) 130 130 { 131 Value protect(this);132 131 putDirect(lengthPropertyName, l, DontDelete|ReadOnly|DontEnum); 133 132 } … … 138 137 } 139 138 140 Value MathFuncImp::call(ExecState *exec, Object &/*thisObj*/, const List &args)141 { 142 double arg = args[0] .toNumber(exec);143 double arg2 = args[1] .toNumber(exec);139 ValueImp *MathFuncImp::callAsFunction(ExecState *exec, ObjectImp */*thisObj*/, const List &args) 140 { 141 double arg = args[0]->toNumber(exec); 142 double arg2 = args[1]->toNumber(exec); 144 143 double result; 145 144 … … 179 178 result = -Inf; 180 179 for ( unsigned int k = 0 ; k < argsCount ; ++k ) { 181 double val = args[k] .toNumber(exec);180 double val = args[k]->toNumber(exec); 182 181 if ( isNaN( val ) ) 183 182 { … … 194 193 result = +Inf; 195 194 for ( unsigned int k = 0 ; k < argsCount ; ++k ) { 196 double val = args[k] .toNumber(exec);195 double val = args[k]->toNumber(exec); 197 196 if ( isNaN( val ) ) 198 197 { -
trunk/JavaScriptCore/kjs/math_object.h
r10076 r10084 33 33 ObjectPrototypeImp *objProto); 34 34 bool getOwnPropertySlot(ExecState *, const Identifier&, PropertySlot&); 35 Value 35 ValueImp *getValueProperty(ExecState *exec, int token) const; 36 36 virtual const ClassInfo *classInfo() const { return &info; } 37 37 static const ClassInfo info; … … 45 45 MathFuncImp(ExecState *exec, int i, int l); 46 46 virtual bool implementsCall() const; 47 virtual Value call(ExecState *exec, Object &thisObj, const List &args);47 virtual ValueImp *callAsFunction(ExecState *exec, ObjectImp *thisObj, const List &args); 48 48 private: 49 49 int id; -
trunk/JavaScriptCore/kjs/nodes.cpp
r10076 r10084 25 25 #include "nodes.h" 26 26 27 //#include <iostream>28 27 #include <math.h> 29 28 #include <assert.h> … … 45 44 #include "operations.h" 46 45 #include "ustring.h" 46 #include "reference_list.h" 47 47 48 48 using namespace KJS; … … 117 117 Reference Node::evaluateReference(ExecState *exec) 118 118 { 119 Value 119 ValueImp *v = evaluate(exec); 120 120 KJS_CHECKEXCEPTIONREFERENCE 121 121 return Reference::makeValueReference(v); … … 134 134 #endif 135 135 136 Value 137 { 138 Object 136 ValueImp *Node::throwError(ExecState *exec, ErrorType e, const char *msg) 137 { 138 ObjectImp *err = Error::create(exec, e, msg, lineNo(), sourceId(), &sourceURL); 139 139 exec->setException(err); 140 140 return err; 141 141 } 142 142 143 Value Node::throwError(ExecState *exec, ErrorType e, const char *msg, Valuev, Node *expr)144 { 145 char *vStr = strdup(v .toString(exec).ascii());143 ValueImp *Node::throwError(ExecState *exec, ErrorType e, const char *msg, ValueImp *v, Node *expr) 144 { 145 char *vStr = strdup(v->toString(exec).ascii()); 146 146 char *exprStr = strdup(expr->toString().ascii()); 147 147 … … 152 152 free(exprStr); 153 153 154 Value 154 ValueImp *result = throwError(exec, e, str); 155 155 delete [] str; 156 156 … … 159 159 160 160 161 Value 161 ValueImp *Node::throwError(ExecState *exec, ErrorType e, const char *msg, Identifier label) 162 162 { 163 163 const char *l = label.ascii(); … … 166 166 sprintf(message, msg, l); 167 167 168 Value 168 ValueImp *result = throwError(exec, e, message); 169 169 delete [] message; 170 170 … … 175 175 { 176 176 if (exec->hadException()) { 177 Object exception = exec->exception().toObject(exec);178 if (!exception .hasProperty(exec, "line") &&179 !exception .hasProperty(exec, "sourceURL")) {180 exception .put(exec, "line", Number(line));181 exception .put(exec, "sourceURL", String(sourceURL));177 ObjectImp *exception = exec->exception()->toObject(exec); 178 if (!exception->hasProperty(exec, "line") && 179 !exception->hasProperty(exec, "sourceURL")) { 180 exception->put(exec, "line", Number(line)); 181 exception->put(exec, "sourceURL", String(sourceURL)); 182 182 } 183 183 } … … 223 223 // ------------------------------ NullNode ------------------------------------- 224 224 225 Value 225 ValueImp *NullNode::evaluate(ExecState */*exec*/) 226 226 { 227 227 return Null(); … … 230 230 // ------------------------------ BooleanNode ---------------------------------- 231 231 232 Value 233 { 234 return Value(value);232 ValueImp *BooleanNode::evaluate(ExecState */*exec*/) 233 { 234 return jsBoolean(value); 235 235 } 236 236 237 237 // ------------------------------ NumberNode ----------------------------------- 238 238 239 Value 240 { 241 return Value(value);239 ValueImp *NumberNode::evaluate(ExecState */*exec*/) 240 { 241 return jsNumber(value); 242 242 } 243 243 244 244 // ------------------------------ StringNode ----------------------------------- 245 245 246 Value 247 { 248 return value;246 ValueImp *StringNode::evaluate(ExecState */*exec*/) 247 { 248 return jsString(value); 249 249 } 250 250 251 251 // ------------------------------ RegExpNode ----------------------------------- 252 252 253 Value 253 ValueImp *RegExpNode::evaluate(ExecState *exec) 254 254 { 255 255 List list; 256 String p(pattern); 257 String f(flags); 258 list.append(p); 259 list.append(f); 260 261 Object reg = exec->lexicalInterpreter()->imp()->builtinRegExp(); 262 return reg.construct(exec,list); 256 list.append(jsString(pattern)); 257 list.append(jsString(flags)); 258 259 ObjectImp *reg = exec->lexicalInterpreter()->imp()->builtinRegExp(); 260 return reg->construct(exec,list); 263 261 } 264 262 … … 266 264 267 265 // ECMA 11.1.1 268 Value 266 ValueImp *ThisNode::evaluate(ExecState *exec) 269 267 { 270 268 return exec->context().imp()->thisValue(); … … 274 272 275 273 // ECMA 11.1.2 & 10.1.4 276 Value 274 ValueImp *ResolveNode::evaluate(ExecState *exec) 277 275 { 278 276 ScopeChain chain = exec->context().imp()->scopeChain(); … … 283 281 do { 284 282 ObjectImp *o = chain.top(); 283 285 284 if (o->getPropertySlot(exec, ident, slot)) 286 285 return slot.getValue(exec, ident); … … 289 288 } while (!chain.isEmpty()); 290 289 291 return Reference( Null(),ident).getValue(exec);290 return Reference(ident).getValue(exec); 292 291 } 293 292 … … 307 306 } while (!chain.isEmpty()); 308 307 309 return Reference(Null(), ident); 310 } 311 308 return Reference(ident); 309 } 312 310 313 311 // ------------------------------ GroupNode ------------------------------------ … … 328 326 329 327 // ECMA 11.1.6 330 Value 328 ValueImp *GroupNode::evaluate(ExecState *exec) 331 329 { 332 330 return group->evaluate(exec); … … 363 361 364 362 // ECMA 11.1.4 365 Value 366 { 367 Object array = exec->lexicalInterpreter()->builtinArray().construct(exec, List::empty());363 ValueImp *ElementNode::evaluate(ExecState *exec) 364 { 365 ObjectImp *array = exec->lexicalInterpreter()->builtinArray()->construct(exec, List::empty()); 368 366 int length = 0; 369 367 for (ElementNode *n = this; n; n = n->list) { 370 Value 368 ValueImp *val = n->node->evaluate(exec); 371 369 KJS_CHECKEXCEPTIONVALUE 372 370 length += n->elision; 373 array .put(exec, length++, val);371 array->put(exec, length++, val); 374 372 } 375 373 return array; … … 393 391 394 392 // ECMA 11.1.4 395 Value 396 { 397 Object 393 ValueImp *ArrayNode::evaluate(ExecState *exec) 394 { 395 ObjectImp *array; 398 396 int length; 399 397 400 398 if (element) { 401 array = Object(static_cast<ObjectImp*>(element->evaluate(exec).imp()));399 array = static_cast<ObjectImp*>(element->evaluate(exec)); 402 400 KJS_CHECKEXCEPTIONVALUE 403 length = opt ? array .get(exec,lengthPropertyName).toInt32(exec) : 0;401 length = opt ? array->get(exec,lengthPropertyName)->toInt32(exec) : 0; 404 402 } else { 405 Value newArr = exec->lexicalInterpreter()->builtinArray().construct(exec,List::empty());406 array = Object(static_cast<ObjectImp*>(newArr.imp()));403 ValueImp *newArr = exec->lexicalInterpreter()->builtinArray()->construct(exec,List::empty()); 404 array = static_cast<ObjectImp*>(newArr); 407 405 length = 0; 408 406 } 409 407 410 408 if (opt) 411 array .put(exec,lengthPropertyName, Value(elision + length), DontEnum | DontDelete);409 array->put(exec,lengthPropertyName, jsNumber(elision + length), DontEnum | DontDelete); 412 410 413 411 return array; … … 431 429 432 430 // ECMA 11.1.5 433 Value 431 ValueImp *ObjectLiteralNode::evaluate(ExecState *exec) 434 432 { 435 433 if (list) 436 434 return list->evaluate(exec); 437 435 438 return exec->lexicalInterpreter()->builtinObject() .construct(exec,List::empty());436 return exec->lexicalInterpreter()->builtinObject()->construct(exec,List::empty()); 439 437 } 440 438 … … 468 466 469 467 // ECMA 11.1.5 470 Value 471 { 472 Object obj = exec->lexicalInterpreter()->builtinObject().construct(exec, List::empty());468 ValueImp *PropertyValueNode::evaluate(ExecState *exec) 469 { 470 ObjectImp *obj = exec->lexicalInterpreter()->builtinObject()->construct(exec, List::empty()); 473 471 474 472 for (PropertyValueNode *p = this; p; p = p->list) { 475 Value 473 ValueImp *n = p->name->evaluate(exec); 476 474 KJS_CHECKEXCEPTIONVALUE 477 Value 475 ValueImp *v = p->assign->evaluate(exec); 478 476 KJS_CHECKEXCEPTIONVALUE 479 477 480 obj .put(exec, Identifier(n.toString(exec)), v);478 obj->put(exec, Identifier(n->toString(exec)), v); 481 479 } 482 480 … … 487 485 488 486 // ECMA 11.1.5 489 Value 490 { 491 Value 487 ValueImp *PropertyNode::evaluate(ExecState */*exec*/) 488 { 489 ValueImp *s; 492 490 493 491 if (str.isNull()) { … … 521 519 522 520 // ECMA 11.2.1a 523 Value AccessorNode1::evaluate(ExecState *exec) 524 { 525 Value v1 = expr1->evaluate(exec); 526 KJS_CHECKEXCEPTIONVALUE 527 Value v2 = expr2->evaluate(exec); 528 KJS_CHECKEXCEPTIONVALUE 529 Object o = v1.toObject(exec); 530 unsigned i; 531 if (v2.toUInt32(i)) 532 return o.get(exec, i); 533 534 String s = v2.toString(exec); 535 return o.get(exec, Identifier(s.value())); 521 ValueImp *AccessorNode1::evaluate(ExecState *exec) 522 { 523 ValueImp *v1 = expr1->evaluate(exec); 524 KJS_CHECKEXCEPTIONVALUE 525 ValueImp *v2 = expr2->evaluate(exec); 526 KJS_CHECKEXCEPTIONVALUE 527 ObjectImp *o = v1->toObject(exec); 528 uint32_t i; 529 if (v2->getUInt32(i)) 530 return o->get(exec, i); 531 return o->get(exec, Identifier(v2->toString(exec))); 536 532 } 537 533 538 534 Reference AccessorNode1::evaluateReference(ExecState *exec) 539 535 { 540 Value 536 ValueImp *v1 = expr1->evaluate(exec); 541 537 KJS_CHECKEXCEPTIONREFERENCE 542 Value 538 ValueImp *v2 = expr2->evaluate(exec); 543 539 KJS_CHECKEXCEPTIONREFERENCE 544 Object o = v1.toObject(exec);545 u nsignedi;546 if (v2 .toUInt32(i))540 ObjectImp *o = v1->toObject(exec); 541 uint32_t i; 542 if (v2->getUInt32(i)) 547 543 return Reference(o, i); 548 String s = v2.toString(exec); 549 return Reference(o, Identifier(s.value())); 550 } 551 544 return Reference(o, Identifier(v2->toString(exec))); 545 } 552 546 553 547 // ------------------------------ AccessorNode2 -------------------------------- … … 568 562 569 563 // ECMA 11.2.1b 570 Value AccessorNode2::evaluate(ExecState *exec) 571 { 572 Value v = expr->evaluate(exec); 573 KJS_CHECKEXCEPTIONVALUE 574 Object o = v.toObject(exec); 575 return o.get(exec, ident); 564 ValueImp *AccessorNode2::evaluate(ExecState *exec) 565 { 566 ValueImp *v = expr->evaluate(exec); 567 KJS_CHECKEXCEPTIONVALUE 568 return v->toObject(exec)->get(exec, ident); 576 569 577 570 } … … 579 572 Reference AccessorNode2::evaluateReference(ExecState *exec) 580 573 { 581 Value 574 ValueImp *v = expr->evaluate(exec); 582 575 KJS_CHECKEXCEPTIONREFERENCE 583 Object o = v.toObject(exec);576 ObjectImp *o = v->toObject(exec); 584 577 return Reference(o, ident); 585 578 } … … 609 602 } 610 603 611 Value 604 ValueImp *ArgumentListNode::evaluate(ExecState */*exec*/) 612 605 { 613 606 assert(0); 614 return Value(); // dummy, see evaluateList()607 return NULL; // dummy, see evaluateList() 615 608 } 616 609 … … 621 614 622 615 for (ArgumentListNode *n = this; n; n = n->list) { 623 Value 616 ValueImp *v = n->expr->evaluate(exec); 624 617 KJS_CHECKEXCEPTIONLIST 625 618 l.append(v); … … 645 638 } 646 639 647 Value 640 ValueImp *ArgumentsNode::evaluate(ExecState */*exec*/) 648 641 { 649 642 assert(0); 650 return Value(); // dummy, see evaluateList()643 return NULL; // dummy, see evaluateList() 651 644 } 652 645 … … 682 675 } 683 676 684 Value 685 { 686 Value 677 ValueImp *NewExprNode::evaluate(ExecState *exec) 678 { 679 ValueImp *v = expr->evaluate(exec); 687 680 KJS_CHECKEXCEPTIONVALUE 688 681 … … 693 686 } 694 687 695 if ( v.type() != ObjectType) {688 if (!v->isObject()) { 696 689 return throwError(exec, TypeError, "Value %s (result of expression %s) is not an object. Cannot be used with new.", v, expr); 697 690 } 698 691 699 Object constr = Object(static_cast<ObjectImp*>(v.imp()));700 if (!constr .implementsConstruct()) {692 ObjectImp *constr = static_cast<ObjectImp*>(v); 693 if (!constr->implementsConstruct()) { 701 694 return throwError(exec, TypeError, "Value %s (result of expression %s) is not a constructor. Cannot be used with new.", v, expr); 702 695 } 703 696 704 Value res = constr.construct(exec,argList); 705 706 return res; 697 return constr->construct(exec, argList); 707 698 } 708 699 … … 728 719 729 720 // ECMA 11.2.3 730 Value 721 ValueImp *FunctionCallNode::evaluate(ExecState *exec) 731 722 { 732 723 Reference ref = expr->evaluateReference(exec); … … 736 727 KJS_CHECKEXCEPTIONVALUE 737 728 738 Value 739 KJS_CHECKEXCEPTIONVALUE 740 741 if ( v.type() != ObjectType) {729 ValueImp *v = ref.getValue(exec); 730 KJS_CHECKEXCEPTIONVALUE 731 732 if (!v->isObject()) { 742 733 return throwError(exec, TypeError, "Value %s (result of expression %s) is not object.", v, expr); 743 734 } 744 745 ObjectImp *func = static_cast<ObjectImp*>(v .imp());735 736 ObjectImp *func = static_cast<ObjectImp*>(v); 746 737 747 738 if (!func->implementsCall()) { … … 751 742 ObjectImp *thisObjImp = 0; 752 743 ValueImp *thisValImp = ref.baseIfMutable(); 753 if (thisValImp && thisValImp-> type() == ObjectType&& !static_cast<ObjectImp *>(thisValImp)->inherits(&ActivationImp::info))744 if (thisValImp && thisValImp->isObject() && !static_cast<ObjectImp *>(thisValImp)->inherits(&ActivationImp::info)) 754 745 thisObjImp = static_cast<ObjectImp *>(thisValImp); 755 746 … … 761 752 // of implementation we use the global object anyway here. This guarantees 762 753 // that in host objects you always get a valid object for this. 763 thisObjImp = exec->dynamicInterpreter()->globalObject() .imp();764 } 765 766 Object 754 thisObjImp = exec->dynamicInterpreter()->globalObject(); 755 } 756 757 ObjectImp *thisObj(thisObjImp); 767 758 return func->call(exec, thisObj, argList); 768 759 } … … 785 776 786 777 // ECMA 11.3 787 Value 778 ValueImp *PostfixNode::evaluate(ExecState *exec) 788 779 { 789 780 Reference ref = expr->evaluateReference(exec); 790 781 KJS_CHECKEXCEPTIONVALUE 791 Value 782 ValueImp *v = ref.getValue(exec); 792 783 793 784 bool knownToBeInteger; 794 double n = v .toNumber(exec, knownToBeInteger);785 double n = v->toNumber(exec, knownToBeInteger); 795 786 796 787 double newValue = (oper == OpPlusPlus) ? n + 1 : n - 1; 797 ref.putValue(exec, Value(newValue, knownToBeInteger));798 799 return Value(n, knownToBeInteger);788 ref.putValue(exec, jsNumber(newValue, knownToBeInteger)); 789 790 return jsNumber(n, knownToBeInteger); 800 791 } 801 792 … … 817 808 818 809 // ECMA 11.4.1 819 Value 810 ValueImp *DeleteNode::evaluate(ExecState *exec) 820 811 { 821 812 Reference ref = expr->evaluateReference(exec); 822 813 KJS_CHECKEXCEPTIONVALUE 823 return Value(ref.deleteValue(exec));814 return jsBoolean(ref.deleteValue(exec)); 824 815 } 825 816 … … 841 832 842 833 // ECMA 11.4.2 843 Value 844 { 845 Value dummy1 =expr->evaluate(exec);834 ValueImp *VoidNode::evaluate(ExecState *exec) 835 { 836 expr->evaluate(exec); 846 837 KJS_CHECKEXCEPTIONVALUE 847 838 … … 866 857 867 858 // ECMA 11.4.3 868 Value 859 ValueImp *TypeOfNode::evaluate(ExecState *exec) 869 860 { 870 861 const char *s = 0L; … … 872 863 KJS_CHECKEXCEPTIONVALUE 873 864 ValueImp *b = ref.baseIfMutable(); 874 if (b && b-> dispatchType() == NullType)875 return Value("undefined");876 Value 877 switch (v .type())865 if (b && b->isNull()) 866 return jsString("undefined"); 867 ValueImp *v = ref.getValue(exec); 868 switch (v->type()) 878 869 { 879 870 case UndefinedType: … … 893 884 break; 894 885 default: 895 if (v .type() == ObjectType && static_cast<ObjectImp*>(v.imp())->implementsCall())886 if (v->isObject() && static_cast<ObjectImp*>(v)->implementsCall()) 896 887 s = "function"; 897 888 else … … 900 891 } 901 892 902 return Value(s);893 return jsString(s); 903 894 } 904 895 … … 920 911 921 912 // ECMA 11.4.4 and 11.4.5 922 Value 913 ValueImp *PrefixNode::evaluate(ExecState *exec) 923 914 { 924 915 Reference ref = expr->evaluateReference(exec); 925 916 KJS_CHECKEXCEPTIONVALUE 926 Value 917 ValueImp *v = ref.getValue(exec); 927 918 928 919 bool knownToBeInteger; 929 double n = v .toNumber(exec, knownToBeInteger);920 double n = v->toNumber(exec, knownToBeInteger); 930 921 931 922 double newValue = (oper == OpPlusPlus) ? n + 1 : n - 1; 932 Value n2(newValue, knownToBeInteger);923 ValueImp *n2 = jsNumber(newValue, knownToBeInteger); 933 924 934 925 ref.putValue(exec, n2); … … 954 945 955 946 // ECMA 11.4.6 956 Value 957 { 958 Value 959 KJS_CHECKEXCEPTIONVALUE 960 961 return Value(v.toNumber(exec)); /* TODO: optimize */947 ValueImp *UnaryPlusNode::evaluate(ExecState *exec) 948 { 949 ValueImp *v = expr->evaluate(exec); 950 KJS_CHECKEXCEPTIONVALUE 951 952 return jsNumber(v->toNumber(exec)); /* TODO: optimize */ 962 953 } 963 954 … … 979 970 980 971 // ECMA 11.4.7 981 Value 982 { 983 Value 972 ValueImp *NegateNode::evaluate(ExecState *exec) 973 { 974 ValueImp *v = expr->evaluate(exec); 984 975 KJS_CHECKEXCEPTIONVALUE 985 976 986 977 bool knownToBeInteger; 987 double n = v .toNumber(exec, knownToBeInteger);988 return Value(-n, knownToBeInteger && n != 0);978 double n = v->toNumber(exec, knownToBeInteger); 979 return jsNumber(-n, knownToBeInteger && n != 0); 989 980 } 990 981 … … 1006 997 1007 998 // ECMA 11.4.8 1008 Value 1009 { 1010 Value 1011 KJS_CHECKEXCEPTIONVALUE 1012 return Value(~v.toInt32(exec));999 ValueImp *BitwiseNotNode::evaluate(ExecState *exec) 1000 { 1001 ValueImp *v = expr->evaluate(exec); 1002 KJS_CHECKEXCEPTIONVALUE 1003 return jsNumber(~v->toInt32(exec)); 1013 1004 } 1014 1005 … … 1030 1021 1031 1022 // ECMA 11.4.9 1032 Value 1033 { 1034 Value 1035 KJS_CHECKEXCEPTIONVALUE 1036 return Value(!v.toBoolean(exec));1023 ValueImp *LogicalNotNode::evaluate(ExecState *exec) 1024 { 1025 ValueImp *v = expr->evaluate(exec); 1026 KJS_CHECKEXCEPTIONVALUE 1027 return jsBoolean(!v->toBoolean(exec)); 1037 1028 } 1038 1029 … … 1058 1049 1059 1050 // ECMA 11.5 1060 Value 1061 { 1062 Value 1063 KJS_CHECKEXCEPTIONVALUE 1064 1065 Value 1051 ValueImp *MultNode::evaluate(ExecState *exec) 1052 { 1053 ValueImp *v1 = term1->evaluate(exec); 1054 KJS_CHECKEXCEPTIONVALUE 1055 1056 ValueImp *v2 = term2->evaluate(exec); 1066 1057 KJS_CHECKEXCEPTIONVALUE 1067 1058 … … 1090 1081 1091 1082 // ECMA 11.6 1092 Value 1093 { 1094 Value 1095 KJS_CHECKEXCEPTIONVALUE 1096 1097 Value 1083 ValueImp *AddNode::evaluate(ExecState *exec) 1084 { 1085 ValueImp *v1 = term1->evaluate(exec); 1086 KJS_CHECKEXCEPTIONVALUE 1087 1088 ValueImp *v2 = term2->evaluate(exec); 1098 1089 KJS_CHECKEXCEPTIONVALUE 1099 1090 … … 1122 1113 1123 1114 // ECMA 11.7 1124 Value 1125 { 1126 Value 1127 KJS_CHECKEXCEPTIONVALUE 1128 Value 1129 KJS_CHECKEXCEPTIONVALUE 1130 unsigned int i2 = v2 .toUInt32(exec);1115 ValueImp *ShiftNode::evaluate(ExecState *exec) 1116 { 1117 ValueImp *v1 = term1->evaluate(exec); 1118 KJS_CHECKEXCEPTIONVALUE 1119 ValueImp *v2 = term2->evaluate(exec); 1120 KJS_CHECKEXCEPTIONVALUE 1121 unsigned int i2 = v2->toUInt32(exec); 1131 1122 i2 &= 0x1f; 1132 1123 1133 1124 switch (oper) { 1134 1125 case OpLShift: 1135 return Value(v1.toInt32(exec) << i2);1126 return jsNumber(v1->toInt32(exec) << i2); 1136 1127 case OpRShift: 1137 return Value(v1.toInt32(exec) >> i2);1128 return jsNumber(v1->toInt32(exec) >> i2); 1138 1129 case OpURShift: 1139 return Value(v1.toUInt32(exec) >> i2);1130 return jsNumber(v1->toUInt32(exec) >> i2); 1140 1131 default: 1141 1132 assert(!"ShiftNode: unhandled switch case"); … … 1165 1156 1166 1157 // ECMA 11.8 1167 Value 1168 { 1169 Value 1170 KJS_CHECKEXCEPTIONVALUE 1171 Value 1158 ValueImp *RelationalNode::evaluate(ExecState *exec) 1159 { 1160 ValueImp *v1 = expr1->evaluate(exec); 1161 KJS_CHECKEXCEPTIONVALUE 1162 ValueImp *v2 = expr2->evaluate(exec); 1172 1163 KJS_CHECKEXCEPTIONVALUE 1173 1164 … … 1187 1178 } else if (oper == OpIn) { 1188 1179 // Is all of this OK for host objects? 1189 if ( v2.type() != ObjectType)1180 if (!v2->isObject()) 1190 1181 return throwError(exec, TypeError, 1191 1182 "Value %s (result of expression %s) is not an object. Cannot be used with IN expression.", v2, expr2); 1192 Object o2(static_cast<ObjectImp*>(v2.imp()));1193 b = o2 .hasProperty(exec, Identifier(v1.toString(exec)));1183 ObjectImp *o2(static_cast<ObjectImp*>(v2)); 1184 b = o2->hasProperty(exec, Identifier(v1->toString(exec))); 1194 1185 } else { 1195 if ( v2.type() != ObjectType)1186 if (!v2->isObject()) 1196 1187 return throwError(exec, TypeError, 1197 1188 "Value %s (result of expression %s) is not an object. Cannot be used with instanceof operator.", v2, expr2); 1198 1189 1199 Object o2(static_cast<ObjectImp*>(v2.imp()));1200 if (!o2 .implementsHasInstance()) {1201 // According to the spec, only some types of objects "im lement" the [[HasInstance]] property.1190 ObjectImp *o2(static_cast<ObjectImp*>(v2)); 1191 if (!o2->implementsHasInstance()) { 1192 // According to the spec, only some types of objects "implement" the [[HasInstance]] property. 1202 1193 // But we are supposed to throw an exception where the object does not "have" the [[HasInstance]] 1203 1194 // property. It seems that all object have the property, but not all implement it, so in this 1204 1195 // case we return false (consistent with mozilla) 1205 return Value(false);1196 return jsBoolean(false); 1206 1197 // return throwError(exec, TypeError, 1207 1198 // "Object does not implement the [[HasInstance]] method." ); 1208 1199 } 1209 return o2.hasInstance(exec, v1);1210 } 1211 1212 return Value(b);1200 return jsBoolean(o2->hasInstance(exec, v1)); 1201 } 1202 1203 return jsBoolean(b); 1213 1204 } 1214 1205 … … 1234 1225 1235 1226 // ECMA 11.9 1236 Value 1237 { 1238 Value 1239 KJS_CHECKEXCEPTIONVALUE 1240 Value 1227 ValueImp *EqualNode::evaluate(ExecState *exec) 1228 { 1229 ValueImp *v1 = expr1->evaluate(exec); 1230 KJS_CHECKEXCEPTIONVALUE 1231 ValueImp *v2 = expr2->evaluate(exec); 1241 1232 KJS_CHECKEXCEPTIONVALUE 1242 1233 … … 1251 1242 result = oper == OpStrEq ? eq : !eq; 1252 1243 } 1253 return Value(result);1244 return jsBoolean(result); 1254 1245 } 1255 1246 … … 1275 1266 1276 1267 // ECMA 11.10 1277 Value 1278 { 1279 Value 1280 KJS_CHECKEXCEPTIONVALUE 1281 Value 1282 KJS_CHECKEXCEPTIONVALUE 1283 int i1 = v1 .toInt32(exec);1284 int i2 = v2 .toInt32(exec);1268 ValueImp *BitOperNode::evaluate(ExecState *exec) 1269 { 1270 ValueImp *v1 = expr1->evaluate(exec); 1271 KJS_CHECKEXCEPTIONVALUE 1272 ValueImp *v2 = expr2->evaluate(exec); 1273 KJS_CHECKEXCEPTIONVALUE 1274 int i1 = v1->toInt32(exec); 1275 int i2 = v2->toInt32(exec); 1285 1276 int result; 1286 1277 if (oper == OpBitAnd) … … 1291 1282 result = i1 | i2; 1292 1283 1293 return Value(result);1284 return jsNumber(result); 1294 1285 } 1295 1286 … … 1315 1306 1316 1307 // ECMA 11.11 1317 Value 1318 { 1319 Value 1320 KJS_CHECKEXCEPTIONVALUE 1321 bool b1 = v1 .toBoolean(exec);1308 ValueImp *BinaryLogicalNode::evaluate(ExecState *exec) 1309 { 1310 ValueImp *v1 = expr1->evaluate(exec); 1311 KJS_CHECKEXCEPTIONVALUE 1312 bool b1 = v1->toBoolean(exec); 1322 1313 if ((!b1 && oper == OpAnd) || (b1 && oper == OpOr)) 1323 1314 return v1; 1324 1315 1325 Value 1316 ValueImp *v2 = expr2->evaluate(exec); 1326 1317 KJS_CHECKEXCEPTIONVALUE 1327 1318 … … 1354 1345 1355 1346 // ECMA 11.12 1356 Value 1357 { 1358 Value 1359 KJS_CHECKEXCEPTIONVALUE 1360 bool b = v .toBoolean(exec);1347 ValueImp *ConditionalNode::evaluate(ExecState *exec) 1348 { 1349 ValueImp *v = logical->evaluate(exec); 1350 KJS_CHECKEXCEPTIONVALUE 1351 bool b = v->toBoolean(exec); 1361 1352 1362 1353 if (b) … … 1390 1381 1391 1382 // ECMA 11.13 1392 Value 1383 ValueImp *AssignNode::evaluate(ExecState *exec) 1393 1384 { 1394 1385 Reference l = left->evaluateReference(exec); 1395 1386 KJS_CHECKEXCEPTIONVALUE 1396 Value e,v;1387 ValueImp *v; 1397 1388 if (oper == OpEqual) { 1398 1389 v = expr->evaluate(exec); 1399 1390 KJS_CHECKEXCEPTIONVALUE 1400 1391 } else { 1401 Value 1402 Value 1392 ValueImp *v1 = l.getValue(exec); 1393 ValueImp *v2 = expr->evaluate(exec); 1403 1394 KJS_CHECKEXCEPTIONVALUE 1404 1395 int i1; … … 1419 1410 break; 1420 1411 case OpLShift: 1421 i1 = v1 .toInt32(exec);1422 i2 = v2 .toInt32(exec);1423 v = Value(i1 << i2);1412 i1 = v1->toInt32(exec); 1413 i2 = v2->toInt32(exec); 1414 v = jsNumber(i1 << i2); 1424 1415 break; 1425 1416 case OpRShift: 1426 i1 = v1 .toInt32(exec);1427 i2 = v2 .toInt32(exec);1428 v = Value(i1 >> i2);1417 i1 = v1->toInt32(exec); 1418 i2 = v2->toInt32(exec); 1419 v = jsNumber(i1 >> i2); 1429 1420 break; 1430 1421 case OpURShift: 1431 ui = v1 .toUInt32(exec);1432 i2 = v2 .toInt32(exec);1433 v = Value(ui >> i2);1422 ui = v1->toUInt32(exec); 1423 i2 = v2->toInt32(exec); 1424 v = jsNumber(ui >> i2); 1434 1425 break; 1435 1426 case OpAndEq: 1436 i1 = v1 .toInt32(exec);1437 i2 = v2 .toInt32(exec);1438 v = Value(i1 & i2);1427 i1 = v1->toInt32(exec); 1428 i2 = v2->toInt32(exec); 1429 v = jsNumber(i1 & i2); 1439 1430 break; 1440 1431 case OpXOrEq: 1441 i1 = v1 .toInt32(exec);1442 i2 = v2 .toInt32(exec);1443 v = Value(i1 ^ i2);1432 i1 = v1->toInt32(exec); 1433 i2 = v2->toInt32(exec); 1434 v = jsNumber(i1 ^ i2); 1444 1435 break; 1445 1436 case OpOrEq: 1446 i1 = v1 .toInt32(exec);1447 i2 = v2 .toInt32(exec);1448 v = Value(i1 | i2);1437 i1 = v1->toInt32(exec); 1438 i2 = v2->toInt32(exec); 1439 v = jsNumber(i1 | i2); 1449 1440 break; 1450 1441 case OpModEq: { 1451 1442 bool d1KnownToBeInteger; 1452 double d1 = v1 .toNumber(exec, d1KnownToBeInteger);1443 double d1 = v1->toNumber(exec, d1KnownToBeInteger); 1453 1444 bool d2KnownToBeInteger; 1454 double d2 = v2 .toNumber(exec, d2KnownToBeInteger);1455 v = Value(fmod(d1, d2), d1KnownToBeInteger && d2KnownToBeInteger && d2 != 0);1445 double d2 = v2->toNumber(exec, d2KnownToBeInteger); 1446 v = jsNumber(fmod(d1, d2), d1KnownToBeInteger && d2KnownToBeInteger && d2 != 0); 1456 1447 } 1457 1448 break; … … 1488 1479 1489 1480 // ECMA 11.14 1490 Value 1491 { 1492 Value dummy =expr1->evaluate(exec);1493 KJS_CHECKEXCEPTIONVALUE 1494 Value 1481 ValueImp *CommaNode::evaluate(ExecState *exec) 1482 { 1483 expr1->evaluate(exec); 1484 KJS_CHECKEXCEPTIONVALUE 1485 ValueImp *v = expr2->evaluate(exec); 1495 1486 KJS_CHECKEXCEPTIONVALUE 1496 1487 … … 1541 1532 KJS_ABORTPOINT 1542 1533 if (exec->hadException()) { 1543 Value 1534 ValueImp *ex = exec->exception(); 1544 1535 exec->clearException(); 1545 1536 return Completion(Throw, ex); … … 1549 1540 return c; 1550 1541 1551 Value 1542 ValueImp *v = c.value(); 1552 1543 1553 1544 for (StatListNode *n = list; n; n = n->list) { … … 1558 1549 1559 1550 if (exec->hadException()) { 1560 Value 1551 ValueImp *ex = exec->exception(); 1561 1552 exec->clearException(); 1562 1553 return Completion(Throw, ex); … … 1594 1585 1595 1586 // ECMA 12.2 1596 Value 1587 ValueImp *AssignExprNode::evaluate(ExecState *exec) 1597 1588 { 1598 1589 return expr->evaluate(exec); … … 1622 1613 1623 1614 // ECMA 12.2 1624 Value 1625 { 1626 Object 1627 1628 Value 1615 ValueImp *VarDeclNode::evaluate(ExecState *exec) 1616 { 1617 ObjectImp *variable = exec->context().imp()->variableObject(); 1618 1619 ValueImp *val; 1629 1620 if (init) { 1630 1621 val = init->evaluate(exec); … … 1633 1624 // already declared? - check with getDirect so you can override 1634 1625 // built-in properties of the global object with var declarations. 1635 if ( variable.imp()->getDirect(ident))1636 return Value();1626 if (variable->getDirect(ident)) 1627 return NULL; 1637 1628 val = Undefined(); 1638 1629 } … … 1648 1639 if (varType == VarDeclNode::Constant) 1649 1640 flags |= ReadOnly; 1650 variable .put(exec, ident, val, flags);1651 1652 return ident.ustring();1641 variable->put(exec, ident, val, flags); 1642 1643 return jsString(ident.ustring()); 1653 1644 } 1654 1645 1655 1646 void VarDeclNode::processVarDecls(ExecState *exec) 1656 1647 { 1657 Object 1648 ObjectImp *variable = exec->context().imp()->variableObject(); 1658 1649 1659 1650 // If a variable by this name already exists, don't clobber it - 1660 1651 // it might be a function parameter 1661 if (!variable .hasProperty(exec, ident)) {1652 if (!variable->hasProperty(exec, ident)) { 1662 1653 int flags = Internal; 1663 1654 if (exec->context().imp()->codeType() != EvalCode) … … 1665 1656 if (varType == VarDeclNode::Constant) 1666 1657 flags |= ReadOnly; 1667 variable .put(exec, ident, Undefined(), flags);1658 variable->put(exec, ident, Undefined(), flags); 1668 1659 } 1669 1660 } … … 1695 1686 1696 1687 // ECMA 12.2 1697 Value 1688 ValueImp *VarDeclListNode::evaluate(ExecState *exec) 1698 1689 { 1699 1690 for (VarDeclListNode *n = this; n; n = n->list) { … … 1815 1806 KJS_BREAKPOINT; 1816 1807 1817 Value 1808 ValueImp *v = expr->evaluate(exec); 1818 1809 KJS_CHECKEXCEPTION 1819 1810 … … 1850 1841 KJS_BREAKPOINT; 1851 1842 1852 Value 1843 ValueImp *v = expr->evaluate(exec); 1853 1844 KJS_CHECKEXCEPTION 1854 bool b = v .toBoolean(exec);1845 bool b = v->toBoolean(exec); 1855 1846 1856 1847 // if ... then … … 1899 1890 KJS_BREAKPOINT; 1900 1891 1901 Value be,bv;1892 ValueImp *bv; 1902 1893 Completion c; 1903 Value value;1904 1894 1905 1895 do { … … 1912 1902 if (!((c.complType() == Continue) && ls.contains(c.target()))) { 1913 1903 if ((c.complType() == Break) && ls.contains(c.target())) 1914 return Completion(Normal, value);1904 return Completion(Normal, NULL); 1915 1905 if (c.complType() != Normal) 1916 1906 return c; … … 1918 1908 bv = expr->evaluate(exec); 1919 1909 KJS_CHECKEXCEPTION 1920 } while (bv .toBoolean(exec));1921 1922 return Completion(Normal, value);1910 } while (bv->toBoolean(exec)); 1911 1912 return Completion(Normal, NULL); 1923 1913 } 1924 1914 … … 1953 1943 KJS_BREAKPOINT; 1954 1944 1955 Value be,bv;1945 ValueImp *bv; 1956 1946 Completion c; 1957 1947 bool b(false); 1958 Value value;1948 ValueImp *value = NULL; 1959 1949 1960 1950 while (1) { 1961 1951 bv = expr->evaluate(exec); 1962 1952 KJS_CHECKEXCEPTION 1963 b = bv .toBoolean(exec);1953 b = bv->toBoolean(exec); 1964 1954 1965 1955 // bail out on error … … 2022 2012 Completion ForNode::execute(ExecState *exec) 2023 2013 { 2024 Value v, cval;2014 ValueImp *v, *cval = NULL; 2025 2015 2026 2016 if (expr1) { … … 2032 2022 v = expr2->evaluate(exec); 2033 2023 KJS_CHECKEXCEPTION 2034 if (!v .toBoolean(exec))2024 if (!v->toBoolean(exec)) 2035 2025 return Completion(Normal, cval); 2036 2026 } … … 2114 2104 Completion ForInNode::execute(ExecState *exec) 2115 2105 { 2116 Value e, retval; 2117 Object v; 2106 ValueImp *e; 2107 ValueImp *retval = NULL; 2108 ObjectImp *v; 2118 2109 Completion c; 2119 2110 ReferenceList propList; … … 2130 2121 // property list but will throw an exception if you attempt to 2131 2122 // access any property. 2132 if (e .type() == UndefinedType || e.type() == NullType) {2133 return Completion(Normal, retval);2123 if (e->isUndefinedOrNull()) { 2124 return Completion(Normal, NULL); 2134 2125 } 2135 2126 2136 2127 KJS_CHECKEXCEPTION 2137 v = e .toObject(exec);2138 propList = v .propList(exec);2128 v = e->toObject(exec); 2129 propList = v->propList(exec); 2139 2130 2140 2131 ReferenceListIterator propIt = propList.begin(); … … 2142 2133 while (propIt != propList.end()) { 2143 2134 Identifier name = propIt->getPropertyName(exec); 2144 if (!v .hasProperty(exec,name)) {2135 if (!v->hasProperty(exec,name)) { 2145 2136 propIt++; 2146 2137 continue; … … 2186 2177 KJS_BREAKPOINT; 2187 2178 2188 Value dummy;2189 2190 2179 if (ident.isEmpty() && !exec->context().imp()->seenLabels()->inIteration()) 2191 2180 return Completion(Throw, … … 2195 2184 throwError(exec, SyntaxError, "Label %s not found.", ident)); 2196 2185 else 2197 return Completion(Continue, dummy, ident);2186 return Completion(Continue, NULL, ident); 2198 2187 } 2199 2188 … … 2204 2193 { 2205 2194 KJS_BREAKPOINT; 2206 2207 Value dummy;2208 2195 2209 2196 if (ident.isEmpty() && !exec->context().imp()->seenLabels()->inIteration() && … … 2215 2202 throwError(exec, SyntaxError, "Label %s not found.", ident)); 2216 2203 else 2217 return Completion(Break, dummy, ident);2204 return Completion(Break, NULL, ident); 2218 2205 } 2219 2206 … … 2247 2234 return Completion(ReturnValue, Undefined()); 2248 2235 2249 Value 2236 ValueImp *v = value->evaluate(exec); 2250 2237 KJS_CHECKEXCEPTION 2251 2238 … … 2278 2265 KJS_BREAKPOINT; 2279 2266 2280 Value 2267 ValueImp *v = expr->evaluate(exec); 2281 2268 KJS_CHECKEXCEPTION 2282 Object o = v.toObject(exec);2269 ObjectImp *o = v->toObject(exec); 2283 2270 KJS_CHECKEXCEPTION 2284 2271 exec->context().imp()->pushScope(o); … … 2315 2302 2316 2303 // ECMA 12.11 2317 Value 2318 { 2319 Value 2304 ValueImp *CaseClauseNode::evaluate(ExecState *exec) 2305 { 2306 ValueImp *v = expr->evaluate(exec); 2320 2307 KJS_CHECKEXCEPTIONVALUE 2321 2308 … … 2362 2349 } 2363 2350 2364 Value 2351 ValueImp *ClauseListNode::evaluate(ExecState */*exec*/) 2365 2352 { 2366 2353 /* should never be called */ 2367 2354 assert(false); 2368 return Value();2355 return NULL; 2369 2356 } 2370 2357 … … 2421 2408 } 2422 2409 2423 Value 2410 ValueImp *CaseBlockNode::evaluate(ExecState */*exec*/) 2424 2411 { 2425 2412 /* should never be called */ 2426 2413 assert(false); 2427 return Value();2414 return NULL; 2428 2415 } 2429 2416 2430 2417 // ECMA 12.11 2431 Completion CaseBlockNode::evalBlock(ExecState *exec, const Value&input)2432 { 2433 Value 2418 Completion CaseBlockNode::evalBlock(ExecState *exec, ValueImp *input) 2419 { 2420 ValueImp *v; 2434 2421 Completion res; 2435 2422 ClauseListNode *a = list1, *b = list2; … … 2525 2512 KJS_BREAKPOINT; 2526 2513 2527 Value 2514 ValueImp *v = expr->evaluate(exec); 2528 2515 KJS_CHECKEXCEPTION 2529 2516 … … 2601 2588 KJS_BREAKPOINT; 2602 2589 2603 Value 2590 ValueImp *v = expr->evaluate(exec); 2604 2591 KJS_CHECKEXCEPTION 2605 2592 … … 2631 2618 2632 2619 // ECMA 12.14 2633 Completion CatchNode::execute(ExecState *exec, const Value &arg)2620 Completion CatchNode::execute(ExecState *exec, ValueImp *arg) 2634 2621 { 2635 2622 /* TODO: correct ? Not part of the spec */ … … 2637 2624 exec->clearException(); 2638 2625 2639 Object 2640 obj .put(exec, ident, arg, DontDelete);2626 ObjectImp *obj(new ObjectImp()); 2627 obj->put(exec, ident, arg, DontDelete); 2641 2628 exec->context().imp()->pushScope(obj); 2642 2629 Completion c = block->execute(exec); … … 2718 2705 2719 2706 if (!_catch) { 2720 Value 2707 ValueImp *lastException = exec->exception(); 2721 2708 exec->clearException(); 2722 2709 … … 2765 2752 2766 2753 // ECMA 13 2767 Value 2754 ValueImp *ParameterNode::evaluate(ExecState */*exec*/) 2768 2755 { 2769 2756 return Undefined(); … … 2808 2795 void FuncDeclNode::processFuncDecl(ExecState *exec) 2809 2796 { 2797 ContextImp *context = exec->context().imp(); 2798 2810 2799 // TODO: let this be an object with [[Class]] property "Function" 2811 FunctionImp *fimp = new DeclaredFunctionImp(exec, ident, body, exec->context().imp()->scopeChain()); 2812 Object func(fimp); // protect from GC 2813 2814 // Value proto = exec->lexicalInterpreter()->builtinObject().construct(exec,List::empty()); 2815 List empty; 2816 Object proto = exec->lexicalInterpreter()->builtinObject().construct(exec,empty); 2817 proto.put(exec, constructorPropertyName, func, ReadOnly|DontDelete|DontEnum); 2818 func.put(exec, prototypePropertyName, proto, Internal|DontDelete); 2800 FunctionImp *fimp = new DeclaredFunctionImp(exec, ident, body, context->scopeChain()); 2801 ObjectImp *func(fimp); // protect from GC 2802 2803 ObjectImp *proto = exec->lexicalInterpreter()->builtinObject()->construct(exec, List::empty()); 2804 proto->put(exec, constructorPropertyName, func, ReadOnly|DontDelete|DontEnum); 2805 func->put(exec, prototypePropertyName, proto, Internal|DontDelete); 2819 2806 2820 2807 int plen = 0; … … 2822 2809 fimp->addParameter(p->ident()); 2823 2810 2824 func.put(exec, lengthPropertyName, Number(plen), ReadOnly|DontDelete|DontEnum); 2825 2826 if (exec->context().imp()->codeType() == EvalCode) { 2827 // ECMA 10.2.2 2828 exec->context().imp()->variableObject().put(exec, ident, func, Internal); 2829 } else { 2830 exec->context().imp()->variableObject().put(exec, ident, func, Internal | DontDelete); 2831 } 2811 func->put(exec, lengthPropertyName, Number(plen), ReadOnly|DontDelete|DontEnum); 2812 2813 // ECMA 10.2.2 2814 context->variableObject()->put(exec, ident, func, Internal | (context->codeType() == EvalCode ? 0 : DontDelete)); 2832 2815 2833 2816 if (body) { 2834 2817 // hack the scope so that the function gets put as a property of func, and it's scope 2835 2818 // contains the func as well as our current scope 2836 Object oldVar = exec->context().imp()->variableObject();2837 exec->context().imp()->setVariableObject(func);2838 exec->context().imp()->pushScope(func);2819 ObjectImp *oldVar = context->variableObject(); 2820 context->setVariableObject(func); 2821 context->pushScope(func); 2839 2822 body->processFuncDecl(exec); 2840 exec->context().imp()->popScope();2841 exec->context().imp()->setVariableObject(oldVar);2823 context->popScope(); 2824 context->setVariableObject(oldVar); 2842 2825 } 2843 2826 } … … 2865 2848 2866 2849 // ECMA 13 2867 Value 2850 ValueImp *FuncExprNode::evaluate(ExecState *exec) 2868 2851 { 2869 2852 FunctionImp *fimp = new DeclaredFunctionImp(exec, Identifier::null(), body, exec->context().imp()->scopeChain()); 2870 Value ret(fimp); 2871 List empty; 2872 Value proto = exec->lexicalInterpreter()->builtinObject().construct(exec,empty); 2853 ValueImp *ret(fimp); 2854 ValueImp *proto = exec->lexicalInterpreter()->builtinObject()->construct(exec, List::empty()); 2873 2855 fimp->put(exec, prototypePropertyName, proto, Internal|DontDelete); 2874 2856 … … 2933 2915 // The spec says to return c2 here, but it seems that mozilla returns c1 if 2934 2916 // c2 doesn't have a value 2935 if ( !c2.value().isNull())2917 if (c2.value()) 2936 2918 c1 = c2; 2937 2919 } -
trunk/JavaScriptCore/kjs/nodes.h
r9768 r10084 83 83 KJS_FAST_ALLOCATED; 84 84 85 virtual Value 85 virtual ValueImp *evaluate(ExecState *exec) = 0; 86 86 virtual Reference evaluateReference(ExecState *exec); 87 87 UString toString() const; … … 104 104 #endif 105 105 protected: 106 Value 107 Value throwError(ExecState *exec, ErrorType e, const char *msg, Valuev, Node *expr);108 Value 106 ValueImp *throwError(ExecState *exec, ErrorType e, const char *msg); 107 ValueImp *throwError(ExecState *exec, ErrorType e, const char *msg, ValueImp *v, Node *expr); 108 ValueImp *throwError(ExecState *exec, ErrorType e, const char *msg, Identifier label); 109 109 void setExceptionDetailsIfNeeded(ExecState *exec); 110 110 int line; … … 137 137 LabelStack ls; 138 138 private: 139 Value 139 ValueImp *evaluate(ExecState */*exec*/) { return Undefined(); } 140 140 int l0, l1; 141 141 int sid; … … 146 146 public: 147 147 NullNode() {} 148 Value 148 ValueImp *evaluate(ExecState *exec); 149 149 virtual void streamTo(SourceStream &s) const; 150 150 }; … … 153 153 public: 154 154 BooleanNode(bool v) : value(v) {} 155 Value 155 ValueImp *evaluate(ExecState *exec); 156 156 virtual void streamTo(SourceStream &s) const; 157 157 private: … … 162 162 public: 163 163 NumberNode(double v) : value(v) { } 164 Value 164 ValueImp *evaluate(ExecState *exec); 165 165 virtual void streamTo(SourceStream &s) const; 166 166 private: … … 171 171 public: 172 172 StringNode(const UString *v) { value = *v; } 173 Value 173 ValueImp *evaluate(ExecState *exec); 174 174 virtual void streamTo(SourceStream &s) const; 175 175 private: … … 181 181 RegExpNode(const UString &p, const UString &f) 182 182 : pattern(p), flags(f) { } 183 Value 183 ValueImp *evaluate(ExecState *exec); 184 184 virtual void streamTo(SourceStream &s) const; 185 185 private: … … 190 190 public: 191 191 ThisNode() {} 192 Value 192 ValueImp *evaluate(ExecState *exec); 193 193 virtual void streamTo(SourceStream &s) const; 194 194 }; … … 197 197 public: 198 198 ResolveNode(const Identifier &s) : ident(s) { } 199 Value 199 ValueImp *evaluate(ExecState *exec); 200 200 virtual Reference evaluateReference(ExecState *exec); 201 201 virtual void streamTo(SourceStream &s) const; … … 209 209 virtual void ref(); 210 210 virtual bool deref(); 211 virtual Value 211 virtual ValueImp *evaluate(ExecState *exec); 212 212 virtual Reference evaluateReference(ExecState *exec); 213 213 virtual void streamTo(SourceStream &s) const { group->streamTo(s); } … … 224 224 virtual void ref(); 225 225 virtual bool deref(); 226 Value 226 ValueImp *evaluate(ExecState *exec); 227 227 virtual void streamTo(SourceStream &s) const; 228 228 private: … … 242 242 virtual void ref(); 243 243 virtual bool deref(); 244 Value 244 ValueImp *evaluate(ExecState *exec); 245 245 virtual void streamTo(SourceStream &s) const; 246 246 private: … … 259 259 virtual void ref(); 260 260 virtual bool deref(); 261 Value 261 ValueImp *evaluate(ExecState *exec); 262 262 virtual void streamTo(SourceStream &s) const; 263 263 private: … … 274 274 virtual void ref(); 275 275 virtual bool deref(); 276 Value 276 ValueImp *evaluate(ExecState *exec); 277 277 virtual void streamTo(SourceStream &s) const; 278 278 private: … … 284 284 PropertyNode(double d) : numeric(d) { } 285 285 PropertyNode(const Identifier &s) : str(s) { } 286 Value 286 ValueImp *evaluate(ExecState *exec); 287 287 virtual void streamTo(SourceStream &s) const; 288 288 private: … … 296 296 virtual void ref(); 297 297 virtual bool deref(); 298 Value 298 ValueImp *evaluate(ExecState *exec); 299 299 virtual Reference evaluateReference(ExecState *exec); 300 300 virtual void streamTo(SourceStream &s) const; … … 309 309 virtual void ref(); 310 310 virtual bool deref(); 311 Value 311 ValueImp *evaluate(ExecState *exec); 312 312 virtual Reference evaluateReference(ExecState *exec); 313 313 virtual void streamTo(SourceStream &s) const; … … 325 325 virtual void ref(); 326 326 virtual bool deref(); 327 Value 327 ValueImp *evaluate(ExecState *exec); 328 328 List evaluateList(ExecState *exec); 329 329 virtual void streamTo(SourceStream &s) const; … … 341 341 virtual void ref(); 342 342 virtual bool deref(); 343 Value 343 ValueImp *evaluate(ExecState *exec); 344 344 List evaluateList(ExecState *exec); 345 345 virtual void streamTo(SourceStream &s) const; … … 354 354 virtual void ref(); 355 355 virtual bool deref(); 356 Value 356 ValueImp *evaluate(ExecState *exec); 357 357 virtual void streamTo(SourceStream &s) const; 358 358 private: … … 366 366 virtual void ref(); 367 367 virtual bool deref(); 368 Value 368 ValueImp *evaluate(ExecState *exec); 369 369 virtual void streamTo(SourceStream &s) const; 370 370 private: … … 378 378 virtual void ref(); 379 379 virtual bool deref(); 380 Value 380 ValueImp *evaluate(ExecState *exec); 381 381 virtual void streamTo(SourceStream &s) const; 382 382 private: … … 390 390 virtual void ref(); 391 391 virtual bool deref(); 392 Value 392 ValueImp *evaluate(ExecState *exec); 393 393 virtual void streamTo(SourceStream &s) const; 394 394 private: … … 401 401 virtual void ref(); 402 402 virtual bool deref(); 403 Value 403 ValueImp *evaluate(ExecState *exec); 404 404 virtual void streamTo(SourceStream &s) const; 405 405 private: … … 412 412 virtual void ref(); 413 413 virtual bool deref(); 414 Value 414 ValueImp *evaluate(ExecState *exec); 415 415 virtual void streamTo(SourceStream &s) const; 416 416 private: … … 423 423 virtual void ref(); 424 424 virtual bool deref(); 425 Value 425 ValueImp *evaluate(ExecState *exec); 426 426 virtual void streamTo(SourceStream &s) const; 427 427 private: … … 435 435 virtual void ref(); 436 436 virtual bool deref(); 437 Value 437 ValueImp *evaluate(ExecState *exec); 438 438 virtual void streamTo(SourceStream &s) const; 439 439 private: … … 446 446 virtual void ref(); 447 447 virtual bool deref(); 448 Value 448 ValueImp *evaluate(ExecState *exec); 449 449 virtual void streamTo(SourceStream &s) const; 450 450 private: … … 457 457 virtual void ref(); 458 458 virtual bool deref(); 459 Value 459 ValueImp *evaluate(ExecState *exec); 460 460 virtual void streamTo(SourceStream &s) const; 461 461 private: … … 468 468 virtual void ref(); 469 469 virtual bool deref(); 470 Value 470 ValueImp *evaluate(ExecState *exec); 471 471 virtual void streamTo(SourceStream &s) const; 472 472 private: … … 479 479 virtual void ref(); 480 480 virtual bool deref(); 481 Value 481 ValueImp *evaluate(ExecState *exec); 482 482 virtual void streamTo(SourceStream &s) const; 483 483 private: … … 491 491 virtual void ref(); 492 492 virtual bool deref(); 493 Value 493 ValueImp *evaluate(ExecState *exec); 494 494 virtual void streamTo(SourceStream &s) const; 495 495 private: … … 504 504 virtual void ref(); 505 505 virtual bool deref(); 506 Value 506 ValueImp *evaluate(ExecState *exec); 507 507 virtual void streamTo(SourceStream &s) const; 508 508 private: … … 517 517 virtual void ref(); 518 518 virtual bool deref(); 519 Value 519 ValueImp *evaluate(ExecState *exec); 520 520 virtual void streamTo(SourceStream &s) const; 521 521 private: … … 530 530 virtual void ref(); 531 531 virtual bool deref(); 532 Value 532 ValueImp *evaluate(ExecState *exec); 533 533 virtual void streamTo(SourceStream &s) const; 534 534 private: … … 543 543 virtual void ref(); 544 544 virtual bool deref(); 545 Value 545 ValueImp *evaluate(ExecState *exec); 546 546 virtual void streamTo(SourceStream &s) const; 547 547 private: … … 559 559 virtual void ref(); 560 560 virtual bool deref(); 561 Value 561 ValueImp *evaluate(ExecState *exec); 562 562 virtual void streamTo(SourceStream &s) const; 563 563 private: … … 575 575 virtual void ref(); 576 576 virtual bool deref(); 577 Value 577 ValueImp *evaluate(ExecState *exec); 578 578 virtual void streamTo(SourceStream &s) const; 579 579 private: … … 586 586 virtual void ref(); 587 587 virtual bool deref(); 588 Value 588 ValueImp *evaluate(ExecState *exec); 589 589 virtual void streamTo(SourceStream &s) const; 590 590 private: … … 599 599 virtual void ref(); 600 600 virtual bool deref(); 601 Value 601 ValueImp *evaluate(ExecState *exec); 602 602 virtual void streamTo(SourceStream &s) const; 603 603 private: … … 626 626 virtual void ref(); 627 627 virtual bool deref(); 628 Value 628 ValueImp *evaluate(ExecState *exec); 629 629 virtual void streamTo(SourceStream &s) const; 630 630 private: … … 638 638 virtual void ref(); 639 639 virtual bool deref(); 640 Value 640 ValueImp *evaluate(ExecState *exec); 641 641 virtual void processVarDecls(ExecState *exec); 642 642 virtual void streamTo(SourceStream &s) const; … … 655 655 virtual void ref(); 656 656 virtual bool deref(); 657 Value 657 ValueImp *evaluate(ExecState *exec); 658 658 virtual void processVarDecls(ExecState *exec); 659 659 virtual void streamTo(SourceStream &s) const; … … 831 831 virtual void ref(); 832 832 virtual bool deref(); 833 Value 833 ValueImp *evaluate(ExecState *exec); 834 834 Completion evalStatements(ExecState *exec); 835 835 virtual void processVarDecls(ExecState *exec); … … 848 848 virtual void ref(); 849 849 virtual bool deref(); 850 Value 850 ValueImp *evaluate(ExecState *exec); 851 851 CaseClauseNode *clause() const { return cl; } 852 852 ClauseListNode *next() const { return nx; } … … 864 864 virtual void ref(); 865 865 virtual bool deref(); 866 Value 867 Completion evalBlock(ExecState *exec, const Value&input);866 ValueImp *evaluate(ExecState *exec); 867 Completion evalBlock(ExecState *exec, ValueImp *input); 868 868 virtual void processVarDecls(ExecState *exec); 869 869 virtual void streamTo(SourceStream &s) const; … … 917 917 virtual bool deref(); 918 918 virtual Completion execute(ExecState *exec); 919 Completion execute(ExecState *exec, const Value &arg);919 Completion execute(ExecState *exec, ValueImp *arg); 920 920 virtual void processVarDecls(ExecState *exec); 921 921 virtual void streamTo(SourceStream &s) const; … … 964 964 virtual void ref(); 965 965 virtual bool deref(); 966 Value 966 ValueImp *evaluate(ExecState *exec); 967 967 Identifier ident() { return id; } 968 968 ParameterNode *nextParam() { return next; } … … 1007 1007 virtual void ref(); 1008 1008 virtual bool deref(); 1009 Value 1009 ValueImp *evaluate(ExecState *exec); 1010 1010 virtual void streamTo(SourceStream &s) const; 1011 1011 private: -
trunk/JavaScriptCore/kjs/number_object.cpp
r10076 r10084 53 53 : NumberInstanceImp(objProto) 54 54 { 55 Value protect(this); 56 setInternalValue(NumberImp::zero()); 55 setInternalValue(jsZero()); 57 56 58 57 // The constructor will be added later, after NumberObjectImp has been constructed … … 73 72 : InternalFunctionImp(funcProto), id(i) 74 73 { 75 Value protect(this);76 74 putDirect(lengthPropertyName, len, DontDelete|ReadOnly|DontEnum); 77 75 } … … 128 126 129 127 // ECMA 15.7.4.2 - 15.7.4.7 130 Value NumberProtoFuncImp::call(ExecState *exec, Object &thisObj, const List &args) 131 { 132 Value result; 133 128 ValueImp *NumberProtoFuncImp::callAsFunction(ExecState *exec, ObjectImp *thisObj, const List &args) 129 { 134 130 // no generic function. "this" has to be a Number object 135 if (!thisObj .inherits(&NumberInstanceImp::info)) {136 Object 131 if (!thisObj->inherits(&NumberInstanceImp::info)) { 132 ObjectImp *err = Error::create(exec,TypeError); 137 133 exec->setException(err); 138 134 return err; 139 135 } 140 136 141 Value v = thisObj.internalValue();137 ValueImp *v = thisObj->internalValue(); 142 138 switch (id) { 143 139 case ToString: { 144 140 double dradix = 10; 145 141 if (!args.isEmpty()) 146 dradix = args[0] .toInteger(exec);142 dradix = args[0]->toInteger(exec); 147 143 if (dradix >= 2 && dradix <= 36 && dradix != 10) { // false for NaN 148 144 int radix = static_cast<int>(dradix); 149 unsigned i = v .toUInt32(exec);145 unsigned i = v->toUInt32(exec); 150 146 char s[33]; 151 147 char *p = s + sizeof(s); … … 155 151 i /= radix; 156 152 } while (i); 157 re sult =String(p);153 return String(p); 158 154 } else 159 result = String(v.toString(exec)); 160 break; 155 return String(v->toString(exec)); 161 156 } 162 157 case ToLocaleString: /* TODO */ 163 result = String(v.toString(exec)); 164 break; 158 return String(v->toString(exec)); 165 159 case ValueOf: 166 result = Number(v.toNumber(exec)); 167 break; 160 return Number(v->toNumber(exec)); 168 161 case ToFixed: 169 162 { 170 Value 171 double df = fractionDigits .toInteger(exec);163 ValueImp *fractionDigits = args[0]; 164 double df = fractionDigits->toInteger(exec); 172 165 if (!(df >= 0 && df <= 20)) { // true for NaN 173 Object 166 ObjectImp *err = Error::create(exec, RangeError, 174 167 "toFixed() digits argument must be between 0 and 20"); 175 168 … … 179 172 int f = (int)df; 180 173 181 double x = v .toNumber(exec);174 double x = v->toNumber(exec); 182 175 if (isNaN(x)) 183 176 return String("NaN"); … … 213 206 } 214 207 case ToExponential: { 215 double x = v .toNumber(exec);208 double x = v->toNumber(exec); 216 209 217 210 if (isNaN(x) || isInf(x)) 218 211 return String(UString::from(x)); 219 212 220 Value 221 double df = fractionDigits .toInteger(exec);213 ValueImp *fractionDigits = args[0]; 214 double df = fractionDigits->toInteger(exec); 222 215 if (!(df >= 0 && df <= 20)) { // true for NaN 223 Object 216 ObjectImp *err = Error::create(exec, RangeError, 224 217 "toExponential() argument must between 0 and 20"); 225 218 exec->setException(err); … … 229 222 230 223 int decimalAdjust = 0; 231 if (!fractionDigits .isA(UndefinedType)) {224 if (!fractionDigits->isUndefined()) { 232 225 double logx = floor(log10(x)); 233 226 x /= pow(10,logx); … … 264 257 buf[i++] = result[0]; 265 258 266 if (fractionDigits .isA(UndefinedType))259 if (fractionDigits->isUndefined()) 267 260 f = length-1; 268 261 … … 311 304 UString m; 312 305 313 double dp = args[0] .toInteger(exec);314 double x = v .toNumber(exec);306 double dp = args[0]->toInteger(exec); 307 double x = v->toNumber(exec); 315 308 if (isNaN(dp) || isNaN(x) || isInf(x)) 316 return String(v .toString(exec));309 return String(v->toString(exec)); 317 310 318 311 UString s = ""; … … 323 316 324 317 if (dp < 1 || dp > 21) { 325 Object 318 ObjectImp *err = Error::create(exec, RangeError, 326 319 "toPrecision() argument must be between 1 and 21"); 327 320 exec->setException(err); … … 373 366 374 367 } 375 return result;368 return NULL; 376 369 } 377 370 … … 395 388 : InternalFunctionImp(funcProto) 396 389 { 397 Value protect(this);398 390 // Number.Prototype 399 391 putDirect(prototypePropertyName, numberProto,DontEnum|DontDelete|ReadOnly); 400 392 401 393 // no. of arguments for constructor 402 putDirect(lengthPropertyName, NumberImp::one(), ReadOnly|DontDelete|DontEnum);394 putDirect(lengthPropertyName, jsOne(), ReadOnly|DontDelete|DontEnum); 403 395 } 404 396 … … 408 400 } 409 401 410 Value 402 ValueImp *NumberObjectImp::getValueProperty(ExecState *, int token) const 411 403 { 412 404 // ECMA 15.7.3 413 405 switch(token) { 414 406 case NaNValue: 415 return Number(NaN);407 return jsNaN(); 416 408 case NegInfinity: 417 409 return Number(-Inf); … … 433 425 434 426 // ECMA 15.7.1 435 Object 436 { 437 ObjectImp *proto = exec->lexicalInterpreter()->builtinNumberPrototype() .imp();438 Object 439 440 Numbern;427 ObjectImp *NumberObjectImp::construct(ExecState *exec, const List &args) 428 { 429 ObjectImp *proto = exec->lexicalInterpreter()->builtinNumberPrototype(); 430 ObjectImp *obj(new NumberInstanceImp(proto)); 431 432 double n; 441 433 if (args.isEmpty()) 442 n = Number(0);434 n = 0; 443 435 else 444 n = args[0] .toNumber(exec);445 446 obj .setInternalValue(n);436 n = args[0]->toNumber(exec); 437 438 obj->setInternalValue(jsNumber(n)); 447 439 448 440 return obj; … … 455 447 456 448 // ECMA 15.7.2 457 Value NumberObjectImp::call(ExecState *exec, Object &/*thisObj*/, const List &args)449 ValueImp *NumberObjectImp::callAsFunction(ExecState *exec, ObjectImp */*thisObj*/, const List &args) 458 450 { 459 451 if (args.isEmpty()) 460 452 return Number(0); 461 453 else 462 return Number(args[0] .toNumber(exec));463 } 454 return Number(args[0]->toNumber(exec)); 455 } -
trunk/JavaScriptCore/kjs/number_object.h
r10076 r10084 61 61 62 62 virtual bool implementsCall() const; 63 virtual Value call(ExecState *exec, Object &thisObj, const List &args);63 virtual ValueImp *callAsFunction(ExecState *exec, ObjectImp *thisObj, const List &args); 64 64 65 65 enum { ToString, ToLocaleString, ValueOf, ToFixed, ToExponential, ToPrecision }; … … 80 80 81 81 virtual bool implementsConstruct() const; 82 virtual Object 82 virtual ObjectImp *construct(ExecState *exec, const List &args); 83 83 84 84 virtual bool implementsCall() const; 85 virtual Value call(ExecState *exec, Object &thisObj, const List &args);85 virtual ValueImp *callAsFunction(ExecState *exec, ObjectImp *thisObj, const List &args); 86 86 87 87 bool getOwnPropertySlot(ExecState *, const Identifier&, PropertySlot&); 88 Value getValueProperty(ExecState *exec, int token) const; 88 ValueImp *getValueProperty(ExecState *exec, int token) const; 89 89 90 virtual const ClassInfo *classInfo() const { return &info; } 90 91 static const ClassInfo info; … … 92 93 93 94 Completion execute(const List &); 94 Object 95 ObjectImp *construct(const List &); 95 96 }; 96 97 -
trunk/JavaScriptCore/kjs/object.cpp
r10076 r10084 41 41 42 42 #ifndef NDEBUG 43 #define JAVASCRIPT_CALL_TRACING Yes 44 #endif 45 46 #if defJAVASCRIPT_CALL_TRACING43 //#define JAVASCRIPT_CALL_TRACING 1 44 #endif 45 46 #if JAVASCRIPT_CALL_TRACING 47 47 static bool _traceJavaScript = false; 48 48 … … 64 64 // ------------------------------ Object --------------------------------------- 65 65 66 Object Object::dynamicCast(const Value &v) 67 { 68 if (v.isNull() || v.type() != ObjectType) 69 return Object(0); 70 71 return Object(static_cast<ObjectImp*>(v.imp())); 72 } 73 74 75 Value Object::call(ExecState *exec, Object &thisObj, const List &args) 76 { 66 ValueImp *ObjectImp::call(ExecState *exec, ObjectImp *thisObj, const List &args) 67 { 68 assert(implementsCall()); 69 77 70 #if KJS_MAX_STACK > 0 78 71 static int depth = 0; // sum of all concurrent interpreters 79 72 80 #if defJAVASCRIPT_CALL_TRACING73 #if JAVASCRIPT_CALL_TRACING 81 74 static bool tracing = false; 82 75 if (traceJavaScript() && !tracing) { … … 88 81 for (int i = 0; i < depth; i++) 89 82 putchar (' '); 90 printf ("*** arg[%d] = %s\n", j, args[j] .toString(exec).ascii());83 printf ("*** arg[%d] = %s\n", j, args[j]->toString(exec).ascii()); 91 84 } 92 85 tracing = false; … … 96 89 if (++depth > KJS_MAX_STACK) { 97 90 --depth; 98 Object 91 ObjectImp *err = Error::create(exec, RangeError, 99 92 "Maximum call stack size exceeded."); 100 93 exec->setException(err); … … 103 96 #endif 104 97 105 Value ret = imp()->call(exec,thisObj,args);98 ValueImp *ret = callAsFunction(exec,thisObj,args); 106 99 107 100 #if KJS_MAX_STACK > 0 … … 109 102 #endif 110 103 111 #if defJAVASCRIPT_CALL_TRACING104 #if JAVASCRIPT_CALL_TRACING 112 105 if (traceJavaScript() && !tracing) { 113 106 tracing = true; 114 107 for (int i = 0; i < depth; i++) 115 108 putchar (' '); 116 printf ("*** returning: %s\n", ret .toString(exec).ascii());109 printf ("*** returning: %s\n", ret->toString(exec).ascii()); 117 110 tracing = false; 118 111 } … … 124 117 // ------------------------------ ObjectImp ------------------------------------ 125 118 126 ObjectImp::ObjectImp(const Object &proto)127 : _proto(static_cast<ObjectImp*>(proto.imp())), _internalValue(0L)128 {129 //fprintf(stderr,"ObjectImp::ObjectImp %p\n",(void*)this);130 }131 132 ObjectImp::ObjectImp(ObjectImp *proto)133 : _proto(proto), _internalValue(0L)134 {135 //fprintf(stderr,"ObjectImp::ObjectImp %p\n",(void*)this);136 }137 138 ObjectImp::ObjectImp()139 {140 //fprintf(stderr,"ObjectImp::ObjectImp %p\n",(void*)this);141 _proto = NullImp::staticNull;142 _internalValue = 0L;143 }144 145 ObjectImp::~ObjectImp()146 {147 //fprintf(stderr,"ObjectImp::~ObjectImp %p\n",(void*)this);148 }149 150 119 void ObjectImp::mark() 151 120 { 152 //fprintf(stderr,"ObjectImp::mark() %p\n",(void*)this);153 ValueImp::mark(); 154 155 if ( _proto && !_proto->marked())156 _proto->mark();121 AllocatedValueImp::mark(); 122 123 ValueImp *proto = _proto; 124 if (!proto->marked()) 125 proto->mark(); 157 126 158 127 _prop.mark(); … … 164 133 } 165 134 135 Type ObjectImp::type() const 136 { 137 return ObjectType; 138 } 139 166 140 const ClassInfo *ObjectImp::classInfo() const 167 141 { 168 142 return 0; 169 }170 171 bool ObjectImp::inherits(const ClassInfo *info) const172 {173 if (!info)174 return false;175 176 const ClassInfo *ci = classInfo();177 if (!ci)178 return false;179 180 while (ci && ci != info)181 ci = ci->parentClass;182 183 return (ci == info);184 }185 186 Type ObjectImp::type() const187 {188 return ObjectType;189 }190 191 Value ObjectImp::prototype() const192 {193 return Value(_proto);194 }195 196 void ObjectImp::setPrototype(const Value &proto)197 {198 _proto = proto.imp();199 143 } 200 144 … … 207 151 } 208 152 209 Value 153 ValueImp *ObjectImp::get(ExecState *exec, const Identifier &propertyName) const 210 154 { 211 155 PropertySlot slot; … … 217 161 } 218 162 219 Value 163 ValueImp *ObjectImp::get(ExecState *exec, unsigned propertyName) const 220 164 { 221 165 PropertySlot slot; … … 226 170 } 227 171 228 bool ObjectImp::getProperty(ExecState *exec, const Identifier& propertyName, Value & result) const172 bool ObjectImp::getProperty(ExecState *exec, const Identifier& propertyName, ValueImp*& result) const 229 173 { 230 174 PropertySlot slot; … … 237 181 } 238 182 239 bool ObjectImp::getProperty(ExecState *exec, unsigned propertyName, Value & result) const183 bool ObjectImp::getProperty(ExecState *exec, unsigned propertyName, ValueImp*& result) const 240 184 { 241 185 PropertySlot slot; … … 257 201 258 202 ValueImp *proto = imp->_proto; 259 if ( proto->dispatchType() != ObjectType)203 if (!proto->isObject()) 260 204 break; 261 205 … … 272 216 273 217 // ECMA 8.6.2.2 274 void ObjectImp::put(ExecState *exec, const Identifier &propertyName, 275 const Value &value, int attr) 276 { 277 assert(!value.isNull()); 218 void ObjectImp::put(ExecState *exec, const Identifier &propertyName, ValueImp *value, int attr) 219 { 220 assert(value); 278 221 279 222 // non-standard netscape extension … … 295 238 } 296 239 297 _prop.put(propertyName,value .imp(),attr);240 _prop.put(propertyName,value,attr); 298 241 } 299 242 300 243 void ObjectImp::put(ExecState *exec, unsigned propertyName, 301 const Value &value, int attr)244 ValueImp *value, int attr) 302 245 { 303 246 put(exec, Identifier::from(propertyName), value, attr); … … 336 279 337 280 bool ObjectImp::hasOwnProperty(ExecState *exec, const Identifier &propertyName) const 281 { 282 PropertySlot slot; 283 return const_cast<ObjectImp *>(this)->getOwnPropertySlot(exec, propertyName, slot); 284 } 285 286 bool ObjectImp::hasOwnProperty(ExecState *exec, unsigned propertyName) const 338 287 { 339 288 PropertySlot slot; … … 371 320 372 321 // ECMA 8.6.2.6 373 Value 322 ValueImp *ObjectImp::defaultValue(ExecState *exec, Type hint) const 374 323 { 375 324 if (hint != StringType && hint != NumberType) { 376 325 /* Prefer String for Date objects */ 377 if (_proto == exec->lexicalInterpreter()->builtinDatePrototype() .imp())326 if (_proto == exec->lexicalInterpreter()->builtinDatePrototype()) 378 327 hint = StringType; 379 328 else … … 381 330 } 382 331 383 Value 332 ValueImp *v; 384 333 if (hint == StringType) 385 334 v = get(exec,toStringPropertyName); … … 387 336 v = get(exec,valueOfPropertyName); 388 337 389 if (v .type() == ObjectType) {390 Object o = Object(static_cast<ObjectImp*>(v.imp()));391 if (o .implementsCall()) { // spec says "not primitive type" but ...392 Object thisObj = Object(const_cast<ObjectImp*>(this));393 Value def = o.call(exec,thisObj,List::empty());394 Type defType = def .type();338 if (v->isObject()) { 339 ObjectImp *o = static_cast<ObjectImp*>(v); 340 if (o->implementsCall()) { // spec says "not primitive type" but ... 341 ObjectImp *thisObj = const_cast<ObjectImp*>(this); 342 ValueImp *def = o->call(exec,thisObj,List::empty()); 343 Type defType = def->type(); 395 344 if (defType == UnspecifiedType || defType == UndefinedType || 396 345 defType == NullType || defType == BooleanType || … … 406 355 v = get(exec,toStringPropertyName); 407 356 408 if (v .type() == ObjectType) {409 Object o = Object(static_cast<ObjectImp*>(v.imp()));410 if (o .implementsCall()) { // spec says "not primitive type" but ...411 Object thisObj = Object(const_cast<ObjectImp*>(this));412 Value def = o.call(exec,thisObj,List::empty());413 Type defType = def .type();357 if (v->isObject()) { 358 ObjectImp *o = static_cast<ObjectImp*>(v); 359 if (o->implementsCall()) { // spec says "not primitive type" but ... 360 ObjectImp *thisObj = const_cast<ObjectImp*>(this); 361 ValueImp *def = o->call(exec,thisObj,List::empty()); 362 Type defType = def->type(); 414 363 if (defType == UnspecifiedType || defType == UndefinedType || 415 364 defType == NullType || defType == BooleanType || … … 423 372 return exec->exception(); 424 373 425 Object 374 ObjectImp *err = Error::create(exec, TypeError, I18N_NOOP("No default value")); 426 375 exec->setException(err); 427 376 return err; 428 377 } 429 378 430 const HashEntry* ObjectImp::findPropertyHashEntry( const Identifier& propertyName ) const 431 { 432 const ClassInfo *info = classInfo(); 433 while (info) { 434 if (info->propHashTable) { 435 const HashEntry *e = Lookup::findEntry(info->propHashTable, propertyName); 436 if (e) 379 const HashEntry* ObjectImp::findPropertyHashEntry(const Identifier& propertyName) const 380 { 381 for (const ClassInfo *info = classInfo(); info; info = info->parentClass) { 382 if (const HashTable *propHashTable = info->propHashTable) { 383 if (const HashEntry *e = Lookup::findEntry(propHashTable, propertyName)) 437 384 return e; 438 385 } 439 info = info->parentClass; 440 } 441 return 0L; 386 } 387 return 0; 442 388 } 443 389 … … 447 393 } 448 394 449 Object 395 ObjectImp *ObjectImp::construct(ExecState */*exec*/, const List &/*args*/) 450 396 { 451 397 assert(false); 452 return Object(0);453 } 454 455 Object 398 return NULL; 399 } 400 401 ObjectImp *ObjectImp::construct(ExecState *exec, const List &args, const UString &/*sourceURL*/, int /*lineNumber*/) 456 402 { 457 403 return construct(exec, args); … … 463 409 } 464 410 465 Value ObjectImp::call(ExecState */*exec*/, Object &/*thisObj*/, const List &/*args*/)411 ValueImp *ObjectImp::callAsFunction(ExecState */*exec*/, ObjectImp */*thisObj*/, const List &/*args*/) 466 412 { 467 413 assert(false); 468 return Object(0);414 return NULL; 469 415 } 470 416 … … 474 420 } 475 421 476 Boolean ObjectImp::hasInstance(ExecState */*exec*/, const Value &/*value*/)422 bool ObjectImp::hasInstance(ExecState */*exec*/, ValueImp */*value*/) 477 423 { 478 424 assert(false); 479 return Boolean(false);425 return false; 480 426 } 481 427 … … 483 429 { 484 430 ReferenceList list; 485 if (_proto && _proto->dispatchType() == ObjectType&& recursive)431 if (_proto->isObject() && recursive) 486 432 list = static_cast<ObjectImp*>(_proto)->propList(exec,recursive); 487 433 488 _prop.addEnumerablesToReferenceList(list, Object(this));434 _prop.addEnumerablesToReferenceList(list, this); 489 435 490 436 // Add properties from the static hashtable of properties … … 505 451 } 506 452 507 Value ObjectImp::internalValue() const 508 { 509 return Value(_internalValue); 510 } 511 512 void ObjectImp::setInternalValue(const Value &v) 513 { 514 _internalValue = v.imp(); 515 } 516 517 void ObjectImp::setInternalValue(ValueImp *v) 518 { 519 _internalValue = v; 520 } 521 522 Value ObjectImp::toPrimitive(ExecState *exec, Type preferredType) const 453 ValueImp *ObjectImp::toPrimitive(ExecState *exec, Type preferredType) const 523 454 { 524 455 return defaultValue(exec,preferredType); … … 532 463 double ObjectImp::toNumber(ExecState *exec) const 533 464 { 534 Value 465 ValueImp *prim = toPrimitive(exec,NumberType); 535 466 if (exec->hadException()) // should be picked up soon in nodes.cpp 536 467 return 0.0; 537 return prim .toNumber(exec);468 return prim->toNumber(exec); 538 469 } 539 470 540 471 UString ObjectImp::toString(ExecState *exec) const 541 472 { 542 Value 473 ValueImp *prim = toPrimitive(exec,StringType); 543 474 if (exec->hadException()) // should be picked up soon in nodes.cpp 544 475 return ""; 545 return prim .toString(exec);546 } 547 548 Object 549 { 550 return Object(const_cast<ObjectImp*>(this));476 return prim->toString(exec); 477 } 478 479 ObjectImp *ObjectImp::toObject(ExecState */*exec*/) const 480 { 481 return const_cast<ObjectImp*>(this); 551 482 } 552 483 … … 558 489 void ObjectImp::putDirect(const Identifier &propertyName, int value, int attr) 559 490 { 560 _prop.put(propertyName, NumberImp::create(value), attr);491 _prop.put(propertyName, jsNumber(value), attr); 561 492 } 562 493 … … 575 506 const char * const * const Error::errorNames = errorNamesArr; 576 507 577 Object 508 ObjectImp *Error::create(ExecState *exec, ErrorType errtype, const char *message, 578 509 int lineno, int sourceId, const UString *sourceURL) 579 510 { 580 Object 511 ObjectImp *cons; 581 512 switch (errtype) { 582 513 case EvalError: … … 607 538 List args; 608 539 args.append(String(message)); 609 Object err = Object::dynamicCast(cons.construct(exec,args));540 ObjectImp *err = static_cast<ObjectImp *>(cons->construct(exec,args)); 610 541 611 542 if (lineno != -1) 612 err .put(exec, "line", Number(lineno));543 err->put(exec, "line", Number(lineno)); 613 544 if (sourceId != -1) 614 err .put(exec, "sourceId", Number(sourceId));545 err->put(exec, "sourceId", Number(sourceId)); 615 546 616 547 if(sourceURL) 617 err .put(exec,"sourceURL", String(*sourceURL));548 err->put(exec,"sourceURL", String(*sourceURL)); 618 549 619 550 return err; … … 621 552 /* 622 553 #ifndef NDEBUG 623 const char *msg = err .get("message").toString().value().ascii();554 const char *msg = err->get("message")->toString().value().ascii(); 624 555 if (l >= 0) 625 556 fprintf(stderr, "KJS: %s at line %d. %s\n", estr, l, msg); … … 634 565 ObjectImp *error(ExecState *exec, ErrorType type, const char *message, int line, int sourceId, const UString *sourceURL) 635 566 { 636 return Error::create(exec, type, message, line, sourceId, sourceURL) .imp();567 return Error::create(exec, type, message, line, sourceId, sourceURL); 637 568 } 638 569 -
trunk/JavaScriptCore/kjs/object.h
r10076 r10084 23 23 */ 24 24 25 26 #ifndef _KJS_OBJECT_H_ 27 #define _KJS_OBJECT_H_ 25 #ifndef KJS_OBJECT_H 26 #define KJS_OBJECT_H 28 27 29 28 // Objects … … 39 38 #endif 40 39 41 #include "types.h"42 40 #include "interpreter.h" 43 #include "reference_list.h"44 41 #include "property_map.h" 45 42 #include "property_slot.h" … … 51 48 class HashEntry; 52 49 class ListImp; 50 51 // ECMA 262-3 8.6.1 52 // Property attributes 53 enum Attribute { None = 0, 54 ReadOnly = 1 << 1, // property can be only read, not written 55 DontEnum = 1 << 2, // property doesn't appear in (for .. in ..) 56 DontDelete = 1 << 3, // property can't be deleted 57 Internal = 1 << 4, // an internal property, set to bypass checks 58 Function = 1 << 5 }; // property is a function - only used by static hashtables 53 59 54 60 /** … … 75 81 }; 76 82 77 inline Object Value::toObject(ExecState *exec) const { return rep->dispatchToObject(exec); } 78 79 class ObjectImp : public ValueImp { 83 class ObjectImp : public AllocatedValueImp { 80 84 public: 81 85 /** … … 84 88 * @param proto The prototype 85 89 */ 86 ObjectImp(const Object &proto);87 90 ObjectImp(ObjectImp *proto); 88 91 89 92 /** 90 93 * Creates a new ObjectImp with a prototype of Null() 91 * (that is, the ECMAScript "null" value, not a null Object).94 * (that is, the ECMAScript "null" value, not a null object pointer). 92 95 * 93 96 */ 94 97 ObjectImp(); 95 96 virtual ~ObjectImp();97 98 98 99 virtual void mark(); … … 170 171 171 172 /** 173 * Returns the prototype of this object. Note that this is not the same as 174 * the "prototype" property. 175 * 176 * See ECMA 8.6.2 177 * 178 * @return The object's prototype 179 */ 180 /** 172 181 * Implementation of the [[Prototype]] internal property (implemented by 173 182 * all Objects) 174 * 175 * @see Object::prototype() 176 */ 177 Value prototype() const; 178 void setPrototype(const Value &proto); 179 183 */ 184 ValueImp *prototype() const; 185 void setPrototype(ValueImp *proto); 186 187 /** 188 * Returns the class name of the object 189 * 190 * See ECMA 8.6.2 191 * 192 * @return The object's class name 193 */ 180 194 /** 181 195 * Implementation of the [[Class]] internal property (implemented by all … … 186 200 * if you simply need a classname, you can reimplement className() 187 201 * instead. 188 *189 * @see Object::className()190 202 */ 191 203 virtual UString className() const; 192 204 205 /** 206 * Retrieves the specified property from the object. If neither the object 207 * or any other object in it's prototype chain have the property, this 208 * function will return Undefined. 209 * 210 * See ECMA 8.6.2.1 211 * 212 * @param exec The current execution state 213 * @param propertyName The name of the property to retrieve 214 * 215 * @return The specified property, or Undefined 216 */ 193 217 /** 194 218 * Implementation of the [[Get]] internal property (implemented by all 195 219 * Objects) 196 *197 * @see Object::get()198 220 */ 199 221 // [[Get]] - must be implemented by all Objects 200 Value 201 Value 202 203 bool getProperty(ExecState *exec, const Identifier& propertyName, Value & result) const;204 bool getProperty(ExecState *exec, unsigned propertyName, Value & result) const;222 ValueImp *get(ExecState *exec, const Identifier &propertyName) const; 223 ValueImp *get(ExecState *exec, unsigned propertyName) const; 224 225 bool getProperty(ExecState *exec, const Identifier& propertyName, ValueImp*& result) const; 226 bool getProperty(ExecState *exec, unsigned propertyName, ValueImp*& result) const; 205 227 206 228 bool getPropertySlot(ExecState *, const Identifier&, PropertySlot&); 207 229 bool getPropertySlot(ExecState *, unsigned, PropertySlot&); 230 208 231 virtual bool getOwnPropertySlot(ExecState *, const Identifier&, PropertySlot&); 209 232 virtual bool getOwnPropertySlot(ExecState *, unsigned index, PropertySlot&); 210 233 211 234 /** 235 * Sets the specified property. 236 * 237 * See ECMA 8.6.2.2 238 * 239 * @param exec The current execution state 240 * @param propertyName The name of the property to set 241 * @param propertyValue The value to set 242 */ 243 /** 212 244 * Implementation of the [[Put]] internal property (implemented by all 213 245 * Objects) 214 *215 * @see Object::put()216 246 */ 217 247 virtual void put(ExecState *exec, const Identifier &propertyName, 218 const Value &value, int attr = None);248 ValueImp *value, int attr = None); 219 249 virtual void put(ExecState *exec, unsigned propertyName, 220 const Value &value, int attr = None); 221 250 ValueImp *value, int attr = None); 251 252 /** 253 * Used to check whether or not a particular property is allowed to be set 254 * on an object 255 * 256 * See ECMA 8.6.2.3 257 * 258 * @param exec The current execution state 259 * @param propertyName The name of the property 260 * @return true if the property can be set, otherwise false 261 */ 222 262 /** 223 263 * Implementation of the [[CanPut]] internal property (implemented by all 224 264 * Objects) 225 *226 * @see Object::canPut()227 265 */ 228 266 virtual bool canPut(ExecState *exec, const Identifier &propertyName) const; 229 267 268 /** 269 * Checks to see whether the object (or any object in it's prototype chain) 270 * has a property with the specified name. 271 * 272 * See ECMA 8.6.2.4 273 * 274 * @param exec The current execution state 275 * @param propertyName The name of the property to check for 276 * @return true if the object has the property, otherwise false 277 */ 230 278 /** 231 279 * Implementation of the [[HasProperty]] internal property (implemented by 232 280 * all Objects) 233 * 234 * @see Object::hasProperty() 235 */ 236 bool hasProperty(ExecState *exec, const Identifier &propertyName) const; 281 */ 282 bool hasProperty(ExecState *exec, 283 const Identifier &propertyName) const; 237 284 bool hasProperty(ExecState *exec, unsigned propertyName) const; 238 285 286 /** 287 * Checks to see whether the object has a property with the specified name. 288 * 289 * See ECMA 15.2.4.5 290 * 291 * @param exec The current execution state 292 * @param propertyName The name of the property to check for 293 * @return true if the object has the property, otherwise false 294 */ 239 295 virtual bool hasOwnProperty(ExecState *exec, const Identifier &propertyName) const; 240 296 virtual bool hasOwnProperty(ExecState *exec, unsigned propertyName) const; 297 298 /** 299 * Removes the specified property from the object. 300 * 301 * See ECMA 8.6.2.5 302 * 303 * @param exec The current execution state 304 * @param propertyName The name of the property to delete 305 * @return true if the property was successfully deleted or did not 306 * exist on the object. false if deleting the specified property is not 307 * allowed. 308 */ 241 309 /** 242 310 * Implementation of the [[Delete]] internal property (implemented by all 243 311 * Objects) 244 *245 * @see Object::deleteProperty()246 312 */ 247 313 virtual bool deleteProperty(ExecState *exec, … … 257 323 258 324 /** 325 * Converts the object into a primitive value. The value return may differ 326 * depending on the supplied hint 327 * 328 * See ECMA 8.6.2.6 329 * 330 * @param exec The current execution state 331 * @param hint The desired primitive type to convert to 332 * @return A primitive value converted from the objetc. Note that the 333 * type of primitive value returned may not be the same as the requested 334 * hint. 335 */ 336 /** 259 337 * Implementation of the [[DefaultValue]] internal property (implemented by 260 338 * all Objects) 261 * 262 * @see Object::defaultValue() 263 */ 264 virtual Value defaultValue(ExecState *exec, Type hint) const; 265 339 */ 340 virtual ValueImp *defaultValue(ExecState *exec, Type hint) const; 341 342 /** 343 * Whether or not the object implements the construct() method. If this 344 * returns false you should not call the construct() method on this 345 * object (typically, an assertion will fail to indicate this). 346 * 347 * @return true if this object implements the construct() method, otherwise 348 * false 349 */ 266 350 virtual bool implementsConstruct() const; 351 352 /** 353 * Creates a new object based on this object. Typically this means the 354 * following: 355 * 1. A new object is created 356 * 2. The prototype of the new object is set to the value of this object's 357 * "prototype" property 358 * 3. The call() method of this object is called, with the new object 359 * passed as the this value 360 * 4. The new object is returned 361 * 362 * In some cases, Host objects may differ from these semantics, although 363 * this is discouraged. 364 * 365 * If an error occurs during construction, the execution state's exception 366 * will be set. This can be tested for with ExecState::hadException(). 367 * Under some circumstances, the exception object may also be returned. 368 * 369 * Note: This function should not be called if implementsConstruct() returns 370 * false, in which case it will result in an assertion failure. 371 * 372 * @param exec The current execution state 373 * @param args The arguments to be passed to call() once the new object has 374 * been created 375 * @return The newly created & initialized object 376 */ 267 377 /** 268 378 * Implementation of the [[Construct]] internal property 269 * 270 * @see Object::construct() 271 */ 272 virtual Object construct(ExecState *exec, const List &args); 273 virtual Object construct(ExecState *exec, const List &args, const UString &sourceURL, int lineNumber); 274 379 */ 380 virtual ObjectImp *construct(ExecState *exec, const List &args); 381 virtual ObjectImp *construct(ExecState *exec, const List &args, const UString &sourceURL, int lineNumber); 382 383 /** 384 * Whether or not the object implements the call() method. If this returns 385 * false you should not call the call() method on this object (typically, 386 * an assertion will fail to indicate this). 387 * 388 * @return true if this object implements the call() method, otherwise 389 * false 390 */ 275 391 virtual bool implementsCall() const; 392 393 /** 394 * Calls this object as if it is a function. 395 * 396 * Note: This function should not be called if implementsCall() returns 397 * false, in which case it will result in an assertion failure. 398 * 399 * See ECMA 8.6.2.3 400 * 401 * @param exec The current execution state 402 * @param thisObj The obj to be used as "this" within function execution. 403 * Note that in most cases this will be different from the C++ "this" 404 * object. For example, if the ECMAScript code "window.location->toString()" 405 * is executed, call() will be invoked on the C++ object which implements 406 * the toString method, with the thisObj being window.location 407 * @param args List of arguments to be passed to the function 408 * @return The return value from the function 409 */ 276 410 /** 277 411 * Implementation of the [[Call]] internal property 278 * 279 * @see Object::call() 280 */ 281 virtual Value call(ExecState *exec, Object &thisObj, 282 const List &args); 283 412 */ 413 ValueImp *call(ExecState *exec, ObjectImp *thisObj, const List &args); 414 virtual ValueImp *callAsFunction(ExecState *exec, ObjectImp *thisObj, const List &args); 415 416 /** 417 * Whether or not the object implements the hasInstance() method. If this 418 * returns false you should not call the hasInstance() method on this 419 * object (typically, an assertion will fail to indicate this). 420 * 421 * @return true if this object implements the hasInstance() method, 422 * otherwise false 423 */ 284 424 virtual bool implementsHasInstance() const; 425 426 /** 427 * Checks whether value delegates behavior to this object. Used by the 428 * instanceof operator. 429 * 430 * @param exec The current execution state 431 * @param value The value to check 432 * @return true if value delegates behavior to this object, otherwise 433 * false 434 */ 285 435 /** 286 436 * Implementation of the [[HasInstance]] internal property 287 * 288 * @see Object::hasInstance() 289 */ 290 virtual Boolean hasInstance(ExecState *exec, const Value &value); 291 437 */ 438 virtual bool hasInstance(ExecState *exec, ValueImp *value); 439 440 /** 441 * Returns the scope of this object. This is used when execution declared 442 * functions - the execution context for the function is initialized with 443 * extra object in it's scope. An example of this is functions declared 444 * inside other functions: 445 * 446 * \code 447 * function f() { 448 * 449 * function b() { 450 * return prototype; 451 * } 452 * 453 * var x = 4; 454 * // do some stuff 455 * } 456 * f.prototype = new String(); 457 * \endcode 458 * 459 * When the function f.b is executed, its scope will include properties of 460 * f. So in the example above the return value of f.b() would be the new 461 * String object that was assigned to f.prototype. 462 * 463 * @param exec The current execution state 464 * @return The function's scope 465 */ 292 466 /** 293 467 * Implementation of the [[Scope]] internal property 294 *295 * @see Object::scope()296 468 */ 297 469 const ScopeChain &scope() const { return _scope; } 298 470 void setScope(const ScopeChain &s) { _scope = s; } 299 471 472 /** 473 * Returns a List of References to all the properties of the object. Used 474 * in "for x in y" statements. The list is created new, so it can be freely 475 * modified without affecting the object's properties. It should be deleted 476 * by the caller. 477 * 478 * Subclasses can override this method in ObjectImpl to provide the 479 * appearance of 480 * having extra properties other than those set specifically with put(). 481 * 482 * @param exec The current execution state 483 * @param recursive Whether or not properties in the object's prototype 484 * chain should be 485 * included in the list. 486 * @return A List of References to properties of the object. 487 **/ 300 488 virtual ReferenceList propList(ExecState *exec, bool recursive = true); 301 489 302 Value internalValue() const; 303 void setInternalValue(const Value &v); 490 /** 491 * Returns the internal value of the object. This is used for objects such 492 * as String and Boolean which are wrappers for native types. The interal 493 * value is the actual value represented by the wrapper objects. 494 * 495 * @see ECMA 8.6.2 496 * @return The internal value of the object 497 */ 498 ValueImp *internalValue() const; 499 500 /** 501 * Sets the internal value of the object 502 * 503 * @see internalValue() 504 * 505 * @param v The new internal value 506 */ 507 304 508 void setInternalValue(ValueImp *v); 305 509 306 Value toPrimitive(ExecState *exec, 307 Type preferredType = UnspecifiedType) const; 510 ValueImp *toPrimitive(ExecState *exec, Type preferredType = UnspecifiedType) const; 308 511 bool toBoolean(ExecState *exec) const; 309 512 double toNumber(ExecState *exec) const; 310 513 UString toString(ExecState *exec) const; 311 Object 514 ObjectImp *toObject(ExecState *exec) const; 312 515 313 516 // This get method only looks at the property map. … … 345 548 346 549 ValueImp *proto = imp->_proto; 347 if ( proto->dispatchType() != ObjectType)550 if (!proto->isObject()) 348 551 break; 349 552 … … 403 606 * @param lineno Optional source id. 404 607 */ 405 static Object 406 const char *message = 0, int lineno = -1,407 int sourceId = -1, const UString *sourceURL = 0);608 static ObjectImp *create(ExecState *exec, ErrorType errtype = GeneralError, 609 const char *message = 0, int lineno = -1, 610 int sourceId = -1, const UString *sourceURL = 0); 408 611 409 612 /** … … 413 616 }; 414 617 415 inline bool ValueImp::isObject(const ClassInfo *info) const 416 { return isObject() && static_cast<const ObjectImp *>(this)->inherits(info); } 417 418 inline ObjectImp *ValueImp::asObject() 419 { return isObject() ? static_cast<ObjectImp *>(this) : 0; } 420 421 inline Object::Object(ObjectImp *o) : Value(o) { } 422 423 inline ObjectImp *Object::imp() const 424 { return static_cast<ObjectImp *>(Value::imp()); } 425 426 inline const ClassInfo *Object::classInfo() const 427 { return imp()->classInfo(); } 428 429 inline bool Object::inherits(const ClassInfo *cinfo) const 430 { return imp()->inherits(cinfo); } 431 432 inline Value Object::prototype() const 433 { return Value(imp()->prototype()); } 434 435 inline UString Object::className() const 436 { return imp()->className(); } 437 438 inline Value Object::get(ExecState *exec, const Identifier &propertyName) const 439 { return imp()->get(exec,propertyName); } 440 441 inline Value Object::get(ExecState *exec, unsigned propertyName) const 442 { return imp()->get(exec,propertyName); } 443 444 inline void Object::put(ExecState *exec, const Identifier &propertyName, const Value &value, int attr) 445 { imp()->put(exec,propertyName,value,attr); } 446 447 inline void Object::put(ExecState *exec, unsigned propertyName, const Value &value, int attr) 448 { imp()->put(exec,propertyName,value,attr); } 449 450 inline bool Object::canPut(ExecState *exec, const Identifier &propertyName) const 451 { return imp()->canPut(exec,propertyName); } 452 453 inline bool Object::hasProperty(ExecState *exec, const Identifier &propertyName) const 454 { return imp()->hasProperty(exec, propertyName); } 455 456 inline bool Object::hasOwnProperty(ExecState *exec, const Identifier &propertyName) const 457 { return imp()->hasOwnProperty(exec, propertyName); } 458 459 inline bool Object::deleteProperty(ExecState *exec, const Identifier &propertyName) 460 { return imp()->deleteProperty(exec,propertyName); } 461 462 inline bool Object::deleteProperty(ExecState *exec, unsigned propertyName) 463 { return imp()->deleteProperty(exec,propertyName); } 464 465 inline Value Object::defaultValue(ExecState *exec, Type hint) const 466 { return imp()->defaultValue(exec,hint); } 467 468 inline bool Object::implementsConstruct() const 469 { return imp()->implementsConstruct(); } 470 471 inline Object Object::construct(ExecState *exec, const List &args) 472 { return imp()->construct(exec,args); } 473 474 inline Object Object::construct(ExecState *exec, const List &args, const UString &sourceURL, int lineNumber) 475 { return imp()->construct(exec,args,sourceURL,lineNumber); } 476 477 inline bool Object::implementsCall() const 478 { return imp()->implementsCall(); } 479 480 inline bool Object::implementsHasInstance() const 481 { return imp()->implementsHasInstance(); } 482 483 inline Boolean Object::hasInstance(ExecState *exec, const Value &value) 484 { return imp()->hasInstance(exec,value); } 485 486 inline const ScopeChain &Object::scope() const 487 { return imp()->scope(); } 488 489 inline void Object::setScope(const ScopeChain &s) 490 { imp()->setScope(s); } 491 492 inline ReferenceList Object::propList(ExecState *exec, bool recursive) 493 { return imp()->propList(exec,recursive); } 494 495 inline Value Object::internalValue() const 496 { return imp()->internalValue(); } 497 498 inline void Object::setInternalValue(const Value &v) 499 { imp()->setInternalValue(v); } 500 501 inline void Object::saveProperties(SavedProperties &p) const 502 { imp()->saveProperties(p); } 503 inline void Object::restoreProperties(const SavedProperties &p) 504 { imp()->restoreProperties(p); } 618 inline bool AllocatedValueImp::isObject(const ClassInfo *info) const 619 { return isObject() && static_cast<const ObjectImp *>(this)->inherits(info); } 620 621 inline ObjectImp::ObjectImp(ObjectImp *proto) 622 : _proto(proto), _internalValue(0) 623 { 624 } 625 626 inline ObjectImp::ObjectImp() 627 : _proto(jsNull()), _internalValue(0) 628 { 629 } 630 631 inline ValueImp *ObjectImp::internalValue() const 632 { 633 return _internalValue; 634 } 635 636 inline void ObjectImp::setInternalValue(ValueImp *v) 637 { 638 _internalValue = v; 639 } 640 641 inline ValueImp *ObjectImp::prototype() const 642 { 643 return _proto; 644 } 645 646 inline void ObjectImp::setPrototype(ValueImp *proto) 647 { 648 _proto = proto; 649 } 650 651 inline bool ObjectImp::inherits(const ClassInfo *info) const 652 { 653 for (const ClassInfo *ci = classInfo(); ci; ci = ci->parentClass) 654 if (ci == info) 655 return true; 656 return false; 657 } 505 658 506 659 } // namespace 507 660 508 #endif // _KJS_OBJECT_H_661 #endif // KJS_OBJECT_H -
trunk/JavaScriptCore/kjs/object_object.cpp
r9889 r10084 38 38 : ObjectImp() // [[Prototype]] is Null() 39 39 { 40 Value protect(this);41 40 putDirect(toStringPropertyName, new ObjectProtoFuncImp(exec,funcProto,ObjectProtoFuncImp::ToString, 0), DontEnum); 42 41 putDirect(toLocaleStringPropertyName, new ObjectProtoFuncImp(exec,funcProto,ObjectProtoFuncImp::ToLocaleString,0), DontEnum); … … 53 52 : InternalFunctionImp(funcProto), id(i) 54 53 { 55 Value protect(this);56 54 putDirect(lengthPropertyName, len, DontDelete|ReadOnly|DontEnum); 57 55 } … … 65 63 // ECMA 15.2.4.2, 15.2.4.4, 15.2.4.5 66 64 67 Value ObjectProtoFuncImp::call(ExecState *exec, Object &thisObj, const List &args)65 ValueImp *ObjectProtoFuncImp::callAsFunction(ExecState *exec, ObjectImp *thisObj, const List &args) 68 66 { 69 67 switch (id) { 70 68 case ValueOf: 71 69 return thisObj; 72 case HasOwnProperty: {70 case HasOwnProperty: 73 71 // Same as the in operator but without checking the prototype 74 Identifier propertyName(args[0].toString(exec)); 75 bool exists = thisObj.hasOwnProperty(exec, propertyName); 76 return Value(exists ? BooleanImp::staticTrue : BooleanImp::staticFalse); 77 } 72 return jsBoolean(thisObj->hasOwnProperty(exec, Identifier(args[0]->toString(exec)))); 78 73 case ToLocaleString: 79 return thisObj.imp()->toString(exec);74 return jsString(thisObj->toString(exec)); 80 75 case ToString: 81 76 default: 82 return String("[object " + thisObj .className() + "]");77 return String("[object " + thisObj->className() + "]"); 83 78 } 84 79 } … … 91 86 : InternalFunctionImp(funcProto) 92 87 { 93 Value protect(this);94 88 // ECMA 15.2.3.1 95 89 putDirect(prototypePropertyName, objProto, DontEnum|DontDelete|ReadOnly); 96 90 97 91 // no. of arguments for constructor 98 putDirect(lengthPropertyName, NumberImp::one(), ReadOnly|DontDelete|DontEnum);92 putDirect(lengthPropertyName, jsOne(), ReadOnly|DontDelete|DontEnum); 99 93 } 100 94 … … 106 100 107 101 // ECMA 15.2.2 108 Object 102 ObjectImp *ObjectObjectImp::construct(ExecState *exec, const List &args) 109 103 { 110 104 // if no arguments have been passed ... 111 105 if (args.isEmpty()) { 112 Object 113 Object 106 ObjectImp *proto = exec->lexicalInterpreter()->builtinObjectPrototype(); 107 ObjectImp *result(new ObjectImp(proto)); 114 108 return result; 115 109 } 116 110 117 Value arg = *(args.begin()); 118 Object obj = Object::dynamicCast(arg); 119 if (!obj.isNull()) { 111 ValueImp *arg = *(args.begin()); 112 if (ObjectImp *obj = arg->getObject()) 120 113 return obj; 121 }122 114 123 switch (arg .type()) {115 switch (arg->type()) { 124 116 case StringType: 125 117 case BooleanType: 126 118 case NumberType: 127 return arg .toObject(exec);119 return arg->toObject(exec); 128 120 default: 129 121 assert(!"unhandled switch case in ObjectConstructor"); 130 122 case NullType: 131 123 case UndefinedType: 132 Object proto = exec->lexicalInterpreter()->builtinObjectPrototype(); 133 return Object(new ObjectImp(proto)); 124 return new ObjectImp(exec->lexicalInterpreter()->builtinObjectPrototype()); 134 125 } 135 126 } … … 140 131 } 141 132 142 Value ObjectObjectImp::call(ExecState *exec, Object &/*thisObj*/, const List &args)133 ValueImp *ObjectObjectImp::callAsFunction(ExecState *exec, ObjectImp */*thisObj*/, const List &args) 143 134 { 144 Value 135 ValueImp *result; 145 136 146 137 List argList; … … 149 140 result = construct(exec,argList); 150 141 } else { 151 Value 152 if (arg .type() == NullType || arg.type() == UndefinedType) {142 ValueImp *arg = args[0]; 143 if (arg->isUndefinedOrNull()) { 153 144 argList.append(arg); 154 145 result = construct(exec,argList); 155 146 } else 156 result = arg .toObject(exec);147 result = arg->toObject(exec); 157 148 } 158 149 return result; -
trunk/JavaScriptCore/kjs/object_object.h
r9768 r10084 48 48 class ObjectProtoFuncImp : public InternalFunctionImp { 49 49 public: 50 ObjectProtoFuncImp(ExecState *exec, FunctionPrototypeImp *funcProto, 51 int i, int len); 50 ObjectProtoFuncImp(ExecState *exec, FunctionPrototypeImp *funcProto, int i, int len); 52 51 53 52 virtual bool implementsCall() const; 54 virtual Value call(ExecState *exec, Object &thisObj, const List &args);53 virtual ValueImp *callAsFunction(ExecState *, ObjectImp *, const List &args); 55 54 56 55 enum { ToString, ToLocaleString, ValueOf, HasOwnProperty }; … … 72 71 73 72 virtual bool implementsConstruct() const; 74 virtual Object construct(ExecState *exec, const List &args);73 virtual ObjectImp *construct(ExecState *, const List &args); 75 74 virtual bool implementsCall() const; 76 virtual Value call(ExecState *exec, Object &thisObj, const List &args);75 virtual ValueImp *callAsFunction(ExecState *, ObjectImp *, const List &args); 77 76 }; 78 77 -
trunk/JavaScriptCore/kjs/operations.cpp
r9768 r10084 112 112 113 113 // ECMA 11.9.3 114 bool KJS::equal(ExecState *exec, const Value& v1, const Value&v2)115 { 116 Type t1 = v1 .type();117 Type t2 = v2 .type();114 bool KJS::equal(ExecState *exec, ValueImp *v1, ValueImp *v2) 115 { 116 Type t1 = v1->type(); 117 Type t2 = v2->type(); 118 118 119 119 if (t1 != t2) { … … 135 135 } else { 136 136 if ((t1 == StringType || t1 == NumberType) && t2 >= ObjectType) 137 return equal(exec, v1, v2 .toPrimitive(exec));137 return equal(exec, v1, v2->toPrimitive(exec)); 138 138 if (t1 >= ObjectType && (t2 == StringType || t2 == NumberType)) 139 return equal(exec, v1 .toPrimitive(exec), v2);139 return equal(exec, v1->toPrimitive(exec), v2); 140 140 if (t1 != t2) 141 141 return false; … … 147 147 148 148 if (t1 == NumberType) { 149 double d1 = v1 .toNumber(exec);150 double d2 = v2 .toNumber(exec);149 double d1 = v1->toNumber(exec); 150 double d2 = v2->toNumber(exec); 151 151 // FIXME: Isn't this already how NaN behaves? 152 152 // Why the extra line of code? … … 157 157 158 158 if (t1 == StringType) 159 return v1 .toString(exec) == v2.toString(exec);159 return v1->toString(exec) == v2->toString(exec); 160 160 161 161 if (t1 == BooleanType) 162 return v1 .toBoolean(exec) == v2.toBoolean(exec);162 return v1->toBoolean(exec) == v2->toBoolean(exec); 163 163 164 164 // types are Object 165 return v1 .imp() == v2.imp();166 } 167 168 bool KJS::strictEqual(ExecState *exec, const Value &v1, const Value &v2)169 { 170 Type t1 = v1 .type();171 Type t2 = v2 .type();165 return v1 == v2; 166 } 167 168 bool KJS::strictEqual(ExecState *exec, ValueImp *v1, ValueImp *v2) 169 { 170 Type t1 = v1->type(); 171 Type t2 = v2->type(); 172 172 173 173 if (t1 != t2) … … 176 176 return true; 177 177 if (t1 == NumberType) { 178 double n1 = v1 .toNumber(exec);179 double n2 = v2 .toNumber(exec);178 double n1 = v1->toNumber(exec); 179 double n2 = v2->toNumber(exec); 180 180 // FIXME: Isn't this already how NaN behaves? 181 181 // Why the extra line of code? … … 187 187 return false; 188 188 } else if (t1 == StringType) { 189 return v1 .toString(exec) == v2.toString(exec);189 return v1->toString(exec) == v2->toString(exec); 190 190 } else if (t2 == BooleanType) { 191 return v1 .toBoolean(exec) == v2.toBoolean(exec);191 return v1->toBoolean(exec) == v2->toBoolean(exec); 192 192 } 193 if (v1 .imp() == v2.imp())193 if (v1 == v2) 194 194 return true; 195 195 /* TODO: joined objects */ … … 198 198 } 199 199 200 int KJS::relation(ExecState *exec, const Value& v1, const Value&v2)201 { 202 Value p1 = v1.toPrimitive(exec,NumberType);203 Value p2 = v2.toPrimitive(exec,NumberType);204 205 if (p1 .type() == StringType && p2.type() == StringType)206 return p1 .toString(exec) < p2.toString(exec) ? 1 : 0;207 208 double n1 = p1 .toNumber(exec);209 double n2 = p2 .toNumber(exec);200 int KJS::relation(ExecState *exec, ValueImp *v1, ValueImp *v2) 201 { 202 ValueImp *p1 = v1->toPrimitive(exec,NumberType); 203 ValueImp *p2 = v2->toPrimitive(exec,NumberType); 204 205 if (p1->isString() && p2->isString()) 206 return p1->toString(exec) < p2->toString(exec) ? 1 : 0; 207 208 double n1 = p1->toNumber(exec); 209 double n2 = p2->toNumber(exec); 210 210 if (n1 < n2) 211 211 return 1; … … 226 226 227 227 // ECMA 11.6 228 Value KJS::add(ExecState *exec, const Value &v1, const Value &v2, char oper)228 ValueImp *KJS::add(ExecState *exec, ValueImp *v1, ValueImp *v2, char oper) 229 229 { 230 230 // exception for the Date exception in defaultValue() 231 231 Type preferred = oper == '+' ? UnspecifiedType : NumberType; 232 Value p1 = v1.toPrimitive(exec, preferred);233 Value p2 = v2.toPrimitive(exec, preferred);234 235 if ((p1 .type() == StringType || p2.type() == StringType) && oper == '+') {236 return p1.toString(exec) + p2.toString(exec);232 ValueImp *p1 = v1->toPrimitive(exec, preferred); 233 ValueImp *p2 = v2->toPrimitive(exec, preferred); 234 235 if ((p1->isString() || p2->isString()) && oper == '+') { 236 return jsString(p1->toString(exec) + p2->toString(exec)); 237 237 } 238 238 239 239 bool n1KnownToBeInteger; 240 double n1 = p1 .toNumber(exec, n1KnownToBeInteger);240 double n1 = p1->toNumber(exec, n1KnownToBeInteger); 241 241 bool n2KnownToBeInteger; 242 double n2 = p2 .toNumber(exec, n2KnownToBeInteger);242 double n2 = p2->toNumber(exec, n2KnownToBeInteger); 243 243 244 244 bool resultKnownToBeInteger = n1KnownToBeInteger && n2KnownToBeInteger; 245 245 246 246 if (oper == '+') 247 return Value(n1 + n2, resultKnownToBeInteger);247 return jsNumber(n1 + n2, resultKnownToBeInteger); 248 248 else 249 return Value(n1 - n2, resultKnownToBeInteger);249 return jsNumber(n1 - n2, resultKnownToBeInteger); 250 250 } 251 251 252 252 // ECMA 11.5 253 Value KJS::mult(ExecState *exec, const Value &v1, const Value &v2, char oper)253 ValueImp *KJS::mult(ExecState *exec, ValueImp *v1, ValueImp *v2, char oper) 254 254 { 255 255 bool n1KnownToBeInteger; 256 double n1 = v1 .toNumber(exec, n1KnownToBeInteger);256 double n1 = v1->toNumber(exec, n1KnownToBeInteger); 257 257 bool n2KnownToBeInteger; 258 double n2 = v2 .toNumber(exec, n2KnownToBeInteger);258 double n2 = v2->toNumber(exec, n2KnownToBeInteger); 259 259 260 260 double result; … … 272 272 } 273 273 274 return Value(result, resultKnownToBeInteger);275 } 274 return jsNumber(result, resultKnownToBeInteger); 275 } -
trunk/JavaScriptCore/kjs/operations.h
r9768 r10084 48 48 #endif 49 49 50 bool equal(ExecState *exec, const Value& v1, const Value&v2);51 bool strictEqual(ExecState *exec, const Value &v1, const Value &v2);50 bool equal(ExecState *exec, ValueImp *v1, ValueImp *v2); 51 bool strictEqual(ExecState *exec, ValueImp *v1, ValueImp *v2); 52 52 /** 53 53 * This operator performs an abstract relational comparison of the two … … 58 58 * equal". -1 if the result is undefined. 59 59 */ 60 int relation(ExecState *exec, const Value& v1, const Value&v2);60 int relation(ExecState *exec, ValueImp *v1, ValueImp *v2); 61 61 int maxInt(int d1, int d2); 62 62 int minInt(int d1, int d2); … … 67 67 * @return The result of the operation. 68 68 */ 69 Value add(ExecState *exec, const Value &v1, const Value &v2, char oper);69 ValueImp *add(ExecState *exec, ValueImp *v1, ValueImp *v2, char oper); 70 70 /** 71 71 * Multiplicative operator. Either multiplies/divides v1 and v2 or … … 75 75 * @return The result of the operation. 76 76 */ 77 Value mult(ExecState *exec, const Value &v1, const Value &v2, char oper);77 ValueImp *mult(ExecState *exec, ValueImp *v1, ValueImp *v2, char oper); 78 78 79 79 }; -
trunk/JavaScriptCore/kjs/property_map.cpp
r10076 r10084 546 546 int size = _table->size; 547 547 Entry *entries = _table->entries; 548 for (int i = 0; i != size; ++i) {548 for (int i = 0; i < size; i++) { 549 549 ValueImp *v = entries[i].value; 550 550 if (v && !v->marked()) … … 564 564 } 565 565 566 void PropertyMap::addEnumerablesToReferenceList(ReferenceList &list, const Object &base) const566 void PropertyMap::addEnumerablesToReferenceList(ReferenceList &list, ObjectImp *base) const 567 567 { 568 568 if (!_table) { … … 606 606 } 607 607 608 void PropertyMap::addSparseArrayPropertiesToReferenceList(ReferenceList &list, const Object &base) const608 void PropertyMap::addSparseArrayPropertiesToReferenceList(ReferenceList &list, ObjectImp *base) const 609 609 { 610 610 if (!_table) { … … 626 626 for (int i = 0; i != size; ++i) { 627 627 UString::Rep *key = entries[i].key; 628 if (key && key != &UString::Rep::null) 629 { 628 if (key && key != &UString::Rep::null) { 630 629 UString k(key); 631 630 bool fitsInUInt32; … … 671 670 if (_singleEntry.key && !(_singleEntry.attributes & (ReadOnly | Function))) { 672 671 prop->key = Identifier(_singleEntry.key); 673 prop->value = Value(_singleEntry.value);672 prop->value = _singleEntry.value; 674 673 prop->attributes = _singleEntry.attributes; 675 674 ++prop; … … 707 706 Entry *e = *q++; 708 707 prop->key = Identifier(e->key); 709 prop->value = Value(e->value);708 prop->value = e->value; 710 709 prop->attributes = e->attributes; 711 710 ++prop; … … 721 720 { 722 721 for (int i = 0; i != p._count; ++i) 723 put(p._properties[i].key, p._properties[i].value .imp(), p._properties[i].attributes);722 put(p._properties[i].key, p._properties[i].value, p._properties[i].attributes); 724 723 } 725 724 -
trunk/JavaScriptCore/kjs/property_map.h
r10076 r10084 28 28 namespace KJS { 29 29 30 class Object ;30 class ObjectImp; 31 31 class ReferenceList; 32 32 class ValueImp; … … 82 82 83 83 void mark() const; 84 void addEnumerablesToReferenceList(ReferenceList &, const Object &) const;85 void addSparseArrayPropertiesToReferenceList(ReferenceList &, const Object &) const;84 void addEnumerablesToReferenceList(ReferenceList &, ObjectImp *) const; 85 void addSparseArrayPropertiesToReferenceList(ReferenceList &, ObjectImp *) const; 86 86 87 87 void save(SavedProperties &) const; -
trunk/JavaScriptCore/kjs/property_slot.cpp
r10076 r10084 26 26 namespace KJS { 27 27 28 Value 28 ValueImp *PropertySlot::undefinedGetter(ExecState *, const Identifier& propertyName, const PropertySlot& slot) 29 29 { 30 30 return Undefined(); -
trunk/JavaScriptCore/kjs/property_slot.h
r10076 r10084 37 37 { 38 38 public: 39 typedef Value 39 typedef ValueImp *(*GetValueFunc)(ExecState *, const Identifier&, const PropertySlot&); 40 40 41 41 bool isSet() { return m_getValue != 0; } 42 Value 42 ValueImp *getValue(ExecState *exec, const Identifier& propertyName) const 43 43 { 44 44 if (m_getValue == VALUE_SLOT_MARKER) … … 47 47 } 48 48 49 Value 49 ValueImp *getValue(ExecState *exec, unsigned propertyName) const 50 50 { 51 51 if (m_getValue == VALUE_SLOT_MARKER) … … 93 93 94 94 private: 95 static Value 95 static ValueImp *undefinedGetter(ExecState *, const Identifier&, const PropertySlot&); 96 96 97 97 GetValueFunc m_getValue; -
trunk/JavaScriptCore/kjs/protect.h
r10076 r10084 49 49 if (val) gcUnprotect(val); 50 50 } 51 52 51 53 class ProtectedValue : public Value { 54 public: 55 ProtectedValue() : Value() {} 56 ProtectedValue(const Value&v) : Value(v) { gcProtectNullTolerant(v.imp()); }; 57 ProtectedValue(const ProtectedValue&v) : Value(v) { gcProtectNullTolerant(v.imp()); }; 58 ~ProtectedValue() { gcUnprotectNullTolerant(imp());} 59 ProtectedValue& operator=(const Value &v) 60 { 61 ValueImp *old = imp(); 62 Value::operator=(v); 63 gcProtectNullTolerant(v.imp()); 64 gcUnprotectNullTolerant(old); 65 return *this; 66 } 67 ProtectedValue& operator=(const ProtectedValue &v) 68 { 69 ValueImp *old = imp(); 70 Value::operator=(v); 71 gcProtectNullTolerant(v.imp()); 72 gcUnprotectNullTolerant(old); 73 return *this; 74 } 75 private: 76 explicit ProtectedValue(ValueImp *v); 77 }; 52 class ProtectedValue { 53 public: 54 ProtectedValue() : m_value(0) { } 55 ProtectedValue(ValueImp *v) : m_value(v) { gcProtectNullTolerant(v); } 56 ProtectedValue(const ProtectedValue& v) : m_value(v.m_value) { gcProtectNullTolerant(m_value); } 57 ~ProtectedValue() { gcUnprotectNullTolerant(m_value); } 58 ProtectedValue& operator=(ValueImp *v) 59 { 60 gcProtectNullTolerant(v); 61 gcUnprotectNullTolerant(m_value); 62 m_value = v; 63 return *this; 64 } 65 ProtectedValue& operator=(const ProtectedValue& v) { return *this = v.m_value; } 66 operator ValueImp *() const { return m_value; } 67 ValueImp *operator->() const { return m_value; } 68 protected: 69 ValueImp *m_value; 70 }; 78 71 79 72 } // namespace -
trunk/JavaScriptCore/kjs/protected_object.h
r10076 r10084 1 // -*- c-basic-offset: 2 -*-2 1 /* 3 2 * This file is part of the KDE libraries … … 21 20 */ 22 21 23 24 #ifndef _KJS_PROTECTED_OBJECT_H_ 25 #define _KJS_PROTECTED_OBJECT_H_ 22 #ifndef KJS_PROTECTED_OBJECT_H 23 #define KJS_PROTECTED_OBJECT_H 26 24 27 25 #include "protect.h" … … 31 29 namespace KJS { 32 30 33 class ProtectedObject : public Object { 34 public: 35 ProtectedObject() : Object() {} 36 ProtectedObject(const Object &o) : Object(o) { gcProtectNullTolerant(o.imp()); }; 37 ProtectedObject(const ProtectedObject &o) : Object(o) { gcProtectNullTolerant(o.imp()); }; 38 ~ProtectedObject() { gcUnprotectNullTolerant(imp());} 39 ProtectedObject& operator=(const Object &o) 40 { 41 ValueImp *old = imp(); 42 Object::operator=(o); 43 gcProtectNullTolerant(o.imp()); 44 gcUnprotectNullTolerant(old); 45 return *this; 46 } 47 ProtectedObject& operator=(const ProtectedObject &o) 48 { 49 ValueImp *old = imp(); 50 Object::operator=(o); 51 gcProtectNullTolerant(o.imp()); 52 gcUnprotectNullTolerant(old); 53 return *this; 54 } 55 private: 56 explicit ProtectedObject(ObjectImp *o); 57 }; 58 31 class ProtectedObject : private ProtectedValue { 32 public: 33 ProtectedObject() { } 34 ProtectedObject(ObjectImp *v) : ProtectedValue(v) { } 35 ProtectedObject(const ProtectedObject& v) : ProtectedValue(v) { } 36 ProtectedObject& operator=(ObjectImp *v) { ProtectedValue::operator=(v); return *this; } 37 ProtectedObject& operator=(const ProtectedObject& v) { ProtectedValue::operator=(v); return *this; } 38 operator ValueImp *() const { return m_value; } 39 operator ObjectImp *() const { return static_cast<ObjectImp *>(m_value); } 40 ObjectImp *operator->() const { return static_cast<ObjectImp *>(m_value); } 41 }; 59 42 60 43 class ProtectedReference : public Reference { 61 44 public: 62 ProtectedReference(const Reference& r) : Reference(r) { gcProtectNullTolerant(r.base.imp()); };63 ~ProtectedReference() { gcUnprotectNullTolerant(base .imp());}45 ProtectedReference(const Reference& r) : Reference(r) { gcProtectNullTolerant(r.base); }; 46 ~ProtectedReference() { gcUnprotectNullTolerant(base);} 64 47 ProtectedReference& operator=(const Reference &r) 65 48 { 66 ValueImp *old = base .imp();49 ValueImp *old = base; 67 50 Reference::operator=(r); 68 gcProtectNullTolerant(r.base .imp());51 gcProtectNullTolerant(r.base); 69 52 gcUnprotectNullTolerant(old); 70 53 return *this; … … 72 55 private: 73 56 ProtectedReference(); 74 ProtectedReference(const Object& b, const Identifier& p);75 ProtectedReference(const Object& b, unsigned p);76 57 ProtectedReference(ObjectImp *b, const Identifier& p); 77 58 ProtectedReference(ObjectImp *b, unsigned p); 78 ProtectedReference(const Null& b, constIdentifier& p);79 ProtectedReference( const Null& b,unsigned p);59 ProtectedReference(const Identifier& p); 60 ProtectedReference(unsigned p); 80 61 }; 81 62 -
trunk/JavaScriptCore/kjs/protected_values.cpp
r9501 r10084 26 26 #include "simple_number.h" 27 27 #include <stdint.h> 28 #include "value.h" 28 29 29 30 namespace KJS { … … 44 45 return 0; 45 46 46 unsigned hash = computeHash(k);47 unsigned hash = pointerHash(k); 47 48 48 49 int i = hash & _tableSizeMask; … … 51 52 numCollisions += _table[i].key && _table[i].key != k; 52 53 #endif 53 while ( ValueImp *key = _table[i].key) {54 while (AllocatedValueImp *key = _table[i].key) { 54 55 if (key == k) { 55 56 return _table[i].value; … … 72 73 expand(); 73 74 74 unsigned hash = computeHash(k);75 unsigned hash = pointerHash(k); 75 76 76 77 int i = hash & _tableSizeMask; … … 79 80 numCollisions += _table[i].key && _table[i].key != k; 80 81 #endif 81 while ( ValueImp *key = _table[i].key) {82 while (AllocatedValueImp *key = _table[i].key) { 82 83 if (key == k) { 83 84 _table[i].value++; … … 87 88 } 88 89 89 _table[i].key = k ;90 _table[i].key = k->downcast(); 90 91 _table[i].value = 1; 91 92 ++_keyCount; … … 95 96 } 96 97 97 inline void ProtectedValues::insert( ValueImp *k, int v)98 inline void ProtectedValues::insert(AllocatedValueImp *k, int v) 98 99 { 99 unsigned hash = computeHash(k);100 unsigned hash = pointerHash(k); 100 101 101 102 int i = hash & _tableSizeMask; … … 118 119 return; 119 120 120 unsigned hash = computeHash(k);121 unsigned hash = pointerHash(k); 121 122 122 ValueImp *key;123 AllocatedValueImp *key; 123 124 124 125 int i = hash & _tableSizeMask; … … 187 188 } 188 189 189 unsigned ProtectedValues::computeHash(ValueImp *pointer)190 {191 return pointerHash(pointer);192 }193 194 190 } // namespace -
trunk/JavaScriptCore/kjs/protected_values.h
r9033 r10084 21 21 */ 22 22 23 24 #ifndef _KJS_PROTECTED_VALUES_H_ 25 #define _KJS_PROTECTED_VALUES_H_ 23 #ifndef KJS_PROTECTED_VALUES_H 24 #define KJS_PROTECTED_VALUES_H 26 25 27 26 namespace KJS { 28 27 class ValueImp; 28 class AllocatedValueImp; 29 29 30 30 class ProtectedValues { 31 struct KeyValue {32 ValueImp *key;33 int value;34 };35 36 31 public: 37 32 static void increaseProtectCount(ValueImp *key); … … 41 36 42 37 private: 43 static void insert( ValueImp *key, int value);38 static void insert(AllocatedValueImp *key, int value); 44 39 static void expand(); 45 40 static void shrink(); 46 41 static void rehash(int newTableSize); 47 static unsigned computeHash(ValueImp *pointer);48 42 49 43 // let the collector scan the table directly for protected values 50 44 friend class Collector; 45 46 struct KeyValue { 47 AllocatedValueImp *key; 48 int value; 49 }; 51 50 52 51 static KeyValue *_table; -
trunk/JavaScriptCore/kjs/reference.cpp
r9768 r10084 28 28 // ------------------------------ Reference ------------------------------------ 29 29 30 Reference::Reference(const Object& b, const Identifier& p)31 : base(b),32 baseIsValue(false),33 propertyNameIsNumber(false),34 prop(p)35 {36 }37 38 Reference::Reference(const Object& b, unsigned p)39 : base(b),40 propertyNameAsNumber(p),41 baseIsValue(false),42 propertyNameIsNumber(true)43 {44 }45 46 30 Reference::Reference(ObjectImp *b, const Identifier& p) 47 31 : base(b), … … 60 44 } 61 45 62 Reference::Reference(const Null& b, constIdentifier& p)63 : base( b),46 Reference::Reference(const Identifier& p) 47 : base(jsNull()), 64 48 baseIsValue(false), 65 49 propertyNameIsNumber(false), … … 68 52 } 69 53 70 Reference::Reference( const Null& b,unsigned p)71 : base( b),54 Reference::Reference(unsigned p) 55 : base(jsNull()), 72 56 propertyNameAsNumber(p), 73 57 baseIsValue(false), … … 76 60 } 77 61 78 Reference Reference::makeValueReference( const Value&v)62 Reference Reference::makeValueReference(ValueImp *v) 79 63 { 80 64 Reference valueRef; … … 84 68 } 85 69 86 Value 70 ValueImp *Reference::getBase(ExecState *exec) const 87 71 { 88 72 if (baseIsValue) { 89 Object 73 ObjectImp *err = Error::create(exec, ReferenceError, I18N_NOOP("Invalid reference base")); 90 74 exec->setException(err); 91 75 return err; … … 109 93 } 110 94 111 Value 95 ValueImp *Reference::getValue(ExecState *exec) const 112 96 { 113 97 if (baseIsValue) { … … 115 99 } 116 100 117 ValueImp *o = base .imp();118 Type t = o ? o-> dispatchType() : NullType;101 ValueImp *o = base; 102 Type t = o ? o->type() : NullType; 119 103 120 104 if (t == NullType) { 121 105 UString m = I18N_NOOP("Can't find variable: ") + getPropertyName(exec).ustring(); 122 Object 106 ObjectImp *err = Error::create(exec, ReferenceError, m.ascii()); 123 107 exec->setException(err); 124 108 return err; … … 127 111 if (t != ObjectType) { 128 112 UString m = I18N_NOOP("Base is not an object"); 129 Object 113 ObjectImp *err = Error::create(exec, ReferenceError, m.ascii()); 130 114 exec->setException(err); 131 115 return err; … … 137 121 } 138 122 139 void Reference::putValue(ExecState *exec, const Value &w)123 void Reference::putValue(ExecState *exec, ValueImp *w) 140 124 { 141 125 if (baseIsValue) { 142 Object 126 ObjectImp *err = Error::create(exec, ReferenceError); 143 127 exec->setException(err); 144 128 return; … … 149 133 #endif 150 134 151 ValueImp *o = base .imp();152 Type t = o ? o-> dispatchType() : NullType;135 ValueImp *o = base; 136 Type t = o ? o->type() : NullType; 153 137 154 138 if (t == NullType) 155 o = exec->lexicalInterpreter()->globalObject() .imp();139 o = exec->lexicalInterpreter()->globalObject(); 156 140 157 141 if (propertyNameIsNumber) … … 163 147 { 164 148 if (baseIsValue) { 165 Object 149 ObjectImp *err = Error::create(exec,ReferenceError); 166 150 exec->setException(err); 167 151 return false; 168 152 } 169 153 170 ValueImp *o = base .imp();171 Type t = o ? o-> dispatchType() : NullType;154 ValueImp *o = base; 155 Type t = o ? o->type() : NullType; 172 156 173 157 // The spec doesn't mention what to do if the base is null... just return true -
trunk/JavaScriptCore/kjs/reference.h
r10076 r10084 25 25 26 26 #include "identifier.h" 27 #include " value.h"27 #include "object.h" 28 28 29 29 namespace KJS { 30 30 31 class Object;32 31 class ObjectImp; 33 32 … … 37 36 friend class ProtectedReference; 38 37 public: 39 Reference(const Object& b, const Identifier& p);40 Reference(const Object& b, unsigned p);41 38 Reference(ObjectImp *b, const Identifier& p); 42 39 Reference(ObjectImp *b, unsigned p); 43 Reference(const Null& b, constIdentifier& p);44 Reference( const Null& b,unsigned p);45 static Reference makeValueReference( const Value& v);40 Reference(const Identifier& p); 41 Reference(unsigned p); 42 static Reference makeValueReference(ValueImp *); 46 43 47 44 /** … … 51 48 * this method is guaranteed to return either Null() or an Object value. 52 49 */ 53 Value 50 ValueImp *getBase(ExecState *exec) const; 54 51 55 52 /** … … 63 60 * (ECMA 8.7.1) 64 61 */ 65 Value 62 ValueImp *getValue(ExecState *exec) const; 66 63 67 64 /** … … 69 66 * (ECMA 8.7.1) 70 67 */ 71 void putValue(ExecState *exec, const Value &w);68 void putValue(ExecState *exec, ValueImp *); 72 69 bool deleteValue(ExecState *exec); 73 70 74 ValueImp *baseIfMutable() const { return baseIsValue ? 0 : base .imp(); }71 ValueImp *baseIfMutable() const { return baseIsValue ? 0 : base; } 75 72 76 73 private: 77 74 Reference() { } 78 75 79 Value 76 ValueImp *base; 80 77 unsigned propertyNameAsNumber; 81 78 bool baseIsValue; … … 83 80 mutable Identifier prop; 84 81 }; 82 85 83 } 86 84 -
trunk/JavaScriptCore/kjs/regexp_object.cpp
r10076 r10084 46 46 : ObjectImp(objProto) 47 47 { 48 Value protect(this);49 48 setInternalValue(String("")); 50 49 … … 64 63 : InternalFunctionImp(funcProto), id(i) 65 64 { 66 Value protect(this);67 65 putDirect(lengthPropertyName, len, DontDelete|ReadOnly|DontEnum); 68 66 } … … 73 71 } 74 72 75 Value RegExpProtoFuncImp::call(ExecState *exec, Object &thisObj, const List &args)76 { 77 if (!thisObj .inherits(&RegExpImp::info)) {78 if (thisObj .inherits(&RegExpPrototypeImp::info)) {73 ValueImp *RegExpProtoFuncImp::callAsFunction(ExecState *exec, ObjectImp *thisObj, const List &args) 74 { 75 if (!thisObj->inherits(&RegExpImp::info)) { 76 if (thisObj->inherits(&RegExpPrototypeImp::info)) { 79 77 switch (id) { 80 78 case ToString: return String("//"); 81 79 } 82 80 } 83 Object 81 ObjectImp *err = Error::create(exec,TypeError); 84 82 exec->setException(err); 85 83 return err; 86 84 } 87 85 88 RegExpImp *reimp = static_cast<RegExpImp*>(thisObj .imp());86 RegExpImp *reimp = static_cast<RegExpImp*>(thisObj); 89 87 RegExp *re = reimp->regExp(); 90 String s;88 UString s; 91 89 UString str; 92 90 switch (id) { … … 94 92 case Test: 95 93 { 96 s = args[0] .toString(exec);97 int length = s. value().size();98 Value lastIndex = thisObj.get(exec,"lastIndex");99 int i = lastIndex .isNull() ? 0 : lastIndex.toInt32(exec);100 bool globalFlag = thisObj .get(exec,"global").toBoolean(exec);94 s = args[0]->toString(exec); 95 int length = s.size(); 96 ValueImp *lastIndex = thisObj->get(exec,"lastIndex"); 97 int i = lastIndex->toInt32(exec); 98 bool globalFlag = thisObj->get(exec,"global")->toBoolean(exec); 101 99 if (!globalFlag) 102 100 i = 0; 103 101 if (i < 0 || i > length) { 104 thisObj .put(exec,"lastIndex", Number(0), DontDelete | DontEnum);102 thisObj->put(exec,"lastIndex", Number(0), DontDelete | DontEnum); 105 103 if (id == Test) 106 104 return Boolean(false); … … 108 106 return Null(); 109 107 } 110 RegExpObjectImp* regExpObj = static_cast<RegExpObjectImp*>(exec->lexicalInterpreter()->builtinRegExp() .imp());111 int **ovector = regExpObj->registerRegexp( re, s .value());112 113 str = re->match(s .value(), i, 0L, ovector);108 RegExpObjectImp* regExpObj = static_cast<RegExpObjectImp*>(exec->lexicalInterpreter()->builtinRegExp()); 109 int **ovector = regExpObj->registerRegexp( re, s ); 110 111 str = re->match(s, i, 0L, ovector); 114 112 regExpObj->setSubPatterns(re->subPatterns()); 115 113 … … 120 118 { 121 119 if (globalFlag) 122 thisObj .put(exec,"lastIndex",Number(0), DontDelete | DontEnum);120 thisObj->put(exec,"lastIndex",Number(0), DontDelete | DontEnum); 123 121 return Null(); 124 122 } … … 126 124 { 127 125 if (globalFlag) 128 thisObj .put(exec,"lastIndex",Number( (*ovector)[1] ), DontDelete | DontEnum);126 thisObj->put(exec,"lastIndex",Number( (*ovector)[1] ), DontDelete | DontEnum); 129 127 return regExpObj->arrayOfMatches(exec,str); 130 128 } … … 132 130 break; 133 131 case ToString: 134 s = thisObj .get(exec,"source").toString(exec);132 s = thisObj->get(exec,"source")->toString(exec); 135 133 str = "/"; 136 str += s .value();134 str += s; 137 135 str += "/"; 138 if (thisObj .get(exec,"global").toBoolean(exec)) {136 if (thisObj->get(exec,"global")->toBoolean(exec)) { 139 137 str += "g"; 140 138 } 141 if (thisObj .get(exec,"ignoreCase").toBoolean(exec)) {139 if (thisObj->get(exec,"ignoreCase")->toBoolean(exec)) { 142 140 str += "i"; 143 141 } 144 if (thisObj .get(exec,"multiline").toBoolean(exec)) {142 if (thisObj->get(exec,"multiline")->toBoolean(exec)) { 145 143 str += "m"; 146 144 } … … 173 171 : InternalFunctionImp(funcProto), lastOvector(0L), lastNrSubPatterns(0) 174 172 { 175 Value protect(this);176 173 // ECMA 15.10.5.1 RegExp.prototype 177 174 putDirect(prototypePropertyName, regProto, DontEnum|DontDelete|ReadOnly); 178 175 179 176 // no. of arguments for constructor 180 putDirect(lengthPropertyName, NumberImp::two(), ReadOnly|DontDelete|DontEnum);177 putDirect(lengthPropertyName, jsTwo(), ReadOnly|DontDelete|DontEnum); 181 178 } 182 179 … … 195 192 } 196 193 197 Object 194 ObjectImp *RegExpObjectImp::arrayOfMatches(ExecState *exec, const UString &result) const 198 195 { 199 196 List list; … … 205 202 int start = lastOvector[2*i]; 206 203 if (start == -1) 207 list.append( UndefinedImp::staticUndefined);204 list.append(jsUndefined()); 208 205 else { 209 206 UString substring = lastString.substr( start, lastOvector[2*i+1] - start ); … … 211 208 } 212 209 } 213 Object arr = exec->lexicalInterpreter()->builtinArray().construct(exec, list);214 arr .put(exec, "index", Number(lastOvector[0]));215 arr .put(exec, "input", String(lastString));210 ObjectImp *arr = exec->lexicalInterpreter()->builtinArray()->construct(exec, list); 211 arr->put(exec, "index", Number(lastOvector[0])); 212 arr->put(exec, "input", String(lastString)); 216 213 return arr; 217 214 } 218 215 219 Value 216 ValueImp *RegExpObjectImp::backrefGetter(ExecState *exec, const Identifier& propertyName, const PropertySlot& slot) 220 217 { 221 218 RegExpObjectImp *thisObj = static_cast<RegExpObjectImp *>(slot.slotBase()); … … 254 251 255 252 // ECMA 15.10.4 256 Object 257 { 258 Object o = Object::dynamicCast(args[0]);259 if ( !o.isNull() && o.inherits(&RegExpImp::info)) {260 if ( args[1].type() != UndefinedType) {261 Object 253 ObjectImp *RegExpObjectImp::construct(ExecState *exec, const List &args) 254 { 255 ObjectImp *o = args[0]->getObject(); 256 if (o && o->inherits(&RegExpImp::info)) { 257 if (!args[1]->isUndefined()) { 258 ObjectImp *err = Error::create(exec,TypeError); 262 259 exec->setException(err); 263 260 return err; … … 266 263 } 267 264 268 UString p = args[0] .type() == UndefinedType ? UString("") : args[0].toString(exec);269 UString flags = args[1] .type() == UndefinedType ? UString("") : args[1].toString(exec);270 271 RegExpPrototypeImp *proto = static_cast<RegExpPrototypeImp*>(exec->lexicalInterpreter()->builtinRegExpPrototype() .imp());265 UString p = args[0]->isUndefined() ? UString("") : args[0]->toString(exec); 266 UString flags = args[1]->isUndefined() ? UString("") : args[1]->toString(exec); 267 268 RegExpPrototypeImp *proto = static_cast<RegExpPrototypeImp*>(exec->lexicalInterpreter()->builtinRegExpPrototype()); 272 269 RegExpImp *dat = new RegExpImp(proto); 273 Object obj(dat); // protect from GC274 270 275 271 bool global = (flags.find("g") >= 0); … … 278 274 // TODO: throw a syntax error on invalid flags 279 275 280 dat->putDirect("global", global ? BooleanImp::staticTrue : BooleanImp::staticFalse, DontDelete | ReadOnly | DontEnum);281 dat->putDirect("ignoreCase", ignoreCase ? BooleanImp::staticTrue : BooleanImp::staticFalse, DontDelete | ReadOnly | DontEnum);282 dat->putDirect("multiline", multiline ? BooleanImp::staticTrue : BooleanImp::staticFalse, DontDelete | ReadOnly | DontEnum);283 284 dat->putDirect("source", new StringImp(p), DontDelete | ReadOnly | DontEnum);285 dat->putDirect("lastIndex", NumberImp::zero(), DontDelete | DontEnum);276 dat->putDirect("global", jsBoolean(global), DontDelete | ReadOnly | DontEnum); 277 dat->putDirect("ignoreCase", jsBoolean(ignoreCase), DontDelete | ReadOnly | DontEnum); 278 dat->putDirect("multiline", jsBoolean(multiline), DontDelete | ReadOnly | DontEnum); 279 280 dat->putDirect("source", jsString(p), DontDelete | ReadOnly | DontEnum); 281 dat->putDirect("lastIndex", jsZero(), DontDelete | DontEnum); 286 282 287 283 int reflags = RegExp::None; … … 294 290 dat->setRegExp(new RegExp(p, reflags)); 295 291 296 return obj;292 return dat; 297 293 } 298 294 … … 303 299 304 300 // ECMA 15.10.3 305 Value RegExpObjectImp::call(ExecState *exec, Object &/*thisObj*/,301 ValueImp *RegExpObjectImp::callAsFunction(ExecState *exec, ObjectImp */*thisObj*/, 306 302 const List &args) 307 303 { -
trunk/JavaScriptCore/kjs/regexp_object.h
r10076 r10084 44 44 45 45 virtual bool implementsCall() const; 46 virtual Value call(ExecState *exec, Object &thisObj, const List &args);46 virtual ValueImp *callAsFunction(ExecState *exec, ObjectImp *thisObj, const List &args); 47 47 48 48 enum { Exec, Test, ToString }; … … 71 71 virtual ~RegExpObjectImp(); 72 72 virtual bool implementsConstruct() const; 73 virtual Object 73 virtual ObjectImp *construct(ExecState *exec, const List &args); 74 74 virtual bool implementsCall() const; 75 virtual Value call(ExecState *exec, Object &thisObj, const List &args);75 virtual ValueImp *callAsFunction(ExecState *exec, ObjectImp *thisObj, const List &args); 76 76 77 77 virtual bool getOwnPropertySlot(ExecState *, const Identifier&, PropertySlot&); 78 78 int ** registerRegexp( const RegExp* re, const UString& s ); 79 79 void setSubPatterns(int num) { lastNrSubPatterns = num; } 80 Object 80 ObjectImp *arrayOfMatches(ExecState *exec, const UString &result) const; 81 81 private: 82 static Value 82 static ValueImp *backrefGetter(ExecState *exec, const Identifier&, const PropertySlot& slot); 83 83 84 84 UString lastString; -
trunk/JavaScriptCore/kjs/string_object.cpp
r10076 r10084 51 51 } 52 52 53 Value 54 { 55 return Value(static_cast<StringInstanceImp *>(slot.slotBase())->internalValue().toString(exec).size());56 } 57 58 Value 59 { 60 const UChar c = static_cast<StringInstanceImp *>(slot.slotBase())->internalValue() .toString(exec)[slot.index()];61 return Value(UString(&c, 1));53 ValueImp *StringInstanceImp::lengthGetter(ExecState *exec, const Identifier& propertyName, const PropertySlot &slot) 54 { 55 return jsNumber(static_cast<StringInstanceImp *>(slot.slotBase())->internalValue()->toString(exec).size()); 56 } 57 58 ValueImp *StringInstanceImp::indexGetter(ExecState *exec, const Identifier& propertyName, const PropertySlot &slot) 59 { 60 const UChar c = static_cast<StringInstanceImp *>(slot.slotBase())->internalValue()->toString(exec)[slot.index()]; 61 return jsString(UString(&c, 1)); 62 62 } 63 63 … … 72 72 const unsigned index = propertyName.toArrayIndex(&ok); 73 73 if (ok) { 74 const UString s = internalValue() .toString(exec);74 const UString s = internalValue()->toString(exec); 75 75 const unsigned length = s.size(); 76 76 if (index >= length) … … 83 83 } 84 84 85 void StringInstanceImp::put(ExecState *exec, const Identifier &propertyName, const Value &value, int attr)85 void StringInstanceImp::put(ExecState *exec, const Identifier &propertyName, ValueImp *value, int attr) 86 86 { 87 87 if (propertyName == lengthPropertyName) … … 143 143 : StringInstanceImp(objProto) 144 144 { 145 Value protect(this);146 145 // The constructor will be added later, after StringObjectImp has been built 147 putDirect(lengthPropertyName, NumberImp::zero(), DontDelete|ReadOnly|DontEnum); 148 146 putDirect(lengthPropertyName, jsZero(), DontDelete|ReadOnly|DontEnum); 149 147 } 150 148 … … 158 156 StringProtoFuncImp::StringProtoFuncImp(ExecState *exec, int i, int len) 159 157 : InternalFunctionImp( 160 static_cast<FunctionPrototypeImp*>(exec->lexicalInterpreter()->builtinFunctionPrototype() .imp())158 static_cast<FunctionPrototypeImp*>(exec->lexicalInterpreter()->builtinFunctionPrototype()) 161 159 ), id(i) 162 160 { 163 Value protect(this);164 161 putDirect(lengthPropertyName, len, DontDelete|ReadOnly|DontEnum); 165 162 } … … 172 169 static inline bool regExpIsGlobal(RegExpImp *regExp, ExecState *exec) 173 170 { 174 Value 175 return globalProperty.type() != UndefinedType && globalProperty.toBoolean(exec);171 ValueImp *globalProperty = regExp->get(exec,"global"); 172 return !globalProperty->isUndefined() && globalProperty->toBoolean(exec); 176 173 } 177 174 … … 260 257 } 261 258 262 static Value replace(ExecState *exec, const UString &source, const Value &pattern, const Value &replacement)259 static ValueImp *replace(ExecState *exec, const UString &source, ValueImp *pattern, ValueImp *replacement) 263 260 { 264 261 ObjectImp *replacementFunction = 0; 265 262 UString replacementString; 266 263 267 if (replacement .type() == ObjectType && replacement.toObject(exec).implementsCall())268 replacementFunction = replacement .toObject(exec).imp();264 if (replacement->isObject() && replacement->toObject(exec)->implementsCall()) 265 replacementFunction = replacement->toObject(exec); 269 266 else 270 replacementString = replacement .toString(exec);271 272 if (pattern .type() == ObjectType && pattern.toObject(exec).inherits(&RegExpImp::info)) {273 RegExpImp* imp = static_cast<RegExpImp *>( pattern .toObject(exec).imp() );267 replacementString = replacement->toString(exec); 268 269 if (pattern->isObject() && pattern->toObject(exec)->inherits(&RegExpImp::info)) { 270 RegExpImp* imp = static_cast<RegExpImp *>( pattern->toObject(exec) ); 274 271 RegExp *reg = imp->regExp(); 275 272 bool global = regExpIsGlobal(imp, exec); 276 273 277 RegExpObjectImp* regExpObj = static_cast<RegExpObjectImp*>(exec->lexicalInterpreter()->builtinRegExp() .imp());274 RegExpObjectImp* regExpObj = static_cast<RegExpObjectImp*>(exec->lexicalInterpreter()->builtinRegExp()); 278 275 279 276 int matchIndex = 0; … … 303 300 List args; 304 301 305 args.append( Value(matchString));302 args.append(jsString(matchString)); 306 303 307 304 for (unsigned i = 0; i < reg->subPatterns(); i++) { … … 309 306 int matchLen = (*ovector)[(i + 1) * 2 + 1] - matchStart; 310 307 311 args.append( Value(source.substr(matchStart, matchLen)));308 args.append(jsString(source.substr(matchStart, matchLen))); 312 309 } 313 310 314 args.append( Value(completeMatchStart));315 args.append( Value(source));311 args.append(jsNumber(completeMatchStart)); 312 args.append(jsString(source)); 316 313 317 314 replacementString = replacementFunction->call(exec, exec->dynamicInterpreter()->globalObject(), 318 args) .toString(exec);315 args)->toString(exec); 319 316 } 320 317 … … 345 342 346 343 // First arg is a string 347 UString patternString = pattern .toString(exec);344 UString patternString = pattern->toString(exec); 348 345 int matchPos = source.find(patternString); 349 346 int matchLen = patternString.size(); … … 355 352 List args; 356 353 357 args.append( Value(source.substr(matchPos, matchLen)));358 args.append( Value(matchPos));359 args.append( Value(source));354 args.append(jsString(source.substr(matchPos, matchLen))); 355 args.append(jsNumber(matchPos)); 356 args.append(jsString(source)); 360 357 361 358 replacementString = replacementFunction->call(exec, exec->dynamicInterpreter()->globalObject(), 362 args) .toString(exec);359 args)->toString(exec); 363 360 } 364 361 … … 367 364 368 365 // ECMA 15.5.4.2 - 15.5.4.20 369 Value StringProtoFuncImp::call(ExecState *exec, Object &thisObj, const List &args)370 { 371 Value result;366 ValueImp *StringProtoFuncImp::callAsFunction(ExecState *exec, ObjectImp *thisObj, const List &args) 367 { 368 ValueImp *result = NULL; 372 369 373 370 // toString and valueOf are no generic function. 374 371 if (id == ToString || id == ValueOf) { 375 if ( thisObj.isNull() || !thisObj.inherits(&StringInstanceImp::info)) {376 Object 372 if (!thisObj || !thisObj->inherits(&StringInstanceImp::info)) { 373 ObjectImp *err = Error::create(exec,TypeError); 377 374 exec->setException(err); 378 375 return err; 379 376 } 380 377 381 return String(thisObj .internalValue().toString(exec));378 return String(thisObj->internalValue()->toString(exec)); 382 379 } 383 380 … … 387 384 double d = 0.0; 388 385 389 UString s = thisObj .toString(exec);386 UString s = thisObj->toString(exec); 390 387 391 388 int len = s.size(); 392 Value 393 Value 389 ValueImp *a0 = args[0]; 390 ValueImp *a1 = args[1]; 394 391 395 392 switch (id) { … … 401 398 // Other browsers treat an omitted parameter as 0 rather than NaN. 402 399 // That doesn't match the ECMA standard, but is needed for site compatibility. 403 dpos = a0 .isA(UndefinedType) ? 0 : a0.toInteger(exec);400 dpos = a0->isUndefined() ? 0 : a0->toInteger(exec); 404 401 if (dpos >= 0 && dpos < len) // false for NaN 405 402 u = s.substr(static_cast<int>(dpos), 1); … … 411 408 // Other browsers treat an omitted parameter as 0 rather than NaN. 412 409 // That doesn't match the ECMA standard, but is needed for site compatibility. 413 dpos = a0 .isA(UndefinedType) ? 0 : a0.toInteger(exec);410 dpos = a0->isUndefined() ? 0 : a0->toInteger(exec); 414 411 if (dpos >= 0 && dpos < len) // false for NaN 415 412 result = Number(s[static_cast<int>(dpos)].unicode()); 416 413 else 417 result = Number(NaN);414 result = jsNaN(); 418 415 break; 419 416 case Concat: { 420 417 ListIterator it = args.begin(); 421 418 for ( ; it != args.end() ; ++it) { 422 s += it-> dispatchToString(exec);419 s += it->toString(exec); 423 420 } 424 421 result = String(s); … … 426 423 } 427 424 case IndexOf: 428 u2 = a0 .toString(exec);429 if (a1 .type() == UndefinedType)425 u2 = a0->toString(exec); 426 if (a1->isUndefined()) 430 427 dpos = 0; 431 428 else { 432 dpos = a1 .toInteger(exec);429 dpos = a1->toInteger(exec); 433 430 if (dpos >= 0) { // false for NaN 434 431 if (dpos > len) … … 440 437 break; 441 438 case LastIndexOf: 442 u2 = a0 .toString(exec);443 d = a1 .toNumber(exec);444 if (a1 .type() == UndefinedType|| KJS::isNaN(d))439 u2 = a0->toString(exec); 440 d = a1->toNumber(exec); 441 if (a1->isUndefined() || KJS::isNaN(d)) 445 442 dpos = len; 446 443 else { 447 dpos = a1 .toInteger(exec);444 dpos = a1->toInteger(exec); 448 445 if (dpos >= 0) { // false for NaN 449 446 if (dpos > len) … … 459 456 RegExp *reg, *tmpReg = 0; 460 457 RegExpImp *imp = 0; 461 if (a0 .isA(ObjectType) && a0.toObject(exec).inherits(&RegExpImp::info))458 if (a0->isObject() && a0->getObject()->inherits(&RegExpImp::info)) 462 459 { 463 imp = static_cast<RegExpImp *>( a0.toObject(exec).imp());460 imp = static_cast<RegExpImp *>(a0); 464 461 reg = imp->regExp(); 465 462 } … … 470 467 * replaced with the result of the expression new RegExp(regexp). 471 468 */ 472 reg = tmpReg = new RegExp(a0 .toString(exec), RegExp::None);473 } 474 RegExpObjectImp* regExpObj = static_cast<RegExpObjectImp*>(exec->lexicalInterpreter()->builtinRegExp() .imp());469 reg = tmpReg = new RegExp(a0->toString(exec), RegExp::None); 470 } 471 RegExpObjectImp* regExpObj = static_cast<RegExpObjectImp*>(exec->lexicalInterpreter()->builtinRegExp()); 475 472 int **ovector = regExpObj->registerRegexp(reg, u); 476 473 UString mstr = reg->match(u, -1, &pos, ovector); … … 493 490 while (pos >= 0) { 494 491 if (mstr.isNull()) 495 list.append( UndefinedImp::staticUndefined);492 list.append(jsUndefined()); 496 493 else 497 494 list.append(String(mstr)); … … 509 506 result = Null(); 510 507 } else { 511 result = exec->lexicalInterpreter()->builtinArray() .construct(exec, list);508 result = exec->lexicalInterpreter()->builtinArray()->construct(exec, list); 512 509 } 513 510 } … … 522 519 { 523 520 // The arg processing is very much like ArrayProtoFunc::Slice 524 double begin = args[0] .toInteger(exec);521 double begin = args[0]->toInteger(exec); 525 522 if (begin >= 0) { // false for NaN 526 523 if (begin > len) … … 532 529 } 533 530 double end = len; 534 if ( args[1].type() != UndefinedType) {535 end = args[1] .toInteger(exec);531 if (!args[1]->isUndefined()) { 532 end = args[1]->toInteger(exec); 536 533 if (end >= 0) { // false for NaN 537 534 if (end > len) … … 548 545 } 549 546 case Split: { 550 Object 551 Object res = Object::dynamicCast(constructor.construct(exec,List::empty()));547 ObjectImp *constructor = exec->lexicalInterpreter()->builtinArray(); 548 ObjectImp *res = static_cast<ObjectImp *>(constructor->construct(exec,List::empty())); 552 549 result = res; 553 550 u = s; 554 551 i = p0 = 0; 555 uint32_t limit = a1 .type() == UndefinedType ? 0xFFFFFFFFU : a1.toUInt32(exec);556 if (a0 .type() == ObjectType && Object::dynamicCast(a0).inherits(&RegExpImp::info)) {557 Object obj0 = Object::dynamicCast(a0);558 RegExp reg(obj0 .get(exec,"source").toString(exec));552 uint32_t limit = a1->isUndefined() ? 0xFFFFFFFFU : a1->toUInt32(exec); 553 if (a0->isObject() && static_cast<ObjectImp *>(a0)->inherits(&RegExpImp::info)) { 554 ObjectImp *obj0 = static_cast<ObjectImp *>(a0); 555 RegExp reg(obj0->get(exec,"source")->toString(exec)); 559 556 if (u.isEmpty() && !reg.match(u, 0).isNull()) { 560 557 // empty string matched by regexp -> empty array 561 res .put(exec,lengthPropertyName, Number(0));558 res->put(exec,lengthPropertyName, Number(0)); 562 559 break; 563 560 } … … 573 570 pos = mpos + (mstr.isEmpty() ? 1 : mstr.size()); 574 571 if (mpos != p0 || !mstr.isEmpty()) { 575 res .put(exec,i, String(u.substr(p0, mpos-p0)));572 res->put(exec,i, String(u.substr(p0, mpos-p0))); 576 573 p0 = mpos + mstr.size(); 577 574 i++; … … 579 576 } 580 577 } else { 581 u2 = a0 .toString(exec);578 u2 = a0->toString(exec); 582 579 if (u2.isEmpty()) { 583 580 if (u.isEmpty()) { … … 587 584 } else { 588 585 while (static_cast<uint32_t>(i) != limit && i < u.size()-1) 589 res .put(exec, i++, String(u.substr(p0++, 1)));586 res->put(exec, i++, String(u.substr(p0++, 1))); 590 587 } 591 588 } else { 592 589 while (static_cast<uint32_t>(i) != limit && (pos = u.find(u2, p0)) >= 0) { 593 res .put(exec, i, String(u.substr(p0, pos-p0)));590 res->put(exec, i, String(u.substr(p0, pos-p0))); 594 591 p0 = pos + u2.size(); 595 592 i++; … … 599 596 // add remaining string, if any 600 597 if (static_cast<uint32_t>(i) != limit) 601 res .put(exec, i++, String(u.substr(p0)));602 res .put(exec,lengthPropertyName, Number(i));598 res->put(exec, i++, String(u.substr(p0))); 599 res->put(exec,lengthPropertyName, Number(i)); 603 600 } 604 601 break; 605 602 case Substr: { 606 double d = a0 .toInteger(exec);607 double d2 = a1 .toInteger(exec);603 double d = a0->toInteger(exec); 604 double d2 = a1->toInteger(exec); 608 605 if (!(d >= 0)) { // true for NaN 609 606 d += len; … … 623 620 } 624 621 case Substring: { 625 double start = a0 .toNumber(exec);626 double end = a1 .toNumber(exec);622 double start = a0->toNumber(exec); 623 double end = a1->toNumber(exec); 627 624 if (KJS::isNaN(start)) 628 625 start = 0; … … 637 634 if (end > len) 638 635 end = len; 639 if (a1 .type() == UndefinedType)636 if (a1->isUndefined()) 640 637 end = len; 641 638 if (start > end) { … … 690 687 break; 691 688 case Fontcolor: 692 result = String("<font color=\"" + a0 .toString(exec) + "\">" + s + "</font>");689 result = String("<font color=\"" + a0->toString(exec) + "\">" + s + "</font>"); 693 690 break; 694 691 case Fontsize: 695 result = String("<font size=\"" + a0 .toString(exec) + "\">" + s + "</font>");692 result = String("<font size=\"" + a0->toString(exec) + "\">" + s + "</font>"); 696 693 break; 697 694 case Anchor: 698 result = String("<a name=\"" + a0 .toString(exec) + "\">" + s + "</a>");695 result = String("<a name=\"" + a0->toString(exec) + "\">" + s + "</a>"); 699 696 break; 700 697 case Link: 701 result = String("<a href=\"" + a0 .toString(exec) + "\">" + s + "</a>");698 result = String("<a href=\"" + a0->toString(exec) + "\">" + s + "</a>"); 702 699 break; 703 700 #endif … … 714 711 : InternalFunctionImp(funcProto) 715 712 { 716 Value protect(this);717 713 // ECMA 15.5.3.1 String.prototype 718 714 putDirect(prototypePropertyName, stringProto, DontEnum|DontDelete|ReadOnly); … … 722 718 723 719 // no. of arguments for constructor 724 putDirect(lengthPropertyName, NumberImp::one(), ReadOnly|DontDelete|DontEnum);720 putDirect(lengthPropertyName, jsOne(), ReadOnly|DontDelete|DontEnum); 725 721 } 726 722 … … 732 728 733 729 // ECMA 15.5.2 734 Object 735 { 736 ObjectImp *proto = exec->lexicalInterpreter()->builtinStringPrototype() .imp();730 ObjectImp *StringObjectImp::construct(ExecState *exec, const List &args) 731 { 732 ObjectImp *proto = exec->lexicalInterpreter()->builtinStringPrototype(); 737 733 if (args.size() == 0) 738 return Object(new StringInstanceImp(proto));739 return Object(new StringInstanceImp(proto, args.begin()->dispatchToString(exec)));734 return new StringInstanceImp(proto); 735 return new StringInstanceImp(proto, args.begin()->toString(exec)); 740 736 } 741 737 … … 746 742 747 743 // ECMA 15.5.1 748 Value StringObjectImp::call(ExecState *exec, Object &/*thisObj*/, const List &args)744 ValueImp *StringObjectImp::callAsFunction(ExecState *exec, ObjectImp */*thisObj*/, const List &args) 749 745 { 750 746 if (args.isEmpty()) 751 747 return String(""); 752 748 else { 753 Value 754 return String(v .toString(exec));749 ValueImp *v = args[0]; 750 return String(v->toString(exec)); 755 751 } 756 752 } … … 762 758 : InternalFunctionImp(funcProto) 763 759 { 764 Value protect(this); 765 putDirect(lengthPropertyName, NumberImp::one(), DontDelete|ReadOnly|DontEnum); 760 putDirect(lengthPropertyName, jsOne(), DontDelete|ReadOnly|DontEnum); 766 761 } 767 762 … … 771 766 } 772 767 773 Value StringObjectFuncImp::call(ExecState *exec, Object &/*thisObj*/, const List &args)768 ValueImp *StringObjectFuncImp::callAsFunction(ExecState *exec, ObjectImp */*thisObj*/, const List &args) 774 769 { 775 770 UString s; -
trunk/JavaScriptCore/kjs/string_object.h
r10076 r10084 34 34 35 35 virtual bool getOwnPropertySlot(ExecState *, const Identifier&, PropertySlot&); 36 virtual void put(ExecState *exec, const Identifier &propertyName, const Value &value, int attr = None);36 virtual void put(ExecState *exec, const Identifier &propertyName, ValueImp *value, int attr = None); 37 37 virtual bool deleteProperty(ExecState *exec, const Identifier &propertyName); 38 38 … … 40 40 static const ClassInfo info; 41 41 private: 42 static Value 43 static Value 42 static ValueImp *lengthGetter(ExecState *exec, const Identifier&, const PropertySlot &slot); 43 static ValueImp *indexGetter(ExecState *exec, const Identifier&, const PropertySlot &slot); 44 44 }; 45 45 … … 70 70 71 71 virtual bool implementsCall() const; 72 virtual Value call(ExecState *exec, Object &thisObj, const List &args);72 virtual ValueImp *callAsFunction(ExecState *exec, ObjectImp *thisObj, const List &args); 73 73 74 74 enum { ToString, ValueOf, CharAt, CharCodeAt, Concat, IndexOf, LastIndexOf, … … 97 97 98 98 virtual bool implementsConstruct() const; 99 virtual Object 99 virtual ObjectImp *construct(ExecState *exec, const List &args); 100 100 virtual bool implementsCall() const; 101 virtual Value call(ExecState *exec, Object &thisObj, const List &args);101 virtual ValueImp *callAsFunction(ExecState *exec, ObjectImp *thisObj, const List &args); 102 102 }; 103 103 … … 112 112 StringObjectFuncImp(ExecState *exec, FunctionPrototypeImp *funcProto); 113 113 virtual bool implementsCall() const; 114 virtual Value call(ExecState *exec, Object &thisObj, const List &args);114 virtual ValueImp *callAsFunction(ExecState *exec, ObjectImp *thisObj, const List &args); 115 115 }; 116 116 -
trunk/JavaScriptCore/kjs/testkjs.cpp
r9781 r10084 38 38 TestFunctionImp(int i, int length); 39 39 virtual bool implementsCall() const { return true; } 40 virtual Value call(ExecState *exec, Object &thisObj, const List &args);40 virtual ValueImp *callAsFunction(ExecState *exec, ObjectImp *thisObj, const List &args); 41 41 42 42 enum { Print, Debug, Quit, GC }; … … 51 51 } 52 52 53 Value TestFunctionImp::call(ExecState *exec, Object &/*thisObj*/, const List &args)53 ValueImp *TestFunctionImp::callAsFunction(ExecState *exec, ObjectImp */*thisObj*/, const List &args) 54 54 { 55 55 switch (id) { 56 56 case Print: 57 57 case Debug: 58 fprintf(stderr,"--> %s\n",args[0] .toString(exec).ascii());58 fprintf(stderr,"--> %s\n",args[0]->toString(exec).ascii()); 59 59 return Undefined(); 60 60 case Quit: … … 77 77 VersionFunctionImp() : ObjectImp() {} 78 78 virtual bool implementsCall() const { return true; } 79 virtual Value call(ExecState *exec, Object &thisObj, const List &args);79 virtual ValueImp *callAsFunction(ExecState *exec, ObjectImp *thisObj, const List &args); 80 80 }; 81 81 82 Value VersionFunctionImp::call(ExecState */*exec*/, Object &/*thisObj*/, const List &/*args*/)82 ValueImp *VersionFunctionImp::callAsFunction(ExecState */*exec*/, ObjectImp */*thisObj*/, const List &/*args*/) 83 83 { 84 84 // We need this function for compatibility with the Mozilla JS tests but for now … … 104 104 Interpreter::lock(); 105 105 106 Object 106 ObjectImp *global(new GlobalImp()); 107 107 108 108 // create interpreter 109 109 Interpreter interp(global); 110 110 // add debug() function 111 global .put(interp.globalExec(), "debug", Object(new TestFunctionImp(TestFunctionImp::Debug,1)));111 global->put(interp.globalExec(), "debug", new TestFunctionImp(TestFunctionImp::Debug, 1)); 112 112 // add "print" for compatibility with the mozilla js shell 113 global .put(interp.globalExec(), "print", Object(new TestFunctionImp(TestFunctionImp::Print,1)));113 global->put(interp.globalExec(), "print", new TestFunctionImp(TestFunctionImp::Print, 1)); 114 114 // add "quit" for compatibility with the mozilla js shell 115 global .put(interp.globalExec(), "quit", Object(new TestFunctionImp(TestFunctionImp::Quit,0)));115 global->put(interp.globalExec(), "quit", new TestFunctionImp(TestFunctionImp::Quit, 0)); 116 116 // add "gc" for compatibility with the mozilla js shell 117 global .put(interp.globalExec(), "gc", Object(new TestFunctionImp(TestFunctionImp::GC,0)));117 global->put(interp.globalExec(), "gc", new TestFunctionImp(TestFunctionImp::GC, 0)); 118 118 // add "version" for compatibility with the mozilla js shell 119 global .put(interp.globalExec(), "version", Object(new VersionFunctionImp()));119 global->put(interp.globalExec(), "version", new VersionFunctionImp()); 120 120 121 121 for (int i = 1; i < argc; i++) { … … 151 151 if (comp.complType() == Throw) { 152 152 ExecState *exec = interp.globalExec(); 153 Value 154 char *msg = exVal .toString(exec).ascii();153 ValueImp *exVal = comp.value(); 154 char *msg = exVal->toString(exec).ascii(); 155 155 int lineno = -1; 156 if (exVal .type() == ObjectType) {157 Value lineVal = Object::dynamicCast(exVal).get(exec,"line");158 if (lineVal .type() == NumberType)159 lineno = int(lineVal .toNumber(exec));156 if (exVal->isObject()) { 157 ValueImp *lineVal = static_cast<ObjectImp *>(exVal)->get(exec,"line"); 158 if (lineVal->isNumber()) 159 lineno = int(lineVal->toNumber(exec)); 160 160 } 161 161 if (lineno != -1) … … 166 166 } 167 167 else if (comp.complType() == ReturnValue) { 168 char *msg = comp.value() .toString(interp.globalExec()).ascii();168 char *msg = comp.value()->toString(interp.globalExec()).ascii(); 169 169 fprintf(stderr,"Return value: %s\n",msg); 170 170 } -
trunk/JavaScriptCore/kjs/value.cpp
r9768 r10084 1 // -*- c-basic-offset: 2 -*-2 1 /* 3 2 * This file is part of the KDE libraries … … 24 23 25 24 #include "value.h" 25 26 26 #include "object.h" 27 27 #include "types.h" 28 28 #include "interpreter.h" 29 29 30 #include <assert.h>31 30 #include <math.h> 32 31 #include <stdio.h> … … 38 37 #include "error_object.h" 39 38 #include "nodes.h" 40 #include "simple_number.h"41 39 42 40 namespace KJS { 43 41 44 // ----------------------------- ValueImp ------------------------------------- 45 46 void ValueImp::mark() 47 { 48 _marked = true; 49 } 50 51 void* ValueImp::operator new(size_t s) 52 { 53 return Collector::allocate(s); 54 } 55 56 void ValueImp::operator delete(void*) 57 { 58 // Do nothing. So far. 59 } 60 61 bool ValueImp::toUInt32(unsigned&) const 62 { 63 return false; 42 AllocatedValueImp *ConstantValues::undefined = NULL; 43 AllocatedValueImp *ConstantValues::null = NULL; 44 AllocatedValueImp *ConstantValues::jsTrue = NULL; 45 AllocatedValueImp *ConstantValues::jsFalse = NULL; 46 AllocatedValueImp *ConstantValues::NaN = NULL; 47 48 static const double D16 = 65536; 49 static const double D32 = 4294967296.0; 50 51 void *AllocatedValueImp::operator new(size_t size) 52 { 53 return Collector::allocate(size); 54 } 55 56 bool AllocatedValueImp::getUInt32(unsigned&) const 57 { 58 return false; 64 59 } 65 60 … … 67 62 double ValueImp::toInteger(ExecState *exec) const 68 63 { 69 uint32_t i;70 if (dispatchToUInt32(i))71 return i;72 return roundValue(exec, Value(const_cast<ValueImp*>(this)));64 uint32_t i; 65 if (getUInt32(i)) 66 return i; 67 return roundValue(exec, const_cast<ValueImp*>(this)); 73 68 } 74 69 75 70 int32_t ValueImp::toInt32(ExecState *exec) const 76 71 { 77 uint32_t i;78 if (dispatchToUInt32(i))79 return i;80 81 double d = roundValue(exec, Value(const_cast<ValueImp*>(this)));82 if (isNaN(d) || isInf(d))83 return 0;84 double d32 = fmod(d, D32);85 86 if (d32 >= D32 / 2.0)87 d32 -= D32;88 else if (d32 < -D32 / 2.0)89 d32 += D32;90 91 return static_cast<int32_t>(d32);72 uint32_t i; 73 if (getUInt32(i)) 74 return i; 75 76 double d = roundValue(exec, const_cast<ValueImp*>(this)); 77 if (isNaN(d) || isInf(d)) 78 return 0; 79 double d32 = fmod(d, D32); 80 81 if (d32 >= D32 / 2) 82 d32 -= D32; 83 else if (d32 < -D32 / 2) 84 d32 += D32; 85 86 return static_cast<int32_t>(d32); 92 87 } 93 88 94 89 uint32_t ValueImp::toUInt32(ExecState *exec) const 95 90 { 96 uint32_t i;97 if (dispatchToUInt32(i))98 return i;99 100 double d = roundValue(exec, Value(const_cast<ValueImp*>(this)));101 if (isNaN(d) || isInf(d))102 return 0;103 double d32 = fmod(d, D32);104 105 if (d32 < 0)106 d32 += D32;107 108 return static_cast<uint32_t>(d32);91 uint32_t i; 92 if (getUInt32(i)) 93 return i; 94 95 double d = roundValue(exec, const_cast<ValueImp*>(this)); 96 if (isNaN(d) || isInf(d)) 97 return 0; 98 double d32 = fmod(d, D32); 99 100 if (d32 < 0) 101 d32 += D32; 102 103 return static_cast<uint32_t>(d32); 109 104 } 110 105 111 106 uint16_t ValueImp::toUInt16(ExecState *exec) const 112 107 { 113 uint32_t i; 114 if (dispatchToUInt32(i)) 115 return i; 116 117 double d = roundValue(exec, Value(const_cast<ValueImp*>(this))); 118 if (isNaN(d) || isInf(d)) 119 return 0; 120 double d16 = fmod(d, D16); 121 122 if (d16 < 0) 123 d16 += D16; 124 125 return static_cast<uint16_t>(d16); 126 } 127 128 Object ValueImp::dispatchToObject(ExecState *exec) const 129 { 130 if (SimpleNumber::is(this)) 131 return static_cast<const NumberImp *>(this)->NumberImp::toObject(exec); 132 return toObject(exec); 133 } 134 135 bool ValueImp::isUndefinedOrNull() const 136 { 137 switch (dispatchType()) { 138 case BooleanType: 139 case NumberType: 140 case ObjectType: 141 case StringType: 142 break; 143 case NullType: 144 case UndefinedType: 145 return true; 146 case UnspecifiedType: 147 assert(false); 148 break; 149 } 150 return false; 151 } 152 153 bool ValueImp::isBoolean(bool &booleanValue) const 108 uint32_t i; 109 if (getUInt32(i)) 110 return i; 111 112 double d = roundValue(exec, const_cast<ValueImp*>(this)); 113 if (isNaN(d) || isInf(d)) 114 return 0; 115 double d16 = fmod(d, D16); 116 117 if (d16 < 0) 118 d16 += D16; 119 120 return static_cast<uint16_t>(d16); 121 } 122 123 ObjectImp *ValueImp::toObject(ExecState *exec) const 124 { 125 if (SimpleNumber::is(this)) 126 return static_cast<const NumberImp *>(this)->NumberImp::toObject(exec); 127 return downcast()->toObject(exec); 128 } 129 130 bool AllocatedValueImp::getBoolean(bool &booleanValue) const 154 131 { 155 132 if (!isBoolean()) … … 159 136 } 160 137 161 bool ValueImp::isNumber(double &numericValue) const138 bool AllocatedValueImp::getNumber(double &numericValue) const 162 139 { 163 140 if (!isNumber()) … … 167 144 } 168 145 169 bool ValueImp::isString(UString &stringValue) const 146 double AllocatedValueImp::getNumber() const 147 { 148 return isNumber() ? static_cast<const NumberImp *>(this)->value() : NaN; 149 } 150 151 bool AllocatedValueImp::getString(UString &stringValue) const 170 152 { 171 153 if (!isString()) … … 175 157 } 176 158 177 UString ValueImp::asString() const159 UString AllocatedValueImp::getString() const 178 160 { 179 161 return isString() ? static_cast<const StringImp *>(this)->value() : UString(); 180 162 } 181 163 182 bool ValueImp::isObject(ObjectImp *&object) 183 { 184 if (!isObject()) 185 return false; 186 object = static_cast<ObjectImp *>(this); 187 return true; 188 } 189 190 // ------------------------------ Value ---------------------------------------- 191 192 Value::Value(bool b) : rep(b ? BooleanImp::staticTrue : BooleanImp::staticFalse) { } 193 194 Value::Value(int i) 195 : rep(SimpleNumber::fits(i) ? SimpleNumber::make(i) : new NumberImp(static_cast<double>(i))) { } 196 197 Value::Value(unsigned u) 198 : rep(SimpleNumber::fits(u) ? SimpleNumber::make(u) : new NumberImp(static_cast<double>(u))) { } 199 200 Value::Value(double d) 201 : rep(SimpleNumber::fits(d) 202 ? SimpleNumber::make(static_cast<long>(d)) 203 : (KJS::isNaN(d) ? NumberImp::staticNaN : new NumberImp(d))) 204 { } 205 206 Value::Value(double d, bool knownToBeInteger) 207 : rep((knownToBeInteger ? SimpleNumber::integerFits(d) : SimpleNumber::fits(d)) 208 ? SimpleNumber::make(static_cast<long>(d)) 209 : ((!knownToBeInteger && KJS::isNaN(d)) ? NumberImp::staticNaN : new NumberImp(d))) 210 { } 211 212 Value::Value(long l) 213 : rep(SimpleNumber::fits(l) ? SimpleNumber::make(l) : new NumberImp(static_cast<double>(l))) { } 214 215 Value::Value(unsigned long l) 216 : rep(SimpleNumber::fits(l) ? SimpleNumber::make(l) : new NumberImp(static_cast<double>(l))) { } 217 218 Value::Value(const char *s) : rep(new StringImp(s)) { } 219 220 Value::Value(const UString &s) : rep(new StringImp(s)) { } 221 222 // ------------------------------ Undefined ------------------------------------ 223 224 Undefined::Undefined() : Value(UndefinedImp::staticUndefined) 225 { 226 } 227 228 Undefined Undefined::dynamicCast(const Value &v) 229 { 230 if (v.isNull() || v.type() != UndefinedType) 231 return Undefined(0); 232 233 return Undefined(); 234 } 235 236 // ------------------------------ Null ----------------------------------------- 237 238 Null::Null() : Value(NullImp::staticNull) 239 { 240 } 241 242 Null Null::dynamicCast(const Value &v) 243 { 244 if (v.isNull() || v.type() != NullType) 245 return Null(0); 246 247 return Null(); 248 } 249 250 // ------------------------------ Boolean -------------------------------------- 251 252 Boolean::Boolean(bool b) 253 : Value(b ? BooleanImp::staticTrue : BooleanImp::staticFalse) 254 { 255 } 256 257 bool Boolean::value() const 258 { 259 assert(rep); 260 return ((BooleanImp*)rep)->value(); 261 } 262 263 Boolean Boolean::dynamicCast(const Value &v) 264 { 265 if (v.isNull() || v.type() != BooleanType) 266 return static_cast<BooleanImp*>(0); 267 268 return static_cast<BooleanImp*>(v.imp()); 269 } 270 271 // ------------------------------ String --------------------------------------- 272 273 String::String(const UString &s) : Value(new StringImp(s)) 274 { 275 } 276 277 UString String::value() const 278 { 279 assert(rep); 280 return ((StringImp*)rep)->value(); 281 } 282 283 String String::dynamicCast(const Value &v) 284 { 285 if (v.isNull() || v.type() != StringType) 286 return String(0); 287 288 return String(static_cast<StringImp*>(v.imp())); 289 } 290 291 // ------------------------------ Number --------------------------------------- 292 293 Number::Number(int i) 294 : Value(SimpleNumber::fits(i) ? SimpleNumber::make(i) : new NumberImp(static_cast<double>(i))) { } 295 296 Number::Number(unsigned int u) 297 : Value(SimpleNumber::fits(u) ? SimpleNumber::make(u) : new NumberImp(static_cast<double>(u))) { } 298 299 Number::Number(double d) 300 : Value(SimpleNumber::fits(d) 301 ? SimpleNumber::make(static_cast<long>(d)) 302 : (KJS::isNaN(d) ? NumberImp::staticNaN : new NumberImp(d))) 303 { } 304 305 Number::Number(double d, bool knownToBeInteger) 306 : Value((knownToBeInteger ? SimpleNumber::integerFits(d) : SimpleNumber::fits(d)) 307 ? SimpleNumber::make(static_cast<long>(d)) 308 : ((!knownToBeInteger && KJS::isNaN(d)) ? NumberImp::staticNaN : new NumberImp(d))) 309 { } 310 311 Number::Number(long int l) 312 : Value(SimpleNumber::fits(l) ? SimpleNumber::make(l) : new NumberImp(static_cast<double>(l))) { } 313 314 Number::Number(long unsigned int l) 315 : Value(SimpleNumber::fits(l) ? SimpleNumber::make(l) : new NumberImp(static_cast<double>(l))) { } 316 317 Number Number::dynamicCast(const Value &v) 318 { 319 if (v.isNull() || v.type() != NumberType) 320 return Number((NumberImp*)0); 321 322 return Number(static_cast<NumberImp*>(v.imp())); 323 } 324 325 double Number::value() const 326 { 327 if (SimpleNumber::is(rep)) 328 return (double)SimpleNumber::value(rep); 329 assert(rep); 330 return ((NumberImp*)rep)->value(); 331 } 332 333 int Number::intValue() const 334 { 335 if (SimpleNumber::is(rep)) 336 return SimpleNumber::value(rep); 337 return (int)((NumberImp*)rep)->value(); 338 } 339 340 bool Number::isNaN() const 341 { 342 return rep == NumberImp::staticNaN; 343 } 344 345 bool Number::isInf() const 346 { 347 if (SimpleNumber::is(rep)) 348 return false; 349 return KJS::isInf(((NumberImp*)rep)->value()); 350 } 351 352 ValueImp *undefined() 353 { 354 return UndefinedImp::staticUndefined; 355 } 356 357 ValueImp *null() 358 { 359 return NullImp::staticNull; 360 } 361 362 ValueImp *boolean(bool b) 363 { 364 return b ? BooleanImp::staticTrue : BooleanImp::staticFalse; 365 } 366 367 ValueImp *string(const char *s) 164 ObjectImp *AllocatedValueImp::getObject() 165 { 166 return isObject() ? static_cast<ObjectImp *>(this) : 0; 167 } 168 169 const ObjectImp *AllocatedValueImp::getObject() const 170 { 171 return isObject() ? static_cast<const ObjectImp *>(this) : 0; 172 } 173 174 AllocatedValueImp *jsString(const char *s) 368 175 { 369 176 return new StringImp(s ? s : ""); 370 177 } 371 178 372 ValueImp *string(const UString &s)179 AllocatedValueImp *jsString(const UString &s) 373 180 { 374 181 return s.isNull() ? new StringImp("") : new StringImp(s); 375 182 } 376 183 377 ValueImp *zero() 378 { 379 return SimpleNumber::make(0); 380 } 381 382 ValueImp *one() 383 { 384 return SimpleNumber::make(1); 385 } 386 387 ValueImp *two() 388 { 389 return SimpleNumber::make(2); 390 } 391 392 ValueImp *number(int i) 393 { 394 return SimpleNumber::fits(i) ? SimpleNumber::make(i) : new NumberImp(static_cast<double>(i)); 395 } 396 397 ValueImp *number(unsigned i) 398 { 399 return SimpleNumber::fits(i) ? SimpleNumber::make(i) : new NumberImp(static_cast<double>(i)); 400 } 401 402 ValueImp *number(long i) 403 { 404 return SimpleNumber::fits(i) ? SimpleNumber::make(i) : new NumberImp(static_cast<double>(i)); 405 } 406 407 ValueImp *number(unsigned long i) 408 { 409 return SimpleNumber::fits(i) ? SimpleNumber::make(i) : new NumberImp(static_cast<double>(i)); 410 } 411 412 ValueImp *number(double d) 184 ValueImp *jsNumber(int i) 185 { 186 return SimpleNumber::fits(i) ? SimpleNumber::make(i) : new NumberImp(static_cast<double>(i)); 187 } 188 189 ValueImp *jsNumber(unsigned i) 190 { 191 return SimpleNumber::fits(i) ? SimpleNumber::make(i) : new NumberImp(static_cast<double>(i)); 192 } 193 194 ValueImp *jsNumber(long i) 195 { 196 return SimpleNumber::fits(i) ? SimpleNumber::make(i) : new NumberImp(static_cast<double>(i)); 197 } 198 199 ValueImp *jsNumber(unsigned long i) 200 { 201 return SimpleNumber::fits(i) ? SimpleNumber::make(i) : new NumberImp(static_cast<double>(i)); 202 } 203 204 ValueImp *jsNumber(double d) 413 205 { 414 206 return SimpleNumber::fits(d) 415 207 ? SimpleNumber::make(static_cast<long>(d)) 416 : (isNaN(d) ? NumberImp::staticNaN: new NumberImp(d));417 } 418 419 ValueImp * number(double d, bool knownToBeInteger)208 : (isNaN(d) ? jsNaN() : new NumberImp(d)); 209 } 210 211 ValueImp *jsNumber(double d, bool knownToBeInteger) 420 212 { 421 213 return (knownToBeInteger ? SimpleNumber::integerFits(d) : SimpleNumber::fits(d)) 422 214 ? SimpleNumber::make(static_cast<long>(d)) 423 : ((!knownToBeInteger && isNaN(d)) ? NumberImp::staticNaN : new NumberImp(d)); 424 } 425 426 } 215 : ((!knownToBeInteger && isNaN(d)) ? jsNaN() : new NumberImp(d)); 216 } 217 218 void ConstantValues::init() 219 { 220 undefined = new UndefinedImp(); 221 null = new NullImp(); 222 jsTrue = new BooleanImp(true); 223 jsFalse = new BooleanImp(false); 224 NaN = new NumberImp(::KJS::NaN); 225 } 226 227 void ConstantValues::clear() 228 { 229 undefined = NULL; 230 null = NULL; 231 jsTrue = NULL; 232 jsFalse = NULL; 233 NaN = NULL; 234 } 235 236 void ConstantValues::mark() 237 { 238 if (AllocatedValueImp *v = undefined) 239 if (!v->marked()) 240 v->mark(); 241 if (AllocatedValueImp *v = null) 242 if (!v->marked()) 243 v->mark(); 244 if (AllocatedValueImp *v = jsTrue) 245 if (!v->marked()) 246 v->mark(); 247 if (AllocatedValueImp *v = jsFalse) 248 if (!v->marked()) 249 v->mark(); 250 if (AllocatedValueImp *v = NaN) 251 if (!v->marked()) 252 v->mark(); 253 } 254 255 } -
trunk/JavaScriptCore/kjs/value.h
r9768 r10084 1 // -*- c-basic-offset: 2 -*-2 1 /* 3 2 * This file is part of the KDE libraries 4 3 * Copyright (C) 1999-2001 Harri Porten ([email protected]) 5 4 * Copyright (C) 2001 Peter Kelly ([email protected]) 6 * Copyright (C) 2003 Apple Computer, Inc.5 * Copyright (C) 2003-2005 Apple Computer, Inc. 7 6 * 8 7 * This library is free software; you can redistribute it and/or … … 23 22 */ 24 23 25 #ifndef _KJS_VALUE_H_26 #define _KJS_VALUE_H_24 #ifndef KJS_VALUE_H 25 #define KJS_VALUE_H 27 26 28 27 #ifndef NDEBUG // protection against problems if committing with KJS_VERBOSE on … … 35 34 #endif 36 35 37 #include <stdlib.h> // Needed for size_t 38 36 #include <assert.h> 37 #include <stdlib.h> // for size_t 38 #include "simple_number.h" 39 39 #include "ustring.h" 40 40 41 #include "simple_number.h"42 43 // Primitive data types44 45 41 namespace KJS { 46 42 47 class Value; 48 class ValueImp; 49 class ValueImpPrivate; 50 class Undefined; 51 class UndefinedImp; 52 class Null; 53 class NullImp; 54 class Boolean; 55 class BooleanImp; 56 class String; 57 class StringImp; 58 class Number; 59 class NumberImp; 60 class Object; 61 class ObjectImp; 62 class Reference; 63 class ReferenceImp; 64 class List; 65 class ListImp; 66 class Completion; 67 class ExecState; 68 class ClassInfo; 69 70 /** 71 * Primitive types 72 */ 73 enum Type { 43 class ClassInfo; 44 class ExecState; 45 class ObjectImp; 46 47 /** 48 * Primitive types 49 */ 50 enum Type { 74 51 UnspecifiedType = 0, 75 52 UndefinedType = 1, … … 79 56 NumberType = 5, 80 57 ObjectType = 6 81 }; 82 83 /** 84 * ValueImp is the base type for all primitives (Undefined, Null, Boolean, 85 * String, Number) and objects in ECMAScript. 86 * 87 * Note: you should never inherit from ValueImp as it is for primitive types 88 * only (all of which are provided internally by KJS). Instead, inherit from 89 * ObjectImp. 90 */ 91 class ValueImp { 92 friend class Collector; 93 friend class Value; 94 friend class ContextImp; 95 friend class FunctionCallNode; 96 public: 97 ValueImp() : _marked(false) { } 98 virtual ~ValueImp() { } 99 100 virtual void mark(); 101 bool marked() const; 102 void* operator new(size_t); 103 void operator delete(void*); 104 58 }; 59 60 /** 61 * ValueImp is the base type for all primitives (Undefined, Null, Boolean, 62 * String, Number) and objects in ECMAScript. 63 * 64 * Note: you should never inherit from ValueImp as it is for primitive types 65 * only (all of which are provided internally by KJS). Instead, inherit from 66 * ObjectImp. 67 */ 68 class ValueImp { 69 friend class AllocatedValueImp; // so it can derive from this class 70 friend class ProtectedValues; // so it can call downcast() 71 72 private: 73 ValueImp(); 74 ~ValueImp(); 75 76 public: 77 // Querying the type. 78 Type type() const; 79 bool isUndefined() const; 80 bool isNull() const; 81 bool isUndefinedOrNull() const; 82 bool isBoolean() const; 83 bool isNumber() const; 84 bool isString() const; 85 bool isObject() const; 86 bool isObject(const ClassInfo *) const; 87 88 // Extracting the value. 89 bool getBoolean(bool&) const; 90 bool getNumber(double&) const; 91 double getNumber() const; // NaN if not a number 92 bool getString(UString&) const; 93 UString getString() const; // null string if not a string 94 ObjectImp *getObject(); // NULL if not an object 95 const ObjectImp *getObject() const; // NULL if not an object 96 97 // Extracting integer values. 98 bool getUInt32(uint32_t&) const; 99 100 // Basic conversions. 101 ValueImp *toPrimitive(ExecState *exec, Type preferredType = UnspecifiedType) const; 102 bool toBoolean(ExecState *exec) const; 103 double toNumber(ExecState *exec) const; 104 double toNumber(ExecState *exec, bool& knownToBeInteger) const; 105 UString toString(ExecState *exec) const; 106 ObjectImp *toObject(ExecState *exec) const; 107 108 // Integer conversions. 105 109 double toInteger(ExecState *exec) const; 106 110 int32_t toInt32(ExecState *exec) const; … … 108 112 uint16_t toUInt16(ExecState *exec) const; 109 113 110 // Dispatch wrappers that handle the special small number case 111 112 Type dispatchType() const; 113 Value dispatchToPrimitive(ExecState *exec, Type preferredType = UnspecifiedType) const; 114 bool dispatchToBoolean(ExecState *exec) const; 115 double dispatchToNumber(ExecState *exec) const; 116 double dispatchToNumber(ExecState *exec, bool &knownToBeInteger) const; 117 UString dispatchToString(ExecState *exec) const; 118 bool dispatchToUInt32(uint32_t&) const; 119 Object dispatchToObject(ExecState *exec) const; 120 121 bool isUndefined() const { return dispatchType() == UndefinedType; } 122 bool isNull() const { return dispatchType() == NullType; } 123 bool isUndefinedOrNull() const; 124 125 bool isBoolean() const { return dispatchType() == BooleanType; } 126 bool isBoolean(bool &booleanValue) const; 127 128 bool isNumber() const { return dispatchType() == NumberType; } 129 bool isNumber(double &numericValue) const; 130 131 bool isString() const { return dispatchType() == StringType; } 132 bool isString(UString &stringValue) const; 133 UString asString() const; // null string if not a string 134 135 bool isObject() const { return dispatchType() == ObjectType; } 136 bool isObject(ObjectImp *&object); 137 ObjectImp *asObject(); // 0 if not an object 138 bool isObject(const ClassInfo *) const; // combine an isObject check with an inherits check 139 140 private: 141 virtual Type type() const = 0; 142 143 // The conversion operations 144 145 virtual Value toPrimitive(ExecState *exec, Type preferredType = UnspecifiedType) const = 0; 146 virtual bool toBoolean(ExecState *exec) const = 0; 147 virtual double toNumber(ExecState *exec) const = 0; 148 virtual UString toString(ExecState *exec) const = 0; 149 virtual Object toObject(ExecState *exec) const = 0; 150 virtual bool toUInt32(unsigned&) const; 151 152 bool _marked; 114 // Garbage collection. 115 void mark(); 116 bool marked() const; 117 118 private: 119 // Implementation details. 120 AllocatedValueImp *downcast(); 121 const AllocatedValueImp *downcast() const; 153 122 154 123 // Give a compile time error if we try to copy one of these. 155 124 ValueImp(const ValueImp&); 156 125 ValueImp& operator=(const ValueImp&); 157 }; 158 159 ValueImp *undefined(); 160 ValueImp *null(); 161 162 ValueImp *boolean(bool = false); 163 164 ValueImp *string(const char * = ""); // returns empty string if passed 0 165 ValueImp *string(const UString &); // returns empty string if passed null string 166 167 ValueImp *zero(); 168 ValueImp *one(); 169 ValueImp *two(); 170 ValueImp *number(int); 171 ValueImp *number(unsigned); 172 ValueImp *number(long); 173 ValueImp *number(unsigned long); 174 ValueImp *number(double); 175 ValueImp *number(double, bool knownToBeInteger); 176 177 /** 178 * FIXME: Now that we have conservative GC, we will be deprecating the 179 * Value wrappers and programming in terms of the ValueImp objects. 180 * Eventually we will remove Value and rename ValueImp to Value. 181 * We'll need to move the comments from Value to ValueImp too. 182 */ 183 /** 184 * Value objects are act as wrappers ("smart pointers") around ValueImp 185 * objects and their descendents. Instead of using ValueImps 186 * (and derivatives) during normal program execution, you should use a 187 * Value-derived class. 188 * 189 * Value maintains a pointer to a ValueImp object and uses a reference 190 * counting scheme to ensure that the ValueImp object is not deleted or 191 * garbage collected. 192 * 193 * Note: The conversion operations all return values of various types - 194 * if an error occurs during conversion, an error object will instead 195 * be returned (where possible), and the execution state's exception 196 * will be set appropriately. 197 */ 198 class Value { 199 public: 200 Value() : rep(0) { } 201 Value(ValueImp *v) : rep(v) { } 202 operator ValueImp *() const { return rep; } 203 204 explicit Value(bool); 205 206 explicit Value(int); 207 explicit Value(unsigned); 208 explicit Value(double); 209 explicit Value(long); 210 explicit Value(unsigned long); 211 Value(double, bool knownToBeInteger); 212 213 explicit Value(const char *); 214 Value(const UString &); 215 216 /** 217 * Returns whether or not this is a valid value. An invalid value 218 * has a 0 implementation pointer and should not be used for 219 * any other operation than this check. Current use: as a 220 * distinct return value signalling failing dynamicCast() calls. 221 */ 222 bool isValid() const { return rep != 0; } 223 /** 224 * @deprecated 225 * Use !isValid() instead. 226 */ 227 bool isNull() const { return rep == 0; } 228 ValueImp *imp() const { return rep; } 229 230 /** 231 * Returns the type of value. This is one of UndefinedType, NullType, 232 * BooleanType, StringType, NumberType, or ObjectType. 233 * 234 * @return The type of value 235 */ 236 Type type() const { return rep->dispatchType(); } 237 238 /** 239 * Checks whether or not the value is of a particular tpye 240 * 241 * @param t The type to compare with 242 * @return true if the value is of the specified type, otherwise false 243 */ 244 bool isA(Type t) const { return rep->dispatchType() == t; } 245 246 /** 247 * Performs the ToPrimitive type conversion operation on this value 248 * (ECMA 9.1) 249 */ 250 Value toPrimitive(ExecState *exec, 251 Type preferredType = UnspecifiedType) const 252 { return rep->dispatchToPrimitive(exec, preferredType); } 253 254 /** 255 * Performs the ToBoolean type conversion operation on this value (ECMA 9.2) 256 */ 257 bool toBoolean(ExecState *exec) const { return rep->dispatchToBoolean(exec); } 258 259 /** 260 * Performs the ToNumber type conversion operation on this value (ECMA 9.3) 261 */ 262 double toNumber(ExecState *exec) const { return rep->dispatchToNumber(exec); } 263 double toNumber(ExecState *exec, bool &knownToBeInteger) const { return rep->dispatchToNumber(exec, knownToBeInteger); } 264 265 /** 266 * Performs the ToInteger type conversion operation on this value (ECMA 9.4) 267 */ 268 double toInteger(ExecState *exec) const { return rep->toInteger(exec); } 269 270 /** 271 * Performs the ToInt32 type conversion operation on this value (ECMA 9.5) 272 */ 273 int32_t toInt32(ExecState *exec) const { return rep->toInt32(exec); } 274 275 /** 276 * Performs the ToUint32 type conversion operation on this value (ECMA 9.6) 277 */ 278 uint32_t toUInt32(ExecState *exec) const { return rep->toUInt32(exec); } 279 280 /** 281 * Performs the ToUint16 type conversion operation on this value (ECMA 9.7) 282 */ 283 uint16_t toUInt16(ExecState *exec) const { return rep->toUInt16(exec); } 284 285 /** 286 * Performs the ToString type conversion operation on this value (ECMA 9.8) 287 */ 288 UString toString(ExecState *exec) const { return rep->dispatchToString(exec); } 289 290 /** 291 * Performs the ToObject type conversion operation on this value (ECMA 9.9) 292 */ 293 Object toObject(ExecState *exec) const; 294 295 /** 296 * Checks if we can do a lossless conversion to UInt32. 297 */ 298 bool toUInt32(uint32_t& i) const { return rep->dispatchToUInt32(i); } 299 300 protected: 301 ValueImp *rep; 302 }; 303 304 // Primitive types 305 306 /** 307 * Represents an primitive Undefined value. All instances of this class 308 * share the same implementation object, so == will always return true 309 * for any comparison between two Undefined objects. 310 */ 311 class Undefined : public Value { 312 public: 313 Undefined(); 314 315 /** 316 * Converts a Value into an Undefined. If the value's type is not 317 * UndefinedType, a null object will be returned (i.e. one with it's 318 * internal pointer set to 0). If you do not know for sure whether the 319 * value is of type UndefinedType, you should check the isValid() 320 * methods afterwards before calling any methods on the returned value. 321 * 322 * @return The value converted to an Undefined 323 */ 324 static Undefined dynamicCast(const Value &v); 325 private: 126 }; 127 128 class AllocatedValueImp : public ValueImp { 129 friend class Collector; 326 130 friend class UndefinedImp; 327 explicit Undefined(UndefinedImp *v);328 329 };330 331 /**332 * Represents an primitive Null value. All instances of this class333 * share the same implementation object, so == will always return true334 * for any comparison between two Null objects.335 */336 class Null : public Value {337 public:338 Null();339 340 /**341 * Converts a Value into an Null. If the value's type is not NullType,342 * a null object will be returned (i.e. one with it's internal pointer set343 * to 0). If you do not know for sure whether the value is of type344 * NullType, you should check the isValid() methods afterwards before345 * calling any methods on the returned value.346 *347 * @return The value converted to a Null348 */349 static Null dynamicCast(const Value &v);350 private:351 131 friend class NullImp; 352 explicit Null(NullImp *v);353 };354 355 /**356 * Represents an primitive Boolean value357 */358 class Boolean : public Value {359 public:360 Boolean(bool b = false);361 362 /**363 * Converts a Value into an Boolean. If the value's type is not BooleanType,364 * a null object will be returned (i.e. one with it's internal pointer set365 * to 0). If you do not know for sure whether the value is of type366 * BooleanType, you should check the isValid() methods afterwards before367 * calling any methods on the returned value.368 *369 * @return The value converted to a Boolean370 */371 static Boolean dynamicCast(const Value &v);372 373 bool value() const;374 private:375 132 friend class BooleanImp; 376 explicit Boolean(BooleanImp *v); 377 }; 378 379 /** 380 * Represents an primitive String value 381 */ 382 class String : public Value { 383 public: 384 String(const UString &s = ""); 385 386 /** 387 * Converts a Value into an String. If the value's type is not StringType, 388 * a null object will be returned (i.e. one with it's internal pointer set 389 * to 0). If you do not know for sure whether the value is of type 390 * StringType, you should check the isValid() methods afterwards before 391 * calling any methods on the returned value. 392 * 393 * @return The value converted to a String 394 */ 395 static String dynamicCast(const Value &v); 396 397 UString value() const; 398 private: 133 friend class NumberImp; 399 134 friend class StringImp; 400 explicit String(StringImp *v); 401 }; 402 403 extern const double NaN; 404 extern const double Inf; 405 406 /** 407 * Represents an primitive Number value 408 */ 409 class Number : public Value { 410 friend class ValueImp; 411 public: 412 Number(int i); 413 Number(unsigned int u); 414 Number(double d = 0.0); 415 Number(long int l); 416 Number(long unsigned int l); 417 Number(double d, bool knownToBeInteger); 418 419 double value() const; 420 int intValue() const; 421 422 bool isNaN() const; 423 bool isInf() const; 424 425 /** 426 * Converts a Value into an Number. If the value's type is not NumberType, 427 * a null object will be returned (i.e. one with it's internal pointer set 428 * to 0). If you do not know for sure whether the value is of type 429 * NumberType, you should check the isNull() methods afterwards before 430 * calling any methods on the returned value. 431 * 432 * @return The value converted to a Number 433 */ 434 static Number dynamicCast(const Value &v); 435 private: 436 friend class NumberImp; 437 explicit Number(NumberImp *v); 438 }; 135 friend class ObjectImp; 136 private: 137 AllocatedValueImp(); 138 virtual ~AllocatedValueImp(); 139 public: 140 // Querying the type. 141 virtual Type type() const = 0; 142 bool isBoolean() const; 143 bool isNumber() const; 144 bool isString() const; 145 bool isObject() const; 146 bool isObject(const ClassInfo *) const; 147 148 // Extracting the value. 149 bool getBoolean(bool&) const; 150 bool getNumber(double&) const; 151 double getNumber() const; // NaN if not a number 152 bool getString(UString&) const; 153 UString getString() const; // null string if not a string 154 ObjectImp *getObject(); // NULL if not an object 155 const ObjectImp *getObject() const; // NULL if not an object 156 157 // Extracting integer values. 158 virtual bool getUInt32(uint32_t&) const; 159 160 // Basic conversions. 161 virtual ValueImp *toPrimitive(ExecState *exec, Type preferredType = UnspecifiedType) const = 0; 162 virtual bool toBoolean(ExecState *exec) const = 0; 163 virtual double toNumber(ExecState *exec) const = 0; 164 double toNumber(ExecState *exec, bool& knownToBeInteger) const; 165 virtual UString toString(ExecState *exec) const = 0; 166 virtual ObjectImp *toObject(ExecState *exec) const = 0; 167 168 // Garbage collection. 169 void *operator new(size_t); 170 virtual void mark(); 171 bool marked() const; 172 173 private: 174 bool m_marked; 175 }; 176 177 AllocatedValueImp *jsUndefined(); 178 AllocatedValueImp *jsNull(); 179 180 AllocatedValueImp *jsBoolean(bool = false); 181 182 ValueImp *jsNumber(double); 183 ValueImp *jsNumber(double, bool knownToBeInteger); 184 AllocatedValueImp *jsNaN(); 185 ValueImp *jsZero(); 186 ValueImp *jsOne(); 187 ValueImp *jsTwo(); 188 ValueImp *jsNumber(int); 189 ValueImp *jsNumber(unsigned); 190 ValueImp *jsNumber(long); 191 ValueImp *jsNumber(unsigned long); 192 193 AllocatedValueImp *jsString(const UString &); // returns empty string if passed null string 194 AllocatedValueImp *jsString(const char * = ""); // returns empty string if passed 0 195 196 extern const double NaN; 197 extern const double Inf; 198 199 class ConstantValues { 200 public: 201 static AllocatedValueImp *undefined; 202 static AllocatedValueImp *null; 203 static AllocatedValueImp *jsFalse; 204 static AllocatedValueImp *jsTrue; 205 static AllocatedValueImp *NaN; 206 207 static void init(); 208 static void clear(); 209 static void mark(); 210 }; 211 212 inline AllocatedValueImp *jsUndefined() 213 { 214 return ConstantValues::undefined; 215 } 216 217 inline AllocatedValueImp *jsNull() 218 { 219 return ConstantValues::null; 220 } 221 222 inline AllocatedValueImp *jsBoolean(bool b) 223 { 224 return b ? ConstantValues::jsTrue : ConstantValues::jsFalse; 225 } 226 227 inline AllocatedValueImp *jsNaN() 228 { 229 return ConstantValues::NaN; 230 } 231 232 inline ValueImp::ValueImp() 233 { 234 } 235 236 inline ValueImp::~ValueImp() 237 { 238 } 239 240 inline AllocatedValueImp::AllocatedValueImp() 241 : m_marked(false) 242 { 243 } 244 245 inline AllocatedValueImp::~AllocatedValueImp() 246 { 247 } 248 249 inline bool AllocatedValueImp::isBoolean() const 250 { 251 return type() == BooleanType; 252 } 253 254 inline bool AllocatedValueImp::isNumber() const 255 { 256 return type() == NumberType; 257 } 258 259 inline bool AllocatedValueImp::isString() const 260 { 261 return type() == StringType; 262 } 263 264 inline bool AllocatedValueImp::isObject() const 265 { 266 return type() == ObjectType; 267 } 268 269 inline bool AllocatedValueImp::marked() const 270 { 271 return m_marked; 272 } 273 274 inline void AllocatedValueImp::mark() 275 { 276 m_marked = true; 277 } 278 279 inline AllocatedValueImp *ValueImp::downcast() 280 { 281 assert(!SimpleNumber::is(this)); 282 return static_cast<AllocatedValueImp *>(this); 283 } 284 285 inline const AllocatedValueImp *ValueImp::downcast() const 286 { 287 assert(!SimpleNumber::is(this)); 288 return static_cast<const AllocatedValueImp *>(this); 289 } 290 291 inline bool ValueImp::isUndefined() const 292 { 293 return this == jsUndefined(); 294 } 295 296 inline bool ValueImp::isNull() const 297 { 298 return this == jsNull(); 299 } 300 301 inline bool ValueImp::isUndefinedOrNull() const 302 { 303 return this == jsUndefined() || this == jsNull(); 304 } 305 306 inline bool ValueImp::isBoolean() const 307 { 308 return !SimpleNumber::is(this) && downcast()->isBoolean(); 309 } 310 311 inline bool ValueImp::isNumber() const 312 { 313 return SimpleNumber::is(this) || downcast()->isNumber(); 314 } 315 316 inline bool ValueImp::isString() const 317 { 318 return !SimpleNumber::is(this) && downcast()->isString(); 319 } 320 321 inline bool ValueImp::isObject() const 322 { 323 return !SimpleNumber::is(this) && downcast()->isObject(); 324 } 325 326 inline bool ValueImp::isObject(const ClassInfo *c) const 327 { 328 return !SimpleNumber::is(this) && downcast()->isObject(c); 329 } 330 331 inline bool ValueImp::getBoolean(bool& v) const 332 { 333 return !SimpleNumber::is(this) && downcast()->getBoolean(v); 334 } 335 336 inline bool ValueImp::getNumber(double& v) const 337 { 338 if (SimpleNumber::is(this)) { 339 v = SimpleNumber::value(this); 340 return true; 341 } 342 return downcast()->getNumber(v); 343 } 344 345 inline double ValueImp::getNumber() const 346 { 347 return SimpleNumber::is(this) ? SimpleNumber::value(this) : downcast()->getNumber(); 348 } 349 350 inline bool ValueImp::getString(UString& s) const 351 { 352 return !SimpleNumber::is(this) && downcast()->getString(s); 353 } 354 355 inline UString ValueImp::getString() const 356 { 357 return SimpleNumber::is(this) ? UString() : downcast()->getString(); 358 } 359 360 inline ObjectImp *ValueImp::getObject() 361 { 362 return SimpleNumber::is(this) ? 0 : downcast()->getObject(); 363 } 364 365 inline const ObjectImp *ValueImp::getObject() const 366 { 367 return SimpleNumber::is(this) ? 0 : downcast()->getObject(); 368 } 369 370 inline bool ValueImp::getUInt32(uint32_t& v) const 371 { 372 if (SimpleNumber::is(this)) { 373 long i = SimpleNumber::value(this); 374 if (i < 0) 375 return false; 376 v = i; 377 return true; 378 } 379 return downcast()->getUInt32(v); 380 } 381 382 inline void ValueImp::mark() 383 { 384 if (!SimpleNumber::is(this)) 385 downcast()->mark(); 386 } 439 387 440 388 inline bool ValueImp::marked() const 441 389 { 442 // Simple numbers are always considered marked. 443 return SimpleNumber::is(this) || _marked; 444 } 445 446 // Dispatchers for virtual functions, to special-case simple numbers which 447 // won't be real pointers. 448 449 inline Type ValueImp::dispatchType() const 450 { 451 if (SimpleNumber::is(this)) 452 return NumberType; 453 return type(); 454 } 455 456 inline Value ValueImp::dispatchToPrimitive(ExecState *exec, Type preferredType) const 457 { 458 if (SimpleNumber::is(this)) 459 return Value(const_cast<ValueImp *>(this)); 460 return toPrimitive(exec, preferredType); 461 } 462 463 inline bool ValueImp::dispatchToBoolean(ExecState *exec) const 464 { 465 if (SimpleNumber::is(this)) 466 return SimpleNumber::value(this); 467 return toBoolean(exec); 468 } 469 470 inline double ValueImp::dispatchToNumber(ExecState *exec) const 471 { 472 if (SimpleNumber::is(this)) 473 return SimpleNumber::value(this); 474 return toNumber(exec); 475 } 476 477 inline double ValueImp::dispatchToNumber(ExecState *exec, bool &knownToBeInteger) const 390 return SimpleNumber::is(this) || downcast()->marked(); 391 } 392 393 inline Type ValueImp::type() const 394 { 395 return SimpleNumber::is(this) ? NumberType : downcast()->type(); 396 } 397 398 inline ValueImp *ValueImp::toPrimitive(ExecState *exec, Type preferredType) const 399 { 400 return SimpleNumber::is(this) ? const_cast<ValueImp *>(this) : downcast()->toPrimitive(exec, preferredType); 401 } 402 403 inline bool ValueImp::toBoolean(ExecState *exec) const 404 { 405 return SimpleNumber::is(this) ? SimpleNumber::value(this) : downcast()->toBoolean(exec); 406 } 407 408 inline double ValueImp::toNumber(ExecState *exec) const 409 { 410 return SimpleNumber::is(this) ? SimpleNumber::value(this) : downcast()->toNumber(exec); 411 } 412 413 inline double ValueImp::toNumber(ExecState *exec, bool& knownToBeInteger) const 478 414 { 479 415 if (SimpleNumber::is(this)) { … … 482 418 } 483 419 knownToBeInteger = false; 484 return toNumber(exec); 485 } 486 487 inline UString ValueImp::dispatchToString(ExecState *exec) const 488 { 489 if (SimpleNumber::is(this)) 490 return UString::from(SimpleNumber::value(this)); 491 return toString(exec); 492 } 493 494 inline bool ValueImp::dispatchToUInt32(uint32_t& result) const 495 { 496 if (SimpleNumber::is(this)) { 497 long i = SimpleNumber::value(this); 498 if (i < 0) 499 return false; 500 result = i; 501 return true; 502 } 503 return toUInt32(result); 504 } 420 return downcast()->toNumber(exec); 421 } 422 423 inline UString ValueImp::toString(ExecState *exec) const 424 { 425 return SimpleNumber::is(this) ? UString::from(SimpleNumber::value(this)) : downcast()->toString(exec); 426 } 427 428 inline ValueImp *jsZero() 429 { 430 return SimpleNumber::make(0); 431 } 432 433 inline ValueImp *jsOne() 434 { 435 return SimpleNumber::make(1); 436 } 437 438 inline ValueImp *jsTwo() 439 { 440 return SimpleNumber::make(2); 441 } 442 443 // compatibility names so we don't have to change so much code 444 445 inline AllocatedValueImp *Undefined() { return jsUndefined(); } 446 inline AllocatedValueImp *Null() { return jsNull(); } 447 inline AllocatedValueImp *Boolean(bool b) { return jsBoolean(b); } 448 inline ValueImp *Number(double n) { return jsNumber(n); } 449 inline ValueImp *Number(int n) { return jsNumber(n); } 450 inline ValueImp *Number(unsigned n) { return jsNumber(n); } 451 inline ValueImp *Number(long n) { return jsNumber(n); } 452 inline ValueImp *Number(unsigned long n) { return jsNumber(n); } 453 inline AllocatedValueImp *String(const UString& s) { return jsString(s); } 454 inline AllocatedValueImp *String(const char *s) { return jsString(s); } 505 455 506 456 } // namespace 507 457 508 #endif // _KJS_VALUE_H_458 #endif // KJS_VALUE_H
Note:
See TracChangeset
for help on using the changeset viewer.