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

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
« no previous file with comments | « mojo/apps/js/bindings/waiting_callback.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/per_context_data.h" 7 #include "gin/per_context_data.h"
8 #include "gin/per_isolate_data.h"
9 8
10 namespace mojo { 9 namespace mojo {
11 namespace js { 10 namespace js {
12 11
13 namespace { 12 namespace {
14 13
15 v8::Handle<v8::String> GetHiddenPropertyName(v8::Isolate* isolate) { 14 v8::Handle<v8::String> GetHiddenPropertyName(v8::Isolate* isolate) {
16 return gin::StringToSymbol(isolate, "::mojo::js::WaitingCallback"); 15 return gin::StringToSymbol(isolate, "::mojo::js::WaitingCallback");
17 } 16 }
18 17
(...skipping 11 matching lines...) Expand all
30 29
31 WaitingCallback::~WaitingCallback() { 30 WaitingCallback::~WaitingCallback() {
32 DCHECK(!wait_id_) << "Waiting callback was destroyed before being cancelled."; 31 DCHECK(!wait_id_) << "Waiting callback was destroyed before being cancelled.";
33 } 32 }
34 33
35 gin::Handle<WaitingCallback> WaitingCallback::Create( 34 gin::Handle<WaitingCallback> WaitingCallback::Create(
36 v8::Isolate* isolate, v8::Handle<v8::Function> callback) { 35 v8::Isolate* isolate, v8::Handle<v8::Function> callback) {
37 return gin::CreateHandle(isolate, new WaitingCallback(isolate, callback)); 36 return gin::CreateHandle(isolate, new WaitingCallback(isolate, callback));
38 } 37 }
39 38
40 void WaitingCallback::EnsureRegistered(v8::Isolate* isolate) {
41 gin::PerIsolateData* data = gin::PerIsolateData::From(isolate);
42 if (!data->GetObjectTemplate(&WaitingCallback::kWrapperInfo).IsEmpty()) {
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 }
49
50 void WaitingCallback::OnHandleReady(MojoResult result) { 39 void WaitingCallback::OnHandleReady(MojoResult result) {
51 wait_id_ = NULL; 40 wait_id_ = NULL;
52 41
53 if (!runner_) 42 if (!runner_)
54 return; 43 return;
55 44
56 gin::Runner::Scope scope(runner_.get()); 45 gin::Runner::Scope scope(runner_.get());
57 v8::Isolate* isolate = runner_->isolate(); 46 v8::Isolate* isolate = runner_->isolate();
58 47
59 v8::Handle<v8::Value> hidden_value = 48 v8::Handle<v8::Value> hidden_value =
60 GetWrapper(isolate)->GetHiddenValue(GetHiddenPropertyName(isolate)); 49 GetWrapper(isolate)->GetHiddenValue(GetHiddenPropertyName(isolate));
61 v8::Handle<v8::Function> callback; 50 v8::Handle<v8::Function> callback;
62 CHECK(gin::ConvertFromV8(isolate, hidden_value, &callback)); 51 CHECK(gin::ConvertFromV8(isolate, hidden_value, &callback));
63 52
64 v8::Handle<v8::Value> args[] = { gin::ConvertToV8(isolate, result) }; 53 v8::Handle<v8::Value> args[] = { gin::ConvertToV8(isolate, result) };
65 runner_->Call(callback, runner_->global(), 1, args); 54 runner_->Call(callback, runner_->global(), 1, args);
66 } 55 }
67 56
68 } // namespace js 57 } // namespace js
69 } // namespace mojo 58 } // namespace mojo
OLDNEW
« no previous file with comments | « 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