]>
git.saurik.com Git - apple/javascriptcore.git/blob - runtime/JSImmediate.cpp
c6cca80b71baec5966d2001a92a17cee8c82ef5f
2 * Copyright (C) 2003-2006, 2008 Apple Inc. All rights reserved.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
22 #include "JSImmediate.h"
24 #include "BooleanConstructor.h"
25 #include "BooleanPrototype.h"
27 #include "ExceptionHelpers.h"
28 #include "JSGlobalObject.h"
29 #include "JSNotAnObject.h"
30 #include "NumberConstructor.h"
31 #include "NumberPrototype.h"
35 JSObject
* JSImmediate::toThisObject(JSValuePtr v
, ExecState
* exec
)
37 ASSERT(isImmediate(v
));
39 return constructNumber(exec
, v
);
41 return constructBooleanFromImmediateBoolean(exec
, v
);
43 return exec
->globalThisValue();
45 JSNotAnObjectErrorStub
* exception
= createNotAnObjectErrorStub(exec
, v
.isNull());
46 exec
->setException(exception
);
47 return new (exec
) JSNotAnObject(exec
, exception
);
50 JSObject
* JSImmediate::toObject(JSValuePtr v
, ExecState
* exec
)
52 ASSERT(isImmediate(v
));
54 return constructNumber(exec
, v
);
56 return constructBooleanFromImmediateBoolean(exec
, v
);
58 JSNotAnObjectErrorStub
* exception
= createNotAnObjectErrorStub(exec
, v
.isNull());
59 exec
->setException(exception
);
60 return new (exec
) JSNotAnObject(exec
, exception
);
63 JSObject
* JSImmediate::prototype(JSValuePtr v
, ExecState
* exec
)
65 ASSERT(isImmediate(v
));
67 return exec
->lexicalGlobalObject()->numberPrototype();
69 return exec
->lexicalGlobalObject()->booleanPrototype();
71 JSNotAnObjectErrorStub
* exception
= createNotAnObjectErrorStub(exec
, v
.isNull());
72 exec
->setException(exception
);
73 return new (exec
) JSNotAnObject(exec
, exception
);
76 UString
JSImmediate::toString(JSValuePtr v
)
78 ASSERT(isImmediate(v
));
79 if (isIntegerNumber(v
))
80 return UString::from(getTruncatedInt32(v
));
81 #if USE(ALTERNATE_JSIMMEDIATE)
83 ASSERT(isDoubleNumber(v
));
84 double value
= doubleValue(v
);
85 if (value
== 0.0) // +0.0 or -0.0
87 return UString::from(value
);
92 if (jsBoolean(false) == v
)
94 if (jsBoolean(true) == v
)
98 ASSERT(v
.isUndefined());
102 NEVER_INLINE
double JSImmediate::nonInlineNaN()
104 return std::numeric_limits
<double>::quiet_NaN();