OLD | NEW |
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 #ifndef GIN_MODULES_MODULE_REGISTRY_H_ | 5 #ifndef GIN_MODULES_MODULE_REGISTRY_H_ |
6 #define GIN_MODULES_MODULE_REGISTRY_H_ | 6 #define GIN_MODULES_MODULE_REGISTRY_H_ |
7 | 7 |
8 #include <list> | 8 #include <list> |
9 #include <string> | 9 #include <string> |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
11 #include "gin/per_context_data.h" | 11 #include "gin/per_context_data.h" |
12 | 12 |
13 namespace gin { | 13 namespace gin { |
14 | 14 |
15 struct PendingModule; | 15 struct PendingModule; |
16 | 16 |
17 // This class implements the Asynchronous Module Definition (AMD) API. | 17 // This class implements the Asynchronous Module Definition (AMD) API. |
18 // https://github.com/amdjs/amdjs-api/wiki/AMD | 18 // https://github.com/amdjs/amdjs-api/wiki/AMD |
19 // | 19 // |
20 // Our implementation isn't complete yet. Missing features: | 20 // Our implementation isn't complete yet. Missing features: |
21 // 1) Built-in support for require, exports, and module. | 21 // 1) Built-in support for require, exports, and module. |
22 // 2) Path resoltuion in module names. | 22 // 2) Path resoltuion in module names. |
23 // | 23 // |
24 // For these reasons, we don't have an "amd" property on the "define" | 24 // For these reasons, we don't have an "amd" property on the "define" |
25 // function. The spec says we should only add that property once our | 25 // function. The spec says we should only add that property once our |
26 // implementation complies with the specification. | 26 // implementation complies with the specification. |
27 // | 27 // |
28 class ModuleRegistry : public ContextSupplement { | 28 class ModuleRegistry : public ContextSupplement { |
29 public: | 29 public: |
| 30 virtual ~ModuleRegistry(); |
| 31 |
30 static ModuleRegistry* From(v8::Handle<v8::Context> context); | 32 static ModuleRegistry* From(v8::Handle<v8::Context> context); |
31 | 33 |
32 static void RegisterGlobals(v8::Isolate* isolate, | 34 static void RegisterGlobals(v8::Isolate* isolate, |
33 v8::Handle<v8::ObjectTemplate> templ); | 35 v8::Handle<v8::ObjectTemplate> templ); |
34 | 36 |
35 // The caller must have already entered our context. | 37 // The caller must have already entered our context. |
36 void AddBuiltinModule(v8::Isolate* isolate, | 38 void AddBuiltinModule(v8::Isolate* isolate, |
37 const std::string& id, | 39 const std::string& id, |
38 v8::Handle<v8::ObjectTemplate> templ); | 40 v8::Handle<v8::ObjectTemplate> templ); |
39 | 41 |
40 // Takes ownership of |pending|. The caller must have already entered | 42 // Takes ownership of |pending|. The caller must have already entered |
41 // our context. | 43 // our context. |
42 void AddPendingModule(v8::Isolate* isolate, PendingModule* pending); | 44 void AddPendingModule(v8::Isolate* isolate, PendingModule* pending); |
43 | 45 |
44 private: | 46 private: |
45 typedef std::list<PendingModule*> PendingModuleList; // Owning reference. | 47 typedef std::list<PendingModule*> PendingModuleList; // Owning reference. |
46 | 48 |
47 explicit ModuleRegistry(v8::Isolate* isolate); | 49 explicit ModuleRegistry(v8::Isolate* isolate); |
48 virtual ~ModuleRegistry(); | |
49 | 50 |
50 // From ContextSupplement: | 51 // From ContextSupplement: |
51 virtual void Detach(v8::Handle<v8::Context> context) OVERRIDE; | 52 virtual void Detach(v8::Handle<v8::Context> context) OVERRIDE; |
52 | 53 |
53 // Takes ownership of |pending|. | 54 // Takes ownership of |pending|. |
54 bool AttemptToLoad(v8::Isolate* isolate, PendingModule* pending); | 55 bool AttemptToLoad(v8::Isolate* isolate, PendingModule* pending); |
55 void AttemptToLoadPendingModules(v8::Isolate* isolate); | 56 void AttemptToLoadPendingModules(v8::Isolate* isolate); |
56 | 57 |
57 v8::Persistent<v8::Object> modules_; | 58 v8::Persistent<v8::Object> modules_; |
58 PendingModuleList pending_modules_; | 59 PendingModuleList pending_modules_; |
59 | 60 |
60 DISALLOW_COPY_AND_ASSIGN(ModuleRegistry); | 61 DISALLOW_COPY_AND_ASSIGN(ModuleRegistry); |
61 }; | 62 }; |
62 | 63 |
63 } // namespace gin | 64 } // namespace gin |
64 | 65 |
65 #endif // GIN_MODULES_MODULE_REGISTRY_H_ | 66 #endif // GIN_MODULES_MODULE_REGISTRY_H_ |
OLD | NEW |