• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • kjs
 

kjs

  • kjs
bool_object.cpp
1 // -*- c-basic-offset: 2 -*-
2 /*
3  * This file is part of the KDE libraries
4  * Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
5  * Copyright (C) 2003 Apple Computer, Inc.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  *
21  */
22 
23 #include "value.h"
24 #include "object.h"
25 #include "types.h"
26 #include "interpreter.h"
27 #include "operations.h"
28 #include "bool_object.h"
29 #include "error_object.h"
30 #include "lookup.h"
31 
32 #include <assert.h>
33 
34 using namespace KJS;
35 
36 // ------------------------------ BooleanInstanceImp ---------------------------
37 
38 const ClassInfo BooleanInstanceImp::info = {"Boolean", 0, 0, 0};
39 
40 BooleanInstanceImp::BooleanInstanceImp(ObjectImp *proto)
41  : ObjectImp(proto)
42 {
43 }
44 
45 // ------------------------------ BooleanPrototypeImp --------------------------
46 
47 // ECMA 15.6.4
48 
49 BooleanPrototypeImp::BooleanPrototypeImp(ExecState *exec,
50  ObjectPrototypeImp *objectProto,
51  FunctionPrototypeImp *funcProto)
52  : BooleanInstanceImp(objectProto)
53 {
54  Value protect(this);
55  // The constructor will be added later by InterpreterImp::InterpreterImp()
56 
57  putDirect(toStringPropertyName, new BooleanProtoFuncImp(exec,funcProto,BooleanProtoFuncImp::ToString,0,toStringPropertyName), DontEnum);
58  putDirect(valueOfPropertyName, new BooleanProtoFuncImp(exec,funcProto,BooleanProtoFuncImp::ValueOf,0,valueOfPropertyName), DontEnum);
59  setInternalValue(Boolean(false));
60 }
61 
62 
63 // ------------------------------ BooleanProtoFuncImp --------------------------
64 
65 BooleanProtoFuncImp::BooleanProtoFuncImp(ExecState * /*exec*/,
66  FunctionPrototypeImp *funcProto, int i, int len, const Identifier &_ident)
67  : InternalFunctionImp(funcProto), id(i)
68 {
69  Value protect(this);
70  putDirect(lengthPropertyName, len, DontDelete|ReadOnly|DontEnum);
71  ident = _ident;
72 }
73 
74 
75 bool BooleanProtoFuncImp::implementsCall() const
76 {
77  return true;
78 }
79 
80 
81 // ECMA 15.6.4.2 + 15.6.4.3
82 Value BooleanProtoFuncImp::call(ExecState *exec, Object &thisObj, const List &/*args*/)
83 {
84  // no generic function. "this" has to be a Boolean object
85  KJS_CHECK_THIS( BooleanInstanceImp, thisObj );
86 
87  // execute "toString()" or "valueOf()", respectively
88 
89  Value v = thisObj.internalValue();
90  assert(v.isValid());
91 
92  if (id == ToString)
93  return String(v.toString(exec));
94  return Boolean(v.toBoolean(exec)); /* TODO: optimize for bool case */
95 }
96 
97 // ------------------------------ BooleanObjectImp -----------------------------
98 
99 
100 BooleanObjectImp::BooleanObjectImp(ExecState * /*exec*/, FunctionPrototypeImp *funcProto,
101  BooleanPrototypeImp *booleanProto)
102  : InternalFunctionImp(funcProto)
103 {
104  Value protect(this);
105  putDirect(prototypePropertyName, booleanProto, DontEnum|DontDelete|ReadOnly);
106 
107  // no. of arguments for constructor
108  putDirect(lengthPropertyName, NumberImp::one(), ReadOnly|DontDelete|DontEnum);
109 }
110 
111 
112 bool BooleanObjectImp::implementsConstruct() const
113 {
114  return true;
115 }
116 
117 // ECMA 15.6.2
118 Object BooleanObjectImp::construct(ExecState *exec, const List &args)
119 {
120  Object obj(new BooleanInstanceImp(exec->lexicalInterpreter()->builtinBooleanPrototype().imp()));
121 
122  Boolean b;
123  if (args.size() > 0)
124  b = args.begin()->dispatchToBoolean(exec);
125  else
126  b = Boolean(false);
127 
128  obj.setInternalValue(b);
129 
130  return obj;
131 }
132 
133 bool BooleanObjectImp::implementsCall() const
134 {
135  return true;
136 }
137 
138 // ECMA 15.6.1
139 Value BooleanObjectImp::call(ExecState *exec, Object &/*thisObj*/, const List &args)
140 {
141  if (args.isEmpty())
142  return Boolean(false);
143  else
144  return Boolean(args[0].toBoolean(exec)); /* TODO: optimize for bool case */
145 }
146 

kjs

Skip menu "kjs"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

kjs

Skip menu "kjs"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for kjs by doxygen 1.8.1.2
This website is maintained by Timothy Pearson.