Project

Profile

Help

Bug #4978

closed

a.ha is not a function

Added by Martynas Jusevicius over 3 years ago. Updated over 3 years ago.

Status:
Closed
Priority:
Normal
Category:
-
Sprint/Milestone:
-
Start date:
2021-04-26
Due date:
% Done:

100%

Estimated time:
Applies to JS Branch:
2
Fix Committed on JS Branch:
2
Fixed in JS Release:
SEF Generated with:
Platforms:
Company:
-
Contact person:
-
Additional contact persons:
-

Description

I'm trying to make the SEF compilation dynamic but I'm not sure I'm using transform() right. Anyway here it is:

<script type="text/javascript">
    <![CDATA[
        window.onload = function() {
            console.log(SaxonJS.getProcessorInfo().productName + " " +
            SaxonJS.getProcessorInfo().productVersion + " " + SaxonJS.getProcessorInfo().releaseDate);
            SaxonJS.XPath.evaluate('transform(map{ "stylesheet-location": "test-pi.xsl", "initial-template": "main" })');
        }
    ]]>
</script>
Can be seen in https://namedgraph.github.io/saxon-js2-test/bootstrap2.xsl which is used as the `xml-stylesheet` processing instruction to bootstrap Saxon-JS.

Which produces an error:

SaxonJS2.rt.js:574 Uncaught TypeError: a.ha is not a function at SaxonJS2.rt.js:574 at h (SaxonJS2.rt.js:568) at transform (SaxonJS2.rt.js:574) at SaxonJS2.rt.js:633 at Object.a [as evaluate] (SaxonJS2.rt.js:592) at Object.evaluate (SaxonJS2.rt.js:790) at window.onload (test-pi2.xml:7)

Can be seen in the console log of https://namedgraph.github.io/saxon-js2-test/test-pi2.xml
Actions #1

Updated by Martynas Jusevicius over 3 years ago

Oops I messed up the formatting...

Actions #2

Updated by Norm Tovey-Walsh over 3 years ago

  • Assignee set to Norm Tovey-Walsh

(From a thread on the XML.com slack)

The error reported above is against the RT version which would never work. With the full JS file, alas, an error still occurs:

SaxonJS2.js:4391 Uncaught TypeError: T.$ is not a function
    at SaxonJS2.js:4391
    at A (SaxonJS2.js:4385)
    at transform (SaxonJS2.js:4391)
    at SaxonJS2.js:4456
    at Object.U [as evaluate] (SaxonJS2.js:4425)
    at Object.evaluate (SaxonJS2.js:4663)
    at window.onload (test-pi2.xml:7)
Actions #3

Updated by Norm Tovey-Walsh over 3 years ago

  • Status changed from New to In Progress

The error appears to be in the attempt to convert the initial-template value into a QName. With the debug version of Saxon-JS, the error is that $a$$.toEQName is not a function.

Actions #4

Updated by Martynas Jusevicius over 3 years ago

Martin Honnen has suggested to wrap the initial-template name into a QName, and the error went away:

SaxonJS.XPath.evaluate('transform(map{ "stylesheet-location": "test-pi.xsl", "initial-template": "QName('main')" })')

However the event handlers are not attached, so it doesn't look like this is a viable alternative to SaxonJS.transform(). I tried this approach in an attempt to avoid having to pre-process the SEF file.

Actions #5

Updated by Martynas Jusevicius over 3 years ago

Sorry this is the correct snippet:

SaxonJS.XPath.evaluate('transform(map{ "stylesheet-location": "test-pi.xsl", "initial-template": QName("", "main") })');
Actions #6

Updated by Martin Honnen over 3 years ago

The fn:transform spec https://www.w3.org/TR/xpath-functions/#func-transform defines the initial-template not as a string but as an xs:QName:

initial-template 2.0, 3.0 The name of a named template in the stylesheet to act as the initial entry point. Type: xs:QName

so I think while the error message is not helpful to understand that the attempt to simply use a string value main instead of QName('', 'main') fails it is probably not a bug in Saxon-JS.

Actions #7

Updated by Martynas Jusevicius over 3 years ago

One question that remains:

whether using fn:transform from the JavaScript API and XPath.evaluate allows you to inject event handlers or in general target the HTML document

Actions #8

Updated by Norm Tovey-Walsh over 3 years ago

I think the answer to that question is, "no." By passing 'document' as the context item to transform(), it's possible to get the stylesheet to transform the source HTML, but ultimately what evaluate does is evaluate an expression and return the results. It isn't connected, interactively to the displayed HTML page.

Actions #9

Updated by Norm Tovey-Walsh over 3 years ago

  • Status changed from In Progress to Resolved

The a.ha message is ultimately caused by the fact that a string is being passed to the initial-template instead of a QName. Saxon-JS was assuming it was a QName and attempting to call one of its methods (.toEQName) which String doesn't have.

I've fixed this by adding a type assertion function and calling it in this case (and a few others). The stylesheet still fails, but the error message is much more useful!

Actions #10

Updated by Michael Kay over 3 years ago

Just to add a word of explanation to any readers who might be mystified: We compile Saxon-JS using the Closure optimizing compiler, and one of the things it does is to rename everything. So the parameter has been renamed "a" and the method has been renamed "ha", so instead of a message like "function param.getEQName does not exist", we get "function a.ha does not exist".

Javascript, of course, being a weakly typed language, means that such errors are never reported until run-time, which makes them much harder to eliminate.

Actions #11

Updated by Norm Tovey-Walsh over 3 years ago

  • Status changed from Resolved to Closed

This issue has been resolved in the Saxon 2.2 maintenance release.

Actions #12

Updated by Debbie Lockett over 3 years ago

  • % Done changed from 0 to 100
  • Fixed in JS Release set to Saxon-JS 2.2
  • Fix Committed on JS Branch 2 added

Please register to edit this issue

Also available in: Atom PDF Tracking page