Qt 4.8
qscriptengine.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtScript module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL-ONLY$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser
11 ** General Public License version 2.1 as published by the Free Software
12 ** Foundation and appearing in the file LICENSE.LGPL included in the
13 ** packaging of this file. Please review the following information to
14 ** ensure the GNU Lesser General Public License version 2.1 requirements
15 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
16 **
17 ** If you have questions regarding the use of this file, please contact
18 ** us via http://www.qt-project.org/.
19 **
20 ** $QT_END_LICENSE$
21 **
22 ****************************************************************************/
23 
24 #include "config.h"
25 #include "qscriptengine.h"
26 #include "qscriptsyntaxchecker_p.h"
27 
28 #include "qscriptengine_p.h"
29 #include "qscriptengineagent_p.h"
30 #include "qscriptcontext_p.h"
31 #include "qscriptstring_p.h"
32 #include "qscriptvalue_p.h"
33 #include "qscriptvalueiterator.h"
34 #include "qscriptclass.h"
35 #include "qscriptcontextinfo.h"
36 #include "qscriptprogram.h"
37 #include "qscriptprogram_p.h"
38 #include "qdebug.h"
39 
40 #include <QtCore/qstringlist.h>
41 #include <QtCore/qmetaobject.h>
42 
43 #include <math.h>
44 
45 #include "CodeBlock.h"
46 #include "Error.h"
47 #include "Interpreter.h"
48 
49 #include "ExceptionHelpers.h"
50 #include "PrototypeFunction.h"
51 #include "InitializeThreading.h"
52 #include "ObjectPrototype.h"
53 #include "SourceCode.h"
54 #include "FunctionPrototype.h"
55 #include "TimeoutChecker.h"
56 #include "JSFunction.h"
57 #include "Parser.h"
58 #include "PropertyNameArray.h"
59 #include "Operations.h"
60 
68 
69 #ifndef QT_NO_QOBJECT
70 #include <QtCore/qcoreapplication.h>
71 #include <QtCore/qdir.h>
72 #include <QtCore/qfile.h>
73 #include <QtCore/qfileinfo.h>
74 #include <QtCore/qpluginloader.h>
75 #include <QtCore/qset.h>
76 #include <QtCore/qtextstream.h>
78 #endif
79 
81 #ifndef QT_NO_QOBJECT
83 #endif
85 
87 
339 {
340 public:
343 
349 };
350 
352 {
353 public:
354  QScriptTypeInfo() : signature(0, '\0'), marshal(0), demarshal(0)
355  { }
356 
360  JSC::JSValue prototype;
361 };
362 
363 namespace QScript
364 {
365 
366 static const qsreal D32 = 4294967296.0;
367 
369 {
370  if (qIsNaN(n) || qIsInf(n) || (n == 0))
371  return 0;
372 
373  qsreal sign = (n < 0) ? -1.0 : 1.0;
374  qsreal abs_n = fabs(n);
375 
376  n = ::fmod(sign * ::floor(abs_n), D32);
377  const double D31 = D32 / 2.0;
378 
379  if (sign == -1 && n < -D31)
380  n += D32;
381 
382  else if (sign != -1 && n >= D31)
383  n -= D32;
384 
385  return qint32 (n);
386 }
387 
389 {
390  if (qIsNaN(n) || qIsInf(n) || (n == 0))
391  return 0;
392 
393  qsreal sign = (n < 0) ? -1.0 : 1.0;
394  qsreal abs_n = fabs(n);
395 
396  n = ::fmod(sign * ::floor(abs_n), D32);
397 
398  if (n < 0)
399  n += D32;
400 
401  return quint32 (n);
402 }
403 
405 {
406  static const qsreal D16 = 65536.0;
407 
408  if (qIsNaN(n) || qIsInf(n) || (n == 0))
409  return 0;
410 
411  qsreal sign = (n < 0) ? -1.0 : 1.0;
412  qsreal abs_n = fabs(n);
413 
414  n = ::fmod(sign * ::floor(abs_n), D16);
415 
416  if (n < 0)
417  n += D16;
418 
419  return quint16 (n);
420 }
421 
423 {
424  if (qIsNaN(n))
425  return 0;
426 
427  if (n == 0 || qIsInf(n))
428  return n;
429 
430  int sign = n < 0 ? -1 : 1;
431  return sign * ::floor(::fabs(n));
432 }
433 
434 #ifdef Q_CC_MSVC
435 // MSVC2008 crashes if these are inlined.
436 
437 QString ToString(qsreal value)
438 {
439  return JSC::UString::from(value);
440 }
441 
442 qsreal ToNumber(const QString &value)
443 {
444  return ((JSC::UString)value).toDouble();
445 }
446 
447 #endif
448 
449 static const qsreal MsPerSecond = 1000.0;
450 
451 static inline int MsFromTime(qsreal t)
452 {
453  int r = int(::fmod(t, MsPerSecond));
454  return (r >= 0) ? r : r + int(MsPerSecond);
455 }
456 
464 QDateTime MsToDateTime(JSC::ExecState *exec, qsreal t)
465 {
466  if (qIsNaN(t))
467  return QDateTime();
468  JSC::GregorianDateTime tm;
469  JSC::msToGregorianDateTime(exec, t, /*output UTC=*/true, tm);
470  int ms = MsFromTime(t);
471  QDateTime convertedUTC = QDateTime(QDate(tm.year + 1900, tm.month + 1, tm.monthDay),
472  QTime(tm.hour, tm.minute, tm.second, ms), Qt::UTC);
473  return convertedUTC.toLocalTime();
474 }
475 
483 qsreal DateTimeToMs(JSC::ExecState *exec, const QDateTime &dt)
484 {
485  if (!dt.isValid())
486  return qSNaN();
487  QDateTime utc = dt.toUTC();
488  QDate date = utc.date();
489  QTime time = utc.time();
490  JSC::GregorianDateTime tm;
491  tm.year = date.year() - 1900;
492  tm.month = date.month() - 1;
493  tm.monthDay = date.day();
494  tm.weekDay = date.dayOfWeek();
495  tm.yearDay = date.dayOfYear();
496  tm.hour = time.hour();
497  tm.minute = time.minute();
498  tm.second = time.second();
499  return JSC::gregorianDateTimeToMS(exec, tm, time.msec(), /*inputIsUTC=*/true);
500 }
501 
502 void GlobalClientData::mark(JSC::MarkStack& markStack)
503 {
504  engine->mark(markStack);
505 }
506 
507 class TimeoutCheckerProxy : public JSC::TimeoutChecker
508 {
509 public:
510  TimeoutCheckerProxy(const JSC::TimeoutChecker& originalChecker)
511  : JSC::TimeoutChecker(originalChecker)
512  , m_shouldProcessEvents(false)
513  , m_shouldAbortEvaluation(false)
514  {}
515 
516  void setShouldProcessEvents(bool shouldProcess) { m_shouldProcessEvents = shouldProcess; }
517  void setShouldAbort(bool shouldAbort) { m_shouldAbortEvaluation = shouldAbort; }
518  bool shouldAbort() { return m_shouldAbortEvaluation; }
519 
520  virtual bool didTimeOut(JSC::ExecState* exec)
521  {
522  if (JSC::TimeoutChecker::didTimeOut(exec))
523  return true;
524 
525  if (m_shouldProcessEvents)
527 
528  return m_shouldAbortEvaluation;
529  }
530 
531 private:
534 };
535 
536 static int toDigit(char c)
537 {
538  if ((c >= '0') && (c <= '9'))
539  return c - '0';
540  else if ((c >= 'a') && (c <= 'z'))
541  return 10 + c - 'a';
542  else if ((c >= 'A') && (c <= 'Z'))
543  return 10 + c - 'A';
544  return -1;
545 }
546 
547 qsreal integerFromString(const char *buf, int size, int radix)
548 {
549  if (size == 0)
550  return qSNaN();
551 
552  qsreal sign = 1.0;
553  int i = 0;
554  if (buf[0] == '+') {
555  ++i;
556  } else if (buf[0] == '-') {
557  sign = -1.0;
558  ++i;
559  }
560 
561  if (((size-i) >= 2) && (buf[i] == '0')) {
562  if (((buf[i+1] == 'x') || (buf[i+1] == 'X'))
563  && (radix < 34)) {
564  if ((radix != 0) && (radix != 16))
565  return 0;
566  radix = 16;
567  i += 2;
568  } else {
569  if (radix == 0) {
570  radix = 8;
571  ++i;
572  }
573  }
574  } else if (radix == 0) {
575  radix = 10;
576  }
577 
578  int j = i;
579  for ( ; i < size; ++i) {
580  int d = toDigit(buf[i]);
581  if ((d == -1) || (d >= radix))
582  break;
583  }
584  qsreal result;
585  if (j == i) {
586  if (!qstrcmp(buf, "Infinity"))
587  result = qInf();
588  else
589  result = qSNaN();
590  } else {
591  result = 0;
592  qsreal multiplier = 1;
593  for (--i ; i >= j; --i, multiplier *= radix)
594  result += toDigit(buf[i]) * multiplier;
595  }
596  result *= sign;
597  return result;
598 }
599 
600 qsreal integerFromString(const QString &str, int radix)
601 {
602  QByteArray ba = str.trimmed().toUtf8();
603  return integerFromString(ba.constData(), ba.size(), radix);
604 }
605 
606 bool isFunction(JSC::JSValue value)
607 {
608  if (!value || !value.isObject())
609  return false;
610  JSC::CallData callData;
611  return (JSC::asObject(value)->getCallData(callData) != JSC::CallTypeNone);
612 }
613 
614 static JSC::JSValue JSC_HOST_CALL functionConnect(JSC::ExecState*, JSC::JSObject*, JSC::JSValue, const JSC::ArgList&);
615 static JSC::JSValue JSC_HOST_CALL functionDisconnect(JSC::ExecState*, JSC::JSObject*, JSC::JSValue, const JSC::ArgList&);
616 
617 JSC::JSValue JSC_HOST_CALL functionDisconnect(JSC::ExecState *exec, JSC::JSObject * /*callee*/, JSC::JSValue thisObject, const JSC::ArgList &args)
618 {
619 #ifndef QT_NO_QOBJECT
620  if (args.size() == 0) {
621  return JSC::throwError(exec, JSC::GeneralError, "Function.prototype.disconnect: no arguments given");
622  }
623 
624  if (!JSC::asObject(thisObject)->inherits(&QScript::QtFunction::info)) {
625  return JSC::throwError(exec, JSC::TypeError, "Function.prototype.disconnect: this object is not a signal");
626  }
627 
628  QScript::QtFunction *qtSignal = static_cast<QScript::QtFunction*>(JSC::asObject(thisObject));
629 
630  const QMetaObject *meta = qtSignal->metaObject();
631  if (!meta) {
632  return JSC::throwError(exec, JSC::TypeError, "Function.prototype.discconnect: cannot disconnect from deleted QObject");
633  }
634 
635  QMetaMethod sig = meta->method(qtSignal->initialIndex());
636  if (sig.methodType() != QMetaMethod::Signal) {
637  QString message = QString::fromLatin1("Function.prototype.disconnect: %0::%1 is not a signal")
638  .arg(QLatin1String(qtSignal->metaObject()->className()))
639  .arg(QLatin1String(sig.signature()));
640  return JSC::throwError(exec, JSC::TypeError, message);
641  }
642 
644 
645  JSC::JSValue receiver;
646  JSC::JSValue slot;
647  JSC::JSValue arg0 = args.at(0);
648  if (args.size() < 2) {
649  slot = arg0;
650  } else {
651  receiver = arg0;
652  JSC::JSValue arg1 = args.at(1);
653  if (isFunction(arg1))
654  slot = arg1;
655  else {
656  QScript::SaveFrameHelper saveFrame(engine, exec);
657  JSC::UString propertyName = QScriptEnginePrivate::toString(exec, arg1);
658  slot = QScriptEnginePrivate::property(exec, arg0, propertyName, QScriptValue::ResolvePrototype);
659  }
660  }
661 
662  if (!isFunction(slot)) {
663  return JSC::throwError(exec, JSC::TypeError, "Function.prototype.disconnect: target is not a function");
664  }
665 
666  bool ok = engine->scriptDisconnect(thisObject, receiver, slot);
667  if (!ok) {
668  QString message = QString::fromLatin1("Function.prototype.disconnect: failed to disconnect from %0::%1")
669  .arg(QLatin1String(qtSignal->metaObject()->className()))
670  .arg(QLatin1String(sig.signature()));
671  return JSC::throwError(exec, JSC::GeneralError, message);
672  }
673  return JSC::jsUndefined();
674 #else
675  Q_UNUSED(eng);
676  return context->throwError(QScriptContext::TypeError,
677  QLatin1String("Function.prototype.disconnect"));
678 #endif // QT_NO_QOBJECT
679 }
680 
681 JSC::JSValue JSC_HOST_CALL functionConnect(JSC::ExecState *exec, JSC::JSObject * /*callee*/, JSC::JSValue thisObject, const JSC::ArgList &args)
682 {
683 #ifndef QT_NO_QOBJECT
684  if (args.size() == 0) {
685  return JSC::throwError(exec, JSC::GeneralError,"Function.prototype.connect: no arguments given");
686  }
687 
688  if (!JSC::asObject(thisObject)->inherits(&QScript::QtFunction::info)) {
689  return JSC::throwError(exec, JSC::TypeError, "Function.prototype.connect: this object is not a signal");
690  }
691 
692  QScript::QtFunction *qtSignal = static_cast<QScript::QtFunction*>(JSC::asObject(thisObject));
693 
694  const QMetaObject *meta = qtSignal->metaObject();
695  if (!meta) {
696  return JSC::throwError(exec, JSC::TypeError, "Function.prototype.connect: cannot connect to deleted QObject");
697  }
698 
699  QMetaMethod sig = meta->method(qtSignal->initialIndex());
700  if (sig.methodType() != QMetaMethod::Signal) {
701  QString message = QString::fromLatin1("Function.prototype.connect: %0::%1 is not a signal")
702  .arg(QLatin1String(qtSignal->metaObject()->className()))
703  .arg(QLatin1String(sig.signature()));
704  return JSC::throwError(exec, JSC::TypeError, message);
705  }
706 
707  {
708  QList<int> overloads = qtSignal->overloadedIndexes();
709  if (!overloads.isEmpty()) {
710  overloads.append(qtSignal->initialIndex());
711  QByteArray signature = sig.signature();
712  QString message = QString::fromLatin1("Function.prototype.connect: ambiguous connect to %0::%1(); candidates are\n")
713  .arg(QLatin1String(qtSignal->metaObject()->className()))
714  .arg(QLatin1String(signature.left(signature.indexOf('('))));
715  for (int i = 0; i < overloads.size(); ++i) {
716  QMetaMethod mtd = meta->method(overloads.at(i));
717  message.append(QString::fromLatin1(" %0\n").arg(QString::fromLatin1(mtd.signature())));
718  }
719  message.append(QString::fromLatin1("Use e.g. object['%0'].connect() to connect to a particular overload")
720  .arg(QLatin1String(signature)));
721  return JSC::throwError(exec, JSC::GeneralError, message);
722  }
723  }
724 
726 
727  JSC::JSValue receiver;
728  JSC::JSValue slot;
729  JSC::JSValue arg0 = args.at(0);
730  if (args.size() < 2) {
731  slot = arg0;
732  } else {
733  receiver = arg0;
734  JSC::JSValue arg1 = args.at(1);
735  if (isFunction(arg1))
736  slot = arg1;
737  else {
738  QScript::SaveFrameHelper saveFrame(engine, exec);
739  JSC::UString propertyName = QScriptEnginePrivate::toString(exec, arg1);
740  slot = QScriptEnginePrivate::property(exec, arg0, propertyName, QScriptValue::ResolvePrototype);
741  }
742  }
743 
744  if (!isFunction(slot)) {
745  return JSC::throwError(exec, JSC::TypeError, "Function.prototype.connect: target is not a function");
746  }
747 
748  bool ok = engine->scriptConnect(thisObject, receiver, slot, Qt::AutoConnection);
749  if (!ok) {
750  QString message = QString::fromLatin1("Function.prototype.connect: failed to connect to %0::%1")
751  .arg(QLatin1String(qtSignal->metaObject()->className()))
752  .arg(QLatin1String(sig.signature()));
753  return JSC::throwError(exec, JSC::GeneralError, message);
754  }
755  return JSC::jsUndefined();
756 #else
757  Q_UNUSED(eng);
758  Q_UNUSED(classInfo);
759  return context->throwError(QScriptContext::TypeError,
760  QLatin1String("Function.prototype.connect"));
761 #endif // QT_NO_QOBJECT
762 }
763 
764 static JSC::JSValue JSC_HOST_CALL functionPrint(JSC::ExecState*, JSC::JSObject*, JSC::JSValue, const JSC::ArgList&);
765 static JSC::JSValue JSC_HOST_CALL functionGC(JSC::ExecState*, JSC::JSObject*, JSC::JSValue, const JSC::ArgList&);
766 static JSC::JSValue JSC_HOST_CALL functionVersion(JSC::ExecState*, JSC::JSObject*, JSC::JSValue, const JSC::ArgList&);
767 
768 JSC::JSValue JSC_HOST_CALL functionPrint(JSC::ExecState* exec, JSC::JSObject*, JSC::JSValue, const JSC::ArgList& args)
769 {
770  QString result;
771  for (unsigned i = 0; i < args.size(); ++i) {
772  if (i != 0)
773  result.append(QLatin1Char(' '));
774  QString s(args.at(i).toString(exec));
775  if (exec->hadException())
776  break;
777  result.append(s);
778  }
779  if (exec->hadException())
780  return exec->exception();
781  qDebug("%s", qPrintable(result));
782  return JSC::jsUndefined();
783 }
784 
785 JSC::JSValue JSC_HOST_CALL functionGC(JSC::ExecState* exec, JSC::JSObject*, JSC::JSValue, const JSC::ArgList&)
786 {
788  engine->collectGarbage();
789  return JSC::jsUndefined();
790 }
791 
792 JSC::JSValue JSC_HOST_CALL functionVersion(JSC::ExecState *exec, JSC::JSObject*, JSC::JSValue, const JSC::ArgList&)
793 {
794  return JSC::JSValue(exec, 1);
795 }
796 
797 #ifndef QT_NO_TRANSLATION
798 
799 static JSC::JSValue JSC_HOST_CALL functionQsTranslate(JSC::ExecState*, JSC::JSObject*, JSC::JSValue, const JSC::ArgList&);
800 static JSC::JSValue JSC_HOST_CALL functionQsTranslateNoOp(JSC::ExecState*, JSC::JSObject*, JSC::JSValue, const JSC::ArgList&);
801 static JSC::JSValue JSC_HOST_CALL functionQsTr(JSC::ExecState*, JSC::JSObject*, JSC::JSValue, const JSC::ArgList&);
802 static JSC::JSValue JSC_HOST_CALL functionQsTrNoOp(JSC::ExecState*, JSC::JSObject*, JSC::JSValue, const JSC::ArgList&);
803 static JSC::JSValue JSC_HOST_CALL functionQsTrId(JSC::ExecState*, JSC::JSObject*, JSC::JSValue, const JSC::ArgList&);
804 static JSC::JSValue JSC_HOST_CALL functionQsTrIdNoOp(JSC::ExecState*, JSC::JSObject*, JSC::JSValue, const JSC::ArgList&);
805 
806 JSC::JSValue JSC_HOST_CALL functionQsTranslate(JSC::ExecState *exec, JSC::JSObject*, JSC::JSValue, const JSC::ArgList &args)
807 {
808  if (args.size() < 2)
809  return JSC::throwError(exec, JSC::GeneralError, "qsTranslate() requires at least two arguments");
810  if (!args.at(0).isString())
811  return JSC::throwError(exec, JSC::GeneralError, "qsTranslate(): first argument (context) must be a string");
812  if (!args.at(1).isString())
813  return JSC::throwError(exec, JSC::GeneralError, "qsTranslate(): second argument (text) must be a string");
814  if ((args.size() > 2) && !args.at(2).isString())
815  return JSC::throwError(exec, JSC::GeneralError, "qsTranslate(): third argument (comment) must be a string");
816  if ((args.size() > 3) && !args.at(3).isString())
817  return JSC::throwError(exec, JSC::GeneralError, "qsTranslate(): fourth argument (encoding) must be a string");
818  if ((args.size() > 4) && !args.at(4).isNumber())
819  return JSC::throwError(exec, JSC::GeneralError, "qsTranslate(): fifth argument (n) must be a number");
820 #ifndef QT_NO_QOBJECT
821  JSC::UString context = args.at(0).toString(exec);
822 #endif
823  JSC::UString text = args.at(1).toString(exec);
824 #ifndef QT_NO_QOBJECT
825  JSC::UString comment;
826  if (args.size() > 2)
827  comment = args.at(2).toString(exec);
829  if (args.size() > 3) {
830  JSC::UString encStr = args.at(3).toString(exec);
831  if (encStr == "CodecForTr")
832  encoding = QCoreApplication::CodecForTr;
833  else if (encStr == "UnicodeUTF8")
835  else
836  return JSC::throwError(exec, JSC::GeneralError, QString::fromLatin1("qsTranslate(): invalid encoding '%0'").arg(encStr));
837  }
838  int n = -1;
839  if (args.size() > 4)
840  n = args.at(4).toInt32(exec);
841 #endif
842  JSC::UString result;
843 #ifndef QT_NO_QOBJECT
844  result = QCoreApplication::translate(context.UTF8String().c_str(),
845  text.UTF8String().c_str(),
846  comment.UTF8String().c_str(),
847  encoding, n);
848 #else
849  result = text;
850 #endif
851  return JSC::jsString(exec, result);
852 }
853 
854 JSC::JSValue JSC_HOST_CALL functionQsTranslateNoOp(JSC::ExecState *, JSC::JSObject*, JSC::JSValue, const JSC::ArgList &args)
855 {
856  if (args.size() < 2)
857  return JSC::jsUndefined();
858  return args.at(1);
859 }
860 
861 JSC::JSValue JSC_HOST_CALL functionQsTr(JSC::ExecState *exec, JSC::JSObject*, JSC::JSValue, const JSC::ArgList &args)
862 {
863  if (args.size() < 1)
864  return JSC::throwError(exec, JSC::GeneralError, "qsTr() requires at least one argument");
865  if (!args.at(0).isString())
866  return JSC::throwError(exec, JSC::GeneralError, "qsTr(): first argument (text) must be a string");
867  if ((args.size() > 1) && !args.at(1).isString())
868  return JSC::throwError(exec, JSC::GeneralError, "qsTr(): second argument (comment) must be a string");
869  if ((args.size() > 2) && !args.at(2).isNumber())
870  return JSC::throwError(exec, JSC::GeneralError, "qsTr(): third argument (n) must be a number");
871 #ifndef QT_NO_QOBJECT
873  JSC::UString context;
874  // The first non-empty source URL in the call stack determines the translation context.
875  {
876  JSC::ExecState *frame = exec->callerFrame()->removeHostCallFrameFlag();
877  while (frame) {
878  if (frame->codeBlock() && QScriptEnginePrivate::hasValidCodeBlockRegister(frame)
879  && frame->codeBlock()->source()
880  && !frame->codeBlock()->source()->url().isEmpty()) {
881  context = engine->translationContextFromUrl(frame->codeBlock()->source()->url());
882  break;
883  }
884  frame = frame->callerFrame()->removeHostCallFrameFlag();
885  }
886  }
887 #endif
888  JSC::UString text = args.at(0).toString(exec);
889 #ifndef QT_NO_QOBJECT
890  JSC::UString comment;
891  if (args.size() > 1)
892  comment = args.at(1).toString(exec);
893  int n = -1;
894  if (args.size() > 2)
895  n = args.at(2).toInt32(exec);
896 #endif
897  JSC::UString result;
898 #ifndef QT_NO_QOBJECT
899  result = QCoreApplication::translate(context.UTF8String().c_str(),
900  text.UTF8String().c_str(),
901  comment.UTF8String().c_str(),
903 #else
904  result = text;
905 #endif
906  return JSC::jsString(exec, result);
907 }
908 
909 JSC::JSValue JSC_HOST_CALL functionQsTrNoOp(JSC::ExecState *, JSC::JSObject*, JSC::JSValue, const JSC::ArgList &args)
910 {
911  if (args.size() < 1)
912  return JSC::jsUndefined();
913  return args.at(0);
914 }
915 
916 JSC::JSValue JSC_HOST_CALL functionQsTrId(JSC::ExecState *exec, JSC::JSObject*, JSC::JSValue, const JSC::ArgList &args)
917 {
918  if (args.size() < 1)
919  return JSC::throwError(exec, JSC::GeneralError, "qsTrId() requires at least one argument");
920  if (!args.at(0).isString())
921  return JSC::throwError(exec, JSC::TypeError, "qsTrId(): first argument (id) must be a string");
922  if ((args.size() > 1) && !args.at(1).isNumber())
923  return JSC::throwError(exec, JSC::TypeError, "qsTrId(): second argument (n) must be a number");
924  JSC::UString id = args.at(0).toString(exec);
925  int n = -1;
926  if (args.size() > 1)
927  n = args.at(1).toInt32(exec);
928  return JSC::jsString(exec, qtTrId(id.UTF8String().c_str(), n));
929 }
930 
931 JSC::JSValue JSC_HOST_CALL functionQsTrIdNoOp(JSC::ExecState *, JSC::JSObject*, JSC::JSValue, const JSC::ArgList &args)
932 {
933  if (args.size() < 1)
934  return JSC::jsUndefined();
935  return args.at(0);
936 }
937 #endif // QT_NO_TRANSLATION
938 
939 static JSC::JSValue JSC_HOST_CALL stringProtoFuncArg(JSC::ExecState*, JSC::JSObject*, JSC::JSValue, const JSC::ArgList&);
940 
941 JSC::JSValue JSC_HOST_CALL stringProtoFuncArg(JSC::ExecState *exec, JSC::JSObject*, JSC::JSValue thisObject, const JSC::ArgList &args)
942 {
943  QString value(thisObject.toString(exec));
944  JSC::JSValue arg = (args.size() != 0) ? args.at(0) : JSC::jsUndefined();
945  QString result;
946  if (arg.isString())
947  result = value.arg(arg.toString(exec));
948  else if (arg.isNumber())
949  result = value.arg(arg.toNumber(exec));
950  return JSC::jsString(exec, result);
951 }
952 
953 
954 #if !defined(QT_NO_QOBJECT) && !defined(QT_NO_LIBRARY)
956 {
957  QString path = ctx->argument(0).toString();
958  QStringList components = path.split(QLatin1Char('.'));
959  QScriptValue o = eng->globalObject();
960  for (int i = 0; i < components.count(); ++i) {
961  QString name = components.at(i);
962  QScriptValue oo = o.property(name);
963  if (!oo.isValid()) {
964  oo = eng->newObject();
965  o.setProperty(name, oo);
966  }
967  o = oo;
968  }
969  return o;
970 }
971 #endif
972 
973 } // namespace QScript
974 
976  : originalGlobalObjectProxy(0), currentFrame(0),
977  qobjectPrototype(0), qmetaobjectPrototype(0), variantPrototype(0),
978  activeAgent(0), agentLineNumber(-1),
979  registeredScriptValues(0), freeScriptValues(0), freeScriptValuesCount(0),
980  registeredScriptStrings(0), processEventsInterval(-1), inEval(false)
981 {
982  qMetaTypeId<QScriptValue>();
983  qMetaTypeId<QList<int> >();
984 #ifndef QT_NO_QOBJECT
985  qMetaTypeId<QObjectList>();
986 #endif
987 
989  qFatal("QScriptEngine: Must construct a Q(Core)Application before a QScriptEngine");
990  return;
991  }
992  JSC::initializeThreading();
993  JSC::IdentifierTable *oldTable = JSC::currentIdentifierTable();
994  globalData = JSC::JSGlobalData::create().releaseRef();
995  globalData->clientData = new QScript::GlobalClientData(this);
996  JSC::JSGlobalObject *globalObject = new (globalData)QScript::GlobalObject();
997 
998  JSC::ExecState* exec = globalObject->globalExec();
999 
1000  scriptObjectStructure = QScriptObject::createStructure(globalObject->objectPrototype());
1002 
1003  qobjectPrototype = new (exec) QScript::QObjectPrototype(exec, QScript::QObjectPrototype::createStructure(globalObject->objectPrototype()), globalObject->prototypeFunctionStructure());
1005 
1006  qmetaobjectPrototype = new (exec) QScript::QMetaObjectPrototype(exec, QScript::QMetaObjectPrototype::createStructure(globalObject->objectPrototype()), globalObject->prototypeFunctionStructure());
1008 
1009  variantPrototype = new (exec) QScript::QVariantPrototype(exec, QScript::QVariantPrototype::createStructure(globalObject->objectPrototype()), globalObject->prototypeFunctionStructure());
1011 
1012  globalObject->putDirectFunction(exec, new (exec)JSC::NativeFunctionWrapper(exec, globalObject->prototypeFunctionStructure(), 1, JSC::Identifier(exec, "print"), QScript::functionPrint));
1013  globalObject->putDirectFunction(exec, new (exec)JSC::NativeFunctionWrapper(exec, globalObject->prototypeFunctionStructure(), 0, JSC::Identifier(exec, "gc"), QScript::functionGC));
1014  globalObject->putDirectFunction(exec, new (exec)JSC::NativeFunctionWrapper(exec, globalObject->prototypeFunctionStructure(), 0, JSC::Identifier(exec, "version"), QScript::functionVersion));
1015 
1016  // ### rather than extending Function.prototype, consider creating a QtSignal.prototype
1017  globalObject->functionPrototype()->putDirectFunction(exec, new (exec)JSC::NativeFunctionWrapper(exec, globalObject->prototypeFunctionStructure(), 1, JSC::Identifier(exec, "disconnect"), QScript::functionDisconnect));
1018  globalObject->functionPrototype()->putDirectFunction(exec, new (exec)JSC::NativeFunctionWrapper(exec, globalObject->prototypeFunctionStructure(), 1, JSC::Identifier(exec, "connect"), QScript::functionConnect));
1019 
1020  JSC::TimeoutChecker* originalChecker = globalData->timeoutChecker;
1021  globalData->timeoutChecker = new QScript::TimeoutCheckerProxy(*originalChecker);
1022  delete originalChecker;
1023 
1024  currentFrame = exec;
1025 
1026  cachedTranslationUrl = JSC::UString();
1027  cachedTranslationContext = JSC::UString();
1028  JSC::setCurrentIdentifierTable(oldTable);
1029 }
1030 
1032 {
1033  QScript::APIShim shim(this);
1034 
1035  //disconnect all loadedScripts and generate all jsc::debugger::scriptUnload events
1037  for (it = loadedScripts.constBegin(); it != loadedScripts.constEnd(); ++it)
1038  it.value()->disconnectFromEngine();
1039 
1040  while (!ownedAgents.isEmpty())
1041  delete ownedAgents.takeFirst();
1042 
1048  globalData->heap.destroy();
1049  globalData->deref();
1050  while (freeScriptValues) {
1052  freeScriptValues = p->next;
1053  qFree(p);
1054  }
1055 }
1056 
1057 QVariant QScriptEnginePrivate::jscValueToVariant(JSC::ExecState *exec, JSC::JSValue value, int targetType)
1058 {
1059  QVariant v(targetType, (void *)0);
1060  if (convertValue(exec, value, targetType, v.data()))
1061  return v;
1062  if (uint(targetType) == QVariant::LastType)
1063  return toVariant(exec, value);
1064  if (isVariant(value)) {
1065  v = variantValue(value);
1066  if (v.canConvert(QVariant::Type(targetType))) {
1067  v.convert(QVariant::Type(targetType));
1068  return v;
1069  }
1071  if (typeName.endsWith('*')
1072  && (QMetaType::type(typeName.left(typeName.size()-1)) == targetType)) {
1073  return QVariant(targetType, *reinterpret_cast<void* *>(v.data()));
1074  }
1075  }
1076  return QVariant();
1077 }
1078 
1079 JSC::JSValue QScriptEnginePrivate::arrayFromStringList(JSC::ExecState *exec, const QStringList &lst)
1080 {
1081  JSC::JSValue arr = newArray(exec, lst.size());
1082  for (int i = 0; i < lst.size(); ++i)
1083  setProperty(exec, arr, i, JSC::jsString(exec, lst.at(i)));
1084  return arr;
1085 }
1086 
1087 QStringList QScriptEnginePrivate::stringListFromArray(JSC::ExecState *exec, JSC::JSValue arr)
1088 {
1089  QStringList lst;
1090  uint len = toUInt32(exec, property(exec, arr, exec->propertyNames().length));
1091  for (uint i = 0; i < len; ++i)
1092  lst.append(toString(exec, property(exec, arr, i)));
1093  return lst;
1094 }
1095 
1096 JSC::JSValue QScriptEnginePrivate::arrayFromVariantList(JSC::ExecState *exec, const QVariantList &lst)
1097 {
1098  JSC::JSValue arr = newArray(exec, lst.size());
1099  for (int i = 0; i < lst.size(); ++i)
1100  setProperty(exec, arr, i, jscValueFromVariant(exec, lst.at(i)));
1101  return arr;
1102 }
1103 
1104 QVariantList QScriptEnginePrivate::variantListFromArray(JSC::ExecState *exec, JSC::JSArray *arr)
1105 {
1107  if (eng->visitedConversionObjects.contains(arr))
1108  return QVariantList(); // Avoid recursion.
1109  eng->visitedConversionObjects.insert(arr);
1110  QVariantList lst;
1111  uint len = toUInt32(exec, property(exec, arr, exec->propertyNames().length));
1112  for (uint i = 0; i < len; ++i)
1113  lst.append(toVariant(exec, property(exec, arr, i)));
1114  eng->visitedConversionObjects.remove(arr);
1115  return lst;
1116 }
1117 
1118 JSC::JSValue QScriptEnginePrivate::objectFromVariantMap(JSC::ExecState *exec, const QVariantMap &vmap)
1119 {
1120  JSC::JSValue obj = JSC::constructEmptyObject(exec);
1122  for (it = vmap.constBegin(); it != vmap.constEnd(); ++it)
1123  setProperty(exec, obj, it.key(), jscValueFromVariant(exec, it.value()));
1124  return obj;
1125 }
1126 
1127 QVariantMap QScriptEnginePrivate::variantMapFromObject(JSC::ExecState *exec, JSC::JSObject *obj)
1128 {
1130  if (eng->visitedConversionObjects.contains(obj))
1131  return QVariantMap(); // Avoid recursion.
1132  eng->visitedConversionObjects.insert(obj);
1133  JSC::PropertyNameArray propertyNames(exec);
1134  obj->getOwnPropertyNames(exec, propertyNames, JSC::IncludeDontEnumProperties);
1135  QVariantMap vmap;
1136  JSC::PropertyNameArray::const_iterator it = propertyNames.begin();
1137  for( ; it != propertyNames.end(); ++it)
1138  vmap.insert(it->ustring(), toVariant(exec, property(exec, obj, *it)));
1139  eng->visitedConversionObjects.remove(obj);
1140  return vmap;
1141 }
1142 
1143 JSC::JSValue QScriptEnginePrivate::defaultPrototype(int metaTypeId) const
1144 {
1145  QScriptTypeInfo *info = m_typeInfos.value(metaTypeId);
1146  if (!info)
1147  return JSC::JSValue();
1148  return info->prototype;
1149 }
1150 
1151 void QScriptEnginePrivate::setDefaultPrototype(int metaTypeId, JSC::JSValue prototype)
1152 {
1153  QScriptTypeInfo *info = m_typeInfos.value(metaTypeId);
1154  if (!info) {
1155  info = new QScriptTypeInfo();
1156  m_typeInfos.insert(metaTypeId, info);
1157  }
1158  info->prototype = prototype;
1159 }
1160 
1162 {
1163  return globalData->head;
1164 }
1165 
1167 {
1169  return glob->customGlobalObject;
1170 }
1171 
1173 {
1175  JSC::ExecState* exec = currentFrame;
1177  }
1179 }
1180 
1182 {
1184  if (glob->customGlobalObject)
1185  return glob->customGlobalObject;
1186  return glob;
1187 }
1188 
1189 void QScriptEnginePrivate::setGlobalObject(JSC::JSObject *object)
1190 {
1191  if (object == globalObject())
1192  return;
1194  if (object == originalGlobalObjectProxy) {
1195  glob->customGlobalObject = 0;
1196  // Sync the internal prototype, since JSObject::prototype() is not virtual.
1197  glob->setPrototype(originalGlobalObjectProxy->prototype());
1198  } else {
1199  Q_ASSERT(object != originalGlobalObject());
1200  glob->customGlobalObject = object;
1201  // Sync the internal prototype, since JSObject::prototype() is not virtual.
1202  glob->setPrototype(object->prototype());
1203  }
1204 }
1205 
1216 JSC::JSValue QScriptEnginePrivate::toUsableValue(JSC::JSValue value)
1217 {
1218  if (!value || !value.isObject() || !JSC::asObject(value)->isGlobalObject())
1219  return value;
1220  Q_ASSERT(JSC::asObject(value) == originalGlobalObject());
1221  if (customGlobalObject())
1222  return customGlobalObject();
1226 }
1231 JSC::JSValue QScriptEnginePrivate::thisForContext(JSC::ExecState *frame)
1232 {
1233  if (frame->codeBlock() != 0) {
1234  return frame->thisValue();
1235  } else if(frame == frame->lexicalGlobalObject()->globalExec()) {
1236  return frame->globalThisValue();
1237  } else {
1238  JSC::Register *thisRegister = thisRegisterForFrame(frame);
1239  return thisRegister->jsValue();
1240  }
1241 }
1242 
1243 JSC::Register* QScriptEnginePrivate::thisRegisterForFrame(JSC::ExecState *frame)
1244 {
1245  Q_ASSERT(frame->codeBlock() == 0); // only for native calls
1246  return frame->registers() - JSC::RegisterFile::CallFrameHeaderSize - frame->argumentCount();
1247 }
1248 
1261 {
1262  if (exec->codeBlock())
1263  return 0; //js function doesn't have flags
1264 
1265  return exec->returnValueRegister();
1266 }
1267 
1268 void QScriptEnginePrivate::setContextFlags(JSC::ExecState *exec, uint flags)
1269 {
1270  Q_ASSERT(!exec->codeBlock());
1271  exec->registers()[JSC::RegisterFile::ReturnValueRegister] = JSC::Register::withInt(flags);
1272 }
1273 
1274 
1275 void QScriptEnginePrivate::mark(JSC::MarkStack& markStack)
1276 {
1277  Q_Q(QScriptEngine);
1278 
1279  if (originalGlobalObject()) {
1280  markStack.append(originalGlobalObject());
1281  markStack.append(globalObject());
1283  markStack.append(originalGlobalObjectProxy);
1284  }
1285 
1286  if (qobjectPrototype)
1287  markStack.append(qobjectPrototype);
1289  markStack.append(qmetaobjectPrototype);
1290  if (variantPrototype)
1291  markStack.append(variantPrototype);
1292 
1293  {
1295  for (it = registeredScriptValues; it != 0; it = it->next) {
1296  if (it->isJSC())
1297  markStack.append(it->jscValue);
1298  }
1299  }
1300 
1301  {
1303  for (it = m_typeInfos.constBegin(); it != m_typeInfos.constEnd(); ++it) {
1304  if ((*it)->prototype)
1305  markStack.append((*it)->prototype);
1306  }
1307  }
1308 
1309  if (q) {
1310  QScriptContext *context = q->currentContext();
1311 
1312  while (context) {
1313  JSC::ScopeChainNode *node = frameForContext(context)->scopeChain();
1314  JSC::ScopeChainIterator it(node);
1315  for (it = node->begin(); it != node->end(); ++it) {
1316  JSC::JSObject *object = *it;
1317  if (object)
1318  markStack.append(object);
1319  }
1320 
1321  context = context->parentContext();
1322  }
1323  }
1324 
1325 #ifndef QT_NO_QOBJECT
1326  markStack.drain(); // make sure everything is marked before marking qobject data
1327  {
1329  for (it = m_qobjectData.constBegin(); it != m_qobjectData.constEnd(); ++it) {
1330  QScript::QObjectData *qdata = it.value();
1331  qdata->mark(markStack);
1332  }
1333  }
1334 #endif
1335 }
1336 
1338 {
1339  return globalData->heap.isBusy();
1340 }
1341 
1343 {
1344  QScript::APIShim shim(this);
1345  globalData->heap.collectAllGarbage();
1346 }
1347 
1349 {
1350  if (size > 0)
1351  globalData->heap.reportExtraMemoryCost(size);
1352 }
1353 
1355 {
1356  return static_cast<QScript::TimeoutCheckerProxy*>(globalData->timeoutChecker);
1357 }
1358 
1360 {
1361  ownedAgents.removeOne(agent);
1362  if (activeAgent == agent) {
1363  QScriptEngineAgentPrivate::get(agent)->detach();
1364  activeAgent = 0;
1365  }
1366 }
1367 
1368 JSC::JSValue QScriptEnginePrivate::evaluateHelper(JSC::ExecState *exec, intptr_t sourceId,
1369  JSC::EvalExecutable *executable,
1370  bool &compile)
1371 {
1372  Q_Q(QScriptEngine);
1373  QBoolBlocker inEvalBlocker(inEval, true);
1374  q->currentContext()->activationObject(); //force the creation of a context for native function;
1375 
1376  JSC::Debugger* debugger = originalGlobalObject()->debugger();
1377  if (debugger)
1378  debugger->evaluateStart(sourceId);
1379 
1380  q->clearExceptions();
1381  JSC::DynamicGlobalObjectScope dynamicGlobalObjectScope(exec, exec->scopeChain()->globalObject);
1382 
1383  if (compile && !executable->isCompiled()) {
1384  JSC::JSObject* error = executable->compile(exec, exec->scopeChain());
1385  if (error) {
1386  compile = false;
1387  exec->setException(error);
1388 
1389  if (debugger) {
1390  debugger->exceptionThrow(JSC::DebuggerCallFrame(exec, error), sourceId, false);
1391  debugger->evaluateStop(error, sourceId);
1392  }
1393 
1394  return error;
1395  }
1396  }
1397 
1398  JSC::JSValue thisValue = thisForContext(exec);
1399  JSC::JSObject* thisObject = (!thisValue || thisValue.isUndefinedOrNull())
1400  ? exec->dynamicGlobalObject() : thisValue.toObject(exec);
1401  JSC::JSValue exceptionValue;
1402  timeoutChecker()->setShouldAbort(false);
1403  if (processEventsInterval > 0)
1404  timeoutChecker()->reset();
1405 
1406  JSC::JSValue result = exec->interpreter()->execute(executable, exec, thisObject, exec->scopeChain(), &exceptionValue);
1407 
1408  if (timeoutChecker()->shouldAbort()) {
1409  if (abortResult.isError())
1410  exec->setException(scriptValueToJSCValue(abortResult));
1411 
1412  if (debugger)
1413  debugger->evaluateStop(scriptValueToJSCValue(abortResult), sourceId);
1414 
1416  }
1417 
1418  if (exceptionValue) {
1419  exec->setException(exceptionValue);
1420 
1421  if (debugger)
1422  debugger->evaluateStop(exceptionValue, sourceId);
1423 
1424  return exceptionValue;
1425  }
1426 
1427  if (debugger)
1428  debugger->evaluateStop(result, sourceId);
1429 
1430  Q_ASSERT(!exec->hadException());
1431  return result;
1432 }
1433 
1434 #ifndef QT_NO_QOBJECT
1435 
1437  QObject *object, QScriptEngine::ValueOwnership ownership,
1438  const QScriptEngine::QObjectWrapOptions &options)
1439 {
1440  if (!object)
1441  return JSC::jsNull();
1442  JSC::ExecState* exec = currentFrame;
1444  bool preferExisting = (options & QScriptEngine::PreferExistingWrapperObject) != 0;
1445  QScriptEngine::QObjectWrapOptions opt = options & ~QScriptEngine::PreferExistingWrapperObject;
1446  QScriptObject *result = 0;
1447  if (preferExisting) {
1448  result = data->findWrapper(ownership, opt);
1449  if (result)
1450  return result;
1451  }
1452  result = new (exec) QScriptObject(qobjectWrapperObjectStructure);
1453  if (preferExisting)
1454  data->registerWrapper(result, ownership, opt);
1455  result->setDelegate(new QScript::QObjectDelegate(object, ownership, options));
1456  /*if (setDefaultPrototype)*/ {
1457  const QMetaObject *meta = object->metaObject();
1458  while (meta) {
1459  QByteArray typeString = meta->className();
1460  typeString.append('*');
1461  int typeId = QMetaType::type(typeString);
1462  if (typeId != 0) {
1463  JSC::JSValue proto = defaultPrototype(typeId);
1464  if (proto) {
1465  result->setPrototype(proto);
1466  break;
1467  }
1468  }
1469  meta = meta->superClass();
1470  }
1471  }
1472  return result;
1473 }
1474 
1476  const QMetaObject *metaObject, JSC::JSValue ctor)
1477 {
1478  if (!metaObject)
1479  return JSC::jsNull();
1480  JSC::ExecState* exec = currentFrame;
1482  return result;
1483 }
1484 
1485 bool QScriptEnginePrivate::convertToNativeQObject(JSC::ExecState *exec, JSC::JSValue value,
1486  const QByteArray &targetType,
1487  void **result)
1488 {
1489  if (!targetType.endsWith('*'))
1490  return false;
1491  if (QObject *qobject = toQObject(exec, value)) {
1492  int start = targetType.startsWith("const ") ? 6 : 0;
1493  QByteArray className = targetType.mid(start, targetType.size()-start-1);
1494  if (void *instance = qobject->qt_metacast(className)) {
1495  *result = instance;
1496  return true;
1497  }
1498  }
1499  return false;
1500 }
1501 
1503 {
1505  it = m_qobjectData.constFind(object);
1506  if (it != m_qobjectData.constEnd())
1507  return it.value();
1508 
1510  m_qobjectData.insert(object, data);
1511  QObject::connect(object, SIGNAL(destroyed(QObject*)),
1512  q_func(), SLOT(_q_objectDestroyed(QObject*)));
1513  return data;
1514 }
1515 
1517 {
1519  it = m_qobjectData.find(object);
1520  Q_ASSERT(it != m_qobjectData.end());
1522  m_qobjectData.erase(it);
1523  delete data;
1524 }
1525 
1527 {
1528  // TODO
1529 /* if (isCollecting()) {
1530  // wait until we're done with GC before deleting it
1531  int index = m_qobjectsToBeDeleted.indexOf(object);
1532  if (index == -1)
1533  m_qobjectsToBeDeleted.append(object);
1534  } else*/ {
1535  delete object;
1536  }
1537 }
1538 
1540 {
1541  Q_Q(QScriptEngine);
1542  emit q->signalHandlerException(q->uncaughtException());
1543 }
1544 
1545 bool QScriptEnginePrivate::scriptConnect(QObject *sender, const char *signal,
1546  JSC::JSValue receiver, JSC::JSValue function,
1548 {
1549  Q_ASSERT(sender);
1550  Q_ASSERT(signal);
1551  const QMetaObject *meta = sender->metaObject();
1552  int index = meta->indexOfSignal(QMetaObject::normalizedSignature(signal+1));
1553  if (index == -1)
1554  return false;
1555  return scriptConnect(sender, index, receiver, function, /*wrapper=*/JSC::JSValue(), type);
1556 }
1557 
1558 bool QScriptEnginePrivate::scriptDisconnect(QObject *sender, const char *signal,
1559  JSC::JSValue receiver, JSC::JSValue function)
1560 {
1561  Q_ASSERT(sender);
1562  Q_ASSERT(signal);
1563  const QMetaObject *meta = sender->metaObject();
1564  int index = meta->indexOfSignal(QMetaObject::normalizedSignature(signal+1));
1565  if (index == -1)
1566  return false;
1567  return scriptDisconnect(sender, index, receiver, function);
1568 }
1569 
1571  JSC::JSValue receiver, JSC::JSValue function,
1572  JSC::JSValue senderWrapper,
1574 {
1576  return data->addSignalHandler(sender, signalIndex, receiver, function, senderWrapper, type);
1577 }
1578 
1580  JSC::JSValue receiver, JSC::JSValue function)
1581 {
1583  if (!data)
1584  return false;
1585  return data->removeSignalHandler(sender, signalIndex, receiver, function);
1586 }
1587 
1588 bool QScriptEnginePrivate::scriptConnect(JSC::JSValue signal, JSC::JSValue receiver,
1589  JSC::JSValue function, Qt::ConnectionType type)
1590 {
1591  QScript::QtFunction *fun = static_cast<QScript::QtFunction*>(JSC::asObject(signal));
1592  int index = fun->mostGeneralMethod();
1593  return scriptConnect(fun->qobject(), index, receiver, function, fun->wrapperObject(), type);
1594 }
1595 
1596 bool QScriptEnginePrivate::scriptDisconnect(JSC::JSValue signal, JSC::JSValue receiver,
1597  JSC::JSValue function)
1598 {
1599  QScript::QtFunction *fun = static_cast<QScript::QtFunction*>(JSC::asObject(signal));
1600  int index = fun->mostGeneralMethod();
1601  return scriptDisconnect(fun->qobject(), index, receiver, function);
1602 }
1603 
1604 #endif
1605 
1607 {
1610  (*it)->detachFromEngine();
1612 }
1613 
1615 {
1617  QScriptValuePrivate *next;
1618  for (it = registeredScriptValues; it != 0; it = next) {
1619  it->detachFromEngine();
1620  next = it->next;
1621  it->prev = 0;
1622  it->next = 0;
1623  }
1625 }
1626 
1628 {
1630  QScriptStringPrivate *next;
1631  for (it = registeredScriptStrings; it != 0; it = next) {
1632  it->detachFromEngine();
1633  next = it->next;
1634  it->prev = 0;
1635  it->next = 0;
1636  }
1638 }
1639 
1640 #ifndef QT_NO_REGEXP
1641 
1643 
1644 JSC::JSValue QScriptEnginePrivate::newRegExp(JSC::ExecState *exec, const QRegExp &regexp)
1645 {
1646  JSC::JSValue buf[2];
1647  JSC::ArgList args(buf, sizeof(buf));
1648 
1649  //convert the pattern to a ECMAScript pattern
1650  QString pattern = qt_regexp_toCanonical(regexp.pattern(), regexp.patternSyntax());
1651  if (regexp.isMinimal()) {
1652  QString ecmaPattern;
1653  int len = pattern.length();
1654  ecmaPattern.reserve(len);
1655  int i = 0;
1656  const QChar *wc = pattern.unicode();
1657  bool inBracket = false;
1658  while (i < len) {
1659  QChar c = wc[i++];
1660  ecmaPattern += c;
1661  switch (c.unicode()) {
1662  case '?':
1663  case '+':
1664  case '*':
1665  case '}':
1666  if (!inBracket)
1667  ecmaPattern += QLatin1Char('?');
1668  break;
1669  case '\\':
1670  if (i < len)
1671  ecmaPattern += wc[i++];
1672  break;
1673  case '[':
1674  inBracket = true;
1675  break;
1676  case ']':
1677  inBracket = false;
1678  break;
1679  default:
1680  break;
1681  }
1682  }
1683  pattern = ecmaPattern;
1684  }
1685 
1686  JSC::UString jscPattern = pattern;
1687  QString flags;
1688  if (regexp.caseSensitivity() == Qt::CaseInsensitive)
1689  flags.append(QLatin1Char('i'));
1690  JSC::UString jscFlags = flags;
1691  buf[0] = JSC::jsString(exec, jscPattern);
1692  buf[1] = JSC::jsString(exec, jscFlags);
1693  return JSC::constructRegExp(exec, args);
1694 }
1695 
1696 #endif
1697 
1698 JSC::JSValue QScriptEnginePrivate::newRegExp(JSC::ExecState *exec, const QString &pattern, const QString &flags)
1699 {
1700  JSC::JSValue buf[2];
1701  JSC::ArgList args(buf, sizeof(buf));
1702  JSC::UString jscPattern = pattern;
1703  QString strippedFlags;
1704  if (flags.contains(QLatin1Char('i')))
1705  strippedFlags += QLatin1Char('i');
1706  if (flags.contains(QLatin1Char('m')))
1707  strippedFlags += QLatin1Char('m');
1708  if (flags.contains(QLatin1Char('g')))
1709  strippedFlags += QLatin1Char('g');
1710  JSC::UString jscFlags = strippedFlags;
1711  buf[0] = JSC::jsString(exec, jscPattern);
1712  buf[1] = JSC::jsString(exec, jscFlags);
1713  return JSC::constructRegExp(exec, args);
1714 }
1715 
1716 JSC::JSValue QScriptEnginePrivate::newVariant(const QVariant &value)
1717 {
1719  obj->setDelegate(new QScript::QVariantDelegate(value));
1720  JSC::JSValue proto = defaultPrototype(value.userType());
1721  if (proto)
1722  obj->setPrototype(proto);
1723  return obj;
1724 }
1725 
1726 JSC::JSValue QScriptEnginePrivate::newVariant(JSC::JSValue objectValue,
1727  const QVariant &value)
1728 {
1729  if (!isObject(objectValue))
1730  return newVariant(value);
1731  JSC::JSObject *jscObject = JSC::asObject(objectValue);
1732  if (!jscObject->inherits(&QScriptObject::info)) {
1733  qWarning("QScriptEngine::newVariant(): changing class of non-QScriptObject not supported");
1734  return JSC::JSValue();
1735  }
1736  QScriptObject *jscScriptObject = static_cast<QScriptObject*>(jscObject);
1737  if (!isVariant(objectValue)) {
1738  jscScriptObject->setDelegate(new QScript::QVariantDelegate(value));
1739  } else {
1740  setVariantValue(objectValue, value);
1741  }
1742  return objectValue;
1743 }
1744 
1745 #ifndef QT_NO_REGEXP
1746 
1747 QRegExp QScriptEnginePrivate::toRegExp(JSC::ExecState *exec, JSC::JSValue value)
1748 {
1749  if (!isRegExp(value))
1750  return QRegExp();
1751  QString pattern = toString(exec, property(exec, value, "source", QScriptValue::ResolvePrototype));
1753  if (toBool(exec, property(exec, value, "ignoreCase", QScriptValue::ResolvePrototype)))
1754  kase = Qt::CaseInsensitive;
1755  return QRegExp(pattern, kase, QRegExp::RegExp2);
1756 }
1757 
1758 #endif
1759 
1760 QVariant QScriptEnginePrivate::toVariant(JSC::ExecState *exec, JSC::JSValue value)
1761 {
1762  if (!value) {
1763  return QVariant();
1764  } else if (isObject(value)) {
1765  if (isVariant(value))
1766  return variantValue(value);
1767 #ifndef QT_NO_QOBJECT
1768  else if (isQObject(value))
1769  return QVariant::fromValue(toQObject(exec, value));
1770 #endif
1771  else if (isDate(value))
1772  return QVariant(toDateTime(exec, value));
1773 #ifndef QT_NO_REGEXP
1774  else if (isRegExp(value))
1775  return QVariant(toRegExp(exec, value));
1776 #endif
1777  else if (isArray(value))
1778  return variantListFromArray(exec, JSC::asArray(value));
1779  else if (QScriptDeclarativeClass *dc = declarativeClass(value))
1780  return dc->toVariant(declarativeObject(value));
1781  return variantMapFromObject(exec, JSC::asObject(value));
1782  } else if (value.isInt32()) {
1783  return QVariant(toInt32(exec, value));
1784  } else if (value.isDouble()) {
1785  return QVariant(toNumber(exec, value));
1786  } else if (value.isString()) {
1787  return QVariant(toString(exec, value));
1788  } else if (value.isBoolean()) {
1789  return QVariant(toBool(exec, value));
1790  }
1791  return QVariant();
1792 }
1793 
1794 JSC::JSValue QScriptEnginePrivate::propertyHelper(JSC::ExecState *exec, JSC::JSValue value, const JSC::Identifier &id, int resolveMode)
1795 {
1796  JSC::JSValue result;
1797  if (!(resolveMode & QScriptValue::ResolvePrototype)) {
1798  // Look in the object's own properties
1799  JSC::JSObject *object = JSC::asObject(value);
1800  JSC::PropertySlot slot(object);
1801  if (object->getOwnPropertySlot(exec, id, slot))
1802  result = slot.getValue(exec, id);
1803  }
1804  if (!result && (resolveMode & QScriptValue::ResolveScope)) {
1805  // ### check if it's a function object and look in the scope chain
1806  JSC::JSValue scope = property(exec, value, "__qt_scope__", QScriptValue::ResolveLocal);
1807  if (isObject(scope))
1808  result = property(exec, scope, id, resolveMode);
1809  }
1810  return result;
1811 }
1812 
1813 JSC::JSValue QScriptEnginePrivate::propertyHelper(JSC::ExecState *exec, JSC::JSValue value, quint32 index, int resolveMode)
1814 {
1815  JSC::JSValue result;
1816  if (!(resolveMode & QScriptValue::ResolvePrototype)) {
1817  // Look in the object's own properties
1818  JSC::JSObject *object = JSC::asObject(value);
1819  JSC::PropertySlot slot(object);
1820  if (object->getOwnPropertySlot(exec, index, slot))
1821  result = slot.getValue(exec, index);
1822  }
1823  return result;
1824 }
1825 
1826 void QScriptEnginePrivate::setProperty(JSC::ExecState *exec, JSC::JSValue objectValue, const JSC::Identifier &id,
1827  JSC::JSValue value, const QScriptValue::PropertyFlags &flags)
1828 {
1829  JSC::JSObject *thisObject = JSC::asObject(objectValue);
1830  JSC::JSValue setter = thisObject->lookupSetter(exec, id);
1831  JSC::JSValue getter = thisObject->lookupGetter(exec, id);
1832  if ((flags & QScriptValue::PropertyGetter) || (flags & QScriptValue::PropertySetter)) {
1833  if (!value) {
1834  // deleting getter/setter
1835  if ((flags & QScriptValue::PropertyGetter) && (flags & QScriptValue::PropertySetter)) {
1836  // deleting both: just delete the property
1837  thisObject->deleteProperty(exec, id);
1838  } else if (flags & QScriptValue::PropertyGetter) {
1839  // preserve setter, if there is one
1840  thisObject->deleteProperty(exec, id);
1841  if (setter && setter.isObject())
1842  thisObject->defineSetter(exec, id, JSC::asObject(setter));
1843  } else { // flags & QScriptValue::PropertySetter
1844  // preserve getter, if there is one
1845  thisObject->deleteProperty(exec, id);
1846  if (getter && getter.isObject())
1847  thisObject->defineGetter(exec, id, JSC::asObject(getter));
1848  }
1849  } else {
1850  if (value.isObject()) { // ### should check if it has callData()
1851  // defining getter/setter
1852  if (id == exec->propertyNames().underscoreProto) {
1853  qWarning("QScriptValue::setProperty() failed: "
1854  "cannot set getter or setter of native property `__proto__'");
1855  } else {
1856  if (flags & QScriptValue::PropertyGetter)
1857  thisObject->defineGetter(exec, id, JSC::asObject(value));
1858  if (flags & QScriptValue::PropertySetter)
1859  thisObject->defineSetter(exec, id, JSC::asObject(value));
1860  }
1861  } else {
1862  qWarning("QScriptValue::setProperty(): getter/setter must be a function");
1863  }
1864  }
1865  } else {
1866  // setting the value
1867  if (getter && getter.isObject() && !(setter && setter.isObject())) {
1868  qWarning("QScriptValue::setProperty() failed: "
1869  "property '%s' has a getter but no setter",
1870  qPrintable(QString(id.ustring())));
1871  return;
1872  }
1873  if (!value) {
1874  // ### check if it's a getter/setter property
1875  thisObject->deleteProperty(exec, id);
1876  } else if (flags != QScriptValue::KeepExistingFlags) {
1877  if (thisObject->hasOwnProperty(exec, id))
1878  thisObject->deleteProperty(exec, id); // ### hmmm - can't we just update the attributes?
1879  thisObject->putWithAttributes(exec, id, value, propertyFlagsToJSCAttributes(flags));
1880  } else {
1881  JSC::PutPropertySlot slot;
1882  thisObject->put(exec, id, value, slot);
1883  }
1884  }
1885 }
1886 
1887 void QScriptEnginePrivate::setProperty(JSC::ExecState *exec, JSC::JSValue objectValue, quint32 index,
1888  JSC::JSValue value, const QScriptValue::PropertyFlags &flags)
1889 {
1890  if (!value) {
1891  JSC::asObject(objectValue)->deleteProperty(exec, index);
1892  } else {
1893  if ((flags & QScriptValue::PropertyGetter) || (flags & QScriptValue::PropertySetter)) {
1894  // fall back to string-based setProperty(), since there is no
1895  // JSC::JSObject::defineGetter(unsigned)
1896  setProperty(exec, objectValue, JSC::Identifier::from(exec, index), value, flags);
1897  } else {
1898  if (flags != QScriptValue::KeepExistingFlags) {
1899  // if (JSC::asObject(d->jscValue)->hasOwnProperty(exec, arrayIndex))
1900  // JSC::asObject(d->jscValue)->deleteProperty(exec, arrayIndex);
1901  unsigned attribs = 0;
1902  if (flags & QScriptValue::ReadOnly)
1903  attribs |= JSC::ReadOnly;
1904  if (flags & QScriptValue::SkipInEnumeration)
1905  attribs |= JSC::DontEnum;
1906  if (flags & QScriptValue::Undeletable)
1907  attribs |= JSC::DontDelete;
1908  attribs |= flags & QScriptValue::UserRange;
1909  JSC::asObject(objectValue)->putWithAttributes(exec, index, value, attribs);
1910  } else {
1911  JSC::asObject(objectValue)->put(exec, index, value);
1912  }
1913  }
1914  }
1915 }
1916 
1917 QScriptValue::PropertyFlags QScriptEnginePrivate::propertyFlags(JSC::ExecState *exec, JSC::JSValue value, const JSC::Identifier &id,
1918  const QScriptValue::ResolveFlags &mode)
1919 {
1920  JSC::JSObject *object = JSC::asObject(value);
1921  unsigned attribs = 0;
1922  JSC::PropertyDescriptor descriptor;
1923  if (object->getOwnPropertyDescriptor(exec, id, descriptor))
1924  attribs = descriptor.attributes();
1925  else {
1926  if ((mode & QScriptValue::ResolvePrototype) && object->prototype() && object->prototype().isObject()) {
1927  JSC::JSValue proto = object->prototype();
1928  return propertyFlags(exec, proto, id, mode);
1929  }
1930  return 0;
1931  }
1932  QScriptValue::PropertyFlags result = 0;
1933  if (attribs & JSC::ReadOnly)
1934  result |= QScriptValue::ReadOnly;
1935  if (attribs & JSC::DontEnum)
1937  if (attribs & JSC::DontDelete)
1938  result |= QScriptValue::Undeletable;
1939  //We cannot rely on attribs JSC::Setter/Getter because they are not necesserly set by JSC (bug?)
1940  if (attribs & JSC::Getter || !object->lookupGetter(exec, id).isUndefinedOrNull())
1941  result |= QScriptValue::PropertyGetter;
1942  if (attribs & JSC::Setter || !object->lookupSetter(exec, id).isUndefinedOrNull())
1943  result |= QScriptValue::PropertySetter;
1944 #ifndef QT_NO_QOBJECT
1945  if (attribs & QScript::QObjectMemberAttribute)
1946  result |= QScriptValue::QObjectMember;
1947 #endif
1949  return result;
1950 }
1951 
1953 {
1954  QScriptString result;
1956  QScriptStringPrivate::init(result, p);
1958  return result;
1959 }
1960 
1961 #ifdef QT_NO_QOBJECT
1962 
1964  : d_ptr(new QScriptEnginePrivate)
1965 {
1966  d_ptr->q_ptr = this;
1967 }
1968 
1972  : d_ptr(&dd)
1973 {
1974  d_ptr->q_ptr = this;
1975 }
1976 #else
1977 
1985  : QObject(*new QScriptEnginePrivate, 0)
1986 {
1987 }
1988 
1997  : QObject(*new QScriptEnginePrivate, parent)
1998 {
1999 }
2000 
2004  : QObject(dd, parent)
2005 {
2006 }
2007 #endif
2008 
2013 {
2014 #ifdef QT_NO_QOBJECT
2015  delete d_ptr;
2016  d_ptr = 0;
2017 #endif
2018 }
2019 
2031 {
2032  Q_D(const QScriptEngine);
2033  QScript::APIShim shim(const_cast<QScriptEnginePrivate*>(d));
2034  JSC::JSObject *result = d->globalObject();
2035  return const_cast<QScriptEnginePrivate*>(d)->scriptValueFromJSCValue(result);
2036 }
2037 
2054 {
2055  Q_D(QScriptEngine);
2056  if (!object.isObject())
2057  return;
2058  QScript::APIShim shim(d);
2059  JSC::JSObject *jscObject = JSC::asObject(d->scriptValueToJSCValue(object));
2060  d->setGlobalObject(jscObject);
2061 }
2062 
2069 {
2070  Q_D(QScriptEngine);
2071  return d->scriptValueFromJSCValue(JSC::jsNull());
2072 }
2073 
2080 {
2081  Q_D(QScriptEngine);
2082  return d->scriptValueFromJSCValue(JSC::jsUndefined());
2083 }
2084 
2111  const QScriptValue &prototype,
2112  int length)
2113 {
2114  Q_D(QScriptEngine);
2115  QScript::APIShim shim(d);
2116  JSC::ExecState* exec = d->currentFrame;
2117  JSC::JSValue function = new (exec)QScript::FunctionWrapper(exec, length, JSC::Identifier(exec, ""), fun);
2118  QScriptValue result = d->scriptValueFromJSCValue(function);
2119  result.setProperty(QLatin1String("prototype"), prototype,
2121  const_cast<QScriptValue&>(prototype)
2122  .setProperty(QLatin1String("constructor"), result, QScriptValue::SkipInEnumeration);
2123  return result;
2124 }
2125 
2126 #ifndef QT_NO_REGEXP
2127 
2135 {
2136  Q_D(QScriptEngine);
2137  QScript::APIShim shim(d);
2138  return d->scriptValueFromJSCValue(d->newRegExp(d->currentFrame, regexp));
2139 }
2140 
2141 #endif // QT_NO_REGEXP
2142 
2154 {
2155  Q_D(QScriptEngine);
2156  QScript::APIShim shim(d);
2157  return d->scriptValueFromJSCValue(d->newVariant(value));
2158 }
2159 
2190  const QVariant &value)
2191 {
2192  Q_D(QScriptEngine);
2193  QScript::APIShim shim(d);
2194  JSC::JSValue jsObject = d->scriptValueToJSCValue(object);
2195  return d->scriptValueFromJSCValue(d->newVariant(jsObject, value));
2196 }
2197 
2198 #ifndef QT_NO_QOBJECT
2199 
2222  const QObjectWrapOptions &options)
2223 {
2224  Q_D(QScriptEngine);
2225  QScript::APIShim shim(d);
2226  JSC::JSValue jscQObject = d->newQObject(object, ownership, options);
2227  return d->scriptValueFromJSCValue(jscQObject);
2228 }
2229 
2261  QObject *qtObject,
2262  ValueOwnership ownership,
2263  const QObjectWrapOptions &options)
2264 {
2265  Q_D(QScriptEngine);
2266  if (!scriptObject.isObject())
2267  return newQObject(qtObject, ownership, options);
2268  QScript::APIShim shim(d);
2269  JSC::JSObject *jscObject = JSC::asObject(QScriptValuePrivate::get(scriptObject)->jscValue);
2270  if (!jscObject->inherits(&QScriptObject::info)) {
2271  qWarning("QScriptEngine::newQObject(): changing class of non-QScriptObject not supported");
2272  return QScriptValue();
2273  }
2274  QScriptObject *jscScriptObject = static_cast<QScriptObject*>(jscObject);
2275  if (!scriptObject.isQObject()) {
2276  jscScriptObject->setDelegate(new QScript::QObjectDelegate(qtObject, ownership, options));
2277  } else {
2278  QScript::QObjectDelegate *delegate = static_cast<QScript::QObjectDelegate*>(jscScriptObject->delegate());
2279  delegate->setValue(qtObject);
2280  delegate->setOwnership(ownership);
2281  delegate->setOptions(options);
2282  }
2283  return scriptObject;
2284 }
2285 
2286 #endif // QT_NO_QOBJECT
2287 
2297 {
2298  Q_D(QScriptEngine);
2299  QScript::APIShim shim(d);
2300  return d->scriptValueFromJSCValue(d->newObject());
2301 }
2302 
2321  const QScriptValue &data)
2322 {
2323  Q_D(QScriptEngine);
2324  QScript::APIShim shim(d);
2325  JSC::ExecState* exec = d->currentFrame;
2326  QScriptObject *result = new (exec) QScriptObject(d->scriptObjectStructure);
2327  result->setDelegate(new QScript::ClassObjectDelegate(scriptClass));
2328  QScriptValue scriptObject = d->scriptValueFromJSCValue(result);
2329  scriptObject.setData(data);
2330  QScriptValue proto = scriptClass->prototype();
2331  if (proto.isValid())
2332  scriptObject.setPrototype(proto);
2333  return scriptObject;
2334 }
2335 
2340 {
2341  qWarning("QScriptEngine::newActivationObject() not implemented");
2342  // ### JSActivation or JSVariableObject?
2343  return QScriptValue();
2344 }
2345 
2390 {
2391  Q_D(QScriptEngine);
2392  QScript::APIShim shim(d);
2393  JSC::ExecState* exec = d->currentFrame;
2394  JSC::JSValue function = new (exec)QScript::FunctionWrapper(exec, length, JSC::Identifier(exec, ""), fun);
2395  QScriptValue result = d->scriptValueFromJSCValue(function);
2396  QScriptValue proto = newObject();
2397  result.setProperty(QLatin1String("prototype"), proto,
2399  proto.setProperty(QLatin1String("constructor"), result, QScriptValue::SkipInEnumeration);
2400  return result;
2401 }
2402 
2408 {
2409  Q_D(QScriptEngine);
2410  QScript::APIShim shim(d);
2411  JSC::ExecState* exec = d->currentFrame;
2412  JSC::JSValue function = new (exec)QScript::FunctionWithArgWrapper(exec, /*length=*/0, JSC::Identifier(exec, ""), fun, arg);
2413  QScriptValue result = d->scriptValueFromJSCValue(function);
2414  QScriptValue proto = newObject();
2415  result.setProperty(QLatin1String("prototype"), proto,
2417  proto.setProperty(QLatin1String("constructor"), result, QScriptValue::SkipInEnumeration);
2418  return result;
2419 }
2420 
2427 {
2428  Q_D(QScriptEngine);
2429  QScript::APIShim shim(d);
2430  return d->scriptValueFromJSCValue(d->newArray(d->currentFrame, length));
2431 }
2432 
2441 {
2442  Q_D(QScriptEngine);
2443  QScript::APIShim shim(d);
2444  return d->scriptValueFromJSCValue(d->newRegExp(d->currentFrame, pattern, flags));
2445 }
2446 
2453 {
2454  Q_D(QScriptEngine);
2455  QScript::APIShim shim(d);
2456  return d->scriptValueFromJSCValue(d->newDate(d->currentFrame, value));
2457 }
2458 
2465 {
2466  Q_D(QScriptEngine);
2467  QScript::APIShim shim(d);
2468  return d->scriptValueFromJSCValue(d->newDate(d->currentFrame, value));
2469 }
2470 
2471 #ifndef QT_NO_QOBJECT
2472 
2488  const QMetaObject *metaObject, const QScriptValue &ctor)
2489 {
2490  Q_D(QScriptEngine);
2491  QScript::APIShim shim(d);
2492  JSC::JSValue jscCtor = d->scriptValueToJSCValue(ctor);
2493  JSC::JSValue jscQMetaObject = d->newQMetaObject(metaObject, jscCtor);
2494  return d->scriptValueFromJSCValue(jscQMetaObject);
2495 }
2496 
2531 #endif // QT_NO_QOBJECT
2532 
2592 bool QScriptEngine::canEvaluate(const QString &program) const
2593 {
2594  return QScriptEnginePrivate::canEvaluate(program);
2595 }
2596 
2597 
2599 {
2600  QScript::SyntaxChecker checker;
2601  QScript::SyntaxChecker::Result result = checker.checkSyntax(program);
2602  return (result.state != QScript::SyntaxChecker::Intermediate);
2603 }
2604 
2615 {
2616  return QScriptEnginePrivate::checkSyntax(program);
2617 }
2618 
2620 {
2621  QScript::SyntaxChecker checker;
2622  QScript::SyntaxChecker::Result result = checker.checkSyntax(program);
2624  switch (result.state) {
2627  break;
2630  break;
2633  break;
2634  }
2635  p->errorLineNumber = result.errorLineNumber;
2637  p->errorMessage = result.errorMessage;
2638  return QScriptSyntaxCheckResult(p);
2639 }
2640 
2641 
2642 
2671 QScriptValue QScriptEngine::evaluate(const QString &program, const QString &fileName, int lineNumber)
2672 {
2673  Q_D(QScriptEngine);
2674  QScript::APIShim shim(d);
2675  WTF::PassRefPtr<QScript::UStringSourceProviderWithFeedback> provider
2676  = QScript::UStringSourceProviderWithFeedback::create(program, fileName, lineNumber, d);
2677  intptr_t sourceId = provider->asID();
2678  JSC::SourceCode source(provider, lineNumber); //after construction of SourceCode provider variable will be null.
2679 
2680  JSC::ExecState* exec = d->currentFrame;
2681  WTF::RefPtr<JSC::EvalExecutable> executable = JSC::EvalExecutable::create(exec, source);
2682  bool compile = true;
2683  return d->scriptValueFromJSCValue(d->evaluateHelper(exec, sourceId, executable.get(), compile));
2684 }
2685 
2696 {
2697  Q_D(QScriptEngine);
2698  QScriptProgramPrivate *program_d = QScriptProgramPrivate::get(program);
2699  if (!program_d)
2700  return QScriptValue();
2701 
2702  QScript::APIShim shim(d);
2703  JSC::ExecState* exec = d->currentFrame;
2704  JSC::EvalExecutable *executable = program_d->executable(exec, d);
2705  bool compile = !program_d->isCompiled;
2706  JSC::JSValue result = d->evaluateHelper(exec, program_d->sourceId,
2707  executable, compile);
2708  if (compile)
2709  program_d->isCompiled = true;
2710  return d->scriptValueFromJSCValue(result);
2711 }
2712 
2721 {
2722  Q_D(const QScriptEngine);
2723  return const_cast<QScriptEnginePrivate*>(d)->contextForFrame(d->currentFrame);
2724 }
2725 
2752 {
2753  Q_D(QScriptEngine);
2754  QScript::APIShim shim(d);
2755 
2756  JSC::CallFrame* newFrame = d->pushContext(d->currentFrame, d->currentFrame->globalData().dynamicGlobalObject,
2757  JSC::ArgList(), /*callee = */0);
2758 
2759  if (agent())
2760  agent()->contextPush();
2761 
2762  return d->contextForFrame(newFrame);
2763 }
2764 
2779  const JSC::ArgList& args, JSC::JSObject *callee, bool calledAsConstructor,
2780  bool clearScopeChain)
2781 {
2782  JSC::JSValue thisObject = _thisObject;
2783  if (!callee) {
2784  // callee can't be zero, as this can cause JSC to crash during GC
2785  // marking phase if the context's Arguments object has been created.
2786  // Fake it by using the global object. Note that this is also handled
2787  // in QScriptContext::callee(), as that function should still return
2788  // an invalid value.
2789  callee = originalGlobalObject();
2790  }
2791  if (calledAsConstructor) {
2792  //JSC doesn't create default created object for native functions. so we do it
2793  JSC::JSValue prototype = callee->get(exec, exec->propertyNames().prototype);
2794  JSC::Structure *structure = prototype.isObject() ? JSC::asObject(prototype)->inheritorID()
2795  : originalGlobalObject()->emptyObjectStructure();
2796  thisObject = new (exec) QScriptObject(structure);
2797  }
2798 
2799  int flags = NativeContext;
2800  if (calledAsConstructor)
2801  flags |= CalledAsConstructorContext;
2802 
2803  //build a frame
2804  JSC::CallFrame *newCallFrame = exec;
2805  if (callee == 0 //called from public QScriptEngine::pushContext
2806  || exec->returnPC() == 0 || (contextFlags(exec) & NativeContext) //called from native-native call
2807  || (exec->codeBlock() && exec->callee() != callee)) { //the interpreter did not build a frame for us.
2808  //We need to check if the Interpreter might have already created a frame for function called from JS.
2809  JSC::Interpreter *interp = exec->interpreter();
2810  JSC::Register *oldEnd = interp->registerFile().end();
2811  int argc = args.size() + 1; //add "this"
2812  JSC::Register *newEnd = oldEnd + argc + JSC::RegisterFile::CallFrameHeaderSize;
2813  if (!interp->registerFile().grow(newEnd))
2814  return 0; //### Stack overflow
2815  newCallFrame = JSC::CallFrame::create(oldEnd);
2816  newCallFrame[0] = thisObject;
2817  int dst = 0;
2818  JSC::ArgList::const_iterator it;
2819  for (it = args.begin(); it != args.end(); ++it)
2820  newCallFrame[++dst] = *it;
2821  newCallFrame += argc + JSC::RegisterFile::CallFrameHeaderSize;
2822 
2823  if (!clearScopeChain) {
2824  newCallFrame->init(0, /*vPC=*/0, exec->scopeChain(), exec, flags | ShouldRestoreCallFrame, argc, callee);
2825  } else {
2826  newCallFrame->init(0, /*vPC=*/0, globalExec()->scopeChain(), exec, flags | ShouldRestoreCallFrame, argc, callee);
2827  }
2828  } else {
2829  setContextFlags(newCallFrame, flags);
2830 #if ENABLE(JIT)
2831  exec->registers()[JSC::RegisterFile::Callee] = JSC::JSValue(callee); //JIT let the callee set the 'callee'
2832 #endif
2833  if (calledAsConstructor) {
2834  //update the new created this
2835  JSC::Register* thisRegister = thisRegisterForFrame(newCallFrame);
2836  *thisRegister = thisObject;
2837  }
2838  }
2839  currentFrame = newCallFrame;
2840  return newCallFrame;
2841 }
2842 
2843 
2851 {
2852  if (agent())
2853  agent()->contextPop();
2854  Q_D(QScriptEngine);
2855  QScript::APIShim shim(d);
2856  if (d->currentFrame->returnPC() != 0 || d->currentFrame->codeBlock() != 0
2857  || !currentContext()->parentContext()) {
2858  qWarning("QScriptEngine::popContext() doesn't match with pushContext()");
2859  return;
2860  }
2861 
2862  d->popContext();
2863 }
2864 
2869 {
2870  uint flags = contextFlags(currentFrame);
2871  bool hasScope = flags & HasScopeContext;
2872  if (flags & ShouldRestoreCallFrame) { //normal case
2873  JSC::RegisterFile &registerFile = currentFrame->interpreter()->registerFile();
2874  JSC::Register *const newEnd = currentFrame->registers() - JSC::RegisterFile::CallFrameHeaderSize - currentFrame->argumentCount();
2875  if (hasScope)
2876  currentFrame->scopeChain()->pop()->deref();
2877  registerFile.shrink(newEnd);
2878  } else if(hasScope) { //the stack frame was created by the Interpreter, we don't need to rewind it.
2879  currentFrame->setScopeChain(currentFrame->scopeChain()->pop());
2880  currentFrame->scopeChain()->deref();
2881  }
2882  currentFrame = currentFrame->callerFrame();
2883 }
2884 
2894 {
2895  Q_D(const QScriptEngine);
2896  JSC::ExecState* exec = d->globalExec();
2897  return exec->hadException() || d->currentException().isValid();
2898 }
2899 
2911 {
2912  Q_D(const QScriptEngine);
2913  QScriptValue result;
2914  JSC::ExecState* exec = d->globalExec();
2915  if (exec->hadException())
2916  result = const_cast<QScriptEnginePrivate*>(d)->scriptValueFromJSCValue(exec->exception());
2917  else
2918  result = d->currentException();
2919  return result;
2920 }
2921 
2931 {
2932  if (!hasUncaughtException())
2933  return -1;
2934  return uncaughtException().property(QLatin1String("lineNumber")).toInt32();
2935 }
2936 
2945 {
2946  if (!hasUncaughtException())
2947  return QStringList();
2948 // ### currently no way to get a full backtrace from JSC without installing a
2949 // debugger that reimplements exception() and store the backtrace there.
2950  QScriptValue value = uncaughtException();
2951  if (!value.isError())
2952  return QStringList();
2953  QStringList result;
2954  result.append(QString::fromLatin1("<anonymous>()@%0:%1")
2955  .arg(value.property(QLatin1String("fileName")).toString())
2956  .arg(value.property(QLatin1String("lineNumber")).toInt32()));
2957  return result;
2958 }
2959 
2971 {
2972  Q_D(QScriptEngine);
2973  JSC::ExecState* exec = d->currentFrame;
2974  exec->clearException();
2975  d->clearCurrentException();
2976 }
2977 
2985 {
2986  Q_D(const QScriptEngine);
2987  return const_cast<QScriptEnginePrivate*>(d)->scriptValueFromJSCValue(d->defaultPrototype(metaTypeId));
2988 }
2989 
3011 {
3012  Q_D(QScriptEngine);
3013  d->setDefaultPrototype(metaTypeId, d->scriptValueToJSCValue(prototype));
3014 }
3015 
3050 {
3051  Q_D(QScriptEngine);
3052  QScript::APIShim shim(d);
3053  return d->scriptValueFromJSCValue(d->create(d->currentFrame, type, ptr));
3054 }
3055 
3056 JSC::JSValue QScriptEnginePrivate::create(JSC::ExecState *exec, int type, const void *ptr)
3057 {
3058  Q_ASSERT(ptr != 0);
3059  JSC::JSValue result;
3060  QScriptEnginePrivate *eng = exec ? QScript::scriptEngineFromExec(exec) : 0;
3061  QScriptTypeInfo *info = eng ? eng->m_typeInfos.value(type) : 0;
3062  if (info && info->marshal) {
3063  result = eng->scriptValueToJSCValue(info->marshal(eng->q_func(), ptr));
3064  } else {
3065  // check if it's one of the types we know
3066  switch (QMetaType::Type(type)) {
3067  case QMetaType::Void:
3068  return JSC::jsUndefined();
3069  case QMetaType::Bool:
3070  return JSC::jsBoolean(*reinterpret_cast<const bool*>(ptr));
3071  case QMetaType::Int:
3072  return JSC::jsNumber(exec, *reinterpret_cast<const int*>(ptr));
3073  case QMetaType::UInt:
3074  return JSC::jsNumber(exec, *reinterpret_cast<const uint*>(ptr));
3075  case QMetaType::LongLong:
3076  return JSC::jsNumber(exec, qsreal(*reinterpret_cast<const qlonglong*>(ptr)));
3077  case QMetaType::ULongLong:
3078  return JSC::jsNumber(exec, qsreal(*reinterpret_cast<const qulonglong*>(ptr)));
3079  case QMetaType::Double:
3080  return JSC::jsNumber(exec, qsreal(*reinterpret_cast<const double*>(ptr)));
3081  case QMetaType::QString:
3082  return JSC::jsString(exec, *reinterpret_cast<const QString*>(ptr));
3083  case QMetaType::Float:
3084  return JSC::jsNumber(exec, *reinterpret_cast<const float*>(ptr));
3085  case QMetaType::Short:
3086  return JSC::jsNumber(exec, *reinterpret_cast<const short*>(ptr));
3087  case QMetaType::UShort:
3088  return JSC::jsNumber(exec, *reinterpret_cast<const unsigned short*>(ptr));
3089  case QMetaType::Char:
3090  return JSC::jsNumber(exec, *reinterpret_cast<const char*>(ptr));
3091  case QMetaType::UChar:
3092  return JSC::jsNumber(exec, *reinterpret_cast<const unsigned char*>(ptr));
3093  case QMetaType::QChar:
3094  return JSC::jsNumber(exec, (*reinterpret_cast<const QChar*>(ptr)).unicode());
3096  result = arrayFromStringList(exec, *reinterpret_cast<const QStringList *>(ptr));
3097  break;
3099  result = arrayFromVariantList(exec, *reinterpret_cast<const QVariantList *>(ptr));
3100  break;
3102  result = objectFromVariantMap(exec, *reinterpret_cast<const QVariantMap *>(ptr));
3103  break;
3104  case QMetaType::QDateTime:
3105  result = newDate(exec, *reinterpret_cast<const QDateTime *>(ptr));
3106  break;
3107  case QMetaType::QDate:
3108  result = newDate(exec, QDateTime(*reinterpret_cast<const QDate *>(ptr)));
3109  break;
3110 #ifndef QT_NO_REGEXP
3111  case QMetaType::QRegExp:
3112  result = newRegExp(exec, *reinterpret_cast<const QRegExp *>(ptr));
3113  break;
3114 #endif
3115 #ifndef QT_NO_QOBJECT
3118  result = eng->newQObject(*reinterpret_cast<QObject* const *>(ptr));
3119  break;
3120 #endif
3121  case QMetaType::QVariant:
3122  result = eng->newVariant(*reinterpret_cast<const QVariant*>(ptr));
3123  break;
3124  default:
3125  if (type == qMetaTypeId<QScriptValue>()) {
3126  result = eng->scriptValueToJSCValue(*reinterpret_cast<const QScriptValue*>(ptr));
3127  if (!result)
3128  return JSC::jsUndefined();
3129  }
3130 
3131 #ifndef QT_NO_QOBJECT
3132  // lazy registration of some common list types
3133  else if (type == qMetaTypeId<QObjectList>()) {
3134  qScriptRegisterSequenceMetaType<QObjectList>(eng->q_func());
3135  return create(exec, type, ptr);
3136  }
3137 #endif
3138  else if (type == qMetaTypeId<QList<int> >()) {
3139  qScriptRegisterSequenceMetaType<QList<int> >(eng->q_func());
3140  return create(exec, type, ptr);
3141  }
3142 
3143  else {
3145  if (typeName.endsWith('*') && !*reinterpret_cast<void* const *>(ptr))
3146  return JSC::jsNull();
3147  else
3148  result = eng->newVariant(QVariant(type, ptr));
3149  }
3150  }
3151  }
3152  if (result && result.isObject() && info && info->prototype
3153  && JSC::JSValue::strictEqual(exec, JSC::asObject(result)->prototype(), eng->originalGlobalObject()->objectPrototype())) {
3154  JSC::asObject(result)->setPrototype(info->prototype);
3155  }
3156  return result;
3157 }
3158 
3159 bool QScriptEnginePrivate::convertValue(JSC::ExecState *exec, JSC::JSValue value,
3160  int type, void *ptr)
3161 {
3162  QScriptEnginePrivate *eng = exec ? QScript::scriptEngineFromExec(exec) : 0;
3163  if (eng) {
3164  QScriptTypeInfo *info = eng->m_typeInfos.value(type);
3165  if (info && info->demarshal) {
3166  info->demarshal(eng->scriptValueFromJSCValue(value), ptr);
3167  return true;
3168  }
3169  }
3170 
3171  // check if it's one of the types we know
3172  switch (QMetaType::Type(type)) {
3173  case QMetaType::Bool:
3174  *reinterpret_cast<bool*>(ptr) = toBool(exec, value);
3175  return true;
3176  case QMetaType::Int:
3177  *reinterpret_cast<int*>(ptr) = toInt32(exec, value);
3178  return true;
3179  case QMetaType::UInt:
3180  *reinterpret_cast<uint*>(ptr) = toUInt32(exec, value);
3181  return true;
3182  case QMetaType::LongLong:
3183  *reinterpret_cast<qlonglong*>(ptr) = qlonglong(toInteger(exec, value));
3184  return true;
3185  case QMetaType::ULongLong:
3186  *reinterpret_cast<qulonglong*>(ptr) = qulonglong(toInteger(exec, value));
3187  return true;
3188  case QMetaType::Double:
3189  *reinterpret_cast<double*>(ptr) = toNumber(exec, value);
3190  return true;
3191  case QMetaType::QString:
3192  if (value.isUndefined() || value.isNull())
3193  *reinterpret_cast<QString*>(ptr) = QString();
3194  else
3195  *reinterpret_cast<QString*>(ptr) = toString(exec, value);
3196  return true;
3197  case QMetaType::Float:
3198  *reinterpret_cast<float*>(ptr) = toNumber(exec, value);
3199  return true;
3200  case QMetaType::Short:
3201  *reinterpret_cast<short*>(ptr) = short(toInt32(exec, value));
3202  return true;
3203  case QMetaType::UShort:
3204  *reinterpret_cast<unsigned short*>(ptr) = QScript::ToUInt16(toNumber(exec, value));
3205  return true;
3206  case QMetaType::Char:
3207  *reinterpret_cast<char*>(ptr) = char(toInt32(exec, value));
3208  return true;
3209  case QMetaType::UChar:
3210  *reinterpret_cast<unsigned char*>(ptr) = (unsigned char)(toInt32(exec, value));
3211  return true;
3212  case QMetaType::QChar:
3213  if (value.isString()) {
3214  QString str = toString(exec, value);
3215  *reinterpret_cast<QChar*>(ptr) = str.isEmpty() ? QChar() : str.at(0);
3216  } else {
3217  *reinterpret_cast<QChar*>(ptr) = QChar(QScript::ToUInt16(toNumber(exec, value)));
3218  }
3219  return true;
3220  case QMetaType::QDateTime:
3221  if (isDate(value)) {
3222  *reinterpret_cast<QDateTime *>(ptr) = toDateTime(exec, value);
3223  return true;
3224  } break;
3225  case QMetaType::QDate:
3226  if (isDate(value)) {
3227  *reinterpret_cast<QDate *>(ptr) = toDateTime(exec, value).date();
3228  return true;
3229  } break;
3230 #ifndef QT_NO_REGEXP
3231  case QMetaType::QRegExp:
3232  if (isRegExp(value)) {
3233  *reinterpret_cast<QRegExp *>(ptr) = toRegExp(exec, value);
3234  return true;
3235  } break;
3236 #endif
3237 #ifndef QT_NO_QOBJECT
3239  if (isQObject(value) || value.isNull()) {
3240  *reinterpret_cast<QObject* *>(ptr) = toQObject(exec, value);
3241  return true;
3242  } break;
3244  if (isQObject(value) || value.isNull()) {
3245  QObject *qo = toQObject(exec, value);
3246  if (!qo || qo->isWidgetType()) {
3247  *reinterpret_cast<QWidget* *>(ptr) = reinterpret_cast<QWidget*>(qo);
3248  return true;
3249  }
3250  } break;
3251 #endif
3253  if (isArray(value)) {
3254  *reinterpret_cast<QStringList *>(ptr) = stringListFromArray(exec, value);
3255  return true;
3256  } break;
3258  if (isArray(value)) {
3259  *reinterpret_cast<QVariantList *>(ptr) = variantListFromArray(exec, JSC::asArray(value));
3260  return true;
3261  } break;
3263  if (isObject(value)) {
3264  *reinterpret_cast<QVariantMap *>(ptr) = variantMapFromObject(exec, JSC::asObject(value));
3265  return true;
3266  } break;
3267  case QMetaType::QVariant:
3268  *reinterpret_cast<QVariant*>(ptr) = toVariant(exec, value);
3269  return true;
3270  default:
3271  ;
3272  }
3273 
3275 #ifndef QT_NO_QOBJECT
3276  if (convertToNativeQObject(exec, value, name, reinterpret_cast<void* *>(ptr)))
3277  return true;
3278 #endif
3279  if (isVariant(value) && name.endsWith('*')) {
3280  int valueType = QMetaType::type(name.left(name.size()-1));
3281  QVariant &var = variantValue(value);
3282  if (valueType == var.userType()) {
3283  *reinterpret_cast<void* *>(ptr) = var.data();
3284  return true;
3285  } else {
3286  // look in the prototype chain
3287  JSC::JSValue proto = JSC::asObject(value)->prototype();
3288  while (proto.isObject()) {
3289  bool canCast = false;
3290  if (isVariant(proto)) {
3291  canCast = (type == variantValue(proto).userType())
3292  || (valueType && (valueType == variantValue(proto).userType()));
3293  }
3294 #ifndef QT_NO_QOBJECT
3295  else if (isQObject(proto)) {
3296  QByteArray className = name.left(name.size()-1);
3297  if (QObject *qobject = toQObject(exec, proto))
3298  canCast = qobject->qt_metacast(className) != 0;
3299  }
3300 #endif
3301  if (canCast) {
3302  QByteArray varTypeName = QMetaType::typeName(var.userType());
3303  if (varTypeName.endsWith('*'))
3304  *reinterpret_cast<void* *>(ptr) = *reinterpret_cast<void* *>(var.data());
3305  else
3306  *reinterpret_cast<void* *>(ptr) = var.data();
3307  return true;
3308  }
3309  proto = JSC::asObject(proto)->prototype();
3310  }
3311  }
3312  } else if (value.isNull() && name.endsWith('*')) {
3313  *reinterpret_cast<void* *>(ptr) = 0;
3314  return true;
3315  } else if (type == qMetaTypeId<QScriptValue>()) {
3316  if (!eng)
3317  return false;
3318  *reinterpret_cast<QScriptValue*>(ptr) = eng->scriptValueFromJSCValue(value);
3319  return true;
3320  }
3321 
3322  // lazy registration of some common list types
3323 #ifndef QT_NO_QOBJECT
3324  else if (type == qMetaTypeId<QObjectList>()) {
3325  if (!eng)
3326  return false;
3327  qScriptRegisterSequenceMetaType<QObjectList>(eng->q_func());
3328  return convertValue(exec, value, type, ptr);
3329  }
3330 #endif
3331  else if (type == qMetaTypeId<QList<int> >()) {
3332  if (!eng)
3333  return false;
3334  qScriptRegisterSequenceMetaType<QList<int> >(eng->q_func());
3335  return convertValue(exec, value, type, ptr);
3336  }
3337 
3338 #if 0
3339  if (!name.isEmpty()) {
3340  qWarning("QScriptEngine::convert: unable to convert value to type `%s'",
3341  name.constData());
3342  }
3343 #endif
3344  return false;
3345 }
3346 
3348 {
3349  switch (QMetaType::Type(type)) {
3350  case QMetaType::Bool:
3351  *reinterpret_cast<bool*>(ptr) = QScript::ToBool(value);
3352  return true;
3353  case QMetaType::Int:
3354  *reinterpret_cast<int*>(ptr) = QScript::ToInt32(value);
3355  return true;
3356  case QMetaType::UInt:
3357  *reinterpret_cast<uint*>(ptr) = QScript::ToUInt32(value);
3358  return true;
3359  case QMetaType::LongLong:
3360  *reinterpret_cast<qlonglong*>(ptr) = qlonglong(QScript::ToInteger(value));
3361  return true;
3362  case QMetaType::ULongLong:
3363  *reinterpret_cast<qulonglong*>(ptr) = qulonglong(QScript::ToInteger(value));
3364  return true;
3365  case QMetaType::Double:
3366  *reinterpret_cast<double*>(ptr) = value;
3367  return true;
3368  case QMetaType::QString:
3369  *reinterpret_cast<QString*>(ptr) = QScript::ToString(value);
3370  return true;
3371  case QMetaType::Float:
3372  *reinterpret_cast<float*>(ptr) = value;
3373  return true;
3374  case QMetaType::Short:
3375  *reinterpret_cast<short*>(ptr) = short(QScript::ToInt32(value));
3376  return true;
3377  case QMetaType::UShort:
3378  *reinterpret_cast<unsigned short*>(ptr) = QScript::ToUInt16(value);
3379  return true;
3380  case QMetaType::Char:
3381  *reinterpret_cast<char*>(ptr) = char(QScript::ToInt32(value));
3382  return true;
3383  case QMetaType::UChar:
3384  *reinterpret_cast<unsigned char*>(ptr) = (unsigned char)(QScript::ToInt32(value));
3385  return true;
3386  case QMetaType::QChar:
3387  *reinterpret_cast<QChar*>(ptr) = QChar(QScript::ToUInt16(value));
3388  return true;
3389  default:
3390  break;
3391  }
3392  return false;
3393 }
3394 
3395 bool QScriptEnginePrivate::convertString(const QString &value, int type, void *ptr)
3396 {
3397  switch (QMetaType::Type(type)) {
3398  case QMetaType::Bool:
3399  *reinterpret_cast<bool*>(ptr) = QScript::ToBool(value);
3400  return true;
3401  case QMetaType::Int:
3402  *reinterpret_cast<int*>(ptr) = QScript::ToInt32(value);
3403  return true;
3404  case QMetaType::UInt:
3405  *reinterpret_cast<uint*>(ptr) = QScript::ToUInt32(value);
3406  return true;
3407  case QMetaType::LongLong:
3408  *reinterpret_cast<qlonglong*>(ptr) = qlonglong(QScript::ToInteger(value));
3409  return true;
3410  case QMetaType::ULongLong:
3411  *reinterpret_cast<qulonglong*>(ptr) = qulonglong(QScript::ToInteger(value));
3412  return true;
3413  case QMetaType::Double:
3414  *reinterpret_cast<double*>(ptr) = QScript::ToNumber(value);
3415  return true;
3416  case QMetaType::QString:
3417  *reinterpret_cast<QString*>(ptr) = value;
3418  return true;
3419  case QMetaType::Float:
3420  *reinterpret_cast<float*>(ptr) = QScript::ToNumber(value);
3421  return true;
3422  case QMetaType::Short:
3423  *reinterpret_cast<short*>(ptr) = short(QScript::ToInt32(value));
3424  return true;
3425  case QMetaType::UShort:
3426  *reinterpret_cast<unsigned short*>(ptr) = QScript::ToUInt16(value);
3427  return true;
3428  case QMetaType::Char:
3429  *reinterpret_cast<char*>(ptr) = char(QScript::ToInt32(value));
3430  return true;
3431  case QMetaType::UChar:
3432  *reinterpret_cast<unsigned char*>(ptr) = (unsigned char)(QScript::ToInt32(value));
3433  return true;
3434  case QMetaType::QChar:
3435  *reinterpret_cast<QChar*>(ptr) = QChar(QScript::ToUInt16(value));
3436  return true;
3437  default:
3438  break;
3439  }
3440  return false;
3441 }
3442 
3444 {
3445  QScriptTypeInfo *info = m_typeInfos.value(type);
3446  return info && (info->demarshal != 0);
3447 }
3448 
3449 JSC::UString QScriptEnginePrivate::translationContextFromUrl(const JSC::UString &url)
3450 {
3451  if (url != cachedTranslationUrl) {
3452  cachedTranslationContext = QFileInfo(url).baseName();
3453  cachedTranslationUrl = url;
3454  }
3455  return cachedTranslationContext;
3456 }
3457 
3461 bool QScriptEngine::convert(const QScriptValue &value, int type, void *ptr)
3462 {
3463  Q_D(QScriptEngine);
3464  QScript::APIShim shim(d);
3465  return QScriptEnginePrivate::convertValue(d->currentFrame, d->scriptValueToJSCValue(value), type, ptr);
3466 }
3467 
3471 bool QScriptEngine::convertV2(const QScriptValue &value, int type, void *ptr)
3472 {
3474  if (vp) {
3475  switch (vp->type) {
3477  if (vp->engine) {
3478  QScript::APIShim shim(vp->engine);
3479  return QScriptEnginePrivate::convertValue(vp->engine->currentFrame, vp->jscValue, type, ptr);
3480  } else {
3481  return QScriptEnginePrivate::convertValue(0, vp->jscValue, type, ptr);
3482  }
3483  }
3485  return QScriptEnginePrivate::convertNumber(vp->numberValue, type, ptr);
3487  return QScriptEnginePrivate::convertString(vp->stringValue, type, ptr);
3488  }
3489  }
3490  return false;
3491 }
3492 
3497  DemarshalFunction df,
3498  const QScriptValue &prototype)
3499 {
3500  Q_D(QScriptEngine);
3501  QScript::APIShim shim(d);
3502  QScriptTypeInfo *info = d->m_typeInfos.value(type);
3503  if (!info) {
3504  info = new QScriptTypeInfo();
3505  d->m_typeInfos.insert(type, info);
3506  }
3507  info->marshal = mf;
3508  info->demarshal = df;
3509  info->prototype = d->scriptValueToJSCValue(prototype);
3510 }
3511 
3537 {
3538  Q_D(QScriptEngine);
3539  QScript::APIShim shim(d);
3540  JSC::ExecState* exec = d->currentFrame;
3541  JSC::JSValue jscObject = d->scriptValueToJSCValue(object);
3542  JSC::JSGlobalObject *glob = d->originalGlobalObject();
3543  if (!jscObject || !jscObject.isObject())
3544  jscObject = d->globalObject();
3545 // unsigned attribs = JSC::DontEnum;
3546 
3547 #ifndef QT_NO_TRANSLATION
3548  JSC::asObject(jscObject)->putDirectFunction(exec, new (exec)JSC::NativeFunctionWrapper(exec, glob->prototypeFunctionStructure(), 5, JSC::Identifier(exec, "qsTranslate"), QScript::functionQsTranslate));
3549  JSC::asObject(jscObject)->putDirectFunction(exec, new (exec)JSC::NativeFunctionWrapper(exec, glob->prototypeFunctionStructure(), 2, JSC::Identifier(exec, "QT_TRANSLATE_NOOP"), QScript::functionQsTranslateNoOp));
3550  JSC::asObject(jscObject)->putDirectFunction(exec, new (exec)JSC::NativeFunctionWrapper(exec, glob->prototypeFunctionStructure(), 3, JSC::Identifier(exec, "qsTr"), QScript::functionQsTr));
3551  JSC::asObject(jscObject)->putDirectFunction(exec, new (exec)JSC::NativeFunctionWrapper(exec, glob->prototypeFunctionStructure(), 1, JSC::Identifier(exec, "QT_TR_NOOP"), QScript::functionQsTrNoOp));
3552  JSC::asObject(jscObject)->putDirectFunction(exec, new (exec)JSC::NativeFunctionWrapper(exec, glob->prototypeFunctionStructure(), 1, JSC::Identifier(exec, "qsTrId"), QScript::functionQsTrId));
3553  JSC::asObject(jscObject)->putDirectFunction(exec, new (exec)JSC::NativeFunctionWrapper(exec, glob->prototypeFunctionStructure(), 1, JSC::Identifier(exec, "QT_TRID_NOOP"), QScript::functionQsTrIdNoOp));
3554 #endif
3555 
3556  glob->stringPrototype()->putDirectFunction(exec, new (exec)JSC::NativeFunctionWrapper(exec, glob->prototypeFunctionStructure(), 1, JSC::Identifier(exec, "arg"), QScript::stringProtoFuncArg));
3557 }
3558 
3573 {
3574 #if defined(QT_NO_QOBJECT) || defined(QT_NO_LIBRARY) || defined(QT_NO_SETTINGS)
3575  Q_UNUSED(extension);
3576 #else
3577  Q_D(QScriptEngine);
3578  QScript::APIShim shim(d);
3579  if (d->importedExtensions.contains(extension))
3580  return undefinedValue(); // already imported
3581 
3582  QScriptContext *context = currentContext();
3584  if (!app)
3585  return context->throwError(QLatin1String("No application object"));
3586 
3587  QObjectList staticPlugins = QPluginLoader::staticInstances();
3588  QStringList libraryPaths = app->libraryPaths();
3589  QString dot = QLatin1String(".");
3590  QStringList pathComponents = extension.split(dot);
3591  QString initDotJs = QLatin1String("__init__.js");
3592 
3593  QString ext;
3594  for (int i = 0; i < pathComponents.count(); ++i) {
3595  if (!ext.isEmpty())
3596  ext.append(dot);
3597  ext.append(pathComponents.at(i));
3598  if (d->importedExtensions.contains(ext))
3599  continue; // already imported
3600 
3601  if (d->extensionsBeingImported.contains(ext)) {
3602  return context->throwError(QString::fromLatin1("recursive import of %0")
3603  .arg(extension));
3604  }
3605  d->extensionsBeingImported.insert(ext);
3606 
3607  QScriptExtensionInterface *iface = 0;
3608  QString initjsContents;
3609  QString initjsFileName;
3610 
3611  // look for the extension in static plugins
3612  for (int j = 0; j < staticPlugins.size(); ++j) {
3613  iface = qobject_cast<QScriptExtensionInterface*>(staticPlugins.at(j));
3614  if (!iface)
3615  continue;
3616  if (iface->keys().contains(ext))
3617  break; // use this one
3618  else
3619  iface = 0; // keep looking
3620  }
3621 
3622  {
3623  // look for __init__.js resource
3624  QString path = QString::fromLatin1(":/qtscriptextension");
3625  for (int j = 0; j <= i; ++j) {
3626  path.append(QLatin1Char('/'));
3627  path.append(pathComponents.at(j));
3628  }
3629  path.append(QLatin1Char('/'));
3630  path.append(initDotJs);
3631  QFile file(path);
3632  if (file.open(QIODevice::ReadOnly)) {
3633  QTextStream ts(&file);
3634  initjsContents = ts.readAll();
3635  initjsFileName = path;
3636  file.close();
3637  }
3638  }
3639 
3640  if (!iface && initjsContents.isEmpty()) {
3641  // look for the extension in library paths
3642  for (int j = 0; j < libraryPaths.count(); ++j) {
3643  QString libPath = libraryPaths.at(j) + QDir::separator() + QLatin1String("script");
3644  QDir dir(libPath);
3645  if (!dir.exists(dot))
3646  continue;
3647 
3648  // look for C++ plugin
3650  for (int k = 0; k < files.count(); ++k) {
3651  QFileInfo entry = files.at(k);
3652  QString filePath = entry.canonicalFilePath();
3653  QPluginLoader loader(filePath);
3654  iface = qobject_cast<QScriptExtensionInterface*>(loader.instance());
3655  if (iface) {
3656  if (iface->keys().contains(ext))
3657  break; // use this one
3658  else
3659  iface = 0; // keep looking
3660  }
3661  }
3662 
3663  // look for __init__.js in the corresponding dir
3664  QDir dirdir(libPath);
3665  bool dirExists = dirdir.exists();
3666  for (int k = 0; dirExists && (k <= i); ++k)
3667  dirExists = dirdir.cd(pathComponents.at(k));
3668  if (dirExists && dirdir.exists(initDotJs)) {
3669  QFile file(dirdir.canonicalPath()
3670  + QDir::separator() + initDotJs);
3671  if (file.open(QIODevice::ReadOnly)) {
3672  QTextStream ts(&file);
3673  initjsContents = ts.readAll();
3674  initjsFileName = file.fileName();
3675  file.close();
3676  }
3677  }
3678 
3679  if (iface || !initjsContents.isEmpty())
3680  break;
3681  }
3682  }
3683 
3684  if (!iface && initjsContents.isEmpty()) {
3685  d->extensionsBeingImported.remove(ext);
3686  return context->throwError(
3687  QString::fromLatin1("Unable to import %0: no such extension")
3688  .arg(extension));
3689  }
3690 
3691  // initialize the extension in a new context
3693  ctx->setThisObject(globalObject());
3694  ctx->activationObject().setProperty(QLatin1String("__extension__"), ext,
3696  ctx->activationObject().setProperty(QLatin1String("__setupPackage__"),
3699 
3700  // the script is evaluated first
3701  if (!initjsContents.isEmpty()) {
3702  QScriptValue ret = evaluate(initjsContents, initjsFileName);
3703  if (hasUncaughtException()) {
3704  popContext();
3705  d->extensionsBeingImported.remove(ext);
3706  return ret;
3707  }
3708  }
3709 
3710  // next, the C++ plugin is called
3711  if (iface) {
3712  iface->initialize(ext, this);
3713  if (hasUncaughtException()) {
3714  QScriptValue ret = uncaughtException(); // ctx_p->returnValue();
3715  popContext();
3716  d->extensionsBeingImported.remove(ext);
3717  return ret;
3718  }
3719  }
3720 
3721  // if the __postInit__ function has been set, we call it
3722  QScriptValue postInit = ctx->activationObject().property(QLatin1String("__postInit__"));
3723  if (postInit.isFunction()) {
3724  postInit.call(globalObject());
3725  if (hasUncaughtException()) {
3726  QScriptValue ret = uncaughtException(); // ctx_p->returnValue();
3727  popContext();
3728  d->extensionsBeingImported.remove(ext);
3729  return ret;
3730  }
3731  }
3732 
3733  popContext();
3734 
3735  d->importedExtensions.insert(ext);
3736  d->extensionsBeingImported.remove(ext);
3737  } // for (i)
3738 #endif // QT_NO_QOBJECT
3739  return undefinedValue();
3740 }
3741 
3755 {
3756 #if defined(QT_NO_QOBJECT) || defined(QT_NO_LIBRARY) || defined(QT_NO_SETTINGS)
3757  return QStringList();
3758 #else
3760  if (!app)
3761  return QStringList();
3762 
3763  QSet<QString> result;
3764 
3765  QObjectList staticPlugins = QPluginLoader::staticInstances();
3766  for (int i = 0; i < staticPlugins.size(); ++i) {
3768  iface = qobject_cast<QScriptExtensionInterface*>(staticPlugins.at(i));
3769  if (iface) {
3770  QStringList keys = iface->keys();
3771  for (int j = 0; j < keys.count(); ++j)
3772  result << keys.at(j);
3773  }
3774  }
3775 
3776  QStringList libraryPaths = app->libraryPaths();
3777  for (int i = 0; i < libraryPaths.count(); ++i) {
3778  QString libPath = libraryPaths.at(i) + QDir::separator() + QLatin1String("script");
3779  QDir dir(libPath);
3780  if (!dir.exists())
3781  continue;
3782 
3783  // look for C++ plugins
3785  for (int j = 0; j < files.count(); ++j) {
3786  QFileInfo entry = files.at(j);
3787  QString filePath = entry.canonicalFilePath();
3788  QPluginLoader loader(filePath);
3790  iface = qobject_cast<QScriptExtensionInterface*>(loader.instance());
3791  if (iface) {
3792  QStringList keys = iface->keys();
3793  for (int k = 0; k < keys.count(); ++k)
3794  result << keys.at(k);
3795  }
3796  }
3797 
3798  // look for scripts
3799  QString initDotJs = QLatin1String("__init__.js");
3800  QList<QFileInfo> stack;
3802  while (!stack.isEmpty()) {
3803  QFileInfo entry = stack.takeLast();
3804  QDir dd(entry.canonicalFilePath());
3805  if (dd.exists(initDotJs)) {
3806  QString rpath = dir.relativeFilePath(dd.canonicalPath());
3807  QStringList components = rpath.split(QLatin1Char('/'));
3808  result << components.join(QLatin1String("."));
3809  stack << dd.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot);
3810  }
3811  }
3812  }
3813 
3814  QStringList lst = result.toList();
3815  qSort(lst);
3816  return lst;
3817 #endif
3818 }
3819 
3832 {
3833  Q_D(const QScriptEngine);
3834  QStringList lst = d->importedExtensions.toList();
3835  qSort(lst);
3836  return lst;
3837 }
3838 
4098 {
4099  Q_D(QScriptEngine);
4100  d->collectGarbage();
4101 }
4102 
4128 {
4129  Q_D(QScriptEngine);
4130  d->reportAdditionalMemoryCost(size);
4131 }
4132 
4157 {
4158  Q_D(QScriptEngine);
4159  d->processEventsInterval = interval;
4160 
4161  if (interval > 0)
4162  d->globalData->timeoutChecker->setCheckInterval(interval);
4163 
4164  d->timeoutChecker()->setShouldProcessEvents(interval > 0);
4165 }
4166 
4175 {
4176  Q_D(const QScriptEngine);
4177  return d->processEventsInterval;
4178 }
4179 
4192 {
4193  Q_D(const QScriptEngine);
4194  return (d->currentFrame != d->globalExec()) || d->inEval;
4195 }
4196 
4217 {
4218  Q_D(QScriptEngine);
4219  if (!isEvaluating())
4220  return;
4221  d->abortResult = result;
4222  d->timeoutChecker()->setShouldAbort(true);
4223  JSC::throwError(d->currentFrame, JSC::createInterruptedExecutionException(&d->currentFrame->globalData()).toObject(d->currentFrame));
4224 }
4225 
4226 #ifndef QT_NO_QOBJECT
4227 
4242 bool qScriptConnect(QObject *sender, const char *signal,
4243  const QScriptValue &receiver, const QScriptValue &function)
4244 {
4245  if (!sender || !signal)
4246  return false;
4247  if (!function.isFunction())
4248  return false;
4249  if (receiver.isObject() && (receiver.engine() != function.engine()))
4250  return false;
4251  QScriptEnginePrivate *engine = QScriptEnginePrivate::get(function.engine());
4252  QScript::APIShim shim(engine);
4253  JSC::JSValue jscReceiver = engine->scriptValueToJSCValue(receiver);
4254  JSC::JSValue jscFunction = engine->scriptValueToJSCValue(function);
4255  return engine->scriptConnect(sender, signal, jscReceiver, jscFunction,
4257 }
4258 
4272 bool qScriptDisconnect(QObject *sender, const char *signal,
4273  const QScriptValue &receiver, const QScriptValue &function)
4274 {
4275  if (!sender || !signal)
4276  return false;
4277  if (!function.isFunction())
4278  return false;
4279  if (receiver.isObject() && (receiver.engine() != function.engine()))
4280  return false;
4281  QScriptEnginePrivate *engine = QScriptEnginePrivate::get(function.engine());
4282  QScript::APIShim shim(engine);
4283  JSC::JSValue jscReceiver = engine->scriptValueToJSCValue(receiver);
4284  JSC::JSValue jscFunction = engine->scriptValueToJSCValue(function);
4285  return engine->scriptDisconnect(sender, signal, jscReceiver, jscFunction);
4286 }
4287 
4302 #include "moc_qscriptengine.cpp"
4304 
4305 #endif // QT_NO_QOBJECT
4306 
4326 {
4327  Q_D(QScriptEngine);
4328  if (agent && (agent->engine() != this)) {
4329  qWarning("QScriptEngine::setAgent(): "
4330  "cannot set agent belonging to different engine");
4331  return;
4332  }
4333  QScript::APIShim shim(d);
4334  if (d->activeAgent)
4335  QScriptEngineAgentPrivate::get(d->activeAgent)->detach();
4336  d->activeAgent = agent;
4337  if (agent) {
4338  QScriptEngineAgentPrivate::get(agent)->attach();
4339  }
4340 }
4341 
4354 {
4355  Q_D(const QScriptEngine);
4356  return d->activeAgent;
4357 }
4358 
4373 {
4374  Q_D(QScriptEngine);
4375  QScript::APIShim shim(d);
4376  return d->toStringHandle(JSC::Identifier(d->currentFrame, str));
4377 }
4378 
4402 {
4403  Q_D(QScriptEngine);
4404  QScript::APIShim shim(d);
4405  JSC::JSValue jscValue = d->scriptValueToJSCValue(value);
4406  if (!jscValue || jscValue.isUndefined() || jscValue.isNull())
4407  return QScriptValue();
4408  JSC::ExecState* exec = d->currentFrame;
4409  JSC::JSValue result = jscValue.toObject(exec);
4410  return d->scriptValueFromJSCValue(result);
4411 }
4412 
4425 {
4426  Q_D(const QScriptEngine);
4427  // Assumes that the cell was not been garbage collected
4428  return const_cast<QScriptEnginePrivate*>(d)->scriptValueFromJSCValue((JSC::JSCell*)id);
4429 }
4430 
4464  : d_ptr(other.d_ptr)
4465 {
4466 }
4467 
4472  : d_ptr(d)
4473 {
4474 }
4475 
4480  : d_ptr(0)
4481 {
4482 }
4483 
4488 {
4489 }
4490 
4495 {
4497  if (!d)
4498  return Valid;
4499  return d->state;
4500 }
4501 
4509 {
4511  if (!d)
4512  return -1;
4513  return d->errorLineNumber;
4514 }
4515 
4523 {
4525  if (!d)
4526  return -1;
4527  return d->errorColumnNumber;
4528 }
4529 
4537 {
4539  if (!d)
4540  return QString();
4541  return d->errorMessage;
4542 }
4543 
4549 {
4550  d_ptr = other.d_ptr;
4551  return *this;
4552 }
4553 
4554 #ifdef QT_BUILD_INTERNAL
4555 Q_AUTOTEST_EXPORT bool qt_script_isJITEnabled()
4556 {
4557 #if ENABLE(JIT)
4558  return true;
4559 #else
4560  return false;
4561 #endif
4562 }
4563 #endif
4564 
4565 #ifdef Q_CC_MSVC
4566 // Try to prevent compiler from crashing.
4567 #pragma optimize("", off)
4568 #endif
4569 
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
QScriptValue newFunction(FunctionSignature signature, int length=0)
Creates a QScriptValue that wraps a native (C++) function.
The QDir class provides access to directory structures and their contents.
Definition: qdir.h:58
static unsigned propertyFlagsToJSCAttributes(const QScriptValue::PropertyFlags &flags)
QBool contains(QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.h:904
int dayOfWeek() const
Returns the weekday (1 = Monday to 7 = Sunday) for this date.
Definition: qdatetime.cpp:408
void(* DemarshalFunction)(const QScriptValue &, void *)
double d
Definition: qnumeric_p.h:62
The QScriptContext class represents a Qt Script function invocation.
The QMetaObject class contains meta-information about Qt objects.
Definition: qobjectdefs.h:304
QScriptObject * wrapperObject() const
QScriptEngine()
Constructs a QScriptEngine object.
QScriptValuePrivate * next
QScriptValue(* FunctionSignature)(QScriptContext *, QScriptEngine *)
QScriptValue evaluate(const QString &program, const QString &fileName=QString(), int lineNumber=1)
Evaluates program, using lineNumber as the base line number, and returns the result of the evaluation...
The QHash::const_iterator class provides an STL-style const iterator for QHash and QMultiHash...
Definition: qhash.h:395
QScriptValue property(const QString &name, const ResolveFlags &mode=ResolvePrototype) const
Returns the value of this QScriptValue&#39;s property with the given name, using the given mode to resolv...
static JSC::JSValue JSC_HOST_CALL functionQsTranslateNoOp(JSC::ExecState *, JSC::JSObject *, JSC::JSValue, const JSC::ArgList &)
static bool isObject(JSC::JSValue)
int type
Definition: qmetatype.cpp:239
static JSC::ExecState * frameForContext(QScriptContext *context)
Encoding
This enum type defines the 8-bit encoding of character string arguments to translate(): ...
QScriptEnginePrivate * scriptEngineFromExec(const JSC::ExecState *exec)
static mach_timebase_info_data_t info
unsigned char c[8]
Definition: qnumeric_p.h:62
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
static bool convertString(const QString &, int type, void *ptr)
WTF::RefPtr< JSC::Structure > variantWrapperObjectStructure
int qint32
Definition: qglobal.h:937
static JSC::JSValue jscValueFromVariant(JSC::ExecState *, const QVariant &value)
static QByteArray normalizedSignature(const char *method)
Normalizes the signature of the given method.
The QScriptClass class provides an interface for defining custom behavior of (a class of) Qt Script o...
Definition: qscriptclass.h:43
static QStringList stringListFromArray(JSC::ExecState *, JSC::JSValue arr)
const QChar at(int i) const
Returns the character at the given index position in the string.
Definition: qstring.h:698
qsreal integerFromString(const QString &str, int radix)
static JSC::Register * thisRegisterForFrame(JSC::ExecState *frame)
bool addSignalHandler(QObject *sender, int signalIndex, JSC::JSValue receiver, JSC::JSValue slot, JSC::JSValue senderWrapper, Qt::ConnectionType type)
void detachAllRegisteredScriptStrings()
bool isFunction() const
Returns true if this QScriptValue is a function; otherwise returns false.
The QRegExp class provides pattern matching using regular expressions.
Definition: qregexp.h:61
ushort unicode() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qchar.h:251
qsreal ToInteger(qsreal n)
virtual ~QScriptEngine()
Destroys this QScriptEngine.
WTF::RefPtr< JSC::Structure > qmetaobjectWrapperObjectStructure
static JSC::JSValue JSC_HOST_CALL functionDisconnect(JSC::ExecState *, JSC::JSObject *, JSC::JSValue, const JSC::ArgList &)
#define it(className, varName)
bool canEvaluate(const QString &program) const
Returns true if program can be evaluated; i.
QObject * qobject() const
QScriptEngine * engine() const
Returns the QScriptEngine that this agent is associated with.
static QScriptEnginePrivate * get(QScriptEngine *q)
bool open(OpenMode flags)
Opens the file using OpenMode mode, returning true if successful; otherwise false.
Definition: qfile.cpp:1064
QByteArray & append(char c)
Appends the character ch to this byte array.
static QVariant toVariant(JSC::ExecState *, JSC::JSValue)
static uint contextFlags(JSC::ExecState *)
For native context, we use the ReturnValueRegister entry in the stackframe header to store flags...
static JSC::JSValue create(JSC::ExecState *, int type, const void *ptr)
JSC::UString cachedTranslationContext
QByteArray toUtf8() const Q_REQUIRED_RESULT
Returns a UTF-8 representation of the string as a QByteArray.
Definition: qstring.cpp:4074
QScript::QObjectData * qobjectData(QObject *object)
static QVariantMap variantMapFromObject(JSC::ExecState *, JSC::JSObject *obj)
static JSC::JSValue JSC_HOST_CALL functionQsTrIdNoOp(JSC::ExecState *, JSC::JSObject *, JSC::JSValue, const JSC::ArgList &)
#define error(msg)
Q_CORE_EXPORT void qFree(void *ptr)
Definition: qmalloc.cpp:58
qint32 toInt32() const
Returns the signed 32-bit integer value of this QScriptValue, using the conversion rules described in...
static JSC::JSValue JSC_HOST_CALL functionPrint(JSC::ExecState *, JSC::JSObject *, JSC::JSValue, const JSC::ArgList &)
WTF::RefPtr< JSC::Structure > staticScopeObjectStructure
bool isError() const
Returns true if this QScriptValue is an object of the Error class; otherwise returns false...
bool remove(const T &value)
Definition: qset.h:89
const_iterator constEnd() const
Definition: qset.h:171
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QScriptSyntaxCheckResult::State state
QScriptValue throwError(Error error, const QString &text)
Throws an error with the given text.
static Expression::Ptr create(Expression *const expr, const YYLTYPE &sourceLocator, const ParserContext *const parseInfo)
JSC::JSValue defaultPrototype(int metaTypeId) const
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
#define SLOT(a)
Definition: qobjectdefs.h:226
int errorLineNumber() const
Returns the error line number of this QScriptSyntaxCheckResult, or -1 if there is no error...
static QRegExp toRegExp(JSC::ExecState *, JSC::JSValue)
static JSC::JSValue JSC_HOST_CALL functionQsTrId(JSC::ExecState *, JSC::JSObject *, JSC::JSValue, const JSC::ArgList &)
int month() const
Returns the number corresponding to the month of this date, using the following convention: ...
Definition: qdatetime.cpp:382
bool removeSignalHandler(QObject *sender, int signalIndex, JSC::JSValue receiver, JSC::JSValue slot)
void registerCustomType(int type, MarshalFunction mf, DemarshalFunction df, const QScriptValue &prototype)
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
QString toString() const
Returns the string value of this QScriptValue, as defined in ECMA-262 section 9.8, "ToString".
bool setProperty(const char *name, const QVariant &value)
Sets the value of the object&#39;s name property to value.
Definition: qobject.cpp:3755
quint32 ToUInt32(qsreal n)
JSC::EvalExecutable * executable(JSC::ExecState *exec, QScriptEnginePrivate *engine)
JSC::CallFrame * pushContext(JSC::CallFrame *exec, JSC::JSValue thisObject, const JSC::ArgList &args, JSC::JSObject *callee, bool calledAsConstructor=false, bool clearScopeChain=false)
JSC native function doesn&#39;t have different stackframe or context.
QScriptValue globalObject() const
Returns this engine&#39;s Global Object.
QScriptValue objectById(qint64 id) const
Returns the object with the given id, or an invalid QScriptValue if there is no object with that id...
virtual bool didTimeOut(JSC::ExecState *exec)
static QScriptValuePrivate * get(const QScriptValue &q)
static PassRefPtr< UStringSourceProviderWithFeedback > create(const JSC::UString &source, const JSC::UString &url, int lineNumber, QScriptEnginePrivate *engine)
static QObject * toQObject(JSC::ExecState *, JSC::JSValue)
void setProcessEventsInterval(int interval)
Sets the interval between calls to QCoreApplication::processEvents to interval milliseconds.
QScriptObjectDelegate * delegate() const
int day() const
Returns the day of the month (1 to 31) of this date.
Definition: qdatetime.cpp:395
static JSC::JSValue JSC_HOST_CALL functionVersion(JSC::ExecState *, JSC::JSObject *, JSC::JSValue, const JSC::ArgList &)
int qMetaTypeId()
Definition: qmetatype.h:224
static bool canEvaluate(const QString &program)
bool isValid() const
Returns true if both the date and the time are valid; otherwise returns false.
Definition: qdatetime.cpp:2346
QScript::QVariantPrototype * variantPrototype
#define QT_END_INCLUDE_NAMESPACE
This macro is equivalent to QT_BEGIN_NAMESPACE.
Definition: qglobal.h:92
QList< QScriptEngineAgent * > ownedAgents
The QDate class provides date functions.
Definition: qdatetime.h:55
QScriptStringPrivate * prev
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
QScriptValue newRegExp(const QRegExp &regexp)
Creates a QtScript object of class RegExp with the given regexp.
int msec() const
Returns the millisecond part (0 to 999) of the time.
Definition: qdatetime.cpp:1611
static void init(QScriptString &q, QScriptStringPrivate *d)
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
JSC::JSObject * globalObject() const
void setShouldProcessEvents(bool shouldProcess)
static QScriptDeclarativeClass * declarativeClass(JSC::JSValue)
static JSC::JSValue JSC_HOST_CALL functionQsTranslate(JSC::ExecState *, JSC::JSObject *, JSC::JSValue, const JSC::ArgList &)
T & value() const
Returns a modifiable reference to the current item&#39;s value.
Definition: qhash.h:348
void popContext()
Pops the current execution context and restores the previous one.
bool hasDemarshalFunction(int type) const
static qsreal toNumber(JSC::ExecState *, JSC::JSValue)
static const JSC::ClassInfo info
The QString class provides a Unicode character string.
Definition: qstring.h:83
QMap< QString, QVariant > QVariantMap
Definition: qvariant.h:444
T * qobject_cast(QObject *object)
Definition: qobject.h:375
static WTF::PassRefPtr< JSC::Structure > createStructure(JSC::JSValue proto)
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
bool startsWith(const QByteArray &a) const
Returns true if this byte array starts with byte array ba; otherwise returns false.
virtual QScriptValue prototype() const
Returns the object to be used as the prototype of new instances of this class (created with QScriptEn...
QByteArray signature
#define Q_D(Class)
Definition: qglobal.h:2482
static QChar separator()
Returns the native directory separator: "/" under Unix (including Mac OS X) and "\\" under Windows...
Definition: qdir.cpp:1831
Qt::CaseSensitivity caseSensitivity() const
Returns Qt::CaseSensitive if the regexp is matched case sensitively; otherwise returns Qt::CaseInsens...
Definition: qregexp.cpp:3985
static QObjectList staticInstances()
Returns a list of static plugin instances (root components) held by the plugin loader.
QScriptString toStringHandle(const QString &str)
Returns a handle that represents the given string, str.
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
void setThisObject(const QScriptValue &thisObject)
Sets the `this&#39; object associated with this QScriptContext to be thisObject.
QStringList keys
const T value(const Key &key) const
Returns the value associated with the key.
Definition: qhash.h:606
static QVariant convertValue(GConfValue *src)
Definition: proxyconf.cpp:64
const char * className
Definition: qwizard.cpp:137
bool exists() const
Returns true if the directory exists; otherwise returns false.
Definition: qdir.cpp:1560
static JSC::JSValue JSC_HOST_CALL functionQsTr(JSC::ExecState *, JSC::JSObject *, JSC::JSValue, const JSC::ArgList &)
JSC::ExecState * currentFrame
static void setContextFlags(JSC::ExecState *, uint)
static void processEvents(QEventLoop::ProcessEventsFlags flags=QEventLoop::AllEvents)
Processes all pending events for the calling thread according to the specified flags until there are ...
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition: qhash.h:753
static QString translate(const char *context, const char *key, const char *disambiguation=0, Encoding encoding=CodecForTr)
QObject * sender() const
Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; othe...
Definition: qobject.cpp:2327
#define Q_Q(Class)
Definition: qglobal.h:2483
~QScriptSyntaxCheckResult()
Destroys this QScriptSyntaxCheckResult.
static int sign(int x)
The QScriptString class acts as a handle to "interned" strings in a QScriptEngine.
Definition: qscriptstring.h:38
void disposeQObject(QObject *object)
QScriptString toStringHandle(const JSC::Identifier &name)
Result checkSyntax(const QString &code)
ConnectionType
Definition: qnamespace.h:1469
QScriptValue(* FunctionWithArgSignature)(QScriptContext *, QScriptEngine *, void *)
Q_CORE_EXPORT void qDebug(const char *,...)
static bool toBool(Register *reg, int type, bool *ok=0)
static JSC::JSValue JSC_HOST_CALL stringProtoFuncArg(JSC::ExecState *, JSC::JSObject *, JSC::JSValue, const JSC::ArgList &)
bool removeOne(const T &t)
Removes the first occurrence of value in the list and returns true on success; otherwise returns fals...
Definition: qlist.h:796
void reserve(int size)
Attempts to allocate memory for at least size characters.
Definition: qstring.h:881
#define SIGNAL(a)
Definition: qobjectdefs.h:227
void setOwnership(QScriptEngine::ValueOwnership ownership)
QScriptSyntaxCheckResult & operator=(const QScriptSyntaxCheckResult &other)
Assigns the other result to this QScriptSyntaxCheckResult, and returns a reference to this QScriptSyn...
QScriptValue defaultPrototype(int metaTypeId) const
Returns the default prototype associated with the given metaTypeId, or an invalid QScriptValue if no ...
static QString toString(Register *reg, int type, bool *ok=0)
static bool convertToNativeQObject(JSC::ExecState *, JSC::JSValue, const QByteArray &targetType, void **result)
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
void * data()
Definition: qvariant.cpp:3077
The QScriptEngine class provides an environment for evaluating Qt Script code.
QStringList uncaughtExceptionBacktrace() const
Returns a human-readable backtrace of the last uncaught exception.
QScriptValuePrivate * prev
QString errorMessage() const
Returns the error message of this QScriptSyntaxCheckResult, or an empty string if there is no error...
The QTime class provides clock time functions.
Definition: qdatetime.h:148
int dayOfYear() const
Returns the day of the year (1 to 365 or 366 on leap years) for this date.
Definition: qdatetime.cpp:420
static bool isVariant(JSC::JSValue)
static qint32 toInt32(JSC::ExecState *, JSC::JSValue)
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
void setValue(QObject *value)
void reportAdditionalMemoryCost(int size)
Reports an additional memory cost of the given size, measured in bytes, to the garbage collector...
static JSC::JSValue JSC_HOST_CALL functionConnect(JSC::ExecState *, JSC::JSObject *, JSC::JSValue, const JSC::ArgList &)
QHash< QObject *, QScript::QObjectData * > m_qobjectData
QScriptStringPrivate * next
JSC::JSValue scriptValueToJSCValue(const QScriptValue &value)
bool canConvert(Type t) const
Returns true if the variant&#39;s type can be cast to the requested type, t.
Definition: qvariant.cpp:2886
Q_CORE_EXPORT QString qt_regexp_toCanonical(const QString &, QRegExp::PatternSyntax)
Definition: qregexp.cpp:1323
static WTF::PassRefPtr< JSC::Structure > createStructure(JSC::JSValue prototype)
static const qsreal D32
const char * typeName
Definition: qmetatype.cpp:239
bool contains(const T &value) const
Definition: qset.h:91
QString trimmed() const Q_REQUIRED_RESULT
Returns a string that has whitespace removed from the start and the end.
Definition: qstring.cpp:4506
QScript::QMetaObjectPrototype * qmetaobjectPrototype
T takeFirst()
Removes the first item in the list and returns it.
Definition: qlist.h:489
QList< T > toList() const
Definition: qset.h:296
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
Definition: qobject.cpp:2580
const QChar * unicode() const
Returns a &#39;\0&#39;-terminated Unicode representation of the string.
Definition: qstring.h:706
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
QDateTime toLocalTime() const
Returns a datetime containing the date and time information in this datetime, but specified using the...
Definition: qdatetime.h:250
JSC::JSGlobalObject * originalGlobalObject() const
static JSC::UString toString(JSC::ExecState *, JSC::JSValue)
void setDefaultPrototype(int metaTypeId, JSC::JSValue prototype)
void installTranslatorFunctions(const QScriptValue &object=QScriptValue())
Installs translator functions on the given object, or on the Global Object if no object is specified...
const char * name
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
#define emit
Definition: qobjectdefs.h:76
QScriptEngine * engine() const
Returns the QScriptEngine that created this QScriptValue, or 0 if this QScriptValue is invalid or the...
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
static WTF::PassRefPtr< JSC::Structure > createStructure(JSC::JSValue prototype)
void mark(JSC::MarkStack &)
static JSC::JSValue arrayFromStringList(JSC::ExecState *, const QStringList &lst)
static void setProperty(JSC::ExecState *, JSC::JSValue object, const JSC::UString &name, JSC::JSValue, const QScriptValue::PropertyFlags &flags=QScriptValue::KeepExistingFlags)
QString canonicalFilePath() const
Returns the canonical path including the file name, i.e.
Definition: qfileinfo.cpp:551
bool qScriptConnect(QObject *sender, const char *signal, const QScriptValue &receiver, const QScriptValue &function)
Creates a connection from the signal in the sender to the given function.
static QDateTime toDateTime(JSC::ExecState *, JSC::JSValue)
const T & value() const
Returns the current item&#39;s value.
Definition: qhash.h:420
unsigned short quint16
Definition: qglobal.h:936
Q_CORE_EXPORT void qWarning(const char *,...)
Type
These are the built-in types supported by QMetaType:
Definition: qmetatype.h:64
QString ToString(qsreal)
bool isFunction(JSC::JSValue value)
int second() const
Returns the second part (0 to 59) of the time.
Definition: qdatetime.cpp:1600
const_iterator insert(const T &value)
Definition: qset.h:179
static const qsreal MsPerSecond
QHash< intptr_t, QScript::UStringSourceProviderWithFeedback * > loadedScripts
JSC::JSValue toUsableValue(JSC::JSValue value)
If the given value is the original global object, returns the custom global object or a proxy to the ...
static const char * data(const QByteArray &arr)
unsigned int uint
Definition: qglobal.h:996
TimeoutCheckerProxy(const JSC::TimeoutChecker &originalChecker)
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
const_iterator constFind(const Key &key) const
Returns an iterator pointing to the item with the key in the hash.
Definition: qhash.h:859
void clear()
Definition: qset.h:87
The QScriptSyntaxCheckResult class provides the result of a script syntax check.
Definition: qscriptengine.h:75
Type
This enum type defines the types of variable that a QVariant can contain.
Definition: qvariant.h:95
JSC::JSObject * getOriginalGlobalObjectProxy()
QScriptValue newObject()
Creates a QtScript object of class Object.
static QScriptValue __setupPackage__(QScriptContext *ctx, QScriptEngine *eng)
ValueOwnership
This enum specifies the ownership when wrapping a C++ value, e.
JSC::UString translationContextFromUrl(const JSC::UString &)
QBool contains(const QString &str, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the list contains the string str; otherwise returns false.
Definition: qstringlist.h:172
QFileInfoList entryInfoList(Filters filters=NoFilter, SortFlags sort=NoSort) const
Returns a list of QFileInfo objects for all the files and directories in the directory, ordered according to the name and attribute filters previously set with setNameFilters() and setFilter(), and sorted according to the flags set with setSorting().
Definition: qdir.cpp:1316
State
This enum specifies the state of a syntax check.
Definition: qscriptengine.h:78
qsreal DateTimeToMs(JSC::ExecState *exec, const QDateTime &dt)
Converts a QDateTime to a JS date value (milliseconds).
int indexOfSignal(const char *signal) const
Finds signal and returns its index; otherwise returns -1.
const T * ptr(const T &t)
qint32 ToInt32(qsreal n)
QScriptObject * findWrapper(QScriptEngine::ValueOwnership ownership, const QScriptEngine::QObjectWrapOptions &options) const
QScriptStringPrivate * registeredScriptStrings
const QMetaObject * metaObject() const
QSet< QScriptProgramPrivate * > registeredScriptPrograms
static JSC::JSValue newRegExp(JSC::ExecState *, const QRegExp &)
__int64 qint64
Definition: qglobal.h:942
QByteArray left(int len) const
Returns a byte array that contains the leftmost len bytes of this byte array.
int minute() const
Returns the minute part (0 to 59) of the time.
Definition: qdatetime.cpp:1589
static int type(const char *typeName)
Returns a handle to the type called typeName, or 0 if there is no such type.
Definition: qmetatype.cpp:607
void setGlobalObject(const QScriptValue &object)
Sets this engine&#39;s Global Object to be the given object.
static JSC::JSValue propertyHelper(JSC::ExecState *, JSC::JSValue, const JSC::Identifier &id, int resolveMode)
static QVariant fromValue(const T &value)
Returns a QVariant containing a copy of value.
Definition: qvariant.h:336
const QMetaObject * superClass() const
Returns the meta-object of the superclass, or 0 if there is no such object.
Definition: qobjectdefs.h:494
void abortEvaluation(const QScriptValue &result=QScriptValue())
Aborts any script evaluation currently taking place in this engine.
QByteArray mid(int index, int len=-1) const
Returns a byte array containing len bytes from this byte array, starting at position pos...
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the map.
Definition: qmap.h:374
const char * typeName() const
Returns the name of the type stored in the variant.
Definition: qvariant.cpp:1984
int indexOf(char c, int from=0) const
Returns the index position of the first occurrence of the character ch in the byte array...
bool cd(const QString &dirName)
Changes the QDir&#39;s directory to dirName.
Definition: qdir.cpp:880
bool ToBool(qsreal)
bool isEvaluating() const
Returns true if this engine is currently evaluating a script, otherwise returns false.
void qSort(RandomAccessIterator start, RandomAccessIterator end)
Definition: qalgorithms.h:177
int uncaughtExceptionLineNumber() const
Returns the line number where the last uncaught exception occurred.
Q_CORE_EXPORT bool qIsNaN(double d)
Returns true if the double {d} is not a number (NaN).
Definition: qnumeric.cpp:55
#define Q_DECLARE_METATYPE(TYPE)
This macro makes the type Type known to QMetaType as long as it provides a public default constructor...
Definition: qmetatype.h:265
JSC::JSValue prototype
static bool convertV2(const QScriptValue &value, int type, void *ptr)
QDateTime toUTC() const
Returns a datetime containing the date and time information in this datetime, but specified using the...
Definition: qdatetime.h:251
QScriptValue newQObject(QObject *object, ValueOwnership ownership=QtOwnership, const QObjectWrapOptions &options=0)
Creates a QtScript object that wraps the given QObject object, using the given ownership.
void detachAllRegisteredScriptPrograms()
Q_CORE_EXPORT double qSNaN()
Returns the bit pattern of a signalling NaN as a double.
Definition: qnumeric.cpp:80
JSC::JSValue newVariant(const QVariant &)
bool convert(Type t)
Casts the variant to the requested type, t.
Definition: qvariant.cpp:2959
QHash< int, QScriptTypeInfo * > m_typeInfos
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
QDate date() const
Returns the date part of the datetime.
Definition: qdatetime.cpp:2357
static bool convertValue(JSC::ExecState *, JSC::JSValue value, int type, void *ptr)
MethodType methodType() const
Returns the type of this method (signal, slot, or method).
static QByteArray prototype(const QList< QByteArray > &parameterTypes, const QList< QByteArray > &parameterNames, bool *ok)
Definition: qaxserver.cpp:685
static bool isDate(JSC::JSValue)
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the hash.
Definition: qhash.h:466
QString join(const QString &sep) const
Joins all the string list&#39;s strings into a single string with each element separated by the given sep...
Definition: qstringlist.h:162
Q_CORE_EXPORT QString qtTrId(const char *id, int n=-1)
CaseSensitivity
Definition: qnamespace.h:1451
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the hash...
Definition: qhash.h:469
static int MsFromTime(qsreal t)
qsreal ToNumber(const QString &)
QString pattern() const
Returns the pattern string of the regular expression.
Definition: qregexp.cpp:3960
static QVariantList variantListFromArray(JSC::ExecState *, JSC::JSArray *arr)
Q_CORE_EXPORT void qFatal(const char *,...)
The QCoreApplication class provides an event loop for console Qt applications.
static bool isRegExp(JSC::JSValue)
bool isWidgetType() const
Returns true if the object is a widget; otherwise returns false.
Definition: qobject.h:146
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the map...
Definition: qmap.h:380
QString baseName() const
Returns the base name of the file without the path.
Definition: qfileinfo.cpp:773
void setProperty(const QString &name, const QScriptValue &value, const PropertyFlags &flags=KeepExistingFlags)
Sets the value of this QScriptValue&#39;s property with the given name to the given value.
static JSC::JSValue arrayFromVariantList(JSC::ExecState *, const QVariantList &lst)
bool scriptDisconnect(QObject *sender, const char *signal, JSC::JSValue receiver, JSC::JSValue function)
QString arg(qlonglong a, int fieldwidth=0, int base=10, const QChar &fillChar=QLatin1Char(' ')) const Q_REQUIRED_RESULT
Definition: qstring.cpp:7186
int userType() const
Returns the storage type of the value stored in the variant.
Definition: qvariant.cpp:1913
WTF::RefPtr< JSC::Structure > scriptObjectStructure
QScriptEngine::DemarshalFunction demarshal
PatternSyntax patternSyntax() const
Returns the syntax used by the regular expression.
Definition: qregexp.cpp:4012
QString & append(QChar c)
Definition: qstring.cpp:1777
PatternSyntax
The syntax used to interpret the meaning of the pattern.
Definition: qregexp.h:64
static JSC::JSValue property(JSC::ExecState *, JSC::JSValue, const JSC::Identifier &id, int resolveMode=QScriptValue::ResolvePrototype)
The QDateTime class provides date and time functions.
Definition: qdatetime.h:216
virtual QStringList keys() const =0
static QScriptSyntaxCheckResult checkSyntax(const QString &program)
The QFile class provides an interface for reading from and writing to files.
Definition: qfile.h:65
static JSC::JSValue newArray(JSC::ExecState *, uint length)
#define Q_CORE_EXPORT
Definition: qglobal.h:1449
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the hash...
Definition: qhash.h:467
void setPrototype(const QScriptValue &prototype)
If this QScriptValue is an object, sets the internal prototype (__proto__ property) of this object to...
JSC::JSObject * customGlobalObject() const
QScript::TimeoutCheckerProxy * timeoutChecker() const
The QTextStream class provides a convenient interface for reading and writing text.
Definition: qtextstream.h:73
static QScriptEngineAgent * get(QScriptEngineAgentPrivate *p)
static QCoreApplication * instance()
Returns a pointer to the application&#39;s QCoreApplication (or QApplication) instance.
PropertyFlags
Definition: qmetaobject_p.h:61
virtual void contextPop()
This function is called when the current script context is about to be popped.
static const char * typeName(int type)
Returns the type name associated with the given type, or 0 if no matching type was found...
Definition: qmetatype.cpp:406
Q_CORE_EXPORT double qInf()
Returns the bit pattern for an infinite number as a double.
Definition: qnumeric.cpp:90
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
QScriptEngineAgent * activeAgent
void setShouldAbort(bool shouldAbort)
QScript::QObjectPrototype * qobjectPrototype
iterator insert(const Key &key, const T &value)
Inserts a new item with the key key and a value of value.
Definition: qmap.h:559
void collectGarbage()
Runs the garbage collector.
static QStringList libraryPaths()
Returns a list of paths that the application will search when dynamically loading libraries...
static bool isQObject(JSC::JSValue)
QString relativeFilePath(const QString &fileName) const
Returns the path to fileName relative to the directory.
Definition: qdir.cpp:722
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
#define ctx
Definition: qgl.cpp:6094
static quint32 toUInt32(JSC::ExecState *, JSC::JSValue)
void reportAdditionalMemoryCost(int size)
QList< QVariant > QVariantList
Definition: qvariant.h:443
int processEventsInterval() const
Returns the interval in milliseconds between calls to QCoreApplication::processEvents() while the int...
The QHash::iterator class provides an STL-style non-const iterator for QHash and QMultiHash.
Definition: qhash.h:330
unsigned int quint32
Definition: qglobal.h:938
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
PropertyFlag
This enum describes the attributes of a property.
Definition: qscriptvalue.h:69
QScriptContext * currentContext() const
Returns the current context.
QScriptValuePrivate * freeScriptValues
virtual void initialize(const QString &key, QScriptEngine *engine)=0
const char * className() const
Returns the class name.
Definition: qobjectdefs.h:491
QMetaObject * metaObject
Definition: qobject.h:107
QScriptValue importExtension(const QString &extension)
Imports the given extension into this QScriptEngine.
QString canonicalPath() const
Returns the canonical path, i.e.
Definition: qdir.cpp:642
JSC::JSObject * customGlobalObject
static QScriptDeclarativeClass::Object * declarativeObject(JSC::JSValue)
#define Q_AUTOTEST_EXPORT
Definition: qglobal.h:1510
JSC::JSObject * originalGlobalObjectProxy
QScriptValue create(int type, const void *ptr)
const_iterator constBegin() const
Definition: qset.h:168
static JSC::JSValue JSC_HOST_CALL functionQsTrNoOp(JSC::ExecState *, JSC::JSObject *, JSC::JSValue, const JSC::ArgList &)
double qsreal
Definition: qscriptvalue.h:52
QScriptContext * pushContext()
Enters a new execution context and returns the associated QScriptContext object.
JSC::JSValue newQObject(QObject *object, QScriptEngine::ValueOwnership ownership=QScriptEngine::QtOwnership, const QScriptEngine::QObjectWrapOptions &options=0)
bool isQObject() const
Returns true if this QScriptValue is a QObject; otherwise returns false.
void clearExceptions()
Clears any uncaught exceptions in this engine.
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402
QSet< JSC::JSObject * > visitedConversionObjects
QScriptValue(* MarshalFunction)(QScriptEngine *, const void *)
quint16 index
QStringList availableExtensions() const
Returns a list naming the available extensions that can be imported using the importExtension() funct...
static QVariant & variantValue(JSC::JSValue value)
static QScriptSyntaxCheckResult checkSyntax(const QString &program)
Checks the syntax of the given program.
#define QT_BEGIN_INCLUDE_NAMESPACE
This macro is equivalent to QT_END_NAMESPACE.
Definition: qglobal.h:91
The QScriptProgram class encapsulates a Qt Script program.
JSC::JSValue jscValue
int mostGeneralMethod(QMetaMethod *out=0) const
static int toDigit(char c)
QScopedPointer< QObjectData > d_ptr
Definition: qobject.h:320
QScriptValue newDate(qsreal value)
Creates a QtScript object of class Date with the given value (the number of milliseconds since 01 Jan...
T takeLast()
Removes the last item in the list and returns it.
Definition: qlist.h:492
QScriptEngineAgent * agent() const
Returns the agent currently installed on this engine, or 0 if no agent is installed.
static bool convertNumber(qsreal, int type, void *ptr)
void setDelegate(QScriptObjectDelegate *delegate)
QDateTime MsToDateTime(JSC::ExecState *exec, qsreal t)
Converts a JS date value (milliseconds) to a QDateTime (local time).
QScriptValue newQMetaObject(const QMetaObject *metaObject, const QScriptValue &ctor=QScriptValue())
Creates a QtScript object that represents a QObject class, using the the given metaObject and constru...
QString readAll()
Reads the entire content of the stream, and returns it as a QString.
virtual void contextPush()
This function is called when a new script context has been pushed.
QMetaMethod method(int index) const
Returns the meta-data for the method with the given index.
void mark(JSC::MarkStack &markStack)
int year() const
Returns the year of this date.
Definition: qdatetime.cpp:353
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
Definition: qbytearray.h:421
quint16 ToUInt16(qsreal n)
static QScriptValue::PropertyFlags propertyFlags(JSC::ExecState *, JSC::JSValue value, const JSC::Identifier &id, const QScriptValue::ResolveFlags &mode)
JSC::JSGlobalData * globalData
QScriptValue scriptValueFromJSCValue(JSC::JSValue value)
QStringList split(const QString &sep, SplitBehavior behavior=KeepEmptyParts, Qt::CaseSensitivity cs=Qt::CaseSensitive) const Q_REQUIRED_RESULT
Splits the string into substrings wherever sep occurs, and returns the list of those strings...
Definition: qstring.cpp:6526
int qstrcmp(const QByteArray &str1, const char *str2)
Definition: qbytearray.cpp:336
QScriptValue activationObject() const
Returns the activation object of this QScriptContext.
QTime time() const
Returns the time part of the datetime.
Definition: qdatetime.cpp:2368
QScriptValue undefinedValue()
Returns a QScriptValue of the primitive type Undefined.
void _q_objectDestroyed(QObject *)
QScriptValuePrivate * registeredScriptValues
JSC::UString cachedTranslationUrl
QObject * instance()
Returns the root component object of the plugin.
bool qScriptDisconnect(QObject *sender, const char *signal, const QScriptValue &receiver, const QScriptValue &function)
Disconnects the signal in the sender from the given (receiver, function) pair.
quint64 qulonglong
Definition: qglobal.h:952
const char * signature() const
Returns the signature of this method (e.g., setValue(double)).
iterator find(const Key &key)
Returns an iterator pointing to the item with the key in the hash.
Definition: qhash.h:865
static void setVariantValue(JSC::JSValue objectValue, const QVariant &value)
QStringList importedExtensions() const
Returns a list naming the extensions that have been imported using the importExtension() function...
static bool toBool(JSC::ExecState *, JSC::JSValue)
static JSC::JSValue JSC_HOST_CALL functionGC(JSC::ExecState *, JSC::JSObject *, JSC::JSValue, const JSC::ArgList &)
bool convert(const QScriptValue &value, int type, void *ptr)
QList< int > overloadedIndexes() const
void setAgent(QScriptEngineAgent *agent)
Installs the given agent on this engine.
static bool isArray(JSC::JSValue)
QScriptValue newArray(uint length=0)
Creates a QtScript object of class Array with the given length.
static JSC::JSValue objectFromVariantMap(JSC::ExecState *, const QVariantMap &vmap)
static QScriptProgramPrivate * get(const QScriptProgram &q)
The QFileInfo class provides system-independent file information.
Definition: qfileinfo.h:60
JSC::JSValue newQMetaObject(const QMetaObject *metaObject, JSC::JSValue ctor)
void setOptions(QScriptEngine::QObjectWrapOptions options)
int errorColumnNumber() const
Returns the error column number of this QScriptSyntaxCheckResult, or -1 if there is no error...
ExecState CallFrame
bool hasUncaughtException() const
Returns true if the last script evaluation resulted in an uncaught exception; otherwise returns false...
void agentDeleted(QScriptEngineAgent *agent)
virtual void close()
Calls QFile::flush() and closes the file.
Definition: qfile.cpp:1680
QScriptValue newActivationObject()
qint64 qlonglong
Definition: qglobal.h:951
JSC::JSValue evaluateHelper(JSC::ExecState *exec, intptr_t sourceId, JSC::EvalExecutable *executable, bool &compile)
void setDefaultPrototype(int metaTypeId, const QScriptValue &prototype)
Sets the default prototype of the C++ type identified by the given metaTypeId to prototype.
#define qPrintable(string)
Definition: qglobal.h:1750
static JSC::JSValue thisForContext(JSC::ExecState *frame)
static qreal dot(const QPointF &a, const QPointF &b)
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57
QScriptValue toObject(const QScriptValue &value)
Converts the given value to an object, if such a conversion is possible; otherwise returns an invalid...
void setGlobalObject(JSC::JSObject *object)
static const JSC::ClassInfo info
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
static QString fileName(const QString &fileUrl)
Q_OUTOFLINE_TEMPLATE void qDeleteAll(ForwardIterator begin, ForwardIterator end)
Definition: qalgorithms.h:319
QExplicitlySharedDataPointer< QScriptSyntaxCheckResultPrivate > d_ptr
Definition: qscriptengine.h:97
The QScriptEngineAgent class provides an interface to report events pertaining to QScriptEngine execu...
WTF::RefPtr< JSC::Structure > qobjectWrapperObjectStructure
QScriptEnginePrivate * engine
QScriptValue call(const QScriptValue &thisObject=QScriptValue(), const QScriptValueList &args=QScriptValueList())
Calls this QScriptValue as a function, using thisObject as the `this&#39; object in the function call...
iterator erase(iterator it)
Removes the (key, value) pair associated with the iterator pos from the hash, and returns an iterator...
Definition: qhash.h:827
QScriptValue argument(int index) const
Returns the function argument at the given index.
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
bool isValid() const
Returns true if this QScriptValue is valid; otherwise returns false.
static QVariant jscValueToVariant(JSC::ExecState *, JSC::JSValue value, int targetType)
The QMetaMethod class provides meta-data about a member function.
Definition: qmetaobject.h:56
QScriptValue abortResult
QScriptValue newVariant(const QVariant &value)
Creates a QtScript object holding the given variant value.
QScriptValue nullValue()
Returns a QScriptValue of the primitive type Null.
QScriptEngine::MarshalFunction marshal
virtual const QMetaObject * metaObject() const
Returns a pointer to the meta-object of this object.
QScriptContext * parentContext() const
Returns the parent context of this QScriptContext.
Q_CORE_EXPORT bool qIsInf(double d)
Returns true if the double {d} is equivalent to infinity.
Definition: qnumeric.cpp:50
static bool hasValidCodeBlockRegister(JSC::ExecState *frame)
bool isObject() const
Returns true if this QScriptValue is of the Object type; otherwise returns false. ...
bool scriptConnect(QObject *sender, const char *signal, JSC::JSValue receiver, JSC::JSValue function, Qt::ConnectionType type)
void registerWrapper(QScriptObject *wrapper, QScriptEngine::ValueOwnership ownership, const QScriptEngine::QObjectWrapOptions &options)
#define text
Definition: qobjectdefs.h:80
QScriptValue uncaughtException() const
Returns the current uncaught exception, or an invalid QScriptValue if there is no uncaught exception...
void setData(const QScriptValue &data)
Sets the internal data of this QScriptValue object.
int hour() const
Returns the hour part (0 to 23) of the time.
Definition: qdatetime.cpp:1578
bool endsWith(const QByteArray &a) const
Returns true if this byte array ends with byte array ba; otherwise returns false. ...
void detachAllRegisteredScriptValues()
The QPluginLoader class loads a plugin at run-time.
Definition: qpluginloader.h:62
int signalIndex(const char *signalName) const
Returns the signal index used in the internal connectionLists vector.
Definition: qobject.cpp:3719
friend class const_iterator
Definition: qmap.h:369
State state() const
Returns the state of this QScriptSyntaxCheckResult.
void registerScriptString(QScriptStringPrivate *value)
INT_PTR intptr_t
bool isMinimal() const
Returns true if minimal (non-greedy) matching is enabled; otherwise returns false.
Definition: qregexp.cpp:4046