Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
math.cc
Go to the documentation of this file.
1// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
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.
4
5#include <ctype.h> // isspace.
6
8
9#include "vm/exceptions.h"
10#include "vm/native_entry.h"
11#include "vm/object.h"
12#include "vm/symbols.h"
13
14namespace dart {
15
16DEFINE_NATIVE_ENTRY(Math_doublePow, 0, 2) {
17 const double operand =
18 Double::CheckedHandle(zone, arguments->NativeArgAt(0)).value();
19 GET_NON_NULL_NATIVE_ARGUMENT(Double, exponent_object,
20 arguments->NativeArgAt(1));
21 const double exponent = exponent_object.value();
22 return Double::New(pow(operand, exponent));
23}
24
25DEFINE_NATIVE_ENTRY(Random_initialSeed, 0, 0) {
26 Random* rnd = isolate->random();
27 uint64_t seed = rnd->NextUInt32();
28 seed |= (static_cast<uint64_t>(rnd->NextUInt32()) << 32);
29 return Integer::New(seed);
30}
31
32DEFINE_NATIVE_ENTRY(SecureRandom_getBytes, 0, 1) {
33 GET_NON_NULL_NATIVE_ARGUMENT(Smi, count, arguments->NativeArgAt(0));
34 const intptr_t n = count.Value();
35 ASSERT((n > 0) && (n <= 8));
36 uint8_t buffer[8];
38 if ((entropy_source == nullptr) || !entropy_source(buffer, n)) {
40 "No source of cryptographically secure random numbers available."));
42 args.SetAt(0, error);
44 }
45 uint64_t result = 0;
46 for (intptr_t i = 0; i < n; i++) {
47 result = (result << 8) | buffer[i];
48 }
49 return Integer::New(result);
50}
51
52} // namespace dart
int count
static ArrayPtr New(intptr_t len, Heap::Space space=Heap::kNew)
Definition object.h:10933
static Dart_EntropySource entropy_source_callback()
Definition dart.h:135
static DoublePtr New(double d, Heap::Space space=Heap::kNew)
Definition object.cc:23481
static DART_NORETURN void ThrowByType(ExceptionType type, const Array &arguments)
static IntegerPtr New(const String &str, Heap::Space space=Heap::kNew)
Definition object.cc:23063
static Object & Handle()
Definition object.h:407
uint32_t NextUInt32()
Definition random.cc:73
static StringPtr New(const char *cstr, Heap::Space space=Heap::kNew)
Definition object.cc:23777
bool(* Dart_EntropySource)(uint8_t *buffer, intptr_t length)
Definition dart_api.h:821
#define ASSERT(E)
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
static const uint8_t buffer[]
const uint8_t uint32_t uint32_t GError ** error
GAsyncResult * result
#define DEFINE_NATIVE_ENTRY(name, type_argument_count, argument_count)
#define GET_NON_NULL_NATIVE_ARGUMENT(type, name, value)