~ubuntu-branches/ubuntu/raring/qtwebkit-source/raring-proposed

« back to all changes in this revision

Viewing changes to Source/JavaScriptCore/runtime/BooleanPrototype.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2013-02-18 14:24:18 UTC
  • Revision ID: package-import@ubuntu.com-20130218142418-eon0jmjg3nj438uy
Tags: upstream-2.3
ImportĀ upstreamĀ versionĀ 2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
 
3
 *  Copyright (C) 2003, 2008, 2011 Apple Inc. All rights reserved.
 
4
 *
 
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.
 
9
 *
 
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.
 
14
 *
 
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
 
18
 *
 
19
 */
 
20
 
 
21
#include "config.h"
 
22
#include "BooleanPrototype.h"
 
23
 
 
24
#include "Error.h"
 
25
#include "ExceptionHelpers.h"
 
26
#include "JSFunction.h"
 
27
#include "JSString.h"
 
28
#include "ObjectPrototype.h"
 
29
 
 
30
namespace JSC {
 
31
 
 
32
static EncodedJSValue JSC_HOST_CALL booleanProtoFuncToString(ExecState*);
 
33
static EncodedJSValue JSC_HOST_CALL booleanProtoFuncValueOf(ExecState*);
 
34
 
 
35
}
 
36
 
 
37
#include "BooleanPrototype.lut.h"
 
38
 
 
39
namespace JSC {
 
40
 
 
41
const ClassInfo BooleanPrototype::s_info = { "Boolean", &BooleanObject::s_info, 0, ExecState::booleanPrototypeTable, CREATE_METHOD_TABLE(BooleanPrototype) };
 
42
 
 
43
/* Source for BooleanPrototype.lut.h
 
44
@begin booleanPrototypeTable
 
45
  toString  booleanProtoFuncToString    DontEnum|Function 0
 
46
  valueOf   booleanProtoFuncValueOf     DontEnum|Function 0
 
47
@end
 
48
*/
 
49
 
 
50
ASSERT_HAS_TRIVIAL_DESTRUCTOR(BooleanPrototype);
 
51
 
 
52
BooleanPrototype::BooleanPrototype(ExecState* exec, Structure* structure)
 
53
    : BooleanObject(exec->globalData(), structure)
 
54
{
 
55
}
 
56
 
 
57
void BooleanPrototype::finishCreation(ExecState* exec, JSGlobalObject*)
 
58
{
 
59
    Base::finishCreation(exec->globalData());
 
60
    setInternalValue(exec->globalData(), jsBoolean(false));
 
61
 
 
62
    ASSERT(inherits(&s_info));
 
63
}
 
64
 
 
65
bool BooleanPrototype::getOwnPropertySlot(JSCell* cell, ExecState* exec, PropertyName propertyName, PropertySlot &slot)
 
66
{
 
67
    return getStaticFunctionSlot<BooleanObject>(exec, ExecState::booleanPrototypeTable(exec), jsCast<BooleanPrototype*>(cell), propertyName, slot);
 
68
}
 
69
 
 
70
bool BooleanPrototype::getOwnPropertyDescriptor(JSObject* object, ExecState* exec, PropertyName propertyName, PropertyDescriptor& descriptor)
 
71
{
 
72
    return getStaticFunctionDescriptor<BooleanObject>(exec, ExecState::booleanPrototypeTable(exec), jsCast<BooleanPrototype*>(object), propertyName, descriptor);
 
73
}
 
74
 
 
75
// ------------------------------ Functions ---------------------------
 
76
 
 
77
EncodedJSValue JSC_HOST_CALL booleanProtoFuncToString(ExecState* exec)
 
78
{
 
79
    JSGlobalData* globalData = &exec->globalData();
 
80
    JSValue thisValue = exec->hostThisValue();
 
81
    if (thisValue == jsBoolean(false))
 
82
        return JSValue::encode(globalData->smallStrings.falseString(globalData));
 
83
 
 
84
    if (thisValue == jsBoolean(true))
 
85
        return JSValue::encode(globalData->smallStrings.trueString(globalData));
 
86
 
 
87
    if (!thisValue.inherits(&BooleanObject::s_info))
 
88
        return throwVMTypeError(exec);
 
89
 
 
90
    if (asBooleanObject(thisValue)->internalValue() == jsBoolean(false))
 
91
        return JSValue::encode(globalData->smallStrings.falseString(globalData));
 
92
 
 
93
    ASSERT(asBooleanObject(thisValue)->internalValue() == jsBoolean(true));
 
94
    return JSValue::encode(globalData->smallStrings.trueString(globalData));
 
95
}
 
96
 
 
97
EncodedJSValue JSC_HOST_CALL booleanProtoFuncValueOf(ExecState* exec)
 
98
{
 
99
    JSValue thisValue = exec->hostThisValue();
 
100
    if (thisValue.isBoolean())
 
101
        return JSValue::encode(thisValue);
 
102
 
 
103
    if (!thisValue.inherits(&BooleanObject::s_info))
 
104
        return throwVMTypeError(exec);
 
105
 
 
106
    return JSValue::encode(asBooleanObject(thisValue)->internalValue());
 
107
}
 
108
 
 
109
} // namespace JSC