Shaka Player Embedded
struct.cc
Go to the documentation of this file.
1 // Copyright 2016 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include "src/mapping/struct.h"
16 
18 
19 namespace shaka {
20 
23 
24 Struct::Struct(const Struct&) = default;
25 Struct::Struct(Struct&&) = default;
26 Struct& Struct::operator=(const Struct&) = default;
27 Struct& Struct::operator=(Struct&&) = default;
28 
29 bool Struct::TryConvert(Handle<JsValue> value) {
30  if (!IsObject(value))
31  return false;
32 
33  LocalVar<JsObject> obj = UnsafeJsCast<JsObject>(value);
34  object_ = obj;
35  for (auto& converter : converters_)
36  converter->SearchAndStore(this, obj);
37  return true;
38 }
39 
40 ReturnVal<JsValue> Struct::ToJsValue() const {
41  if (object_.empty())
42  object_ = CreateObject();
43 
44  for (auto& converter : converters_)
45  converter->AddToObject(this, object_.handle());
46  return object_.value();
47 }
48 
49 void Struct::Trace(memory::HeapTracer* tracer) const {
50  tracer->Trace(&object_);
51  for (auto& converter : converters_)
52  converter->Trace(this, tracer);
53 }
54 
55 } // namespace shaka
bool empty() const
Definition: weak_js_ptr.h:78
ReturnVal< JsObject > CreateObject()
Definition: js_wrappers.cc:296
bool IsObject(Handle< JsValue > value)
Definition: js_wrappers.cc:315
ReturnVal< JsValue > ToJsValue() const override
Definition: struct.cc:40
Struct & operator=(const Struct &)
ReturnVal< JsValue > value() const
Definition: weak_js_ptr.h:97
void Trace(const Traceable *ptr)
Definition: heap_tracer.cc:43
bool TryConvert(Handle< JsValue > value) override
Definition: struct.cc:29
Handle< T > handle() const
Definition: weak_js_ptr.h:87
~Struct() override
Definition: struct.cc:22
void Trace(memory::HeapTracer *tracer) const override
Definition: struct.cc:49