Files
sdk/runtime/lib/math.cc
T
Alexander Markov b48008ebd0 [vm] Remove unused dart:math and Double native methods
Flow graph builder implementation of certain dart:math and Double
methods is now used unconditionally, so corresponding native
methods are never used and can be removed.

This is a follow-up to
https://dart-review.googlesource.com/c/sdk/+/371980.

TEST=ci

Change-Id: Ibca2729f70f39af26a899d99724ce62efc3c8dae
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/372180
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2024-06-18 21:51:16 +00:00

44 lines
1.4 KiB
C++

// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
#include <ctype.h> // isspace.
#include "vm/bootstrap_natives.h"
#include "vm/exceptions.h"
#include "vm/native_entry.h"
#include "vm/object.h"
#include "vm/symbols.h"
namespace dart {
DEFINE_NATIVE_ENTRY(Random_initialSeed, 0, 0) {
Random* rnd = isolate->random();
uint64_t seed = rnd->NextUInt32();
seed |= (static_cast<uint64_t>(rnd->NextUInt32()) << 32);
return Integer::New(seed);
}
DEFINE_NATIVE_ENTRY(SecureRandom_getBytes, 0, 1) {
GET_NON_NULL_NATIVE_ARGUMENT(Smi, count, arguments->NativeArgAt(0));
const intptr_t n = count.Value();
ASSERT((n > 0) && (n <= 8));
uint8_t buffer[8];
Dart_EntropySource entropy_source = Dart::entropy_source_callback();
if ((entropy_source == nullptr) || !entropy_source(buffer, n)) {
const String& error = String::Handle(String::New(
"No source of cryptographically secure random numbers available."));
const Array& args = Array::Handle(Array::New(1));
args.SetAt(0, error);
Exceptions::ThrowByType(Exceptions::kUnsupported, args);
}
uint64_t result = 0;
for (intptr_t i = 0; i < n; i++) {
result = (result << 8) | buffer[i];
}
return Integer::New(result);
}
} // namespace dart