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

Side by Side Diff: runtime/lib/integers.cc

Issue 1690903003: Remove support for Javascript warnings in the VM. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 10 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
« no previous file with comments | « runtime/lib/identical.cc ('k') | runtime/lib/math_patch.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/bootstrap_natives.h" 5 #include "vm/bootstrap_natives.h"
6 6
7 #include "include/dart_api.h" 7 #include "include/dart_api.h"
8 #include "vm/dart_entry.h" 8 #include "vm/dart_entry.h"
9 #include "vm/dart_api_impl.h" 9 #include "vm/dart_api_impl.h"
10 #include "vm/exceptions.h" 10 #include "vm/exceptions.h"
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 if (result.IsSmi()) { 244 if (result.IsSmi()) {
245 return result.raw(); 245 return result.raw();
246 } 246 }
247 return result.CheckAndCanonicalize(NULL); 247 return result.CheckAndCanonicalize(NULL);
248 } 248 }
249 } 249 }
250 return default_value.raw(); 250 return default_value.raw();
251 } 251 }
252 252
253 253
254 // Passing true for 'silent' prevents throwing JavascriptIntegerOverflow.
255 static RawInteger* ShiftOperationHelper(Token::Kind kind, 254 static RawInteger* ShiftOperationHelper(Token::Kind kind,
256 const Integer& value, 255 const Integer& value,
257 const Smi& amount, 256 const Smi& amount) {
258 const bool silent = false) {
259 if (amount.Value() < 0) { 257 if (amount.Value() < 0) {
260 Exceptions::ThrowArgumentError(amount); 258 Exceptions::ThrowArgumentError(amount);
261 } 259 }
262 if (value.IsSmi()) { 260 if (value.IsSmi()) {
263 const Smi& smi_value = Smi::Cast(value); 261 const Smi& smi_value = Smi::Cast(value);
264 return smi_value.ShiftOp(kind, amount, Heap::kNew, silent); 262 return smi_value.ShiftOp(kind, amount, Heap::kNew);
265 } 263 }
266 if (value.IsMint()) { 264 if (value.IsMint()) {
267 const int64_t mint_value = value.AsInt64Value(); 265 const int64_t mint_value = value.AsInt64Value();
268 const int count = Utils::HighestBit(mint_value); 266 const int count = Utils::HighestBit(mint_value);
269 intptr_t shift_count = amount.Value(); 267 intptr_t shift_count = amount.Value();
270 if (kind == Token::kSHR) { 268 if (kind == Token::kSHR) {
271 shift_count = -shift_count; 269 shift_count = -shift_count;
272 } 270 }
273 if ((count + shift_count) < Mint::kBits) { 271 if ((count + shift_count) < Mint::kBits) {
274 switch (kind) { 272 switch (kind) {
275 case Token::kSHL: 273 case Token::kSHL:
276 return Integer::New(mint_value << shift_count, Heap::kNew, silent); 274 return Integer::New(mint_value << shift_count, Heap::kNew);
277 case Token::kSHR: 275 case Token::kSHR:
278 shift_count = 276 shift_count =
279 (-shift_count > Mint::kBits) ? Mint::kBits : -shift_count; 277 (-shift_count > Mint::kBits) ? Mint::kBits : -shift_count;
280 return Integer::New(mint_value >> shift_count, Heap::kNew, silent); 278 return Integer::New(mint_value >> shift_count, Heap::kNew);
281 default: 279 default:
282 UNIMPLEMENTED(); 280 UNIMPLEMENTED();
283 } 281 }
284 } else { 282 } else {
285 // Overflow in shift, use Bigints 283 // Overflow in shift, use Bigints
286 return Integer::null(); 284 return Integer::null();
287 } 285 }
288 } else { 286 } else {
289 ASSERT(value.IsBigint()); 287 ASSERT(value.IsBigint());
290 } 288 }
291 return Integer::null(); 289 return Integer::null();
292 } 290 }
293 291
294 292
295 DEFINE_NATIVE_ENTRY(Integer_leftShiftWithMask32, 3) { 293 DEFINE_NATIVE_ENTRY(Integer_leftShiftWithMask32, 3) {
296 const Integer& value = Integer::CheckedHandle(arguments->NativeArgAt(0)); 294 const Integer& value = Integer::CheckedHandle(arguments->NativeArgAt(0));
297 GET_NON_NULL_NATIVE_ARGUMENT(Integer, shift_count, arguments->NativeArgAt(1)); 295 GET_NON_NULL_NATIVE_ARGUMENT(Integer, shift_count, arguments->NativeArgAt(1));
298 GET_NON_NULL_NATIVE_ARGUMENT(Integer, mask, arguments->NativeArgAt(2)); 296 GET_NON_NULL_NATIVE_ARGUMENT(Integer, mask, arguments->NativeArgAt(2));
299 ASSERT(CheckInteger(value)); 297 ASSERT(CheckInteger(value));
300 ASSERT(CheckInteger(shift_count)); 298 ASSERT(CheckInteger(shift_count));
301 ASSERT(CheckInteger(mask)); 299 ASSERT(CheckInteger(mask));
302 if (!shift_count.IsSmi()) { 300 if (!shift_count.IsSmi()) {
303 // Shift count is too large.. 301 // Shift count is too large..
304 const Instance& exception = 302 const Instance& exception =
305 Instance::Handle(isolate->object_store()->out_of_memory()); 303 Instance::Handle(isolate->object_store()->out_of_memory());
306 Exceptions::Throw(thread, exception); 304 Exceptions::Throw(thread, exception);
307 } 305 }
308 const Smi& smi_shift_count = Smi::Cast(shift_count); 306 const Smi& smi_shift_count = Smi::Cast(shift_count);
309 const Integer& shift_result = Integer::Handle( 307 const Integer& shift_result = Integer::Handle(
310 ShiftOperationHelper(Token::kSHL, value, smi_shift_count, true)); 308 ShiftOperationHelper(Token::kSHL, value, smi_shift_count));
311 const Integer& result = 309 const Integer& result =
312 Integer::Handle(shift_result.BitOp(Token::kBIT_AND, mask)); 310 Integer::Handle(shift_result.BitOp(Token::kBIT_AND, mask));
313 return result.AsValidInteger(); 311 return result.AsValidInteger();
314 } 312 }
315 313
316 314
317 DEFINE_NATIVE_ENTRY(Smi_shrFromInt, 2) { 315 DEFINE_NATIVE_ENTRY(Smi_shrFromInt, 2) {
318 const Smi& amount = Smi::CheckedHandle(arguments->NativeArgAt(0)); 316 const Smi& amount = Smi::CheckedHandle(arguments->NativeArgAt(0));
319 GET_NON_NULL_NATIVE_ARGUMENT(Integer, value, arguments->NativeArgAt(1)); 317 GET_NON_NULL_NATIVE_ARGUMENT(Integer, value, arguments->NativeArgAt(1));
320 ASSERT(CheckInteger(amount)); 318 ASSERT(CheckInteger(amount));
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 DEFINE_NATIVE_ENTRY(Bigint_allocate, 4) { 424 DEFINE_NATIVE_ENTRY(Bigint_allocate, 4) {
427 // First arg is null type arguments, since class Bigint is not parameterized. 425 // First arg is null type arguments, since class Bigint is not parameterized.
428 const Bool& neg = Bool::CheckedHandle(arguments->NativeArgAt(1)); 426 const Bool& neg = Bool::CheckedHandle(arguments->NativeArgAt(1));
429 const Smi& used = Smi::CheckedHandle(arguments->NativeArgAt(2)); 427 const Smi& used = Smi::CheckedHandle(arguments->NativeArgAt(2));
430 const TypedData& digits = TypedData::CheckedHandle(arguments->NativeArgAt(3)); 428 const TypedData& digits = TypedData::CheckedHandle(arguments->NativeArgAt(3));
431 ASSERT(!digits.IsNull()); 429 ASSERT(!digits.IsNull());
432 return Bigint::New(neg.value(), used.Value(), digits); 430 return Bigint::New(neg.value(), used.Value(), digits);
433 } 431 }
434 432
435 } // namespace dart 433 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/lib/identical.cc ('k') | runtime/lib/math_patch.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698