OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
| 3 * |
| 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are |
| 6 * met: |
| 7 * |
| 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above |
| 11 * copyright notice, this list of conditions and the following disclaimer |
| 12 * in the documentation and/or other materials provided with the |
| 13 * distribution. |
| 14 * * Neither the name of Google Inc. nor the names of its |
| 15 * contributors may be used to endorse or promote products derived from |
| 16 * this software without specific prior written permission. |
| 17 * |
| 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ |
| 30 |
| 31 #include "config.h" |
| 32 #include "bindings/core/dart/DartDOMData.h" |
| 33 |
| 34 #include "bindings/core/dart/DartApplicationLoader.h" |
| 35 #include "bindings/core/dart/ThreadSafeDartIsolateWrapper.h" |
| 36 #include "core/dom/ExecutionContext.h" |
| 37 |
| 38 namespace blink { |
| 39 |
| 40 DartDOMData::DartDOMData(ExecutionContext* context, const char* scriptURL, const
char* packageRoot, bool isDOMEnabled) |
| 41 : m_scriptURL(strdup(scriptURL)) |
| 42 , m_packageRoot(packageRoot? strdup(packageRoot) : packageRoot) |
| 43 , m_scriptExecutionContext(context) |
| 44 , m_isDOMEnabled(isDOMEnabled) |
| 45 , m_recursion(0) |
| 46 , m_stringCache() |
| 47 , m_threadSafeIsolateWrapper() |
| 48 , m_isolateWrapperMutex() |
| 49 , m_applicationLoader() |
| 50 , m_applicationSnapshot() |
| 51 , m_reachableWeakHandle(0) |
| 52 , m_objectMap() |
| 53 , m_messagePortMap() |
| 54 , m_isolateDestructionObservers() |
| 55 , m_classHandleCache() |
| 56 , m_libraryHandleCache() |
| 57 , m_functionType(0) |
| 58 , m_currentException(0) |
| 59 , m_rootScriptState(0) |
| 60 , m_weakReferenceSetForRootMap(0) |
| 61 , m_documentWeakReferenceSet(0) |
| 62 , m_weakReferenceSetBuilder(0) |
| 63 { |
| 64 } |
| 65 |
| 66 DartDOMData::~DartDOMData() |
| 67 { |
| 68 ASSERT(m_objectMap.isEmpty()); |
| 69 ASSERT(m_messagePortMap.isEmpty()); |
| 70 |
| 71 free(m_scriptURL); |
| 72 setApplicationLoader(nullptr); |
| 73 } |
| 74 |
| 75 DartDOMData* DartDOMData::current() |
| 76 { |
| 77 ASSERT(Dart_CurrentIsolate()); |
| 78 return static_cast<DartDOMData*>(Dart_CurrentIsolateData()); |
| 79 } |
| 80 |
| 81 void DartDOMData::setApplicationLoader(PassRefPtr<DartApplicationLoader> applica
tionLoader) |
| 82 { |
| 83 ASSERT(!m_applicationLoader || !applicationLoader); |
| 84 m_applicationLoader = applicationLoader; |
| 85 } |
| 86 |
| 87 PassRefPtr<DartApplicationLoader> DartDOMData::applicationLoader() |
| 88 { |
| 89 ASSERT(m_applicationLoader); |
| 90 return m_applicationLoader; |
| 91 } |
| 92 |
| 93 void DartDOMData::setThreadSafeIsolateWrapper(PassRefPtr<ThreadSafeDartIsolateWr
apper> threadSafeIsolateWrapper) |
| 94 { |
| 95 ASSERT(!m_threadSafeIsolateWrapper); |
| 96 MutexLocker locker(m_isolateWrapperMutex); |
| 97 m_threadSafeIsolateWrapper = threadSafeIsolateWrapper; |
| 98 } |
| 99 |
| 100 PassRefPtr<ThreadSafeDartIsolateWrapper> DartDOMData::threadSafeIsolateWrapper() |
| 101 { |
| 102 ASSERT(m_threadSafeIsolateWrapper); |
| 103 MutexLocker locker(m_isolateWrapperMutex); |
| 104 return m_threadSafeIsolateWrapper; |
| 105 } |
| 106 |
| 107 Dart_PersistentHandle DartDOMData::getLibrary(int libraryId, const char* name) |
| 108 { |
| 109 Dart_Handle lib = Dart_LookupLibrary(Dart_NewStringFromCString(name)); |
| 110 ASSERT(!Dart_IsError(lib)); |
| 111 Dart_PersistentHandle persistentLib = Dart_NewPersistentHandle(lib); |
| 112 m_libraryHandleCache[libraryId] = persistentLib; |
| 113 return persistentLib; |
| 114 } |
| 115 |
| 116 } |
OLD | NEW |