Commit c475562b authored by weinig's avatar weinig

JavaScriptCore:

        Reviewed by Darin.

        Second pass at fixing implicit 64-32 bit conversion errors.
        <rdar://problem/5292262>

        - Add a toFloat() method to JSValue for float conversion.

        * JavaScriptCore.exp:
        * kjs/value.cpp:
        (KJS::JSValue::toFloat):
        * kjs/value.h:

WebCore:

        Reviewed by Darin.

        Second pass at fixing implicit 64-32 bit conversion errors.
        <rdar://problem/5292262>

        - Use new JSValue::toFloat() method instead of toNumber() where
          appropriate.

        * bindings/js/JSCanvasRenderingContext2DCustom.cpp:
        (WebCore::JSCanvasRenderingContext2D::setFillColor):
        (WebCore::JSCanvasRenderingContext2D::setStrokeColor):
        (WebCore::JSCanvasRenderingContext2D::strokeRect):
        (WebCore::JSCanvasRenderingContext2D::drawImage):
        (WebCore::JSCanvasRenderingContext2D::drawImageFromRect):
        (WebCore::JSCanvasRenderingContext2D::setShadow):
        * bindings/js/JSHTMLSelectElementCustom.cpp:
        (WebCore::JSHTMLSelectElement::remove):
        * bindings/js/JSSVGMatrixCustom.cpp:
        (WebCore::JSSVGMatrix::rotateFromVector):
        * bindings/js/kjs_events.cpp:
        (KJS::JSClipboardPrototypeFunction::callAsFunction):
        * bindings/scripts/CodeGeneratorJS.pm:
        * ksvg2/svg/SVGScriptElement.cpp:
        (WebCore::SVGScriptElement::executeScript):



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@23892 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 8766c152
2007-06-29 Sam Weinig <sam@webkit.org>
Reviewed by Darin.
Second pass at fixing implicit 64-32 bit conversion errors.
<rdar://problem/5292262>
- Add a toFloat() method to JSValue for float conversion.
* JavaScriptCore.exp:
* kjs/value.cpp:
(KJS::JSValue::toFloat):
* kjs/value.h:
2007-06-27 Kevin McCullough <kmccullough@apple.com>
Reviewed by Darin.
......
......@@ -243,6 +243,7 @@ __ZNK3KJS6JSCell9getNumberEv
__ZNK3KJS6JSCell9getStringERNS_7UStringE
__ZNK3KJS6JSCell9getStringEv
__ZNK3KJS6JSCell9getUInt32ERj
__ZNK3KJS7JSValue7toFloatEPNS_9ExecStateE
__ZNK3KJS7JSValue7toInt32EPNS_9ExecStateE
__ZNK3KJS7JSValue7toInt32EPNS_9ExecStateERb
__ZNK3KJS7JSValue8toUInt32EPNS_9ExecStateE
......
......@@ -128,6 +128,11 @@ uint16_t JSValue::toUInt16(ExecState *exec) const
return static_cast<uint16_t>(d16);
}
float JSValue::toFloat(ExecState* exec) const
{
return static_cast<float>(toNumber(exec));
}
bool JSCell::getNumber(double &numericValue) const
{
if (!isNumber())
......
......@@ -102,6 +102,9 @@ public:
uint32_t toUInt32(ExecState*, bool& ok) const;
uint16_t toUInt16(ExecState*) const;
// Floating point conversions.
float toFloat(ExecState*) const;
// Garbage collection.
void mark();
bool marked() const;
......
2007-06-29 Sam Weinig <sam@webkit.org>
Reviewed by Darin.
Second pass at fixing implicit 64-32 bit conversion errors.
<rdar://problem/5292262>
- Use new JSValue::toFloat() method instead of toNumber() where
appropriate.
* bindings/js/JSCanvasRenderingContext2DCustom.cpp:
(WebCore::JSCanvasRenderingContext2D::setFillColor):
(WebCore::JSCanvasRenderingContext2D::setStrokeColor):
(WebCore::JSCanvasRenderingContext2D::strokeRect):
(WebCore::JSCanvasRenderingContext2D::drawImage):
(WebCore::JSCanvasRenderingContext2D::drawImageFromRect):
(WebCore::JSCanvasRenderingContext2D::setShadow):
* bindings/js/JSHTMLSelectElementCustom.cpp:
(WebCore::JSHTMLSelectElement::remove):
* bindings/js/JSSVGMatrixCustom.cpp:
(WebCore::JSSVGMatrix::rotateFromVector):
* bindings/js/kjs_events.cpp:
(KJS::JSClipboardPrototypeFunction::callAsFunction):
* bindings/scripts/CodeGeneratorJS.pm:
* ksvg2/svg/SVGScriptElement.cpp:
(WebCore::SVGScriptElement::executeScript):
2007-06-29 Adele Peterson <adele@apple.com>
Rolling out fix for <rdar://problem/5301322> since it broke layout tests.
......@@ -11677,7 +11677,6 @@
0867D690FE84028FC02AAC07 /* Project object */ = {
isa = PBXProject;
buildConfigurationList = 149C284308902B11008A9EFC /* Build configuration list for PBXProject "WebCore" */;
compatibilityVersion = "Xcode 2.4";
hasScannedForEncodings = 1;
knownRegions = (
English,
/*
* Copyright (C) 2006 Apple Computer, Inc.
* Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
......@@ -16,6 +16,7 @@
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include "config.h"
#include "JSCanvasRenderingContext2D.h"
......@@ -95,21 +96,21 @@ JSValue* JSCanvasRenderingContext2D::setFillColor(ExecState* exec, const List& a
if (args[0]->isString())
context->setFillColor(args[0]->toString(exec));
else
context->setFillColor(args[0]->toNumber(exec));
context->setFillColor(args[0]->toFloat(exec));
break;
case 2:
if (args[0]->isString())
context->setFillColor(args[0]->toString(exec), args[1]->toNumber(exec));
context->setFillColor(args[0]->toString(exec), args[1]->toFloat(exec));
else
context->setFillColor(args[0]->toNumber(exec), args[1]->toNumber(exec));
context->setFillColor(args[0]->toFloat(exec), args[1]->toFloat(exec));
break;
case 4:
context->setFillColor(args[0]->toNumber(exec), args[1]->toNumber(exec),
args[2]->toNumber(exec), args[3]->toNumber(exec));
context->setFillColor(args[0]->toFloat(exec), args[1]->toFloat(exec),
args[2]->toFloat(exec), args[3]->toFloat(exec));
break;
case 5:
context->setFillColor(args[0]->toNumber(exec), args[1]->toNumber(exec),
args[2]->toNumber(exec), args[3]->toNumber(exec), args[4]->toNumber(exec));
context->setFillColor(args[0]->toFloat(exec), args[1]->toFloat(exec),
args[2]->toFloat(exec), args[3]->toFloat(exec), args[4]->toFloat(exec));
break;
default:
return throwError(exec, SyntaxError);
......@@ -132,21 +133,21 @@ JSValue* JSCanvasRenderingContext2D::setStrokeColor(ExecState* exec, const List&
if (args[0]->isString())
context->setStrokeColor(args[0]->toString(exec));
else
context->setStrokeColor(args[0]->toNumber(exec));
context->setStrokeColor(args[0]->toFloat(exec));
break;
case 2:
if (args[0]->isString())
context->setStrokeColor(args[0]->toString(exec), args[1]->toNumber(exec));
context->setStrokeColor(args[0]->toString(exec), args[1]->toFloat(exec));
else
context->setStrokeColor(args[0]->toNumber(exec), args[1]->toNumber(exec));
context->setStrokeColor(args[0]->toFloat(exec), args[1]->toFloat(exec));
break;
case 4:
context->setStrokeColor(args[0]->toNumber(exec), args[1]->toNumber(exec),
args[2]->toNumber(exec), args[3]->toNumber(exec));
context->setStrokeColor(args[0]->toFloat(exec), args[1]->toFloat(exec),
args[2]->toFloat(exec), args[3]->toFloat(exec));
break;
case 5:
context->setStrokeColor(args[0]->toNumber(exec), args[1]->toNumber(exec),
args[2]->toNumber(exec), args[3]->toNumber(exec), args[4]->toNumber(exec));
context->setStrokeColor(args[0]->toFloat(exec), args[1]->toFloat(exec),
args[2]->toFloat(exec), args[3]->toFloat(exec), args[4]->toFloat(exec));
break;
default:
return throwError(exec, SyntaxError);
......@@ -161,11 +162,11 @@ JSValue* JSCanvasRenderingContext2D::strokeRect(ExecState* exec, const List& arg
ExceptionCode ec;
if (args.size() <= 4)
context->strokeRect(args[0]->toNumber(exec), args[1]->toNumber(exec),
args[2]->toNumber(exec), args[3]->toNumber(exec), ec);
context->strokeRect(args[0]->toFloat(exec), args[1]->toFloat(exec),
args[2]->toFloat(exec), args[3]->toFloat(exec), ec);
else
context->strokeRect(args[0]->toNumber(exec), args[1]->toNumber(exec),
args[2]->toNumber(exec), args[3]->toNumber(exec), args[4]->toNumber(exec), ec);
context->strokeRect(args[0]->toFloat(exec), args[1]->toFloat(exec),
args[2]->toFloat(exec), args[3]->toFloat(exec), args[4]->toFloat(exec), ec);
setDOMException(exec, ec);
return jsUndefined();
......@@ -191,18 +192,18 @@ JSValue* JSCanvasRenderingContext2D::drawImage(ExecState* exec, const List& args
HTMLImageElement* imgElt = static_cast<HTMLImageElement*>(static_cast<JSHTMLElement*>(args[0])->impl());
switch (args.size()) {
case 3:
context->drawImage(imgElt, args[1]->toNumber(exec), args[2]->toNumber(exec));
context->drawImage(imgElt, args[1]->toFloat(exec), args[2]->toFloat(exec));
break;
case 5:
context->drawImage(imgElt, args[1]->toNumber(exec), args[2]->toNumber(exec),
args[3]->toNumber(exec), args[4]->toNumber(exec), ec);
context->drawImage(imgElt, args[1]->toFloat(exec), args[2]->toFloat(exec),
args[3]->toFloat(exec), args[4]->toFloat(exec), ec);
setDOMException(exec, ec);
break;
case 9:
context->drawImage(imgElt, FloatRect(args[1]->toNumber(exec), args[2]->toNumber(exec),
args[3]->toNumber(exec), args[4]->toNumber(exec)),
FloatRect(args[5]->toNumber(exec), args[6]->toNumber(exec),
args[7]->toNumber(exec), args[8]->toNumber(exec)), ec);
context->drawImage(imgElt, FloatRect(args[1]->toFloat(exec), args[2]->toFloat(exec),
args[3]->toFloat(exec), args[4]->toFloat(exec)),
FloatRect(args[5]->toFloat(exec), args[6]->toFloat(exec),
args[7]->toFloat(exec), args[8]->toFloat(exec)), ec);
setDOMException(exec, ec);
break;
default:
......@@ -212,18 +213,18 @@ JSValue* JSCanvasRenderingContext2D::drawImage(ExecState* exec, const List& args
HTMLCanvasElement* canvas = static_cast<HTMLCanvasElement*>(static_cast<JSHTMLElement*>(args[0])->impl());
switch (args.size()) {
case 3:
context->drawImage(canvas, args[1]->toNumber(exec), args[2]->toNumber(exec));
context->drawImage(canvas, args[1]->toFloat(exec), args[2]->toFloat(exec));
break;
case 5:
context->drawImage(canvas, args[1]->toNumber(exec), args[2]->toNumber(exec),
args[3]->toNumber(exec), args[4]->toNumber(exec), ec);
context->drawImage(canvas, args[1]->toFloat(exec), args[2]->toFloat(exec),
args[3]->toFloat(exec), args[4]->toFloat(exec), ec);
setDOMException(exec, ec);
break;
case 9:
context->drawImage(canvas, FloatRect(args[1]->toNumber(exec), args[2]->toNumber(exec),
args[3]->toNumber(exec), args[4]->toNumber(exec)),
FloatRect(args[5]->toNumber(exec), args[6]->toNumber(exec),
args[7]->toNumber(exec), args[8]->toNumber(exec)), ec);
context->drawImage(canvas, FloatRect(args[1]->toFloat(exec), args[2]->toFloat(exec),
args[3]->toFloat(exec), args[4]->toFloat(exec)),
FloatRect(args[5]->toFloat(exec), args[6]->toFloat(exec),
args[7]->toFloat(exec), args[8]->toFloat(exec)), ec);
setDOMException(exec, ec);
break;
default:
......@@ -249,10 +250,10 @@ JSValue* JSCanvasRenderingContext2D::drawImageFromRect(ExecState* exec, const Li
if (!o->inherits(&JSHTMLImageElement::info))
return throwError(exec, TypeError);
context->drawImageFromRect(static_cast<HTMLImageElement*>(static_cast<JSHTMLElement*>(args[0])->impl()),
args[1]->toNumber(exec), args[2]->toNumber(exec),
args[3]->toNumber(exec), args[4]->toNumber(exec),
args[5]->toNumber(exec), args[6]->toNumber(exec),
args[7]->toNumber(exec), args[8]->toNumber(exec),
args[1]->toFloat(exec), args[2]->toFloat(exec),
args[3]->toFloat(exec), args[4]->toFloat(exec),
args[5]->toFloat(exec), args[6]->toFloat(exec),
args[7]->toFloat(exec), args[8]->toFloat(exec),
args[9]->toString(exec));
return jsUndefined();
}
......@@ -263,38 +264,38 @@ JSValue* JSCanvasRenderingContext2D::setShadow(ExecState* exec, const List& args
switch (args.size()) {
case 3:
context->setShadow(args[0]->toNumber(exec), args[1]->toNumber(exec),
args[2]->toNumber(exec));
context->setShadow(args[0]->toFloat(exec), args[1]->toFloat(exec),
args[2]->toFloat(exec));
break;
case 4:
if (args[3]->isString())
context->setShadow(args[0]->toNumber(exec), args[1]->toNumber(exec),
args[2]->toNumber(exec), args[3]->toString(exec));
context->setShadow(args[0]->toFloat(exec), args[1]->toFloat(exec),
args[2]->toFloat(exec), args[3]->toString(exec));
else
context->setShadow(args[0]->toNumber(exec), args[1]->toNumber(exec),
args[2]->toNumber(exec), args[3]->toNumber(exec));
context->setShadow(args[0]->toFloat(exec), args[1]->toFloat(exec),
args[2]->toFloat(exec), args[3]->toFloat(exec));
break;
case 5:
if (args[3]->isString())
context->setShadow(args[0]->toNumber(exec), args[1]->toNumber(exec),
args[2]->toNumber(exec), args[3]->toString(exec),
args[4]->toNumber(exec));
context->setShadow(args[0]->toFloat(exec), args[1]->toFloat(exec),
args[2]->toFloat(exec), args[3]->toString(exec),
args[4]->toFloat(exec));
else
context->setShadow(args[0]->toNumber(exec), args[1]->toNumber(exec),
args[2]->toNumber(exec), args[3]->toNumber(exec),
args[4]->toNumber(exec));
context->setShadow(args[0]->toFloat(exec), args[1]->toFloat(exec),
args[2]->toFloat(exec), args[3]->toFloat(exec),
args[4]->toFloat(exec));
break;
case 7:
context->setShadow(args[0]->toNumber(exec), args[1]->toNumber(exec),
args[2]->toNumber(exec), args[3]->toNumber(exec),
args[4]->toNumber(exec), args[5]->toNumber(exec),
args[6]->toNumber(exec));
context->setShadow(args[0]->toFloat(exec), args[1]->toFloat(exec),
args[2]->toFloat(exec), args[3]->toFloat(exec),
args[4]->toFloat(exec), args[5]->toFloat(exec),
args[6]->toFloat(exec));
break;
case 8:
context->setShadow(args[0]->toNumber(exec), args[1]->toNumber(exec),
args[2]->toNumber(exec), args[3]->toNumber(exec),
args[4]->toNumber(exec), args[5]->toNumber(exec),
args[6]->toNumber(exec), args[7]->toNumber(exec));
context->setShadow(args[0]->toFloat(exec), args[1]->toFloat(exec),
args[2]->toFloat(exec), args[3]->toFloat(exec),
args[4]->toFloat(exec), args[5]->toFloat(exec),
args[6]->toFloat(exec), args[7]->toFloat(exec));
break;
default:
return throwError(exec, SyntaxError);
......
......@@ -42,7 +42,7 @@ JSValue* JSHTMLSelectElement::remove(ExecState* exec, const List& args)
if (element && element->hasTagName(optionTag))
select.remove(static_cast<HTMLOptionElement*>(element)->index());
else
select.remove(static_cast<int>(args[0]->toNumber(exec)));
select.remove(args[0]->toInt32(exec));
return jsUndefined();
}
......
......@@ -45,8 +45,8 @@ JSValue* JSSVGMatrix::rotateFromVector(ExecState* exec, const List& args)
{
AffineTransform& imp(*impl());
float x = args[0]->toNumber(exec);
float y = args[1]->toNumber(exec);
float x = args[0]->toFloat(exec);
float y = args[1]->toFloat(exec);
KJS::JSValue* result = toJS(exec, new JSSVGPODTypeWrapper<AffineTransform>(imp.rotateFromVector(x, y)));
......
......@@ -475,8 +475,8 @@ JSValue* JSClipboardPrototypeFunction::callAsFunction(ExecState* exec, JSObject*
if (args.size() != 3)
return throwError(exec, SyntaxError, "setDragImage: Invalid number of arguments");
int x = static_cast<int>(args[1]->toNumber(exec));
int y = static_cast<int>(args[2]->toNumber(exec));
int x = args[1]->toInt32(exec);
int y = args[2]->toInt32(exec);
// See if they passed us a node
Node* node = toNode(args[0]);
......
......@@ -1361,7 +1361,8 @@ sub JSValueToNative
my $type = $codeGenerator->StripModule($signature->type);
return "$value->toBoolean(exec)" if $type eq "boolean";
return "$value->toNumber(exec)" if $type eq "float" or $type eq "SVGNumber";
return "$value->toNumber(exec)" if $type eq "SVGNumber";
return "$value->toFloat(exec)" if $type eq "float";
return "$value->toInt32(exec${maybeOkParam})" if $type eq "unsigned long" or $type eq "long" or $type eq "unsigned short";
return "static_cast<Range::CompareHow>($value->toInt32(exec))" if $type eq "CompareHow";
......
......@@ -87,7 +87,7 @@ void SVGScriptElement::executeScript(Document *document, StringImpl *jsCode)
if (exVal->isObject()) {
KJS::JSValue *lineVal = static_cast<KJS::JSObject *>(exVal)->get(exec, "line");
if(lineVal->type() == KJS::NumberType)
lineno = int(lineVal->toNumber(exec));
lineno = lineVal->toInt32(exec);
}
// Fire ERROR_EVENT upon errors...
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment