Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(90)

Side by Side Diff: Source/bindings/dart/DartUtilities.cpp

Issue 27767003: Convert serialized values to ints if they are whole and less than 53 bits. (Closed) Base URL: svn://svn.chromium.org/multivm/trunk/webkit
Patch Set: Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2011, Google Inc. 1 // Copyright 2011, Google Inc.
2 // All rights reserved. 2 // All rights reserved.
3 // 3 //
4 // Redistribution and use in source and binary forms, with or without 4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are 5 // modification, are permitted provided that the following conditions are
6 // met: 6 // met:
7 // 7 //
8 // * Redistributions of source code must retain the above copyright 8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer. 9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above 10 // * Redistributions in binary form must reproduce the above
(...skipping 22 matching lines...) Expand all
33 #include "DartBlob.h" 33 #include "DartBlob.h"
34 #include "DartHTMLElement.h" 34 #include "DartHTMLElement.h"
35 #include "DartIDBKeyRange.h" 35 #include "DartIDBKeyRange.h"
36 #include "DartImageData.h" 36 #include "DartImageData.h"
37 #include "DartMessagePort.h" 37 #include "DartMessagePort.h"
38 #include "bindings/dart/DartDOMData.h" 38 #include "bindings/dart/DartDOMData.h"
39 #include "bindings/dart/DartHandleProxy.h" 39 #include "bindings/dart/DartHandleProxy.h"
40 #include "bindings/dart/V8Converter.h" 40 #include "bindings/dart/V8Converter.h"
41 #include "bindings/v8/ScriptController.h" 41 #include "bindings/v8/ScriptController.h"
42 #include "bindings/v8/SerializedScriptValue.h" 42 #include "bindings/v8/SerializedScriptValue.h"
43 #include "bindings/v8/V8Binding.h"
43 #include "core/dom/Document.h" 44 #include "core/dom/Document.h"
44 #include "core/html/canvas/DataView.h" 45 #include "core/html/canvas/DataView.h"
45 #include "core/inspector/ScriptArguments.h" 46 #include "core/inspector/ScriptArguments.h"
46 #include "core/inspector/ScriptCallStack.h" 47 #include "core/inspector/ScriptCallStack.h"
47 #include "core/loader/FrameLoader.h" 48 #include "core/loader/FrameLoader.h"
48 #include "core/page/DOMWindow.h" 49 #include "core/page/DOMWindow.h"
49 #include "core/page/Frame.h" 50 #include "core/page/Frame.h"
50 #include "core/platform/network/ResourceRequest.h" 51 #include "core/platform/network/ResourceRequest.h"
51 #include "core/platform/sql/SQLValue.h" 52 #include "core/platform/sql/SQLValue.h"
52 53
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 return 0; 275 return 0;
275 if (value < 0) { 276 if (value < 0) {
276 exception = Dart_NewStringFromCString("value out of range"); 277 exception = Dart_NewStringFromCString("value out of range");
277 return 0; 278 return 0;
278 } 279 }
279 return value; 280 return value;
280 } 281 }
281 282
282 Dart_Handle DartUtilities::numberToDart(double value) 283 Dart_Handle DartUtilities::numberToDart(double value)
283 { 284 {
284 int intValue = static_cast<int>(value); 285 // JS can store integer values that are no greater than 2^53 - 1.
285 if (value == intValue) 286 if (value <= kJSMaxInteger && value >= -kJSMaxInteger) {
sra1 2013/10/18 02:56:28 nit: This would be slightly more readable: if (-k
286 return intToDart(intValue); 287 int64_t intValue = static_cast<int64_t>(value);
288 if (value == intValue)
289 return intToDart(intValue);
290 }
287 return doubleToDart(value); 291 return doubleToDart(value);
288 } 292 }
289 293
290 ScriptValue DartUtilities::dartToScriptValue(Dart_Handle object, Dart_Handle& ex ception) 294 ScriptValue DartUtilities::dartToScriptValue(Dart_Handle object, Dart_Handle& ex ception)
291 { 295 {
292 return ScriptValue(V8Converter::toV8(object, exception)); 296 return ScriptValue(V8Converter::toV8(object, exception));
293 } 297 }
294 298
295 Dart_Handle DartUtilities::scriptValueToDart(const ScriptValue& value) 299 Dart_Handle DartUtilities::scriptValueToDart(const ScriptValue& value)
296 { 300 {
(...skipping 802 matching lines...) Expand 10 before | Expand all | Expand 10 after
1099 Dart_PersistentHandle library = domData->htmlLibrary(); 1103 Dart_PersistentHandle library = domData->htmlLibrary();
1100 ASSERT(!Dart_IsError(library)); 1104 ASSERT(!Dart_IsError(library));
1101 1105
1102 Dart_Handle utilsClass = Dart_GetType(library, Dart_NewStringFromCString("_U tils"), 0, 0); 1106 Dart_Handle utilsClass = Dart_GetType(library, Dart_NewStringFromCString("_U tils"), 0, 0);
1103 ASSERT(!Dart_IsError(utilsClass)); 1107 ASSERT(!Dart_IsError(utilsClass));
1104 1108
1105 return Dart_Invoke(utilsClass, Dart_NewStringFromCString(methodName), argCou nt, args); 1109 return Dart_Invoke(utilsClass, Dart_NewStringFromCString(methodName), argCou nt, args);
1106 } 1110 }
1107 1111
1108 } 1112 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698