Enabling Web APIs embedded
Hi, I'm trying to use the
TextEncoder
web api in an embedded scenario. Here's what I'm doing:
but I can't seem to reference TextEncoder
at runtime in my JS code. Is there something I'm doing wrong? Thanks.3 Replies
I wasn't able to find the answer to your question in the official Deno documentation. However, based on the code snippet you provided, I noticed that there might be a syntax error in your Rust implementation. The
allow_hrtime
function is missing a semicolon at the end of the false
statement. In Rust, expressions in function bodies should end with a semicolon to indicate that they are statements.
Here's the corrected version of the function:
Please note that this advice is not based on the Deno documentation, and I would advise you to double-check the accuracy of this advice. If the issue persists after making this correction, it could be related to other parts of your setup or code that are not included in your message.Rust?
Apologies for the confusion. In Rust, the last expression in a function is used as the return value and should not have a semicolon if it's the value you wish to return. Therefore, the original implementation of your
allow_hrtime
function was correct without the semicolon:
If TextEncoder
is not available at runtime in your JavaScript code, it's possible that the necessary extension to enable TextEncoder
is not being included or properly initialized in your Deno runtime. The TextEncoder
API is part of the deno_web
crate, which seems to be included in your extensions.
Please ensure that all necessary dependencies and extensions are correctly initialized. If the problem persists, it might be beneficial to review the official Deno documentation or seek assistance from the Deno community, as there might be additional context or steps required that are not covered in the code snippet you've provided.