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

Side by Side Diff: mojo/apps/js/bindings/waiting_callback.cc

Issue 113893005: [gin] Introduce Wrappable::GetObjectTemplate (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: updates Created 7 years 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "mojo/apps/js/bindings/waiting_callback.h" 5 #include "mojo/apps/js/bindings/waiting_callback.h"
6 6
7 #include "gin/object_template_builder.h"
7 #include "gin/per_context_data.h" 8 #include "gin/per_context_data.h"
8 #include "gin/per_isolate_data.h"
9 9
10 namespace mojo { 10 namespace mojo {
11 namespace js { 11 namespace js {
12 12
13 namespace { 13 namespace {
14 14
15 v8::Handle<v8::String> GetHiddenPropertyName(v8::Isolate* isolate) { 15 v8::Handle<v8::String> GetHiddenPropertyName(v8::Isolate* isolate) {
16 return gin::StringToSymbol(isolate, "::mojo::js::WaitingCallback"); 16 return gin::StringToSymbol(isolate, "::mojo::js::WaitingCallback");
17 } 17 }
18 18
(...skipping 11 matching lines...) Expand all
30 30
31 WaitingCallback::~WaitingCallback() { 31 WaitingCallback::~WaitingCallback() {
32 DCHECK(!wait_id_) << "Waiting callback was destroyed before being cancelled."; 32 DCHECK(!wait_id_) << "Waiting callback was destroyed before being cancelled.";
33 } 33 }
34 34
35 gin::Handle<WaitingCallback> WaitingCallback::Create( 35 gin::Handle<WaitingCallback> WaitingCallback::Create(
36 v8::Isolate* isolate, v8::Handle<v8::Function> callback) { 36 v8::Isolate* isolate, v8::Handle<v8::Function> callback) {
37 return gin::CreateHandle(isolate, new WaitingCallback(isolate, callback)); 37 return gin::CreateHandle(isolate, new WaitingCallback(isolate, callback));
38 } 38 }
39 39
40 void WaitingCallback::EnsureRegistered(v8::Isolate* isolate) { 40 v8::Local<v8::ObjectTemplate> WaitingCallback::GetObjectTemplate(
41 gin::PerIsolateData* data = gin::PerIsolateData::From(isolate); 41 v8::Isolate* isolate) {
42 if (!data->GetObjectTemplate(&WaitingCallback::kWrapperInfo).IsEmpty()) { 42 return gin::ObjectTemplateBuilder(isolate).Build();
43 return;
44 }
45 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(isolate);
46 templ->SetInternalFieldCount(gin::kNumberOfInternalFields);
47 data->SetObjectTemplate(&WaitingCallback::kWrapperInfo, templ);
48 } 43 }
49 44
50 void WaitingCallback::OnHandleReady(MojoResult result) { 45 void WaitingCallback::OnHandleReady(MojoResult result) {
51 wait_id_ = NULL; 46 wait_id_ = NULL;
52 47
53 if (!runner_) 48 if (!runner_)
54 return; 49 return;
55 50
56 gin::Runner::Scope scope(runner_.get()); 51 gin::Runner::Scope scope(runner_.get());
57 v8::Isolate* isolate = runner_->isolate(); 52 v8::Isolate* isolate = runner_->isolate();
58 53
59 v8::Handle<v8::Value> hidden_value = 54 v8::Handle<v8::Value> hidden_value =
60 GetWrapper(isolate)->GetHiddenValue(GetHiddenPropertyName(isolate)); 55 GetWrapper(isolate)->GetHiddenValue(GetHiddenPropertyName(isolate));
61 v8::Handle<v8::Function> callback; 56 v8::Handle<v8::Function> callback;
62 CHECK(gin::ConvertFromV8(isolate, hidden_value, &callback)); 57 CHECK(gin::ConvertFromV8(isolate, hidden_value, &callback));
63 58
64 v8::Handle<v8::Value> args[] = { gin::ConvertToV8(isolate, result) }; 59 v8::Handle<v8::Value> args[] = { gin::ConvertToV8(isolate, result) };
65 runner_->Call(callback, runner_->global(), 1, args); 60 runner_->Call(callback, runner_->global(), 1, args);
66 } 61 }
67 62
68 } // namespace js 63 } // namespace js
69 } // namespace mojo 64 } // namespace mojo
OLDNEW
« mojo/apps/js/bindings/gl/context.cc ('K') | « mojo/apps/js/bindings/waiting_callback.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698