Disable the ASan SEGV handler for NaCl processes on Mac.
[chromium-blink-merge.git] / gin / dictionary.h
blobbc55087d8413fc14d72c53a3fafee667dbd5b1cb
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef GIN_DICTIONARY_H_
6 #define GIN_DICTIONARY_H_
8 #include "gin/converter.h"
10 namespace gin {
12 // Dictionary is useful when writing bindings for a function that either
13 // receives an arbitrary JavaScript object as an argument or returns an
14 // arbitrary JavaScript object as a result. For example, Dictionary is useful
15 // when you might use the |dictionary| type in WebIDL:
17 // http://heycam.github.io/webidl/#idl-dictionaries
19 // WARNING: You cannot retain a Dictionary object in the heap. The underlying
20 // storage for Dictionary is tied to the closest enclosing
21 // v8::HandleScope. Generally speaking, you should store a Dictionary
22 // on the stack.
24 class Dictionary {
25 public:
26 explicit Dictionary(v8::Isolate* isolate);
27 Dictionary(v8::Isolate* isolate, v8::Handle<v8::Object> object);
28 ~Dictionary();
30 static Dictionary CreateEmpty(v8::Isolate* isolate);
32 template<typename T>
33 bool Get(const std::string& key, T* out) {
34 v8::Handle<v8::Value> val = object_->Get(StringToV8(isolate_, key));
35 return ConvertFromV8(isolate_, val, out);
38 template<typename T>
39 bool Set(const std::string& key, T val) {
40 return object_->Set(StringToV8(isolate_, key), ConvertToV8(isolate_, val));
43 v8::Isolate* isolate() const { return isolate_; }
45 private:
46 friend struct Converter<Dictionary>;
48 // TODO(aa): Remove this. Instead, get via FromV8(), Set(), and Get().
49 v8::Isolate* isolate_;
50 v8::Handle<v8::Object> object_;
53 template<>
54 struct Converter<Dictionary> {
55 static v8::Handle<v8::Value> ToV8(v8::Isolate* isolate,
56 Dictionary val);
57 static bool FromV8(v8::Isolate* isolate,
58 v8::Handle<v8::Value> val,
59 Dictionary* out);
62 } // namespace gin
64 #endif // GIN_DICTIONARY_H_