Coverage Report

Created: 2026-09-03 07:12

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/moddable/xs/sources/xsBoolean.c
Line
Count
Source
1
/*
2
 * Copyright (c) 2016-2017  Moddable Tech, Inc.
3
 *
4
 *   This file is part of the Moddable SDK Runtime.
5
 * 
6
 *   The Moddable SDK Runtime is free software: you can redistribute it and/or modify
7
 *   it under the terms of the GNU Lesser General Public License as published by
8
 *   the Free Software Foundation, either version 3 of the License, or
9
 *   (at your option) any later version.
10
 * 
11
 *   The Moddable SDK Runtime is distributed in the hope that it will be useful,
12
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 *   GNU Lesser General Public License for more details.
15
 * 
16
 *   You should have received a copy of the GNU Lesser General Public License
17
 *   along with the Moddable SDK Runtime.  If not, see <http://www.gnu.org/licenses/>.
18
 *
19
 * This file incorporates work covered by the following copyright and  
20
 * permission notice:  
21
 *
22
 *       Copyright (C) 2010-2016 Marvell International Ltd.
23
 *       Copyright (C) 2002-2010 Kinoma, Inc.
24
 *
25
 *       Licensed under the Apache License, Version 2.0 (the "License");
26
 *       you may not use this file except in compliance with the License.
27
 *       You may obtain a copy of the License at
28
 *
29
 *        http://www.apache.org/licenses/LICENSE-2.0
30
 *
31
 *       Unless required by applicable law or agreed to in writing, software
32
 *       distributed under the License is distributed on an "AS IS" BASIS,
33
 *       WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
34
 *       See the License for the specific language governing permissions and
35
 *       limitations under the License.
36
 */
37
38
#include "xsAll.h"
39
40
static txSlot* fxCheckBoolean(txMachine* the, txSlot* it);
41
42
void fxBuildBoolean(txMachine* the)
43
25.0k
{
44
25.0k
  txSlot* slot;
45
25.0k
  mxPush(mxObjectPrototype);
46
25.0k
  slot = fxLastProperty(the, fxNewBooleanInstance(the));
47
25.0k
  slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Boolean_prototype_toString), 0, mxID(_toString), XS_DONT_ENUM_FLAG);
48
25.0k
  slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Boolean_prototype_valueOf), 0, mxID(_valueOf), XS_DONT_ENUM_FLAG);
49
25.0k
  mxBooleanPrototype = *the->stack;
50
25.0k
  slot = fxBuildHostConstructor(the, mxCallback(fx_Boolean), 1, mxID(_Boolean));
51
25.0k
  mxBooleanConstructor = *the->stack;
52
25.0k
  mxPop();
53
25.0k
}
54
55
txSlot* fxNewBooleanInstance(txMachine* the)
56
475k
{
57
475k
  txSlot* instance;
58
475k
  instance = fxNewObjectInstance(the);
59
475k
  fxNextBooleanProperty(the, instance, 0, XS_NO_ID, XS_INTERNAL_FLAG);
60
475k
  return instance;
61
475k
}
62
63
void fx_Boolean(txMachine* the)
64
29.3k
{
65
29.3k
  txBoolean value = (mxArgc > 0) ? fxToBoolean(the, mxArgv(0)) : 0;
66
29.3k
  if (!mxHasTarget) {
67
12.5k
    mxResult->kind = XS_BOOLEAN_KIND;
68
12.5k
    mxResult->value.boolean = value;
69
12.5k
  }
70
16.8k
  else {
71
16.8k
    txSlot* instance;
72
16.8k
    mxPushSlot(mxTarget);
73
16.8k
    fxGetPrototypeFromConstructor(the, &mxBooleanPrototype);
74
16.8k
    instance = fxNewBooleanInstance(the);
75
16.8k
    instance->next->value.boolean = value;
76
16.8k
    mxPullSlot(mxResult);
77
16.8k
  }
78
29.3k
}
79
80
void fx_Boolean_prototype_toString(txMachine* the)
81
573
{
82
573
  txSlot* slot = fxCheckBoolean(the, mxThis);
83
573
  if (!slot) mxTypeError("this: not a boolean");
84
563
  mxResult->kind = slot->kind;
85
563
  mxResult->value = slot->value;
86
563
  fxToString(the, mxResult);
87
563
}
88
89
void fx_Boolean_prototype_valueOf(txMachine* the)
90
2.65k
{
91
2.65k
  txSlot* slot = fxCheckBoolean(the, mxThis);
92
2.65k
  if (!slot) mxTypeError("this: not a boolean");
93
2.49k
  mxResult->kind = slot->kind;
94
2.49k
  mxResult->value = slot->value;
95
2.49k
}
96
97
txSlot* fxCheckBoolean(txMachine* the, txSlot* it)
98
3.22k
{
99
3.22k
  txSlot* result = C_NULL;
100
3.22k
  if (it->kind == XS_BOOLEAN_KIND)
101
688
    result = it;
102
2.53k
  else if (it->kind == XS_REFERENCE_KIND) {
103
2.53k
    txSlot* instance = it->value.reference;
104
2.53k
    it = instance->next;
105
2.53k
    if ((it) && (it->flag & XS_INTERNAL_FLAG) && (it->kind == XS_BOOLEAN_KIND))
106
2.36k
      result = it;
107
2.53k
  }
108
3.22k
  return result;
109
3.22k
}