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