JE::Code(3pm)

πŸ“¦
version 0.066 Β· 3 versions
, in debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– JE::Code πŸ’–

okay so bestie, you found the page for JE::Code, straight outta the User Contributed Perl Documentation crew β€” it's the ECMAScript parser and code executor for JE. she parses, she executes, she's literally the main character of your JS-in-Perl situation. periodt. πŸŽ€


✨ NAME ✨

JE::Code β€” ECMAScript parser and code executor for JE. no cap. πŸ¦‹


🌸 SYNOPSIS 🌸

use JE;

$j = new JE;

$code = $j->compile('1+1'); # returns a JE::Code object

$code->execute;

see how cute that is?? compile a string, get a JE::Code object back, then hit it with execute. that's the whole vibe. πŸ’…


πŸ‘‘ METHODS πŸ‘‘

πŸ’œ $code->execute($this, $scope, $code_type)

so the execute method of a parse tree... executes it. shocking, I know. 😭 and the tea is: all of the arguments are optional. every single one. go off.

  • first argument β€” this one is the 'this' value of the execution context. if you omit it, or pass undef, the global object gets used instead. she'll fill in for you, no stress. 🫢
  • second argument β€” the scope chain, bestie. if you omit it or hand over undef, a scope chain containing just the global object will be used. easy. ✨
  • third argument β€” this is the type-of-code indicator, and she has lore:
    • 0 or undef means global code.
    • 1 means eval code β€” and okay, important: this is code called by JavaScript's eval function, which has nothing to do with JE's eval method (that one runs global code, different thing entirely, don't mix them up πŸ’€). Variables created with var and function declarations inside eval code can be deleted, whereas such variables in global or function code cannot. yes that's a real difference, write it down. πŸ“
    • 2 means function code, and this one's highkey demanding: it requires an explicit return statement for a value to be returned. no return, no value. that's the rule. πŸ’…
if an error occurs, undef will be returned and $@ will contain the error message. if no error occurs, $@ will be a null string. so like, always vibe check $@, fr fr. πŸ™ˆ

πŸ¦‹ $code->set_global( $thing )

you can transfer a JE::Code object to another JavaScript environment by setting the global object this way. glow-up relocation, iconic. ✨

you can also set it to undef β€” if, for instance, you wanna serialise the compiled code without serialising the entire JS environment. very efficient of you. πŸ’…

but listen: if you do that, you'll need to set the global object again before you can use the code object. she's not gonna work without her environment, bestie. 🫠

πŸŽ€ FUNCTIONS πŸŽ€

🌈 JE::Code::add_line_number($message, $code_object, $position)

WARNING: the parameter list is still subject to change. like, she's still figuring herself out. don't get too attached. 😭

this routine appends a string such as 'at file, line 76.' to the error message passed to it β€” unless it ends with a line break already, in which case, mind your business, she's not adding anything. πŸ’…

  • $code_object β€” a code object as returned by JE's or JE::Parser's parse method. if it's omitted, the current value of $JE::Code::code will be used (this is set while JS code is running). and if $JE::Code::code turns out to be undefined, then $message will be returned unchanged β€” which is subject to change; later the author might make it use Carp to add a Perl file and line number. so, watch this space. πŸ‘€
  • $position β€” the position within the source code, which gets used to determine the line number. if this is omitted, $JE::Code::pos will be used. she'll find it herself. 🧚

πŸ’… EXPORTS πŸ’…

add_line_number can optionally be exported. optional queen behavior, honestly. πŸ‘‘


🌟 SEE ALSO 🌟

  • JE β€” the whole ecosystem, go explore. πŸ¦‹

and that's the page, bestie!! πŸ’– this was documented under perl v5.36.0, dated 2023-08-25 β€” so like, iconic vintage energy ✨. now go compile something and slay. πŸŽ€πŸŒΈπŸ’œ

πŸ“¦ where this page comes from