Hitachi Vantara Pentaho Community Forums
Results 1 to 8 of 8

Thread: JavaScript: Cannot add a property to a sealed object

  1. #1

    Default JavaScript: Cannot add a property to a sealed object

    I needed a dateParse function so I added some utility script to a JS module but it is complaining:

    2007/10/15 20:09:53 - Modified Java Script Value.0 - ERROR (version 3.0.0-RC1, build 299003 from 2007/10/01 23:14:52) : Unexpected error :
    2007/10/15 20:09:53 - Modified Java Script Value.0 - ERROR (version 3.0.0-RC1, build 299003 from 2007/10/01 23:14:52) : org.pentaho.di.core.exception.KettleValueException:
    2007/10/15 20:09:53 - Modified Java Script Value.0 - ERROR (version 3.0.0-RC1, build 299003 from 2007/10/01 23:14:52) : Javascript error:
    2007/10/15 20:09:53 - Modified Java Script Value.0 - ERROR (version 3.0.0-RC1, build 299003 from 2007/10/01 23:14:52) : Cannot add a property to a sealed object: LZ. (script#28)
    2007/10/15 20:09:53 - Modified Java Script Value.0 - ERROR (version 3.0.0-RC1, build 299003 from 2007/10/01 23:14:52) :

    The line it is complaining about is this:
    Date.LZ = function(x) {return(x<0||x>9?"":"0")+x};

    I guess it's trying to modify a builtin object. How can I add this utility without causing this error?

    Gerry

  2. #2
    Join Date
    May 2006
    Posts
    4,882

    Default

    Not, as far as I can see ... http://www.mozilla.org/js/simple-packages.html
    Standard objects are sealed, it's not PDI it's javascript

    Regards,
    Sven

  3. #3

    Default

    Ok, I read this link but I believe that sealing is optional. Is there some parameter that can be set to control this behavior? This sealing has broken just about every good utility that extends javascript objects.

    Gerry

  4. #4
    Join Date
    May 2006
    Posts
    4,882

    Default

    In the current version of PDI it's not optional:

    A notion of a sealed object is a JavaScript extension supported by Rhino and it means that properties can not be added/deleted to the object and the existing object properties can not be changed. Any attempt to modify sealed object throws an exception. To seal all objects in the standard library pass true for the sealed argument when calling Context.initStandardObjects(ScriptableObject, boolean):

    ScriptableObject sealedSharedScope = cx.initStandardObjects(null, true);

    This seals only all standard library objects
    PDI uses true as second argument. I doubt it's a good idea changing the standard objects. Then again, who am I

    Regards,
    Sven
    Last edited by sboden; 10-17-2007 at 02:16 AM.

  5. #5

    Default

    Is there an overriding reason for sealing the standard library? The main app, Kettle, is not based on javascript, so allowing users to extend standard javascript objects is not going to corrupt Kettle. This is more to protect a pure javascript application from users but in this instance it is actually severely restricting the ability to use some very useful javascript utility libraries. I would favor having this restriction removed.

    Gerry

  6. #6
    Join Date
    May 2006
    Posts
    4,882

    Default

    It would avoid having people doing too silly with JavaScript in PDI... I consider javascript step a last resort, not something to start writing a couple of A4-pages of javascript code in. But as before, who am I ... you can still raise a JIRA tracker.

    Regards,
    Sven

  7. #7
    Join Date
    Nov 1999
    Posts
    9,729

    Default

    More to the point Sven, I guess again we both don't see the use-case.

  8. #8

    Default

    Javascript is proving to be incredibly useful and is defintely not a tool of last-resort. No matter how many modules ever get developed for PDI there will always be a huge number of scenarios that call for the use of Javascript to customize data transformations and for me having the ability to use commonly available JS libraries that I can just cut and paste into PDI would be a big help. A lot of these extend standard objects and so right now they will not run in PDI. I've opened a Jira case for this issue PDI-324 and it lists the reasons behind the request.

    Gerry

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Privacy Policy | Legal Notices | Safe Harbor Privacy Policy

Copyright © 2005 - 2019 Hitachi Vantara Corporation. All Rights Reserved.