-
Notifications
You must be signed in to change notification settings - Fork 206
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cleanup
js::core::Context
, move functionality to `ExtensionInterfac…
…e`s (#6163)
- Loading branch information
1 parent
8cc1c42
commit b10483a
Showing
49 changed files
with
2,664 additions
and
3,080 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,4 @@ | |
( V ) / . \ | +---=---' | ||
/--x-m- /--n-n---xXx--/--yY------>>>----<<<>>]]{{}}---||-/\---.. | ||
2024__ | ||
! | ||
!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the Apache 2.0 License. | ||
#pragma once | ||
|
||
#include "js/core/context.h" | ||
#include "js/extensions/ccf/converters.h" | ||
#include "js/extensions/ccf/crypto.h" | ||
#include "js/extensions/ccf/kv.h" | ||
#include "js/extensions/console.h" | ||
#include "js/extensions/math/random.h" | ||
|
||
namespace ccf::js | ||
{ | ||
// This is intended to extend a js::core::Context with various CCF-specific | ||
// extensions, expected to be accessible in every execution context (eg - | ||
// ccf.bufToStr converters, ccf.crypto helpers, kv access). This is | ||
// implemented as a CRTP mixin so that you could build your own hierarchy. | ||
template <typename Base> | ||
class WithCommonExtensions : public Base | ||
{ | ||
public: | ||
WithCommonExtensions(TxAccess acc, kv::Tx* tx) : Base(acc) | ||
{ | ||
// override Math.random | ||
Base::add_extension( | ||
std::make_shared<ccf::js::extensions::MathRandomExtension>()); | ||
|
||
// add console.[debug|log|...] | ||
Base::add_extension( | ||
std::make_shared<ccf::js::extensions::ConsoleExtension>()); | ||
|
||
// add ccf.[strToBuf|bufToStr|...] | ||
Base::add_extension( | ||
std::make_shared<ccf::js::extensions::ConvertersExtension>()); | ||
|
||
// add ccf.crypto.* | ||
Base::add_extension( | ||
std::make_shared<ccf::js::extensions::CryptoExtension>()); | ||
|
||
// add ccf.kv.* | ||
Base::add_extension( | ||
std::make_shared<ccf::js::extensions::KvExtension>(tx)); | ||
} | ||
}; | ||
|
||
using CommonContext = WithCommonExtensions<js::core::Context>; | ||
} |
Oops, something went wrong.