Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions src/bun.js/bindings/ProcessIdentifier.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright (C) 2017 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/

#include "config.h"
#include "ProcessIdentifier.h"

#include <wtf/MainThread.h>

namespace WebCore {
namespace ProcessIdent {

static std::optional<ProcessIdentifier> globalIdentifier;

void setIdentifier(ProcessIdentifier processIdentifier)
{
ASSERT(isUIThread());
globalIdentifier = processIdentifier;
}

ProcessIdentifier identifier()
{
static std::once_flag onceFlag;
std::call_once(onceFlag, [] {
if (!globalIdentifier)
globalIdentifier = ProcessIdentifier::generate();
});

return *globalIdentifier;
}

} // namespace ProcessIdent
} // namespace WebCore
41 changes: 41 additions & 0 deletions src/bun.js/bindings/ProcessIdentifier.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright (C) 2017 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/

#pragma once

#include <wtf/ObjectIdentifier.h>

namespace WebCore {

enum ProcessIdentifierType {};
using ProcessIdentifier = ObjectIdentifier<ProcessIdentifierType>;

namespace ProcessIdent {

WEBCORE_EXPORT void setIdentifier(ProcessIdentifier);
WEBCORE_EXPORT ProcessIdentifier identifier();

} // namespace ProcessIdent
} // namespace WebCore
7 changes: 7 additions & 0 deletions src/bun.js/bindings/ScriptExecutionContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,11 @@ void ScriptExecutionContext::removeFromContextsMap()
// allScriptExecutionContextsMap().remove(m_identifier);
}

ScriptExecutionContext* executionContext(JSC::JSGlobalObject* globalObject)
{
if (!globalObject || !globalObject->inherits<JSDOMGlobalObject>())
return nullptr;
return JSC::jsCast<JSDOMGlobalObject*>(globalObject)->scriptExecutionContext();
}

}
15 changes: 15 additions & 0 deletions src/bun.js/bindings/ScriptExecutionContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,18 @@ class ScriptExecutionContext : public CanMakeWeakPtr<ScriptExecutionContext> {
// {
// }

#if ENABLE(WEB_CRYPTO)
// These two methods are used when CryptoKeys are serialized into IndexedDB. As a side effect, it is also
// used for things that utilize the same structure clone algorithm, for example, message passing between
// worker and document.

// For now these will return false. In the future, we will want to implement these similar to how WorkerGlobalScope.cpp does.
// virtual bool wrapCryptoKey(const Vector<uint8_t>& key, Vector<uint8_t>& wrappedKey) = 0;
// virtual bool unwrapCryptoKey(const Vector<uint8_t>& wrappedKey, Vector<uint8_t>& key) = 0;
bool wrapCryptoKey(const Vector<uint8_t>& key, Vector<uint8_t>& wrappedKey) { return false; }
bool unwrapCryptoKey(const Vector<uint8_t>& wrappedKey, Vector<uint8_t>& key) { return false; }
#endif

static bool postTaskTo(ScriptExecutionContextIdentifier identifier, Function<void(ScriptExecutionContext&)>&& task);

void regenerateIdentifier();
Expand Down Expand Up @@ -194,4 +206,7 @@ class ScriptExecutionContext : public CanMakeWeakPtr<ScriptExecutionContext> {
}
}
};

ScriptExecutionContext* executionContext(JSC::JSGlobalObject*);

}
46 changes: 46 additions & 0 deletions src/bun.js/bindings/ZigGeneratedClasses.cpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading