Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | |
|
Aaron Boodman
2013/11/09 21:40:35
I don't see what runner is used by in this cl?
abarth-chromium
2013/11/10 02:12:20
Currently it's just used in runner_unittest.cc. I
| |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef GIN_RUNNER_H_ | |
| 6 #define GIN_RUNNER_H_ | |
| 7 | |
| 8 #include "base/basictypes.h" | |
| 9 #include "v8/include/v8.h" | |
| 10 | |
| 11 namespace gin { | |
| 12 | |
| 13 class Runner; | |
| 14 | |
| 15 class RunnerDelegate { | |
| 16 public: | |
| 17 // Returns the object that is passed to the script's |main| function. | |
| 18 virtual v8::Handle<v8::Object> CreateRootObject(Runner* runner) = 0; | |
| 19 | |
| 20 protected: | |
| 21 virtual ~RunnerDelegate(); | |
| 22 }; | |
| 23 | |
| 24 class Runner { | |
| 25 public: | |
| 26 Runner(RunnerDelegate* delegate, v8::Isolate* isolate); | |
| 27 ~Runner(); | |
| 28 | |
| 29 void Run(v8::Handle<v8::Script> script); | |
| 30 | |
| 31 v8::Isolate* isolate() const { return isolate_; } | |
| 32 | |
| 33 v8::Handle<v8::Context> context() const { | |
| 34 return v8::Local<v8::Context>::New(isolate_, context_); | |
| 35 } | |
| 36 | |
| 37 v8::Handle<v8::Object> global() const { | |
| 38 return context()->Global(); | |
| 39 } | |
| 40 | |
| 41 class Scope { | |
| 42 public: | |
| 43 explicit Scope(Runner* runner); | |
| 44 ~Scope(); | |
| 45 | |
| 46 private: | |
| 47 v8::HandleScope handle_scope_; | |
| 48 v8::Context::Scope scope_; | |
| 49 | |
| 50 DISALLOW_COPY_AND_ASSIGN(Scope); | |
| 51 }; | |
| 52 | |
| 53 private: | |
| 54 friend class Scope; | |
| 55 | |
| 56 v8::Handle<v8::Function> GetMain(); | |
| 57 | |
| 58 RunnerDelegate* delegate_; | |
| 59 v8::Isolate* isolate_; | |
| 60 v8::Persistent<v8::Context> context_; | |
| 61 | |
| 62 DISALLOW_COPY_AND_ASSIGN(Runner); | |
| 63 }; | |
| 64 | |
| 65 } // namespace gin | |
| 66 | |
| 67 #endif // GIN_RUNNER_H_ | |
| OLD | NEW |