mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-07-17 00:06:17 +02:00
82 lines
2.7 KiB
C++
82 lines
2.7 KiB
C++
//
|
|
// ScriptValueIteratorV8Wrapper.cpp
|
|
// libraries/script-engine/src/v8
|
|
//
|
|
// Created by Heather Anderson on 8/29/21.
|
|
// Modified for V8 by dr Karol Suprynowicz on 2022/10/08
|
|
// Copyright 2021 Vircadia contributors.
|
|
// Copyright 2022 Overte e.V.
|
|
//
|
|
// Distributed under the Apache License, Version 2.0.
|
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
|
//
|
|
|
|
#include "ScriptValueIteratorV8Wrapper.h"
|
|
|
|
V8ScriptValueIterator::V8ScriptValueIterator(ScriptEngineV8* engine, v8::Local<v8::Value> object) : _engine(engine) {
|
|
_context.Reset(_engine->getIsolate(), _engine->getContext());
|
|
auto context = _context.Get(_engine->getIsolate());
|
|
v8::Local<v8::Object> v8Object;
|
|
if (!object->ToObject(context).ToLocal(&v8Object)) {
|
|
Q_ASSERT(false);
|
|
}
|
|
_object.Reset(_engine->getIsolate(), v8Object);
|
|
_propertyNames.Reset(_engine->getIsolate(), v8Object->GetOwnPropertyNames(context).ToLocalChecked());
|
|
_length = _propertyNames.Get(_engine->getIsolate())->Length();
|
|
_currentIndex = 0;
|
|
}
|
|
|
|
bool V8ScriptValueIterator::hasNext() const {
|
|
return _currentIndex < _length - 1;
|
|
}
|
|
|
|
QString V8ScriptValueIterator::name() const {
|
|
auto context = _context.Get(_engine->getIsolate());
|
|
v8::Local<v8::Value> propertyName;
|
|
if (!_propertyNames.Get(_engine->getIsolate())->Get(context, _length).ToLocal(&propertyName)) {
|
|
Q_ASSERT(false);
|
|
}
|
|
return QString(*v8::String::Utf8Value(_engine->getIsolate(), propertyName));
|
|
}
|
|
|
|
void V8ScriptValueIterator::next() {
|
|
if (_length < _currentIndex - 1) {
|
|
_length++;
|
|
}
|
|
}
|
|
|
|
V8ScriptValue V8ScriptValueIterator::value() {
|
|
auto context = _context.Get(_engine->getIsolate());
|
|
v8::Local<v8::Value> v8Value;
|
|
v8::Local<v8::Value> propertyName;
|
|
if (!_propertyNames.Get(_engine->getIsolate())->Get(context, _length).ToLocal(&propertyName)) {
|
|
Q_ASSERT(false);
|
|
}
|
|
if (!_object.Get(_engine->getIsolate())->Get(context, propertyName->ToString(context).ToLocalChecked()).ToLocal(&v8Value)) {
|
|
Q_ASSERT(false);
|
|
}
|
|
return V8ScriptValue(_engine->getIsolate(), v8Value);
|
|
}
|
|
|
|
ScriptValue::PropertyFlags ScriptValueIteratorV8Wrapper::flags() const {
|
|
//V8TODO
|
|
//return (ScriptValue::PropertyFlags)(int)_value.flags();
|
|
return (ScriptValue::PropertyFlags)(0);
|
|
}
|
|
|
|
bool ScriptValueIteratorV8Wrapper::hasNext() const {
|
|
return _value->hasNext();
|
|
}
|
|
|
|
QString ScriptValueIteratorV8Wrapper::name() const {
|
|
return _value->name();
|
|
}
|
|
|
|
void ScriptValueIteratorV8Wrapper::next() {
|
|
_value->next();
|
|
}
|
|
|
|
ScriptValue ScriptValueIteratorV8Wrapper::value() const {
|
|
V8ScriptValue result = _value->value();
|
|
return ScriptValue(new ScriptValueV8Wrapper(_engine, std::move(result)));
|
|
}
|