Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(99)

Side by Side Diff: webkit/glue/devtools/bound_object.cc

Issue 113836: DevTools: introduce bound object on the agent side. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « webkit/glue/devtools/bound_object.h ('k') | webkit/glue/devtools/js/devtools.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2009 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.
4
5 #include "config.h"
6
7 #include <string>
8
9 #include "v8_proxy.h"
10 #include "webkit/glue/devtools/bound_object.h"
11
12 using namespace WebCore;
13
14 BoundObject::BoundObject(
15 v8::Handle<v8::Context> context,
16 void* v8_this,
17 const char* object_name)
18 : context_(context),
19 object_name_(object_name) {
20 v8::HandleScope scope;
21 v8::Context::Scope context_scope(context);
22 v8_this_ = v8::Persistent<v8::External>::New(v8::External::New(v8_this));
23
24 v8::Local<v8::FunctionTemplate> local_template =
25 v8::FunctionTemplate::New(V8Proxy::CheckNewLegal);
26 host_template_ = v8::Persistent<v8::FunctionTemplate>::New(local_template);
27 host_template_->SetClassName(v8::String::New(object_name));
28 }
29
30 BoundObject::~BoundObject() {
31 bound_object_.Dispose();
32 host_template_.Dispose();
33 v8_this_.Dispose();
34 }
35
36 void BoundObject::AddProtoFunction(
37 const char* name,
38 v8::InvocationCallback callback) {
39 v8::HandleScope scope;
40 v8::Local<v8::Signature> signature = v8::Signature::New(host_template_);
41 v8::Local<v8::ObjectTemplate> proto = host_template_->PrototypeTemplate();
42 proto->Set(
43 v8::String::New(name),
44 v8::FunctionTemplate::New(
45 callback,
46 v8_this_,
47 signature),
48 static_cast<v8::PropertyAttribute>(v8::DontDelete));
49 }
50
51 void BoundObject::Build() {
52 v8::HandleScope scope;
53 v8::Context::Scope frame_scope(context_);
54
55 v8::Local<v8::Function> constructor = host_template_->GetFunction();
56 bound_object_ = v8::Persistent<v8::Object>::New(
57 SafeAllocation::NewInstance(constructor));
58
59 v8::Handle<v8::Object> global = context_->Global();
60 global->Set(v8::String::New(object_name_), bound_object_);
61 }
OLDNEW
« no previous file with comments | « webkit/glue/devtools/bound_object.h ('k') | webkit/glue/devtools/js/devtools.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698