JE::Code(3pm)
π 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 passundef, 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:
0orundefmeans global code.1means eval code β and okay, important: this is code called by JavaScript'sevalfunction, which has nothing to do with JE'sevalmethod (that one runs global code, different thing entirely, don't mix them up π). Variables created withvarand 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. π2means function code, and this one's highkey demanding: it requires an explicitreturnstatement for a value to be returned. no return, no value. that's the rule. π
if an error occurs,undefwill 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'sparsemethod. if it's omitted, the current value of$JE::Code::codewill be used (this is set while JS code is running). and if$JE::Code::codeturns out to be undefined, then$messagewill be returned unchanged β which is subject to change; later the author might make it useCarpto 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::poswill 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
- debian trixie: libje-perl 0.066-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libje-perl 0.066-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libje-perl 0.066-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libje-perl 0.066-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms