diff options
author | abarth@chromium.org <abarth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-17 17:46:07 +0000 |
---|---|---|
committer | abarth@chromium.org <abarth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-17 17:46:07 +0000 |
commit | 97f21cad04bb80834a8cc84bfc3dd24a96531a16 (patch) | |
tree | 4e49aa68b49f90e4e68c220cc9d9b04be95a6a5d /gin/context_holder.cc | |
parent | 00509a3ac0c1c11e97852d2331d116df6754eb5d (diff) | |
download | chromium_src-97f21cad04bb80834a8cc84bfc3dd24a96531a16.zip chromium_src-97f21cad04bb80834a8cc84bfc3dd24a96531a16.tar.gz chromium_src-97f21cad04bb80834a8cc84bfc3dd24a96531a16.tar.bz2 |
This CL implements the Asynchronous Module Definition (AMD)
API, which we plan to use for JavaScript in Mojo. We don't
yet implement every feature in the AMD spec
<https://github.com/amdjs/amdjs-api/wiki/AMD>, but we
implement the basic framework, which will let us get started
writing and testing JavaScript modules in Mojo.
The two other leading choices for a modules system are
CommonJS and ES6 modules. We decided not to use CommonJS,
despite its popularity, because it implies the ability to
load modules synchronously. That works well in server
environments like node.js, but it won't work well for Mojo
where modules might be loaded across a network.
I would really like to have used ES6 modules, but the spec
isn't finalized yet and V8 doesn't yet implement them. It's
likely that we'll replace this AMD module system with ES6
modules once ES6 modules are ready.
Structurally, I've implemented AMD in the ModuleRegistry
class in a new "modules" directory in Gin. Nothing else in
Gin (except the tests) depends on ModuleRegistry, which
means folks are free to use Gin without AMD. At the Mojo
layer, I've added a dependency on AMD.
BUG=317398
Review URL: https://codereview.chromium.org/62333018
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@235543 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'gin/context_holder.cc')
-rw-r--r-- | gin/context_holder.cc | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/gin/context_holder.cc b/gin/context_holder.cc new file mode 100644 index 0000000..077feb7 --- /dev/null +++ b/gin/context_holder.cc @@ -0,0 +1,34 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "gin/context_holder.h" + +#include <assert.h> +#include "gin/per_context_data.h" + +namespace gin { + +ContextHolder::ContextHolder(v8::Isolate* isolate) + : isolate_(isolate) { +} + +ContextHolder::~ContextHolder() { + v8::HandleScope handle_scope(isolate()); + v8::Handle<v8::Context> context = this->context(); + + PerContextData* data = PerContextData::From(context); + data->Detach(context); + delete data; + + // TODO(abarth): Figure out how to set kResetInDestructor to true. + context_.Reset(); +} + +void ContextHolder::SetContext(v8::Handle<v8::Context> context) { + assert(context_.IsEmpty()); + context_.Reset(isolate_, context); + new PerContextData(context); // Deleted in ~ContextHolder. +} + +} // namespace gin |