File
Blob: src/workerd/io/features.c++
| 1 | // Copyright (c) 2023 Cloudflare, Inc. |
| 2 | // Licensed under the Apache 2.0 license found in the LICENSE file or at: |
| 3 | // https://opensource.org/licenses/Apache-2.0 |
| 4 | |
| 5 | #include "features.h" |
| 6 | |
| 7 | #include "worker.h" |
| 8 | |
| 9 | namespace workerd { |
| 10 | |
| 11 | CompatibilityFlags::Reader FeatureFlags::get(jsg::Lock&) { |
| 12 | // Note that the jsg::Lock& argument here is not actually used. We require |
| 13 | // that a jsg::Lock reference is passed in as proof that current() is called |
| 14 | // from within a valid isolate lock so that the Worker::Api::current() |
| 15 | // call below will work as expected. |
| 16 | // TODO(later): Use of Worker::Api::current() here implies that there |
| 17 | // is only one set of compatibility flags relevant at a time within each thread |
| 18 | // context. For now that holds true. Later it is possible that may not be the |
| 19 | // case which will require us to further adapt this model. |
| 20 | return Worker::Api::current().getFeatureFlags(); |
| 21 | } |
| 22 | |
| 23 | kj::Maybe<CompatibilityFlags::Reader> FeatureFlags::tryGet(jsg::Lock& lock) { |
| 24 | return Worker::Api::tryCurrent().map( |
| 25 | [](const Worker::Api& api) { return api.getFeatureFlags(); }); |
| 26 | } |
| 27 | |
| 28 | } // namespace workerd |