Coverage Report

Created: 2026-01-17 06:14

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/wt/src/Wt/WJavaScriptExposableObject.C
Line
Count
Source
1
// This may look like C code, but it's really -*- C++ -*-
2
/*
3
 * Copyright (C) 2015 Emweb bv, Herent, Belgium.
4
 *
5
 * See the LICENSE file for terms of use.
6
 */
7
8
#include "WJavaScriptExposableObject.h"
9
#include "Wt/WException.h"
10
#include "Wt/WLogger.h"
11
12
#include <cassert>
13
14
namespace Wt {
15
16
WJavaScriptExposableObject::WJavaScriptExposableObject()
17
10
  : clientBinding_(nullptr)
18
10
{ }
19
20
WJavaScriptExposableObject::WJavaScriptExposableObject(const WJavaScriptExposableObject &other)
21
#ifndef WT_TARGET_JAVA
22
0
  : clientBinding_(other.clientBinding_ ?
23
0
                   new JSInfo(*other.clientBinding_) : nullptr)
24
#else
25
  : clientBinding_(other.clientBinding_)
26
#endif
27
0
{ }
28
29
#ifndef WT_TARGET_JAVA
30
WJavaScriptExposableObject &WJavaScriptExposableObject::operator=(const WJavaScriptExposableObject &rhs)
31
0
{
32
0
  if (clientBinding_ != nullptr && rhs.clientBinding_ != clientBinding_) {
33
0
    delete clientBinding_;
34
0
  }
35
0
  if (rhs.clientBinding_ != nullptr) {
36
0
    clientBinding_ = new JSInfo(*rhs.clientBinding_);
37
0
  } else {
38
0
    clientBinding_ = nullptr;
39
0
  }
40
41
0
  return *this;
42
0
}
43
#endif
44
45
bool WJavaScriptExposableObject::isJavaScriptBound() const
46
10
{
47
10
  return clientBinding_;
48
10
}
49
50
WJavaScriptExposableObject::~WJavaScriptExposableObject()
51
0
{
52
0
  delete clientBinding_;
53
0
}
54
55
std::string WJavaScriptExposableObject::jsRef() const
56
0
{
57
0
  if (clientBinding_) return clientBinding_->jsRef_;
58
0
  else return jsValue();
59
0
}
60
61
bool WJavaScriptExposableObject::sameBindingAs(const WJavaScriptExposableObject &rhs) const
62
0
{
63
0
  if (!clientBinding_ && !rhs.clientBinding_) return true; // No binding
64
0
  else if (clientBinding_ && rhs.clientBinding_) return (*clientBinding_) == (*rhs.clientBinding_);
65
0
  else return false; // One is bound, the other is not
66
0
}
67
68
void WJavaScriptExposableObject::assignBinding(const WJavaScriptExposableObject &rhs)
69
0
{
70
0
  assert(rhs.clientBinding_ != nullptr);
71
0
  if (&rhs != this) {
72
0
    if (clientBinding_) delete clientBinding_;
73
0
#ifndef WT_TARGET_JAVA
74
0
    clientBinding_ = new WJavaScriptExposableObject::JSInfo(*rhs.clientBinding_);
75
#else
76
    clientBinding_ = rhs.clientBinding_;
77
#endif
78
0
  }
79
0
}
80
81
void WJavaScriptExposableObject::assignBinding(const WJavaScriptExposableObject &rhs,
82
                                               const std::string &jsRef)
83
0
{
84
0
  assert(rhs.clientBinding_ != nullptr);
85
0
  if (&rhs != this) {
86
0
    if (clientBinding_) delete clientBinding_;
87
0
    clientBinding_ = new WJavaScriptExposableObject::JSInfo(*rhs.clientBinding_);
88
0
  }
89
0
  clientBinding_->jsRef_ = jsRef;
90
0
}
91
92
void WJavaScriptExposableObject::checkModifiable()
93
10
{
94
10
  if (isJavaScriptBound()) {
95
0
    throw WException("Trying to modify a JavaScript bound object!");
96
0
  }
97
10
}
98
99
WJavaScriptExposableObject::JSInfo::JSInfo(WJavaScriptObjectStorage *context, const std::string &jsRef)
100
0
  : context_(context), jsRef_(jsRef)
101
0
{ }
102
103
WJavaScriptExposableObject::JSInfo::JSInfo(const WJavaScriptExposableObject::JSInfo &other)
104
0
  : context_(other.context_), jsRef_(other.jsRef_)
105
0
{ }
106
107
WJavaScriptExposableObject::JSInfo &WJavaScriptExposableObject::JSInfo::operator= (const WJavaScriptExposableObject::JSInfo &rhs)
108
0
{
109
0
  context_ = rhs.context_;
110
0
  jsRef_ = rhs.jsRef_;
111
0
  return *this;
112
0
}
113
114
bool WJavaScriptExposableObject::JSInfo::operator== (const WJavaScriptExposableObject::JSInfo &rhs) const
115
0
{
116
0
  return context_ == rhs.context_ && jsRef_ == rhs.jsRef_;
117
0
}
118
119
}