diff options
Diffstat (limited to 'JavaScriptCore/qt/api/qscriptengine_p.cpp')
-rw-r--r-- | JavaScriptCore/qt/api/qscriptengine_p.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/JavaScriptCore/qt/api/qscriptengine_p.cpp b/JavaScriptCore/qt/api/qscriptengine_p.cpp index fd7978b..23e41c4 100644 --- a/JavaScriptCore/qt/api/qscriptengine_p.cpp +++ b/JavaScriptCore/qt/api/qscriptengine_p.cpp @@ -31,11 +31,14 @@ QScriptEnginePrivate::QScriptEnginePrivate(const QScriptEngine* engine) : q_ptr(const_cast<QScriptEngine*>(engine)) , m_context(JSGlobalContextCreate(0)) + , m_exception(0) { } QScriptEnginePrivate::~QScriptEnginePrivate() { + if (m_exception) + JSValueUnprotect(m_context, m_exception); JSGlobalContextRelease(m_context); } @@ -77,11 +80,35 @@ QScriptValuePrivate* QScriptEnginePrivate::evaluate(const QScriptProgramPrivate* return new QScriptValuePrivate(this, evaluate(*program, program->file(), program->line())); } +QScriptValuePrivate* QScriptEnginePrivate::uncaughtException() const +{ + return m_exception ? new QScriptValuePrivate(this, m_exception) : new QScriptValuePrivate(); +} + QScriptValuePrivate* QScriptEnginePrivate::newObject() const { return new QScriptValuePrivate(this, JSObjectMake(m_context, /* jsClass */ 0, /* userData */ 0)); } +QScriptValuePrivate* QScriptEnginePrivate::newArray(uint length) +{ + JSValueRef exception = 0; + JSObjectRef array = JSObjectMakeArray(m_context, /* argumentCount */ 0, /* arguments */ 0, &exception); + + if (!exception) { + if (length > 0) { + JSRetainPtr<JSStringRef> lengthRef(Adopt, JSStringCreateWithUTF8CString("length")); + // array is an Array instance, so an exception should not occure here. + JSObjectSetProperty(m_context, array, lengthRef.get(), JSValueMakeNumber(m_context, length), kJSPropertyAttributeNone, /* exception */ 0); + } + } else { + setException(exception, NotNullException); + return new QScriptValuePrivate(); + } + + return new QScriptValuePrivate(this, array); +} + QScriptValuePrivate* QScriptEnginePrivate::globalObject() const { JSObjectRef globalObject = JSContextGetGlobalObject(m_context); |