summaryrefslogtreecommitdiffstats
path: root/content/public/renderer/v8_value_converter.h
blob: bed8cdbac60ef70c5b4ccdd44e5f08e317c211e6 (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
50
51
52
53
54
55
56
57
58
// Copyright (c) 2012 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.

#ifndef CONTENT_PUBLIC_RENDERER_V8_VALUE_CONVERTER_H_
#define CONTENT_PUBLIC_RENDERER_V8_VALUE_CONVERTER_H_

#include "content/common/content_export.h"
#include "v8/include/v8.h"

namespace base {
class Value;
}

namespace content {

// Converts between v8::Value (JavaScript values in the v8 heap) and Chrome's
// values (from base/values.h). Lists and dictionaries are converted
// recursively.
//
// The JSON types (null, boolean, string, number, array, and object) as well as
// binary values are supported. For binary values, we convert to WebKit
// ArrayBuffers, and support converting from an ArrayBuffer or any of the
// ArrayBufferView subclasses (Uint8Array, etc.).
class CONTENT_EXPORT V8ValueConverter {
 public:
  static V8ValueConverter* create();

  virtual ~V8ValueConverter() {}

  // Use the following setters to support additional types other than the
  // default ones.
  virtual bool GetUndefinedAllowed() const = 0;
  virtual void SetUndefinedAllowed(bool val) = 0;

  virtual bool GetDateAllowed() const = 0;
  virtual void SetDateAllowed(bool val) = 0;

  virtual bool GetRegexpAllowed() const = 0;
  virtual void SetRegexpAllowed(bool val) = 0;

  // Converts Value to v8::Value. Unsupported types are replaced with null.
  // If an array or object throws while setting a value, that property or item
  // is skipped, leaving a hole in the case of arrays.
  virtual v8::Handle<v8::Value> ToV8Value(
      const base::Value* value,
      v8::Handle<v8::Context> context) const = 0;

  // Converts v8::Value to Value. Unsupported types are replaced with null.
  // If an array or object throws while getting a value, that property or item
  // is replaced with null.
  virtual base::Value* FromV8Value(v8::Handle<v8::Value> value,
                                   v8::Handle<v8::Context> context) const = 0;
};

}  // namespace content

#endif  // CONTENT_PUBLIC_RENDERER_V8_VALUE_CONVERTER_H_