summaryrefslogtreecommitdiff
path: root/ext/url/lib.rs
diff options
context:
space:
mode:
authorMatt Mastracci <matthew@mastracci.com>2023-03-17 12:22:15 -0600
committerGitHub <noreply@github.com>2023-03-17 18:22:15 +0000
commite55b448730160a6e4df9815a268d4049ac89deab (patch)
tree35d80fd60f2f1d1d06903caff256484a7d703d76 /ext/url/lib.rs
parent0bc6bf5d33b8198253954d7f04558270de45c925 (diff)
feat(core) deno_core::extension! macro to simplify extension registration (#18210)
This implements two macros to simplify extension registration and centralize a lot of the boilerplate as a base for future improvements: * `deno_core::ops!` registers a block of `#[op]`s, optionally with type parameters, useful for places where we share lists of ops * `deno_core::extension!` is used to register an extension, and creates two methods that can be used at runtime/snapshot generation time: `init_ops` and `init_ops_and_esm`. --------- Co-authored-by: Bartek IwaƄczuk <biwanczuk@gmail.com>
Diffstat (limited to 'ext/url/lib.rs')
-rw-r--r--ext/url/lib.rs44
1 files changed, 15 insertions, 29 deletions
diff --git a/ext/url/lib.rs b/ext/url/lib.rs
index 8a20c9bc6..cfb6497c3 100644
--- a/ext/url/lib.rs
+++ b/ext/url/lib.rs
@@ -4,13 +4,10 @@ mod urlpattern;
use deno_core::error::type_error;
use deno_core::error::AnyError;
-use deno_core::include_js_files;
use deno_core::op;
use deno_core::url::form_urlencoded;
use deno_core::url::quirks;
use deno_core::url::Url;
-use deno_core::Extension;
-use deno_core::ExtensionBuilder;
use deno_core::OpState;
use deno_core::ZeroCopyBuf;
use std::path::PathBuf;
@@ -18,32 +15,21 @@ use std::path::PathBuf;
use crate::urlpattern::op_urlpattern_parse;
use crate::urlpattern::op_urlpattern_process_match_input;
-fn ext() -> ExtensionBuilder {
- Extension::builder_with_deps(env!("CARGO_PKG_NAME"), &["deno_webidl"])
-}
-
-fn ops(ext: &mut ExtensionBuilder) -> &mut ExtensionBuilder {
- ext.ops(vec![
- op_url_reparse::decl(),
- op_url_parse::decl(),
- op_url_get_serialization::decl(),
- op_url_parse_with_base::decl(),
- op_url_parse_search_params::decl(),
- op_url_stringify_search_params::decl(),
- op_urlpattern_parse::decl(),
- op_urlpattern_process_match_input::decl(),
- ])
-}
-
-pub fn init_ops_and_esm() -> Extension {
- ops(&mut ext())
- .esm(include_js_files!("00_url.js", "01_urlpattern.js",))
- .build()
-}
-
-pub fn init_ops() -> Extension {
- ops(&mut ext()).build()
-}
+deno_core::extension!(
+ deno_url,
+ deps = [deno_webidl],
+ ops = [
+ op_url_reparse,
+ op_url_parse,
+ op_url_get_serialization,
+ op_url_parse_with_base,
+ op_url_parse_search_params,
+ op_url_stringify_search_params,
+ op_urlpattern_parse,
+ op_urlpattern_process_match_input
+ ],
+ esm = ["00_url.js", "01_urlpattern.js"],
+);
/// Parse `href` with a `base_href`. Fills the out `buf` with URL components.
#[op]