]>
git.saurik.com Git - apple/javascriptcore.git/blob - kjs/bool_object.cpp
2 * Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
3 * Copyright (C) 2003, 2008 Apple Inc. All rights reserved.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 #include "bool_object.h"
24 #include "JSGlobalObject.h"
25 #include "error_object.h"
26 #include "operations.h"
27 #include <wtf/Assertions.h>
31 // ------------------------------ BooleanInstance ---------------------------
33 const ClassInfo
BooleanInstance::info
= { "Boolean", 0, 0 };
35 BooleanInstance::BooleanInstance(JSObject
* proto
)
36 : JSWrapperObject(proto
)
40 // ------------------------------ BooleanPrototype --------------------------
43 static JSValue
* booleanProtoFuncToString(ExecState
*, JSObject
*, const List
&);
44 static JSValue
* booleanProtoFuncValueOf(ExecState
*, JSObject
*, const List
&);
48 BooleanPrototype::BooleanPrototype(ExecState
* exec
, ObjectPrototype
* objectPrototype
, FunctionPrototype
* functionPrototype
)
49 : BooleanInstance(objectPrototype
)
51 setInternalValue(jsBoolean(false));
53 putDirectFunction(new PrototypeFunction(exec
, functionPrototype
, 0, exec
->propertyNames().toString
, booleanProtoFuncToString
), DontEnum
);
54 putDirectFunction(new PrototypeFunction(exec
, functionPrototype
, 0, exec
->propertyNames().valueOf
, booleanProtoFuncValueOf
), DontEnum
);
58 // ------------------------------ Functions --------------------------
60 // ECMA 15.6.4.2 + 15.6.4.3
62 JSValue
* booleanProtoFuncToString(ExecState
* exec
, JSObject
* thisObj
, const List
&)
64 if (!thisObj
->inherits(&BooleanInstance::info
))
65 return throwError(exec
, TypeError
);
67 JSValue
* v
= static_cast<BooleanInstance
*>(thisObj
)->internalValue();
70 return jsString(v
->toString(exec
));
72 JSValue
* booleanProtoFuncValueOf(ExecState
* exec
, JSObject
* thisObj
, const List
&)
74 if (!thisObj
->inherits(&BooleanInstance::info
))
75 return throwError(exec
, TypeError
);
77 JSValue
* v
= static_cast<BooleanInstance
*>(thisObj
)->internalValue();
80 // TODO: optimize for bool case
81 return jsBoolean(v
->toBoolean(exec
));
84 // ------------------------------ BooleanObjectImp -----------------------------
87 BooleanObjectImp::BooleanObjectImp(ExecState
* exec
, FunctionPrototype
* functionPrototype
, BooleanPrototype
* booleanPrototype
)
88 : InternalFunctionImp(functionPrototype
, booleanPrototype
->classInfo()->className
)
90 putDirect(exec
->propertyNames().prototype
, booleanPrototype
, DontEnum
| DontDelete
| ReadOnly
);
92 // no. of arguments for constructor
93 putDirect(exec
->propertyNames().length
, jsNumber(1), ReadOnly
| DontDelete
| DontEnum
);
97 bool BooleanObjectImp::implementsConstruct() const
103 JSObject
* BooleanObjectImp::construct(ExecState
* exec
, const List
& args
)
105 BooleanInstance
* obj(new BooleanInstance(exec
->lexicalGlobalObject()->booleanPrototype()));
106 obj
->setInternalValue(jsBoolean(args
[0]->toBoolean(exec
)));
111 JSValue
* BooleanObjectImp::callAsFunction(ExecState
* exec
, JSObject
*, const List
& args
)
113 // TODO: optimize for bool case
114 return jsBoolean(args
[0]->toBoolean(exec
));