-
-
Notifications
You must be signed in to change notification settings - Fork 413
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
161 changed files
with
4,150 additions
and
2,943 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,81 @@ | ||
use boa_engine::{ | ||
js_str, js_string, object::ObjectInitializer, property::Attribute, string::JsStrVariant, | ||
Context, JsNativeError, JsObject, JsResult, JsValue, NativeFunction, | ||
}; | ||
|
||
fn storage(_: &JsValue, args: &[JsValue], _: &mut Context) -> JsResult<JsValue> { | ||
let Some(value) = args.first() else { | ||
return Err(JsNativeError::typ() | ||
.with_message("expected string argument") | ||
.into()); | ||
}; | ||
|
||
let Some(string) = value.as_string() else { | ||
return Err(JsNativeError::typ() | ||
.with_message(format!("expected string, got {}", value.type_of())) | ||
.into()); | ||
}; | ||
|
||
let storage = if string.is_static() { "static" } else { "heap" }; | ||
Ok(js_string!(storage).into()) | ||
} | ||
|
||
fn encoding(_: &JsValue, args: &[JsValue], _: &mut Context) -> JsResult<JsValue> { | ||
let Some(value) = args.first() else { | ||
return Err(JsNativeError::typ() | ||
.with_message("expected string argument") | ||
.into()); | ||
}; | ||
|
||
let Some(string) = value.as_string() else { | ||
return Err(JsNativeError::typ() | ||
.with_message(format!("expected string, got {}", value.type_of())) | ||
.into()); | ||
}; | ||
|
||
let str = string.as_str(); | ||
let encoding = match str.variant() { | ||
JsStrVariant::Ascii(_) => "ascii", | ||
JsStrVariant::U16(_) => "U16", | ||
}; | ||
Ok(js_string!(encoding).into()) | ||
} | ||
|
||
fn summary(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> { | ||
let Some(value) = args.first() else { | ||
return Err(JsNativeError::typ() | ||
.with_message("expected string argument") | ||
.into()); | ||
}; | ||
|
||
let Some(string) = value.as_string() else { | ||
return Err(JsNativeError::typ() | ||
.with_message(format!("expected string, got {}", value.type_of())) | ||
.into()); | ||
}; | ||
|
||
let storage = if string.is_static() { "static" } else { "heap" }; | ||
let encoding = match string.as_str().variant() { | ||
JsStrVariant::Ascii(_) => "ascii", | ||
JsStrVariant::U16(_) => "U16", | ||
}; | ||
|
||
let summary = ObjectInitializer::new(context) | ||
.property(js_str!("storage"), js_string!(storage), Attribute::all()) | ||
.property(js_str!("encoding"), js_string!(encoding), Attribute::all()) | ||
.build(); | ||
|
||
Ok(summary.into()) | ||
} | ||
|
||
pub(super) fn create_string(context: &mut Context) -> JsObject { | ||
ObjectInitializer::new(context) | ||
.function(NativeFunction::from_fn_ptr(storage), js_str!("storage"), 1) | ||
.function( | ||
NativeFunction::from_fn_ptr(encoding), | ||
js_str!("encoding"), | ||
1, | ||
) | ||
.function(NativeFunction::from_fn_ptr(summary), js_str!("summary"), 1) | ||
.build() | ||
} |
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
Oops, something went wrong.