Showing the changes to libraries/script-engine/src/qtscript/ScriptContextQtWrapper.cpp (1 of 38 files). Show all
Unified · Split
| @@ -0,0 +1,92 @@ | ||
| 1 | +// | |
| 2 | +// ScriptContextQtWrapper.cpp | |
| 3 | +// libraries/script-engine/src | |
| 4 | +// | |
| 5 | +// Created by Heather Anderson on 5/22/21. | |
| 6 | +// Copyright 2021 Vircadia contributors. | |
| 7 | +// | |
| 8 | +// Distributed under the Apache License, Version 2.0. | |
| 9 | +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html | |
| 10 | +// | |
| 11 | + | |
| 12 | +#include "ScriptContextQtWrapper.h" | |
| 13 | + | |
| 14 | +#include <QtScript/QScriptContext> | |
| 15 | + | |
| 16 | +#include "ScriptEngineQtScript.h" | |
| 17 | +#include "ScriptValueQtWrapper.h" | |
| 18 | + | |
| 19 | +ScriptContextQtWrapper* ScriptContextQtWrapper::unwrap(ScriptContext* val) { | |
| 20 | + if (!val) { | |
| 21 | + return nullptr; | |
| 22 | + } | |
| 23 | + | |
| 24 | + return dynamic_cast<ScriptContextQtWrapper*>(val); | |
| 25 | +} | |
| 26 | + | |
| 27 | +int ScriptContextQtWrapper::argumentCount() const { | |
| 28 | + return _context->argumentCount(); | |
| 29 | +} | |
| 30 | + | |
| 31 | +ScriptValuePointer ScriptContextQtWrapper::argument(int index) const { | |
| 32 | + QScriptValue result = _context->argument(index); | |
| 33 | + return ScriptValuePointer(new ScriptValueQtWrapper(_engine, std::move(result))); | |
| 34 | +} | |
| 35 | + | |
| 36 | +QStringList ScriptContextQtWrapper::backtrace() const { | |
| 37 | + return _context->backtrace(); | |
| 38 | +} | |
| 39 | + | |
| 40 | +ScriptValuePointer ScriptContextQtWrapper::callee() const { | |
| 41 | + QScriptValue result = _context->callee(); | |
| 42 | + return ScriptValuePointer(new ScriptValueQtWrapper(_engine, std::move(result))); | |
| 43 | +} | |
| 44 | + | |
| 45 | +ScriptEnginePointer ScriptContextQtWrapper::engine() const { | |
| 46 | + return _engine->sharedFromThis(); | |
| 47 | +} | |
| 48 | + | |
| 49 | +ScriptFunctionContextPointer ScriptContextQtWrapper::functionContext() const { | |
| 50 | + return ScriptFunctionContextPointer(new ScriptFunctionContextQtWrapper(_context)); | |
| 51 | +} | |
| 52 | + | |
| 53 | +ScriptContextPointer ScriptContextQtWrapper::parentContext() const { | |
| 54 | + QScriptContext* result = _context->parentContext(); | |
| 55 | + return ScriptContextPointer(new ScriptContextQtWrapper(_engine, result)); | |
| 56 | +} | |
| 57 | + | |
| 58 | +ScriptValuePointer ScriptContextQtWrapper::thisObject() const { | |
| 59 | + QScriptValue result = _context->thisObject(); | |
| 60 | + return ScriptValuePointer(new ScriptValueQtWrapper(_engine, std::move(result))); | |
| 61 | +} | |
| 62 | + | |
| 63 | +ScriptValuePointer ScriptContextQtWrapper::throwError(const QString& text) { | |
| 64 | + QScriptValue result = _context->throwError(text); | |
| 65 | + return ScriptValuePointer(new ScriptValueQtWrapper(_engine, std::move(result))); | |
| 66 | +} | |
| 67 | + | |
| 68 | +ScriptValuePointer ScriptContextQtWrapper::throwValue(const ScriptValuePointer& value) { | |
| 69 | + ScriptValueQtWrapper* unwrapped = ScriptValueQtWrapper::unwrap(value); | |
| 70 | + if (!unwrapped) { | |
| 71 | + return _engine->undefinedValue(); | |
| 72 | + } | |
| 73 | + QScriptValue result = _context->throwValue(unwrapped->toQtValue()); | |
| 74 | + return ScriptValuePointer(new ScriptValueQtWrapper(_engine, std::move(result))); | |
| 75 | +} | |
| 76 | + | |
| 77 | + | |
| 78 | +QString ScriptFunctionContextQtWrapper::fileName() const { | |
| 79 | + return _value.fileName(); | |
| 80 | +} | |
| 81 | + | |
| 82 | +QString ScriptFunctionContextQtWrapper::functionName() const { | |
| 83 | + return _value.functionName(); | |
| 84 | +} | |
| 85 | + | |
| 86 | +ScriptFunctionContext::FunctionType ScriptFunctionContextQtWrapper::functionType() const { | |
| 87 | + return static_cast<ScriptFunctionContext::FunctionType>(_value.functionType()); | |
| 88 | +} | |
| 89 | + | |
| 90 | +int ScriptFunctionContextQtWrapper::lineNumber() const { | |
| 91 | + return _value.lineNumber(); | |
| 92 | +} | |