summaryrefslogtreecommitdiffstats
path: root/mojo/apps/js/v8_environment.cc
blob: 1b4ee834a247e7dc7a9611873a57aad553503f3e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "mojo/apps/js/v8_environment.h"

#include <stdlib.h>
#include <string.h>

#include "mojo/public/system/macros.h"
#include "v8/include/v8.h"

namespace mojo {
namespace apps {

namespace {

class ArrayBufferAllocator : public v8::ArrayBuffer::Allocator {
  virtual void* Allocate(size_t length) MOJO_OVERRIDE {
    return calloc(1, length);
  }
  virtual void* AllocateUninitialized(size_t length) MOJO_OVERRIDE {
    return malloc(length);
  }
  virtual void Free(void* data, size_t length) MOJO_OVERRIDE {
    free(data);
  }
};

bool GenerateEntropy(unsigned char* buffer, size_t amount) {
  // TODO(abarth): Mojo needs a source of entropy.
  // https://code.google.com/p/chromium/issues/detail?id=316387
  return false;
}

const char kFlags[] = "--use_strict --harmony";

}

void InitializeV8() {
  v8::V8::SetArrayBufferAllocator(new ArrayBufferAllocator());
  v8::V8::InitializeICU();
  v8::V8::SetFlagsFromString(kFlags, strlen(kFlags));
  v8::V8::SetEntropySource(&GenerateEntropy);
  v8::V8::Initialize();
}

}  // namespace apps
}  // mojo