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

Unified Diff: Source/bindings/core/v8/ToV8.cpp

Issue 1083003004: bindings: Moves toV8 and v8SetReturnValue out to ToV8.h and V8Binding.h. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 8 months 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 side-by-side diff with in-line comments
Download patch
Index: Source/bindings/core/v8/ToV8.cpp
diff --git a/Source/bindings/core/v8/ToV8.cpp b/Source/bindings/core/v8/ToV8.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..5f764c5df9f9cdbc42492d0f25639db258daf75b
--- /dev/null
+++ b/Source/bindings/core/v8/ToV8.cpp
@@ -0,0 +1,61 @@
+// Copyright 2015 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 "config.h"
+#include "bindings/core/v8/ToV8.h"
+
+#include "core/events/EventTarget.h"
+#include "core/frame/DOMWindow.h"
+#include "core/workers/WorkerGlobalScope.h"
+
+namespace blink {
+
+v8::Handle<v8::Value> toV8(DOMWindow* window, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
+{
+ // Notice that we explicitly ignore creationContext because the DOMWindow is its own creationContext.
haraken 2015/04/24 11:57:38 is => has
Yuki 2015/04/27 12:42:33 Done.
+
+ if (!window)
+ return v8::Null(isolate);
+ // Initializes environment of a frame, and return the global object
+ // of the frame.
+ Frame * frame = window->frame();
+ if (!frame)
+ return v8Undefined();
+
+ v8::Local<v8::Context> context = toV8Context(frame, DOMWrapperWorld::current(isolate));
+ if (context.IsEmpty())
+ return v8Undefined();
+
+ v8::Local<v8::Object> global = context->Global();
+ ASSERT(!global.IsEmpty());
+ return global;
+}
+
+v8::Handle<v8::Value> toV8(EventTarget* impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
+{
+ if (UNLIKELY(!impl))
haraken 2015/04/24 11:57:38 Remove UNLIKELY for consistency.
Yuki 2015/04/27 12:42:33 Well, other versions such as ScriptWrappable* and
haraken 2015/04/28 00:56:42 Sounds reasonable, then let's add UNLIKELY.
+ return v8::Null(isolate);
+
+ if (impl->interfaceName() == EventTargetNames::DOMWindow)
+ return toV8(static_cast<DOMWindow*>(impl), creationContext, isolate);
+ return toV8(static_cast<ScriptWrappable*>(impl), creationContext, isolate);
+}
+
+v8::Handle<v8::Value> toV8(WorkerGlobalScope* impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
+{
+ // Notice that we explicitly ignore creationContext because the WorkerGlobalScope is its own creationContext.
haraken 2015/04/24 11:57:38 is => has
Yuki 2015/04/27 12:42:33 Done.
+
+ if (!impl)
+ return v8::Null(isolate);
+
+ WorkerScriptController* script = impl->script();
+ if (!script)
+ return v8::Null(isolate);
+
+ v8::Local<v8::Object> global = script->context()->Global();
+ ASSERT(!global.IsEmpty());
+ return global;
+}
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698