Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 1198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1209 DATA_VIEW_GETTER(Int8, int8_t, NumberFromInt32) | 1209 DATA_VIEW_GETTER(Int8, int8_t, NumberFromInt32) |
| 1210 DATA_VIEW_GETTER(Uint16, uint16_t, NumberFromUint32) | 1210 DATA_VIEW_GETTER(Uint16, uint16_t, NumberFromUint32) |
| 1211 DATA_VIEW_GETTER(Int16, int16_t, NumberFromInt32) | 1211 DATA_VIEW_GETTER(Int16, int16_t, NumberFromInt32) |
| 1212 DATA_VIEW_GETTER(Uint32, uint32_t, NumberFromUint32) | 1212 DATA_VIEW_GETTER(Uint32, uint32_t, NumberFromUint32) |
| 1213 DATA_VIEW_GETTER(Int32, int32_t, NumberFromInt32) | 1213 DATA_VIEW_GETTER(Int32, int32_t, NumberFromInt32) |
| 1214 DATA_VIEW_GETTER(Float32, float, NumberFromDouble) | 1214 DATA_VIEW_GETTER(Float32, float, NumberFromDouble) |
| 1215 DATA_VIEW_GETTER(Float64, double, NumberFromDouble) | 1215 DATA_VIEW_GETTER(Float64, double, NumberFromDouble) |
| 1216 | 1216 |
| 1217 #undef DATA_VIEW_GETTER | 1217 #undef DATA_VIEW_GETTER |
| 1218 | 1218 |
| 1219 | |
| 1220 template <typename T> | |
| 1221 static T DataViewValueConverter(double value); | |
|
titzer
2013/07/12 16:37:02
Can we name this function verb-ly, such as "Conver
Dmitry Lomov (no reviews)
2013/07/12 18:22:45
Done.
ConvertValueToDataView is not a good name -
| |
| 1222 | |
| 1223 | |
| 1224 template <> | |
| 1225 int8_t DataViewValueConverter<int8_t>(double value) { | |
| 1226 return static_cast<int8_t>(DoubleToInt32(value)); | |
| 1227 } | |
| 1228 | |
| 1229 | |
| 1230 template <> | |
| 1231 int16_t DataViewValueConverter<int16_t>(double value) { | |
| 1232 return static_cast<int16_t>(DoubleToInt32(value)); | |
| 1233 } | |
| 1234 | |
| 1235 | |
| 1236 template <> | |
| 1237 int32_t DataViewValueConverter<int32_t>(double value) { | |
| 1238 return DoubleToInt32(value); | |
| 1239 } | |
| 1240 | |
| 1241 | |
| 1242 template <> | |
| 1243 uint8_t DataViewValueConverter<uint8_t>(double value) { | |
| 1244 return static_cast<uint8_t>(DoubleToUint32(value)); | |
| 1245 } | |
| 1246 | |
| 1247 | |
| 1248 template <> | |
| 1249 uint16_t DataViewValueConverter<uint16_t>(double value) { | |
| 1250 return static_cast<uint16_t>(DoubleToUint32(value)); | |
| 1251 } | |
| 1252 | |
| 1253 | |
| 1254 template <> | |
| 1255 uint32_t DataViewValueConverter<uint32_t>(double value) { | |
| 1256 return DoubleToUint32(value); | |
| 1257 } | |
| 1258 | |
| 1259 | |
| 1260 template <> | |
| 1261 float DataViewValueConverter<float>(double value) { | |
| 1262 return static_cast<float>(value); | |
| 1263 } | |
| 1264 | |
| 1265 | |
| 1266 template <> | |
| 1267 double DataViewValueConverter<double>(double value) { | |
| 1268 return value; | |
| 1269 } | |
| 1270 | |
| 1271 | |
| 1219 #define DATA_VIEW_SETTER(TypeName, Type) \ | 1272 #define DATA_VIEW_SETTER(TypeName, Type) \ |
| 1220 RUNTIME_FUNCTION(MaybeObject*, Runtime_DataViewSet##TypeName) { \ | 1273 RUNTIME_FUNCTION(MaybeObject*, Runtime_DataViewSet##TypeName) { \ |
| 1221 HandleScope scope(isolate); \ | 1274 HandleScope scope(isolate); \ |
| 1222 ASSERT(args.length() == 4); \ | 1275 ASSERT(args.length() == 4); \ |
| 1223 CONVERT_ARG_HANDLE_CHECKED(JSDataView, holder, 0); \ | 1276 CONVERT_ARG_HANDLE_CHECKED(JSDataView, holder, 0); \ |
| 1224 CONVERT_ARG_HANDLE_CHECKED(Object, offset, 1); \ | 1277 CONVERT_ARG_HANDLE_CHECKED(Object, offset, 1); \ |
| 1225 CONVERT_ARG_HANDLE_CHECKED(Object, value, 2); \ | 1278 CONVERT_ARG_HANDLE_CHECKED(Object, value, 2); \ |
| 1226 CONVERT_BOOLEAN_ARG_CHECKED(is_little_endian, 3); \ | 1279 CONVERT_BOOLEAN_ARG_CHECKED(is_little_endian, 3); \ |
| 1227 Type v = static_cast<Type>(value->Number()); \ | 1280 Type v = DataViewValueConverter<Type>(value->Number()); \ |
| 1228 if (DataViewSetValue( \ | 1281 if (DataViewSetValue( \ |
| 1229 isolate, holder, offset, is_little_endian, v)) { \ | 1282 isolate, holder, offset, is_little_endian, v)) { \ |
| 1230 return isolate->heap()->undefined_value(); \ | 1283 return isolate->heap()->undefined_value(); \ |
| 1231 } else { \ | 1284 } else { \ |
| 1232 return isolate->Throw(*isolate->factory()->NewRangeError( \ | 1285 return isolate->Throw(*isolate->factory()->NewRangeError( \ |
| 1233 "invalid_data_view_accessor_offset", \ | 1286 "invalid_data_view_accessor_offset", \ |
| 1234 HandleVector<Object>(NULL, 0))); \ | 1287 HandleVector<Object>(NULL, 0))); \ |
| 1235 } \ | 1288 } \ |
| 1236 } | 1289 } |
| 1237 | 1290 |
| (...skipping 12800 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 14038 // Handle last resort GC and make sure to allow future allocations | 14091 // Handle last resort GC and make sure to allow future allocations |
| 14039 // to grow the heap without causing GCs (if possible). | 14092 // to grow the heap without causing GCs (if possible). |
| 14040 isolate->counters()->gc_last_resort_from_js()->Increment(); | 14093 isolate->counters()->gc_last_resort_from_js()->Increment(); |
| 14041 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, | 14094 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, |
| 14042 "Runtime::PerformGC"); | 14095 "Runtime::PerformGC"); |
| 14043 } | 14096 } |
| 14044 } | 14097 } |
| 14045 | 14098 |
| 14046 | 14099 |
| 14047 } } // namespace v8::internal | 14100 } } // namespace v8::internal |
| OLD | NEW |