/**************************************************************************** ** ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** ** This file is part of the V4VM module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in ** a written agreement between you and Digia. For licensing terms and ** conditions see http://qt.digia.com/licensing. For further information ** use the contact form at http://qt.digia.com/contact-us. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser ** General Public License version 2.1 as published by the Free Software ** Foundation and appearing in the file LICENSE.LGPL included in the ** packaging of this file. Please review the following information to ** ensure the GNU Lesser General Public License version 2.1 requirements ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. ** ** In addition, as a special exception, Digia gives you certain additional ** rights. These rights are described in the Digia Qt LGPL Exception ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. ** ** GNU General Public License Usage ** Alternatively, this file may be used under the terms of the GNU ** General Public License version 3.0 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. Please review the following information to ** ensure the GNU General Public License version 3.0 requirements will be ** met: http://www.gnu.org/copyleft/gpl.html. ** ** ** $QT_END_LICENSE$ ** ****************************************************************************/ #include "qv4v8.h" #include "qv4engine.h" #include "qv4runtime.h" #include "qv4mm.h" #include "qv4managed.h" #include "qv4functionobject.h" #include "qv4value.h" #include "qv4isel_masm_p.h" #include "qv4globalobject.h" #include "qv4regexpobject.h" #include "qv4dateobject.h" #include "qv4numberobject.h" #include "qv4booleanobject.h" #include "qv4stringobject.h" #include "qv4objectproto.h" #include using namespace QQmlJS; using namespace QQmlJS::VM; namespace v8 { #define currentEngine() Isolate::GetCurrent()->GetCurrentContext()->GetEngine() #define Q_D(obj) QQmlJS::VM::Value *d = reinterpret_cast(obj) #define ValuePtr(obj) reinterpret_cast(obj) #define ConstValuePtr(obj) reinterpret_cast(obj) void *gcProtect(void *handle) { Q_D(handle); if (VM::Managed *m = d->asManaged()) { currentEngine()->memoryManager->protect(m); return currentEngine()->memoryManager; } } void gcProtect(void *memoryManager, void *handle) { Q_D(handle); if (VM::Managed *m = d->asManaged()) if (memoryManager) static_cast(memoryManager)->protect(m); } void gcUnprotect(void *memoryManager, void *handle) { Q_D(handle); if (VM::Managed *m = d->asManaged()) if (memoryManager) static_cast(memoryManager)->unprotect(m); } struct V8AccessorGetter: FunctionObject { AccessorGetter getter; Persistent data; Persistent name; V8AccessorGetter(ExecutionContext *scope, const Handle &name, const AccessorGetter &getter, Handle data) : FunctionObject(scope) { vtbl = &static_vtbl; this->getter = getter; this->data = Persistent::New(data); this->name = Persistent::New(name); } using Object::construct; static VM::Value call(Managed *that, ExecutionContext *context, const VM::Value &thisObject, VM::Value *args, int argc) { V8AccessorGetter *getter = static_cast(that); AccessorInfo info(thisObject, getter->data); VM::Value result = VM::Value::undefinedValue(); try { result = getter->getter(Local::New(getter->name), info)->vmValue(); } catch (VM::Exception &e) { Isolate::GetCurrent()->setException(e.value()); e.accept(context); } return result; } protected: static const ManagedVTable static_vtbl; }; DEFINE_MANAGED_VTABLE(V8AccessorGetter); struct V8AccessorSetter: FunctionObject { AccessorSetter setter; Persistent data; Persistent name; V8AccessorSetter(ExecutionContext *scope, const Handle &name, const AccessorSetter &setter, Handle data) : FunctionObject(scope) { vtbl = &static_vtbl; this->setter = setter; this->data = Persistent::New(data); this->name = Persistent::New(name); } using Object::construct; static VM::Value call(Managed *that, ExecutionContext *context, const VM::Value &thisObject, VM::Value *args, int argc) { if (!argc) return VM::Value::undefinedValue(); V8AccessorSetter *setter = static_cast(that); AccessorInfo info(thisObject, setter->data); try { setter->setter(Local::New(setter->name), Local::New(Value::fromVmValue(args[0])), info); } catch (VM::Exception &e) { Isolate::GetCurrent()->setException(e.value()); e.accept(context); } return VM::Value::undefinedValue(); } protected: static const ManagedVTable static_vtbl; }; DEFINE_MANAGED_VTABLE(V8AccessorSetter); ScriptOrigin::ScriptOrigin(Handle resource_name, Handle resource_line_offset, Handle resource_column_offset) { m_fileName = resource_name->ToString()->asQString(); m_lineNumber = resource_line_offset->ToInt32()->Value(); m_columnNumber = resource_column_offset->ToInt32()->Value(); } Handle ScriptOrigin::ResourceName() const { return Value::fromVmValue(VM::Value::fromString(currentEngine()->current, m_fileName)); } Handle ScriptOrigin::ResourceLineOffset() const { return Integer::New(m_lineNumber); } Handle ScriptOrigin::ResourceColumnOffset() const { return Integer::New(m_columnNumber); } Local