Changeset 61003 in webkit
- Timestamp:
- Jun 11, 2010 3:36:18 AM (14 years ago)
- Location:
- trunk/JavaScriptCore
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/ChangeLog
r61002 r61003 1 2010-06-11 Jedrzej Nowacki <jedrzej.nowacki@nokia.com> 2 3 Reviewed by Simon Hausmann. 4 5 [Qt] Explicit conversions from QtScript types to JSC opaque types were removed. 6 https://bugs.webkit.org/show_bug.cgi?id=40412 7 8 Conversion between a JSC C types and a QtScript private types, takes 9 main part of the source code. In most cases a mapping between the types 10 is one to one. New cast operators were added to simplify the code. 11 12 The QScriptValuePrivate could be casted to the JSValueRef and the JSObjectRef. 13 The QScriptEnginePrivate could be casted to the JSGlobalContext. 14 The QScriptProgramPrivate could be casted to the JSStringRef. 15 16 * qt/api/qscriptengine_p.cpp: 17 (QScriptEnginePrivate::evaluate): 18 (QScriptEnginePrivate::newObject): 19 (QScriptEnginePrivate::globalObject): 20 * qt/api/qscriptengine_p.h: 21 (QScriptEnginePrivate::operator JSGlobalContextRef): 22 * qt/api/qscriptprogram_p.h: 23 (QScriptProgramPrivate::operator JSStringRef): 24 * qt/api/qscriptsyntaxcheckresult.cpp: 25 (QScriptSyntaxCheckResultPrivate::~QScriptSyntaxCheckResultPrivate): 26 (QScriptSyntaxCheckResultPrivate::errorMessage): 27 (QScriptSyntaxCheckResultPrivate::errorLineNumber): 28 * qt/api/qscriptvalue_p.h: 29 (QScriptValuePrivate::~QScriptValuePrivate): 30 (QScriptValuePrivate::QScriptValuePrivate): 31 (QScriptValuePrivate::isBool): 32 (QScriptValuePrivate::isNumber): 33 (QScriptValuePrivate::isNull): 34 (QScriptValuePrivate::isString): 35 (QScriptValuePrivate::isUndefined): 36 (QScriptValuePrivate::isFunction): 37 (QScriptValuePrivate::toString): 38 (QScriptValuePrivate::toNumber): 39 (QScriptValuePrivate::toBool): 40 (QScriptValuePrivate::toObject): 41 (QScriptValuePrivate::equals): 42 (QScriptValuePrivate::strictlyEquals): 43 (QScriptValuePrivate::instanceOf): 44 (QScriptValuePrivate::call): 45 (QScriptValuePrivate::operator JSValueRef): 46 (QScriptValuePrivate::operator JSObjectRef): 47 (QScriptValuePrivate::setValue): 48 (QScriptValuePrivate::inherits): 49 (QScriptValuePrivate::refinedJSValue): 50 1 51 2010-05-31 Jocelyn Turcotte <jocelyn.turcotte@nokia.com> 2 52 -
trunk/JavaScriptCore/qt/api/qscriptengine_p.cpp
r60583 r61003 75 75 if (program->isNull()) 76 76 return new QScriptValuePrivate; 77 return new QScriptValuePrivate(this, evaluate( program->program(), program->file(), program->line()));77 return new QScriptValuePrivate(this, evaluate(*program, program->file(), program->line())); 78 78 } 79 79 80 80 QScriptValuePrivate* QScriptEnginePrivate::newObject() const 81 81 { 82 return new QScriptValuePrivate(this, JSObjectMake( context(), /* jsClass */ 0, /* userData */ 0));82 return new QScriptValuePrivate(this, JSObjectMake(m_context, /* jsClass */ 0, /* userData */ 0)); 83 83 } 84 84 85 85 QScriptValuePrivate* QScriptEnginePrivate::globalObject() const 86 86 { 87 JSObjectRef globalObject = JSContextGetGlobalObject( context());87 JSObjectRef globalObject = JSContextGetGlobalObject(m_context); 88 88 return new QScriptValuePrivate(this, globalObject, globalObject); 89 89 } -
trunk/JavaScriptCore/qt/api/qscriptengine_p.h
r60583 r61003 62 62 inline QScriptStringPrivate* toStringHandle(const QString& str) const; 63 63 64 inline JSGlobalContextRef context() const;64 inline operator JSGlobalContextRef() const; 65 65 private: 66 66 QScriptEngine* q_ptr; … … 134 134 } 135 135 136 JSGlobalContextRef QScriptEnginePrivate::context() const136 QScriptEnginePrivate::operator JSGlobalContextRef() const 137 137 { 138 Q_ASSERT(this); 138 139 return m_context; 139 140 } -
trunk/JavaScriptCore/qt/api/qscriptprogram_p.h
r56320 r61003 53 53 inline bool operator!=(const QScriptProgramPrivate& other) const; 54 54 55 inline JSStringRef program() const;55 inline operator JSStringRef() const; 56 56 inline JSStringRef file() const; 57 57 inline int line() const; … … 123 123 } 124 124 125 JSStringRef QScriptProgramPrivate::program() const { return m_program; } 125 QScriptProgramPrivate::operator JSStringRef() const 126 { 127 return m_program; 128 } 129 126 130 JSStringRef QScriptProgramPrivate::file() const {return m_fileName; } 127 131 int QScriptProgramPrivate::line() const { return m_line; } -
trunk/JavaScriptCore/qt/api/qscriptsyntaxcheckresult.cpp
r57626 r61003 120 120 { 121 121 if (m_exception) 122 JSValueUnprotect( m_engine->context(), m_exception);122 JSValueUnprotect(*m_engine, m_exception); 123 123 } 124 124 … … 128 128 return QString(); 129 129 130 JSStringRef tmp = JSValueToStringCopy( m_engine->context(), m_exception, /* exception */ 0);130 JSStringRef tmp = JSValueToStringCopy(*m_engine, m_exception, /* exception */ 0); 131 131 QString message = QScriptConverter::toString(tmp); 132 132 JSStringRelease(tmp); … … 140 140 // m_exception is an instance of the Exception so it has "line" attribute. 141 141 JSStringRef lineAttrName = QScriptConverter::toString("line"); 142 JSValueRef line = JSObjectGetProperty( m_engine->context(),142 JSValueRef line = JSObjectGetProperty(*m_engine, 143 143 m_exception, 144 144 lineAttrName, 145 145 /* exceptions */0); 146 146 JSStringRelease(lineAttrName); 147 return JSValueToNumber( m_engine->context(), line, /* exceptions */0);147 return JSValueToNumber(*m_engine, line, /* exceptions */0); 148 148 } -
trunk/JavaScriptCore/qt/api/qscriptvalue_p.h
r60725 r61003 60 60 Each state keep all necessary information to invoke all methods, if not it should be changed to 61 61 a proper state. Changed state shouldn't be reverted. 62 63 The QScriptValuePrivate use the JSC C API directly. The QSVP type is equal to combination of 64 the JSValueRef and the JSObjectRef, and it could be automatically casted to these types by cast 65 operators. 62 66 */ 63 67 … … 115 119 inline QScriptValuePrivate* call(const QScriptValuePrivate* , const QScriptValueList& args); 116 120 117 inline JSGlobalContextRef context() const;118 inline JSValueRef value() const;119 inline JSObjectRef object() const; 121 inline operator JSValueRef() const; 122 inline operator JSObjectRef() const; 123 120 124 inline QScriptEnginePrivate* engine() const; 121 125 … … 164 168 { 165 169 if (m_value) 166 JSValueUnprotect( context(), m_value);170 JSValueUnprotect(*m_engine, m_value); 167 171 } 168 172 … … 220 224 { 221 225 Q_ASSERT(engine); 222 JSValueProtect( context(), m_value);226 JSValueProtect(*m_engine, m_value); 223 227 } 224 228 … … 229 233 { 230 234 Q_ASSERT(engine); 231 JSValueProtect( context(), m_value);235 JSValueProtect(*m_engine, m_value); 232 236 } 233 237 … … 238 242 { 239 243 Q_ASSERT(engine); 240 JSValueProtect( context(), m_value);244 JSValueProtect(*m_engine, m_value); 241 245 } 242 246 … … 247 251 { 248 252 Q_ASSERT(engine); 249 JSValueProtect( context(), m_value);253 JSValueProtect(*m_engine, m_value); 250 254 } 251 255 … … 256 260 { 257 261 Q_ASSERT(engine); 258 JSValueProtect( context(), m_value);262 JSValueProtect(*m_engine, m_value); 259 263 } 260 264 … … 265 269 { 266 270 Q_ASSERT(engine); 267 JSValueProtect( context(), m_value);271 JSValueProtect(*m_engine, m_value); 268 272 } 269 273 … … 275 279 Q_ASSERT(engine); 276 280 Q_ASSERT(value); 277 JSValueProtect( context(), m_value);281 JSValueProtect(*m_engine, m_value); 278 282 } 279 283 … … 287 291 Q_ASSERT(value); 288 292 Q_ASSERT(object); 289 JSValueProtect( context(), m_value);293 JSValueProtect(*m_engine, m_value); 290 294 } 291 295 … … 302 306 // Fall-through. 303 307 case JSPrimitive: 304 return JSValueIsBoolean( context(), value());308 return JSValueIsBoolean(*m_engine, *this); 305 309 default: 306 310 return false; … … 318 322 // Fall-through. 319 323 case JSPrimitive: 320 return JSValueIsNumber( context(), value());324 return JSValueIsNumber(*m_engine, *this); 321 325 default: 322 326 return false; … … 334 338 // Fall-through. 335 339 case JSPrimitive: 336 return JSValueIsNull( context(), value());340 return JSValueIsNull(*m_engine, *this); 337 341 default: 338 342 return false; … … 350 354 // Fall-through. 351 355 case JSPrimitive: 352 return JSValueIsString( context(), value());356 return JSValueIsString(*m_engine, *this); 353 357 default: 354 358 return false; … … 366 370 // Fall-through. 367 371 case JSPrimitive: 368 return JSValueIsUndefined( context(), value());372 return JSValueIsUndefined(*m_engine, *this); 369 373 default: 370 374 return false; … … 407 411 // Fall-through. 408 412 case JSObject: 409 return JSObjectIsFunction( context(), object());413 return JSObjectIsFunction(*m_engine, *this); 410 414 default: 411 415 return false; … … 431 435 case JSPrimitive: 432 436 case JSObject: 433 JSRetainPtr<JSStringRef> ptr(Adopt, JSValueToStringCopy( context(), value(), /* exception */ 0));437 JSRetainPtr<JSStringRef> ptr(Adopt, JSValueToStringCopy(*m_engine, *this, /* exception */ 0)); 434 438 return QScriptConverter::toString(ptr.get()); 435 439 } … … 445 449 case JSPrimitive: 446 450 case JSObject: 447 return JSValueToNumber( context(), value(), /* exception */ 0);451 return JSValueToNumber(*m_engine, *this, /* exception */ 0); 448 452 case CNumber: 449 453 return m_number; … … 477 481 case JSValue: 478 482 case JSPrimitive: 479 return JSValueToBoolean( context(), value());483 return JSValueToBoolean(*m_engine, *this); 480 484 case JSObject: 481 485 return true; … … 548 552 { 549 553 // Exception can't occur here. 550 JSObjectRef object = JSValueToObject( engine->context(), engine->makeJSValue(m_string), /* exception */ 0);554 JSObjectRef object = JSValueToObject(*engine, engine->makeJSValue(m_string), /* exception */ 0); 551 555 Q_ASSERT(object); 552 556 return new QScriptValuePrivate(engine, object, object); … … 555 559 { 556 560 // Exception can't occur here. 557 JSObjectRef object = JSValueToObject( engine->context(), engine->makeJSValue(m_number), /* exception */ 0);561 JSObjectRef object = JSValueToObject(*engine, engine->makeJSValue(m_number), /* exception */ 0); 558 562 Q_ASSERT(object); 559 563 return new QScriptValuePrivate(engine, object, object); … … 562 566 { 563 567 // Exception can't occure here. 564 JSObjectRef object = JSValueToObject( engine->context(), engine->makeJSValue(static_cast<bool>(m_number)), /* exception */ 0);568 JSObjectRef object = JSValueToObject(*engine, engine->makeJSValue(static_cast<bool>(m_number)), /* exception */ 0); 565 569 Q_ASSERT(object); 566 570 return new QScriptValuePrivate(engine, object, object); … … 574 578 if (engine != this->engine()) 575 579 qWarning("QScriptEngine::toObject: cannot convert value created in a different engine"); 576 JSObjectRef object = JSValueToObject( context(), value(), /* exception */ 0);580 JSObjectRef object = JSValueToObject(*m_engine, *this, /* exception */ 0); 577 581 if (object) 578 582 return new QScriptValuePrivate(m_engine.constData(), object); … … 632 636 } 633 637 634 return JSValueIsEqual( context(), value(), other->value(), /* exception */ 0);638 return JSValueIsEqual(*m_engine, *this, *other, /* exception */ 0); 635 639 } 636 640 … … 641 645 if (!other->isJSBased()) { 642 646 if (other->assignEngine(engine())) 643 return JSValueIsStrictEqual( context(), value(), other->value());647 return JSValueIsStrictEqual(*m_engine, *this, *other); 644 648 return false; 645 649 } … … 648 652 return false; 649 653 } 650 return JSValueIsStrictEqual( context(), value(), other->value());654 return JSValueIsStrictEqual(*m_engine, *this, *other); 651 655 } 652 656 if (isStringBased()) { … … 655 659 if (other->isJSBased()) { 656 660 assignEngine(other->engine()); 657 return JSValueIsStrictEqual( context(), value(), other->value());661 return JSValueIsStrictEqual(*m_engine, *this, *other); 658 662 } 659 663 } … … 663 667 if (other->isJSBased()) { 664 668 assignEngine(other->engine()); 665 return JSValueIsStrictEqual( context(), value(), other->value());669 return JSValueIsStrictEqual(*m_engine, *this, *other); 666 670 } 667 671 } … … 676 680 if (!isJSBased() || !other->isObject()) 677 681 return false; 678 return JSValueIsInstanceOfConstructor( context(), value(), other->object(), /* exception */ 0);682 return JSValueIsInstanceOfConstructor(*m_engine, *this, *other, /* exception */ 0); 679 683 } 680 684 … … 733 737 return new QScriptValuePrivate; 734 738 } 735 argv[j] = value->value();739 argv[j] = *value; 736 740 } 737 741 738 742 // Make the call 739 743 JSValueRef exception = 0; 740 JSValueRef result = JSObjectCallAsFunction( context(), object(), /* thisObject */ 0, argc, argv.constData(), &exception);744 JSValueRef result = JSObjectCallAsFunction(*m_engine, *this, /* thisObject */ 0, argc, argv.constData(), &exception); 741 745 if (!result && exception) 742 746 return new QScriptValuePrivate(engine(), exception); … … 757 761 } 758 762 759 JSGlobalContextRef QScriptValuePrivate::context() const 760 { 761 Q_ASSERT(isJSBased()); 762 return m_engine->context(); 763 } 764 765 JSValueRef QScriptValuePrivate::value() const 763 QScriptValuePrivate::operator JSValueRef() const 766 764 { 767 765 Q_ASSERT(isJSBased()); … … 769 767 } 770 768 771 JSObjectRef QScriptValuePrivate::object() const769 QScriptValuePrivate::operator JSObjectRef() const 772 770 { 773 771 Q_ASSERT(m_state == JSObject); … … 778 776 { 779 777 if (m_value) 780 JSValueUnprotect( context(), m_value);778 JSValueUnprotect(*m_engine, m_value); 781 779 if (value) 782 JSValueProtect( context(), value);780 JSValueProtect(*m_engine, value); 783 781 m_value = value; 784 782 } … … 792 790 { 793 791 Q_ASSERT(isJSBased()); 794 JSObjectRef globalObject = JSContextGetGlobalObject( context());792 JSObjectRef globalObject = JSContextGetGlobalObject(*m_engine); 795 793 JSStringRef errorAttrName = QScriptConverter::toString(name); 796 JSValueRef error = JSObjectGetProperty( context(), globalObject, errorAttrName, /* exception */ 0);794 JSValueRef error = JSObjectGetProperty(*m_engine, globalObject, errorAttrName, /* exception */ 0); 797 795 JSStringRelease(errorAttrName); 798 return JSValueIsInstanceOfConstructor( context(), value(), JSValueToObject(context(), error, /* exception */ 0), /* exception */ 0);796 return JSValueIsInstanceOfConstructor(*m_engine, *this, JSValueToObject(*m_engine, error, /* exception */ 0), /* exception */ 0); 799 797 } 800 798 … … 806 804 { 807 805 Q_ASSERT(m_state == JSValue); 808 if (!JSValueIsObject( context(), value())) {806 if (!JSValueIsObject(*m_engine, *this)) { 809 807 m_state = JSPrimitive; 810 808 } else { 811 809 m_state = JSObject; 812 810 // We are sure that value is an JSObject, so we can const_cast safely without 813 // calling JSC C API (JSValueToObject( context(), value(), /* exceptions */ 0)).811 // calling JSC C API (JSValueToObject(*m_engine, *this, /* exceptions */ 0)). 814 812 m_object = const_cast<JSObjectRef>(m_value); 815 813 }
Note: See TracChangeset
for help on using the changeset viewer.