Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

port to spidermonkey 60 #2345

Merged
merged 5 commits into from Dec 20, 2019
Merged

port to spidermonkey 60 #2345

merged 5 commits into from Dec 20, 2019

Conversation

jiangphcn
Copy link
Contributor

@jiangphcn jiangphcn commented Dec 7, 2019

Overview

Port SpiderMonkey from 1.8.5 to 6.0, i.e mozjs-60.1.1pre3 from https://ftp.mozilla.org/pub/spidermonkey/prereleases/60/pre3/ aligning with the version used in planned CouchDB 4.0. This allows CouchDB 3.0 to address existing issues in legacy spidermonkey version and use new features provided in new version of spidermonkey.

One outstanding topic is about CouchDB-style function declaration.
"map": "function(doc) {emit(doc._id, doc._id);}"

By means of the original transpile idea from the couch-chakra PoC from @dmunch, currently both traditional CouchDB-style function declaration and modern function declaration like below are supported in CouchDB 3.0 if spidermonkey 6.0 is selected.

"map": "(function (doc) {emit(doc._id, doc._id);});"

In order to provide enough flexibility, one switch is introduced when running configure. Currently, the supported value is 1.8.5 and 60. (the default value is 1.8.5 and will be changed to 60 later)

./configure  --spidermonkey-version 60 (non-windows version)
powershell -ExecutionPolicy Bypass .\configure.ps1 -WithCurl -SpiderMonkeyVersion=60 (windows version)

Testing recommendations

All tests below are involved and run successfully again.

 - Make test-cluster-with-quorum
 - Make test-cluster-without-quorum
 - Make eunit
 - Make javascript
 - Make mango-test
 - Make elixir

Related Issues or Pull Requests

#2170 is PR when starting to work on this task.
apache/couchdb-glazier#11

Checklist

  • Code is written and works correctly
  • Changes are covered by tests
  • Any new configurable parameters are documented in rel/overlay/etc/default.ini
  • A PR for documentation changes has been made in https://github.com/apache/couchdb-documentation

@wohali
Copy link
Member

wohali commented Dec 12, 2019

Hi @jiangphcn , this is a big PR and it's taking me a bit of time to work through.

While I'm doing that, I went and had a look for pre-built versions of SM60.

libmozjs-60 is available pre-built only on:

  • Debian buster (10.x) and newer.
  • Ubuntu disco (19.04) and newer - but no LTS releases past bionic (18.04LTS) exist yet.

@willholley so far I cannot find libmozjs60 precompiled for any version of RHEL/CentOS, is this true?

This probably means that for the rest of our binary build matrix, we'll have to start building libmozjs60 and distributing it ourselves, as we do today for the ancient 1.8.5 library. That means building it for:

  • Debian stretch (9.x)
  • Ubuntu xenial (16.04LTS)
  • Ubuntu bionic (18.04LTS)
  • CentOS 7
  • CentOS 8
  • Windows 64-bit

I'm intentionally excluding CentOS 6 from that list because it will go End-Of-Life on November 2020; people stuck on it can live with 1.8.5 a little longer, I think. 😉

The alternative is that we only ship our binaries with 60 in them only for Debian buster, and maybe Windows (tech preview), then add in the other platforms over time, as packages materialise (or if we decide to pick up the slack). Perhaps we know someone over at RH/CentOS who can get a mozjs60 package released for CentOS 8 at the very least...

The good news is that the Docker container can probably be moved from stretch to buster fairly easily (there was a single bug outstanding against ppc64le, which may actually be a qemu bug) so our Docker users can enjoy the new support with this release.

What do you think?

@wohali
Copy link
Member

wohali commented Dec 12, 2019

@tilgovi In the past you've helped with checking out things like sandbox quality / escape mechanisms on JavaScript. Would you be able to review if things have changed with this SM60 PR?

@jiangphcn
Copy link
Contributor Author

Hi @wohali, thanks indeed for taking time to review this PR.

Regarding pre-built version of SM60, again, thanks for thoughtful consideration for its distribution. Yes, there are limited pre-built versions for libmozjs-60. For the rest of them you mentioned, we or the users need to built them and then use spidermonkey 60 based codes.

For now, I am able to build for Debian stretch and Windows 64-bit. Because we have switch to use between 1.8.5 and 6.0 and still want to set 1.8.5 as default, I think that we can move forward step by step. As you suggested, we can ship some library (such as Debian stretch, buster, Ubuntu disco, Windows 64 bit), and ship them on request later.

Also, we can publish step I come up with to help user to build by themselves for the platforms they need.

Thanks,
Peng Hui

@@ -0,0 +1 @@
(function(b){function a(b,d){if({}.hasOwnProperty.call(a.cache,b))return a.cache[b];var e=a.resolve(b);if(!e)throw new Error('Failed to resolve module '+b);var c={id:b,require:a,filename:b,exports:{},loaded:!1,parent:d,children:[]};d&&d.children.push(c);var f=b.slice(0,b.lastIndexOf('/')+1);return a.cache[b]=c.exports,e.call(c.exports,c,c.exports,f,b),c.loaded=!0,a.cache[b]=c.exports}a.modules={},a.cache={},a.resolve=function(b){return{}.hasOwnProperty.call(a.modules,b)?a.modules[b]:void 0},a.define=function(b,c){a.modules[b]=c};var c=function(a){return a='/',{title:'browser',version:'v6.8.0',browser:!0,env:{},argv:[],nextTick:b.setImmediate||function(a){setTimeout(a,0)},cwd:function(){return a},chdir:function(b){a=b}}}();a.define('/tools/entry-point.js',function(c,d,e,f){!function(){'use strict';b.escodegen=a('/escodegen.js',c),escodegen.browser=!0}()}),a.define('/escodegen.js',function(d,c,e,f){!function(k,e,af,N,_,m,J,n,F,A,Z,ae,S,ad,i,f,W,ac,L,aa,t,Y,B,C,x,a9,a7,w,E,G,V,Q,q,U,P,g,R,a6,X,l,y,K,a5,a4){'use strict';function ap(a){return o.Expression.hasOwnProperty(a.type)}function a3(a){return o.Statement.hasOwnProperty(a.type)}function a2(){return{indent:null,base:null,parse:null,comment:!1,format:{indent:{style:' ',base:0,adjustMultilineComment:!1},newline:'\n',space:' ',json:!1,renumber:!1,hexadecimal:!1,quotes:'single',escapeless:!1,compact:!1,parentheses:!0,semicolons:!0,safeConcatenation:!1,preserveBlankLines:!1},moz:{comprehensionExpressionStartsWithAssignment:!1,starlessGenerator:!1},sourceMap:null,sourceMapRoot:null,sourceMapWithCode:!1,directive:!1,raw:!0,verbatim:null,sourceCode:null}}function H(b,a){var c='';for(a|=0;a>0;a>>>=1,b+=b)a&1&&(c+=b);return c}function am(a){return/[\r\n]/g.test(a)}function r(b){var a=b.length;return a&&m.code.isLineTerminator(b.charCodeAt(a-1))}function a0(c,b){var a;for(a in b)b.hasOwnProperty(a)&&(c[a]=b[a]);return c}function T(b,d){function e(a){return typeof a==='object'&&a instanceof Object&&!(a instanceof RegExp)}var a,c;for(a in d)d.hasOwnProperty(a)&&(c=d[a],e(c)?e(b[a])?T(b[a],c):b[a]=T({},c):b[a]=c);return b}function ao(c){var b,e,a,f,d;if(c!==c)throw new Error('Numeric literal whose value is NaN');if(c<0||c===0&&1/c<0)throw new Error('Numeric literal whose value is negative');if(c===1/0)return A?'null':Z?'1e400':'1e+400';if(b=''+c,!Z||b.length<3)return b;e=b.indexOf('.'),!A&&b.charCodeAt(0)===48&&e===1&&(e=0,b=b.slice(1)),a=b,b=b.replace('e+','e'),f=0,(d=a.indexOf('e'))>0&&(f=+a.slice(d+1),a=a.slice(0,d)),e>=0&&(f-=a.length-e-1,a=+(a.slice(0,e)+a.slice(e+1))+''),d=0;while(a.charCodeAt(a.length+d-1)===48)--d;return d!==0&&(f-=d,a=a.slice(0,d)),f!==0&&(a+='e'+f),(a.length<b.length||ae&&c>1e12&&Math.floor(c)===c&&(a='0x'+c.toString(16)).length<b.length)&&+a===c&&(b=a),b}function a8(a,b){return(a&-2)===8232?(b?'u':'\\u')+(a===8232?'2028':'2029'):a===10||a===13?(b?'':'\\')+(a===10?'n':'r'):String.fromCharCode(a)}function aq(d){var g,a,h,e,i,b,f,c;if(a=d.toString(),d.source){if(g=a.match(/\/([^\/]*)$/),!g)return a;for(h=g[1],a='',f=!1,c=!1,e=0,i=d.source.length;e<i;++e)b=d.source.charCodeAt(e),c?(a+=a8(b,c),c=!1):(f?b===93&&(f=!1):b===47?a+='\\':b===91&&(f=!0),a+=a8(b,c),c=b===92);return'/'+a+'/'+h}return a}function ar(a,c){var b;return a===8?'\\b':a===12?'\\f':a===9?'\\t':(b=a.toString(16).toUpperCase(),A||a>255?'\\u'+'0000'.slice(b.length)+b:a===0&&!m.code.isDecimalDigit(c)?'\\0':a===11?'\\x0B':'\\x'+'00'.slice(b.length)+b)}function ai(a){if(a===92)return'\\\\';if(a===10)return'\\n';if(a===13)return'\\r';if(a===8232)return'\\u2028';if(a===8233)return'\\u2029';throw new Error('Incorrectly classified character')}function aj(d){var a,e,c,b;for(b=S==='double'?'"':"'",a=0,e=d.length;a<e;++a){if(c=d.charCodeAt(a),c===39){b='"';break}if(c===34){b="'";break}c===92&&++a}return b+d+b}function ak(d){var b='',c,g,a,h=0,i=0,e,f;for(c=0,g=d.length;c<g;++c){if(a=d.charCodeAt(c),a===39)++h;else if(a===34)++i;else if(a===47&&A)b+='\\';else if(m.code.isLineTerminator(a)||a===92){b+=ai(a);continue}else if(!m.code.isIdentifierPartES5(a)&&(A&&a<32||!(A||ad)&&(a<32||a>126))){b+=ar(a,d.charCodeAt(c+1));continue}b+=String.fromCharCode(a)}if(e=!(S==='double'||S==='auto'&&i<h),f=e?"'":'"',!(e?h:i))return f+b+f;for(d=b,b=f,c=0,g=d.length;c<g;++c)a=d.charCodeAt(c),(a===39&&e||a===34&&!e)&&(b+='\\'),b+=String.fromCharCode(a);return b+f}function a1(d){var a,e,b,c='';for(a=0,e=d.length;a<e;++a)b=d[a],c+=J(b)?a1(b):b;return c}function j(b,a){if(!B)return J(b)?a1(b):b;if(a==null)if(b instanceof N)return b;else a={};return a.loc==null?new N(null,null,B,b,a.name||null):new N(a.loc.start.line,a.loc.start.column,B===!0?a.loc.source||null:B,b,a.name||null)}function v(){return f?f:' '}function h(c,d){var e,g,a,b;return e=j(c).toString(),e.length===0?[d]:(g=j(d).toString(),g.length===0?[c]:(a=e.charCodeAt(e.length-1),b=g.charCodeAt(0),(a===43||a===45)&&a===b||m.code.isIdentifierPartES5(a)&&m.code.isIdentifierPartES5(b)||a===47&&b===105?[c,v(),d]:m.code.isWhiteSpace(a)||m.code.isLineTerminator(a)||m.code.isWhiteSpace(b)||m.code.isLineTerminator(b)?[c,d]:[c,f,d]))}function u(a){return[n,a]}function p(b){var a;a=n,n+=F,b(n),n=a}function as(b){var a;for(a=b.length-1;a>=0;--a)if(m.code.isLineTerminator(b.charCodeAt(a)))break;return b.length-1-a}function ah(k,i){var b,a,e,g,d,c,f,h;for(b=k.split(/\r\n|[\r\n]/),c=Number.MAX_VALUE,a=1,e=b.length;a<e;++a){g=b[a],d=0;while(d<g.length&&m.code.isWhiteSpace(g.charCodeAt(d)))++d;c>d&&(c=d)}for(i!==void 0?(f=n,b[1][c]==='*'&&(i+=' '),n=i):(c&1&&--c,f=n),a=1,e=b.length;a<e;++a)h=j(u(b[a].slice(c))),b[a]=B?h.join(''):h;return n=f,b.join('\n')}function D(a,c){if(a.type==='Line')if(r(a.value))return'//'+a.value;else{var b='//'+a.value;return x||(b+='\n'),b}return t.format.indent.adjustMultilineComment&&/[\n\r]/.test(a.value)?ah('/*'+a.value+'*/',c):'/*'+a.value+'*/'}function $(d,a){var c,g,b,q,p,m,l,i,f,o,h,s,t,e;if(d.leadingComments&&d.leadingComments.length>0){if(q=a,x){for(b=d.leadingComments[0],a=[],i=b.extendedRange,f=b.range,h=C.substring(i[0],f[0]),e=(h.match(/\n/g)||[]).length,e>0?(a.push(H('\n',e)),a.push(u(D(b)))):(a.push(h),a.push(D(b))),o=f,c=1,g=d.leadingComments.length;c<g;c++)b=d.leadingComments[c],f=b.range,s=C.substring(o[1],f[0]),e=(s.match(/\n/g)||[]).length,a.push(H('\n',e)),a.push(u(D(b))),o=f;t=C.substring(f[1],i[1]),e=(t.match(/\n/g)||[]).length,a.push(H('\n',e))}else for(b=d.leadingComments[0],a=[],L&&d.type===k.Program&&d.body.length===0&&a.push('\n'),a.push(D(b)),r(j(a).toString())||a.push('\n'),c=1,g=d.leadingComments.length;c<g;++c)b=d.leadingComments[c],l=[D(b)],r(j(l).toString())||l.push('\n'),a.push(u(l));a.push(u(q))}if(d.trailingComments)if(x)b=d.trailingComments[0],i=b.extendedRange,f=b.range,h=C.substring(i[0],f[0]),e=(h.match(/\n/g)||[]).length,e>0?(a.push(H('\n',e)),a.push(u(D(b)))):(a.push(h),a.push(D(b)));else for(p=!r(j(a).toString()),m=H(' ',as(j([n,a,F]).toString())),c=0,g=d.trailingComments.length;c<g;++c)b=d.trailingComments[c],p?(c===0?a=[a,F]:a=[a,m],a.push(D(b,m))):a=[a,u(D(b))],c!==g-1&&!r(j(a).toString())&&(a=[a,'\n']);return a}function I(c,d,e){var a,b=0;for(a=c;a<d;a++)C[a]==='\n'&&b++;for(a=1;a<b;a++)e.push(i)}function s(a,b,c){return b<c?['(',a,')']:a}function ab(d){var a,c,b;for(b=d.split(/\r\n|\n/),a=1,c=b.length;a<c;a++)b[a]=i+n+b[a];return b}function an(c,d){var a,b,f;return a=c[t.verbatim],typeof a==='string'?b=s(ab(a),e.Sequence,d):(b=ab(a.content),f=a.precedence!=null?a.precedence:e.Sequence,b=s(b,f,d)),j(b,c)}function o(){}function z(a){return j(a.name,a)}function M(a,b){return a.async?'async'+(b?v():f):''}function O(b){var a=b.generator&&!t.moz.starlessGenerator;return a?'*'+f:''}function ag(b){var a=b.value;return a.async?M(a,!b.computed):O(a)?'*':''}function at(a){var b;if(b=new o,a3(a))return b.generateStatement(a,l);if(ap(a))return b.generateExpression(a,e.Sequence,g);throw new Error('Unknown node type: '+a.type)}function al(k,e){var h=a2(),j,g;return e!=null?(typeof e.indent==='string'&&(h.format.indent.style=e.indent),typeof e.base==='number'&&(h.format.indent.base=e.base),e=T(h,e),F=e.format.indent.style,typeof e.base==='string'?n=e.base:n=H(F,e.format.indent.base)):(e=h,F=e.format.indent.style,n=H(F,e.format.indent.base)),A=e.format.json,Z=e.format.renumber,ae=A?!1:e.format.hexadecimal,S=A?'double':e.format.quotes,ad=e.format.escapeless,i=e.format.newline,f=e.format.space,e.format.compact&&(i=f=F=n=''),W=e.format.parentheses,ac=e.format.semicolons,L=e.format.safeConcatenation,aa=e.directive,Y=A?null:e.parse,B=e.sourceMap,C=e.sourceCode,x=e.format.preserveBlankLines&&C!==null,t=e,B&&(c.browser?N=b.sourceMap.SourceNode:N=a('/node_modules/source-map/lib/source-map.js',d).SourceNode),j=at(k),B?(g=j.toStringWithSourceMap({file:e.file,sourceRoot:e.sourceMapRoot}),e.sourceContent&&g.map.setSourceContent(e.sourceMap,e.sourceContent),e.sourceMapWithCode?g:g.map.toString()):(g={code:j.toString(),map:null},e.sourceMapWithCode?g:g.code)}_=a('/node_modules/estraverse/estraverse.js',d),m=a('/node_modules/esutils/lib/utils.js',d),k=_.Syntax,e={Sequence:0,Yield:1,Await:1,Assignment:1,Conditional:2,ArrowFunction:2,LogicalOR:3,LogicalAND:4,BitwiseOR:5,BitwiseXOR:6,BitwiseAND:7,Equality:8,Relational:9,BitwiseSHIFT:10,Additive:11,Multiplicative:12,Unary:13,Postfix:14,Call:15,New:16,TaggedTemplate:17,Member:18,Primary:19},af={'||':e.LogicalOR,'&&':e.LogicalAND,'|':e.BitwiseOR,'^':e.BitwiseXOR,'&':e.BitwiseAND,'==':e.Equality,'!=':e.Equality,'===':e.Equality,'!==':e.Equality,is:e.Equality,isnt:e.Equality,'<':e.Relational,'>':e.Relational,'<=':e.Relational,'>=':e.Relational,'in':e.Relational,'instanceof':e.Relational,'<<':e.BitwiseSHIFT,'>>':e.BitwiseSHIFT,'>>>':e.BitwiseSHIFT,'+':e.Additive,'-':e.Additive,'*':e.Multiplicative,'%':e.Multiplicative,'/':e.Multiplicative},w=1,E=2,G=4,V=8,Q=16,q=32,U=E|G,P=w|E,g=w|E|G,R=w,a6=G,X=w|G,l=w,y=w|q,K=0,a5=w|Q,a4=w|V,J=Array.isArray,J||(J=function a(b){return Object.prototype.toString.call(b)==='[object Array]'}),o.prototype.maybeBlock=function(a,c){var d,b,e=this;return b=!t.comment||!a.leadingComments,a.type===k.BlockStatement&&b?[f,this.generateStatement(a,c)]:a.type===k.EmptyStatement&&b?';':(p(function(){d=[i,u(e.generateStatement(a,c))]}),d)},o.prototype.maybeBlockSuffix=function(c,a){var b=r(j(a).toString());return c.type===k.BlockStatement&&!(t.comment&&c.leadingComments)&&!b?[a,f]:b?[a,n]:[a,i,n]},o.prototype.generatePattern=function(a,b,c){return a.type===k.Identifier?z(a):this.generateExpression(a,b,c)},o.prototype.generateFunctionParams=function(a){var c,d,b,h;if(h=!1,a.type===k.ArrowFunctionExpression&&!a.rest&&(!a.defaults||a.defaults.length===0)&&a.params.length===1&&a.params[0].type===k.Identifier)b=[M(a,!0),z(a.params[0])];else{for(b=a.type===k.ArrowFunctionExpression?[M(a,!1)]:[],b.push('('),a.defaults&&(h=!0),c=0,d=a.params.length;c<d;++c)h&&a.defaults[c]?b.push(this.generateAssignment(a.params[c],a.defaults[c],'=',e.Assignment,g)):b.push(this.generatePattern(a.params[c],e.Assignment,g)),c+1<d&&b.push(','+f);a.rest&&(a.params.length&&b.push(','+f),b.push('...'),b.push(z(a.rest))),b.push(')')}return b},o.prototype.generateFunctionBody=function(b){var a,c;return a=this.generateFunctionParams(b),b.type===k.ArrowFunctionExpression&&(a.push(f),a.push('=>')),b.expression?(a.push(f),c=this.generateExpression(b.body,e.Assignment,g),c.toString().charAt(0)==='{'&&(c=['(',c,')']),a.push(c)):a.push(this.maybeBlock(b.body,a4)),a},o.prototype.generateIterationForStatement=function(d,b,i){var a=['for'+f+'('],c=this;return p(function(){b.left.type===k.VariableDeclaration?p(function(){a.push(b.left.kind+v()),a.push(c.generateStatement(b.left.declarations[0],K))}):a.push(c.generateExpression(b.left,e.Call,g)),a=h(a,d),a=[h(a,c.generateExpression(b.right,e.Sequence,g)),')']}),a.push(this.maybeBlock(b.body,i)),a},o.prototype.generatePropertyKey=function(d,b,c){var a=[];return b&&a.push('['),c.type==='AssignmentPattern'?a.push(this.AssignmentPattern(c,e.Sequence,g)):a.push(this.generateExpression(d,e.Sequence,g)),b&&a.push(']'),a},o.prototype.generateAssignment=function(c,d,g,b,a){return e.Assignment<b&&(a|=w),s([this.generateExpression(c,e.Call,a),f+g+f,this.generateExpression(d,e.Assignment,a)],e.Assignment,b)},o.prototype.semicolon=function(a){return!ac&&a&q?'':';'},o.Statement={BlockStatement:function(a,f){var c,d,b=['{',i],e=this;return p(function(){a.body.length===0&&x&&(c=a.range,c[1]-c[0]>2)&&(d=C.substring(c[0]+1,c[1]-1),d[0]==='\n'&&(b=['{']),b.push(d));var g,h,m,k;for(k=l,f&V&&(k|=Q),g=0,h=a.body.length;g<h;++g)x&&(g===0&&(a.body[0].leadingComments&&(c=a.body[0].leadingComments[0].extendedRange,d=C.substring(c[0],c[1]),d[0]==='\n'&&(b=['{'])),a.body[0].leadingComments||I(a.range[0],a.body[0].range[0],b)),g>0&&!(a.body[g-1].trailingComments||a.body[g].leadingComments)&&I(a.body[g-1].range[1],a.body[g].range[0],b)),g===h-1&&(k|=q),a.body[g].leadingComments&&x?m=e.generateStatement(a.body[g],k):m=u(e.generateStatement(a.body[g],k)),b.push(m),r(j(m).toString())||(x&&g<h-1?a.body[g+1].leadingComments||b.push(i):b.push(i)),x&&g===h-1&&(a.body[g].trailingComments||I(a.body[g].range[1],a.range[1],b))}),b.push(u('}')),b},BreakStatement:function(a,b){return a.label?'break '+a.label.name+this.semicolon(b):'break'+this.semicolon(b)},ContinueStatement:function(a,b){return a.label?'continue '+a.label.name+this.semicolon(b):'continue'+this.semicolon(b)},ClassBody:function(b,d){var a=['{',i],c=this;return p(function(h){var d,f;for(d=0,f=b.body.length;d<f;++d)a.push(h),a.push(c.generateExpression(b.body[d],e.Sequence,g)),d+1<f&&a.push(i)}),r(j(a).toString())||a.push(i),a.push(n),a.push('}'),a},ClassDeclaration:function(b,d){var a,c;return a=['class'],b.id&&(a=h(a,this.generateExpression(b.id,e.Sequence,g))),b.superClass&&(c=h('extends',this.generateExpression(b.superClass,e.Assignment,g)),a=h(a,c)),a.push(f),a.push(this.generateStatement(b.body,y)),a},DirectiveStatement:function(a,b){return t.raw&&a.raw?a.raw+this.semicolon(b):aj(a.directive)+this.semicolon(b)},DoWhileStatement:function(b,c){var a=h('do',this.maybeBlock(b.body,l));return a=this.maybeBlockSuffix(b.body,a),h(a,['while'+f+'(',this.generateExpression(b.test,e.Sequence,g),')'+this.semicolon(c)])},CatchClause:function(a,d){var b,c=this;return p(function(){var d;b=['catch'+f+'(',c.generateExpression(a.param,e.Sequence,g),')'],a.guard&&(d=c.generateExpression(a.guard,e.Sequence,g),b.splice(2,0,' if ',d))}),b.push(this.maybeBlock(a.body,l)),b},DebuggerStatement:function(b,a){return'debugger'+this.semicolon(a)},EmptyStatement:function(a,b){return';'},ExportDefaultDeclaration:function(b,c){var a=['export'],d;return d=c&q?y:l,a=h(a,'default'),a3(b.declaration)?a=h(a,this.generateStatement(b.declaration,d)):a=h(a,this.generateExpression(b.declaration,e.Assignment,g)+this.semicolon(c)),a},ExportNamedDeclaration:function(b,c){var a=['export'],d,m=this;return d=c&q?y:l,b.declaration?h(a,this.generateStatement(b.declaration,d)):(b.specifiers&&(b.specifiers.length===0?a=h(a,'{'+f+'}'):b.specifiers[0].type===k.ExportBatchSpecifier?a=h(a,this.generateExpression(b.specifiers[0],e.Sequence,g)):(a=h(a,'{'),p(function(f){var c,d;for(a.push(i),c=0,d=b.specifiers.length;c<d;++c)a.push(f),a.push(m.generateExpression(b.specifiers[c],e.Sequence,g)),c+1<d&&a.push(','+i)}),r(j(a).toString())||a.push(i),a.push(n+'}')),b.source?a=h(a,['from'+f,this.generateExpression(b.source,e.Sequence,g),this.semicolon(c)]):a.push(this.semicolon(c))),a)},ExportAllDeclaration:function(a,b){return['export'+f,'*'+f,'from'+f,this.generateExpression(a.source,e.Sequence,g),this.semicolon(b)]},ExpressionStatement:function(c,d){function f(b){var a;return b.slice(0,5)!=='class'?!1:(a=b.charCodeAt(5),a===123||m.code.isWhiteSpace(a)||m.code.isLineTerminator(a))}function h(b){var a;return b.slice(0,8)!=='function'?!1:(a=b.charCodeAt(8),a===40||m.code.isWhiteSpace(a)||a===42||m.code.isLineTerminator(a))}function i(b){var c,a,d;if(b.slice(0,5)!=='async')return!1;if(!m.code.isWhiteSpace(b.charCodeAt(5)))return!1;for(a=6,d=b.length;a<d;++a)if(!m.code.isWhiteSpace(b.charCodeAt(a)))break;return a===d?!1:b.slice(a,a+8)!=='function'?!1:(c=b.charCodeAt(a+8),c===40||m.code.isWhiteSpace(c)||c===42||m.code.isLineTerminator(c))}var a,b;return a=[this.generateExpression(c.expression,e.Sequence,g)],b=j(a).toString(),b.charCodeAt(0)===123||f(b)||h(b)||i(b)||aa&&d&Q&&c.expression.type===k.Literal&&typeof c.expression.value==='string'?a=['(',a,')'+this.semicolon(d)]:a.push(this.semicolon(d)),a},ImportDeclaration:function(b,d){var a,c,l=this;return b.specifiers.length===0?['import',f,this.generateExpression(b.source,e.Sequence,g),this.semicolon(d)]:(a=['import'],c=0,b.specifiers[c].type===k.ImportDefaultSpecifier&&(a=h(a,[this.generateExpression(b.specifiers[c],e.Sequence,g)]),++c),b.specifiers[c]&&(c!==0&&a.push(','),b.specifiers[c].type===k.ImportNamespaceSpecifier?a=h(a,[f,this.generateExpression(b.specifiers[c],e.Sequence,g)]):(a.push(f+'{'),b.specifiers.length-c===1?(a.push(f),a.push(this.generateExpression(b.specifiers[c],e.Sequence,g)),a.push(f+'}'+f)):(p(function(h){var d,f;for(a.push(i),d=c,f=b.specifiers.length;d<f;++d)a.push(h),a.push(l.generateExpression(b.specifiers[d],e.Sequence,g)),d+1<f&&a.push(','+i)}),r(j(a).toString())||a.push(i),a.push(n+'}'+f)))),a=h(a,['from'+f,this.generateExpression(b.source,e.Sequence,g),this.semicolon(d)]),a)},VariableDeclarator:function(a,c){var b=c&w?g:U;return a.init?[this.generateExpression(a.id,e.Assignment,b),f,'=',f,this.generateExpression(a.init,e.Assignment,b)]:this.generatePattern(a.id,e.Assignment,b)},VariableDeclaration:function(c,h){function j(){for(b=c.declarations[0],t.comment&&b.leadingComments?(a.push('\n'),a.push(u(e.generateStatement(b,d)))):(a.push(v()),a.push(e.generateStatement(b,d))),g=1,k=c.declarations.length;g<k;++g)b=c.declarations[g],t.comment&&b.leadingComments?(a.push(','+i),a.push(u(e.generateStatement(b,d)))):(a.push(','+f),a.push(e.generateStatement(b,d)))}var a,g,k,b,d,e=this;return a=[c.kind],d=h&w?l:K,c.declarations.length>1?p(j):j(),a.push(this.semicolon(h)),a},ThrowStatement:function(a,b){return[h('throw',this.generateExpression(a.argument,e.Sequence,g)),this.semicolon(b)]},TryStatement:function(b,f){var a,c,d,e;if(a=['try',this.maybeBlock(b.block,l)],a=this.maybeBlockSuffix(b.block,a),b.handlers)for(c=0,d=b.handlers.length;c<d;++c)a=h(a,this.generateStatement(b.handlers[c],l)),(b.finalizer||c+1!==d)&&(a=this.maybeBlockSuffix(b.handlers[c].body,a));else{for(e=b.guardedHandlers||[],c=0,d=e.length;c<d;++c)a=h(a,this.generateStatement(e[c],l)),(b.finalizer||c+1!==d)&&(a=this.maybeBlockSuffix(e[c].body,a));if(b.handler)if(J(b.handler))for(c=0,d=b.handler.length;c<d;++c)a=h(a,this.generateStatement(b.handler[c],l)),(b.finalizer||c+1!==d)&&(a=this.maybeBlockSuffix(b.handler[c].body,a));else a=h(a,this.generateStatement(b.handler,l)),b.finalizer&&(a=this.maybeBlockSuffix(b.handler.body,a))}return b.finalizer&&(a=h(a,['finally',this.maybeBlock(b.finalizer,l)])),a},SwitchStatement:function(c,n){var a,d,b,h,k,m=this;if(p(function(){a=['switch'+f+'(',m.generateExpression(c.discriminant,e.Sequence,g),')'+f+'{'+i]}),c.cases)for(k=l,b=0,h=c.cases.length;b<h;++b)b===h-1&&(k|=q),d=u(this.generateStatement(c.cases[b],k)),a.push(d),r(j(d).toString())||a.push(i);return a.push(u('}')),a},SwitchCase:function(c,o){var a,f,b,d,n,m=this;return p(function(){for(c.test?a=[h('case',m.generateExpression(c.test,e.Sequence,g)),':']:a=['default:'],b=0,d=c.consequent.length,d&&c.consequent[0].type===k.BlockStatement&&(f=m.maybeBlock(c.consequent[0],l),a.push(f),b=1),b!==d&&!r(j(a).toString())&&a.push(i),n=l;b<d;++b)b===d-1&&o&q&&(n|=q),f=u(m.generateStatement(c.consequent[b],n)),a.push(f),b+1!==d&&!r(j(f).toString())&&a.push(i)}),a},IfStatement:function(b,j){var a,c,d,i=this;return p(function(){a=['if'+f+'(',i.generateExpression(b.test,e.Sequence,g),')']}),d=j&q,c=l,d&&(c|=q),b.alternate?(a.push(this.maybeBlock(b.consequent,l)),a=this.maybeBlockSuffix(b.consequent,a),b.alternate.type===k.IfStatement?a=h(a,['else ',this.generateStatement(b.alternate,c)]):a=h(a,h('else',this.maybeBlock(b.alternate,c)))):a.push(this.maybeBlock(b.consequent,c)),a},ForStatement:function(b,d){var a,c=this;return p(function(){a=['for'+f+'('],b.init?b.init.type===k.VariableDeclaration?a.push(c.generateStatement(b.init,K)):(a.push(c.generateExpression(b.init,e.Sequence,U)),a.push(';')):a.push(';'),b.test?(a.push(f),a.push(c.generateExpression(b.test,e.Sequence,g)),a.push(';')):a.push(';'),b.update?(a.push(f),a.push(c.generateExpression(b.update,e.Sequence,g)),a.push(')')):a.push(')')}),a.push(this.maybeBlock(b.body,d&q?y:l)),a},ForInStatement:function(a,b){return this.generateIterationForStatement('in',a,b&q?y:l)},ForOfStatement:function(a,b){return this.generateIterationForStatement('of',a,b&q?y:l)},LabeledStatement:function(a,b){return[a.label.name+':',this.maybeBlock(a.body,b&q?y:l)]},Program:function(b,g){var c,e,a,d,f;for(d=b.body.length,c=[L&&d>0?'\n':''],f=a5,a=0;a<d;++a)!L&&a===d-1&&(f|=q),x&&(a===0&&(b.body[0].leadingComments||I(b.range[0],b.body[a].range[0],c)),a>0&&!(b.body[a-1].trailingComments||b.body[a].leadingComments)&&I(b.body[a-1].range[1],b.body[a].range[0],c)),e=u(this.generateStatement(b.body[a],f)),c.push(e),a+1<d&&!r(j(e).toString())&&(x?b.body[a+1].leadingComments||c.push(i):c.push(i)),x&&a===d-1&&(b.body[a].trailingComments||I(b.body[a].range[1],b.range[1],c));return c},FunctionDeclaration:function(a,b){return[M(a,!0),'function',O(a)||v(),a.id?z(a.id):'',this.generateFunctionBody(a)]},ReturnStatement:function(a,b){return a.argument?[h('return',this.generateExpression(a.argument,e.Sequence,g)),this.semicolon(b)]:['return'+this.semicolon(b)]},WhileStatement:function(b,d){var a,c=this;return p(function(){a=['while'+f+'(',c.generateExpression(b.test,e.Sequence,g),')']}),a.push(this.maybeBlock(b.body,d&q?y:l)),a},WithStatement:function(b,d){var a,c=this;return p(function(){a=['with'+f+'(',c.generateExpression(b.object,e.Sequence,g),')']}),a.push(this.maybeBlock(b.body,d&q?y:l)),a}},a0(o.prototype,o.Statement),o.Expression={SequenceExpression:function(d,g,h){var b,a,c;for(e.Sequence<g&&(h|=w),b=[],a=0,c=d.expressions.length;a<c;++a)b.push(this.generateExpression(d.expressions[a],e.Assignment,h)),a+1<c&&b.push(','+f);return s(b,e.Sequence,g)},AssignmentExpression:function(a,b,c){return this.generateAssignment(a.left,a.right,a.operator,b,c)},ArrowFunctionExpression:function(a,b,c){return s(this.generateFunctionBody(a),e.ArrowFunction,b)},ConditionalExpression:function(b,c,a){return e.Conditional<c&&(a|=w),s([this.generateExpression(b.test,e.LogicalOR,a),f+'?'+f,this.generateExpression(b.consequent,e.Assignment,a),f+':'+f,this.generateExpression(b.alternate,e.Assignment,a)],e.Conditional,c)},LogicalExpression:function(a,b,c){return this.BinaryExpression(a,b,c)},BinaryExpression:function(a,g,e){var c,d,b,f;return d=af[a.operator],d<g&&(e|=w),b=this.generateExpression(a.left,d,e),f=b.toString(),f.charCodeAt(f.length-1)===47&&m.code.isIdentifierPartES5(a.operator.charCodeAt(0))?c=[b,v(),a.operator]:c=h(b,a.operator),b=this.generateExpression(a.right,d+1,e),a.operator==='/'&&b.toString().charAt(0)==='/'||a.operator.slice(-1)==='<'&&b.toString().slice(0,3)==='!--'?(c.push(v()),c.push(b)):c=h(c,b),a.operator==='in'&&!(e&w)?['(',c,')']:s(c,d,g)},CallExpression:function(c,h,i){var a,b,d;for(a=[this.generateExpression(c.callee,e.Call,P)],a.push('('),b=0,d=c['arguments'].length;b<d;++b)a.push(this.generateExpression(c['arguments'][b],e.Assignment,g)),b+1<d&&a.push(','+f);return a.push(')'),i&E?s(a,e.Call,h):['(',a,')']},NewExpression:function(d,l,j){var a,c,b,i,k;if(c=d['arguments'].length,k=j&G&&!W&&c===0?X:R,a=h('new',this.generateExpression(d.callee,e.New,k)),!(j&G)||W||c>0){for(a.push('('),b=0,i=c;b<i;++b)a.push(this.generateExpression(d['arguments'][b],e.Assignment,g)),b+1<i&&a.push(','+f);a.push(')')}return s(a,e.New,l)},MemberExpression:function(c,f,d){var a,b;return a=[this.generateExpression(c.object,e.Call,d&E?P:R)],c.computed?(a.push('['),a.push(this.generateExpression(c.property,e.Sequence,d&E?g:X)),a.push(']')):(c.object.type===k.Literal&&typeof c.object.value==='number'&&(b=j(a).toString(),b.indexOf('.')<0&&!/[eExX]/.test(b)&&m.code.isDecimalDigit(b.charCodeAt(b.length-1))&&!(b.length>=2&&b.charCodeAt(0)===48)&&a.push('.')),a.push('.'),a.push(z(c.property))),s(a,e.Member,f)},MetaProperty:function(b,c,d){var a;return a=[],a.push(b.meta),a.push('.'),a.push(b.property),s(a,e.Member,c)},UnaryExpression:function(d,l,n){var a,b,i,k,c;return b=this.generateExpression(d.argument,e.Unary,g),f===''?a=h(d.operator,b):(a=[d.operator],d.operator.length>2?a=h(a,b):(k=j(a).toString(),c=k.charCodeAt(k.length-1),i=b.toString().charCodeAt(0),(c===43||c===45)&&c===i||m.code.isIdentifierPartES5(c)&&m.code.isIdentifierPartES5(i)?(a.push(v()),a.push(b)):a.push(b))),s(a,e.Unary,l)},YieldExpression:function(b,c,d){var a;return b.delegate?a='yield*':a='yield',b.argument&&(a=h(a,this.generateExpression(b.argument,e.Yield,g))),s(a,e.Yield,c)},AwaitExpression:function(a,c,d){var b=h(a.all?'await*':'await',this.generateExpression(a.argument,e.Await,g));return s(b,e.Await,c)},UpdateExpression:function(a,b,c){return a.prefix?s([a.operator,this.generateExpression(a.argument,e.Unary,g)],e.Unary,b):s([this.generateExpression(a.argument,e.Postfix,g),a.operator],e.Postfix,b)},FunctionExpression:function(a,c,d){var b=[M(a,!0),'function'];return a.id?(b.push(O(a)||v()),b.push(z(a.id))):b.push(O(a)||f),b.push(this.generateFunctionBody(a)),b},ArrayPattern:function(a,b,c){return this.ArrayExpression(a,b,c,!0)},ArrayExpression:function(c,k,l,h){var a,b,d=this;return c.elements.length?(b=h?!1:c.elements.length>1,a=['[',b?i:''],p(function(k){var h,j;for(h=0,j=c.elements.length;h<j;++h)c.elements[h]?(a.push(b?k:''),a.push(d.generateExpression(c.elements[h],e.Assignment,g))):(b&&a.push(k),h+1===j&&a.push(',')),h+1<j&&a.push(','+(b?i:f))}),b&&!r(j(a).toString())&&a.push(i),a.push(b?n:''),a.push(']'),a):'[]'},RestElement:function(a,b,c){return'...'+this.generatePattern(a.argument)},ClassExpression:function(b,d,i){var a,c;return a=['class'],b.id&&(a=h(a,this.generateExpression(b.id,e.Sequence,g))),b.superClass&&(c=h('extends',this.generateExpression(b.superClass,e.Assignment,g)),a=h(a,c)),a.push(f),a.push(this.generateStatement(b.body,y)),a},MethodDefinition:function(a,d,e){var b,c;return a['static']?b=['static'+f]:b=[],a.kind==='get'||a.kind==='set'?c=[h(a.kind,this.generatePropertyKey(a.key,a.computed,a.value)),this.generateFunctionBody(a.value)]:c=[ag(a),this.generatePropertyKey(a.key,a.computed,a.value),this.generateFunctionBody(a.value)],h(b,c)},Property:function(a,b,c){return a.kind==='get'||a.kind==='set'?[a.kind,v(),this.generatePropertyKey(a.key,a.computed,a.value),this.generateFunctionBody(a.value)]:a.shorthand?this.generatePropertyKey(a.key,a.computed,a.value):a.method?[ag(a),this.generatePropertyKey(a.key,a.computed,a.value),this.generateFunctionBody(a.value)]:[this.generatePropertyKey(a.key,a.computed,a.value),':'+f,this.generateExpression(a.value,e.Assignment,g)]},ObjectExpression:function(b,k,l){var d,a,c,h=this;return b.properties.length?(d=b.properties.length>1,p(function(){c=h.generateExpression(b.properties[0],e.Sequence,g)}),d||am(j(c).toString())?(p(function(k){var f,j;if(a=['{',i,k,c],d)for(a.push(','+i),f=1,j=b.properties.length;f<j;++f)a.push(k),a.push(h.generateExpression(b.properties[f],e.Sequence,g)),f+1<j&&a.push(','+i)}),r(j(a).toString())||a.push(i),a.push(n),a.push('}'),a):['{',f,c,f,'}']):'{}'},AssignmentPattern:function(a,b,c){return this.generateAssignment(a.left,a.right,'=',b,c)},ObjectPattern:function(c,o,q){var a,d,l,b,h,m=this;if(!c.properties.length)return'{}';if(b=!1,c.properties.length===1)h=c.properties[0],h.value.type!==k.Identifier&&(b=!0);else for(d=0,l=c.properties.length;d<l;++d)if(h=c.properties[d],!h.shorthand){b=!0;break}return a=['{',b?i:''],p(function(j){var d,h;for(d=0,h=c.properties.length;d<h;++d)a.push(b?j:''),a.push(m.generateExpression(c.properties[d],e.Sequence,g)),d+1<h&&a.push(','+(b?i:f))}),b&&!r(j(a).toString())&&a.push(i),a.push(b?n:''),a.push('}'),a},ThisExpression:function(a,b,c){return'this'},Super:function(a,b,c){return'super'},Identifier:function(a,b,c){return z(a)},ImportDefaultSpecifier:function(a,b,c){return z(a.id||a.local)},ImportNamespaceSpecifier:function(c,d,e){var a=['*'],b=c.id||c.local;return b&&a.push(f+'as'+v()+z(b)),a},ImportSpecifier:function(d,e,f){var b=d.imported,c=[b.name],a=d.local;return a&&a.name!==b.name&&c.push(v()+'as'+v()+z(a)),c},ExportSpecifier:function(d,e,f){var b=d.local,c=[b.name],a=d.exported;return a&&a.name!==b.name&&c.push(v()+'as'+v()+z(a)),c},Literal:function(a,c,d){var b;if(a.hasOwnProperty('raw')&&Y&&t.raw)try{if(b=Y(a.raw).body[0].expression,b.type===k.Literal&&b.value===a.value)return a.raw}catch(a){}return a.value===null?'null':typeof a.value==='string'?ak(a.value):typeof a.value==='number'?ao(a.value):typeof a.value==='boolean'?a.value?'true':'false':a.regex?'/'+a.regex.pattern+'/'+a.regex.flags:aq(a.value)},GeneratorExpression:function(a,b,c){return this.ComprehensionExpression(a,b,c)},ComprehensionExpression:function(b,l,m){var a,d,i,c,j=this;return a=b.type===k.GeneratorExpression?['(']:['['],t.moz.comprehensionExpressionStartsWithAssignment&&(c=this.generateExpression(b.body,e.Assignment,g),a.push(c)),b.blocks&&p(function(){for(d=0,i=b.blocks.length;d<i;++d)c=j.generateExpression(b.blocks[d],e.Sequence,g),d>0||t.moz.comprehensionExpressionStartsWithAssignment?a=h(a,c):a.push(c)}),b.filter&&(a=h(a,'if'+f),c=this.generateExpression(b.filter,e.Sequence,g),a=h(a,['(',c,')'])),t.moz.comprehensionExpressionStartsWithAssignment||(c=this.generateExpression(b.body,e.Assignment,g),a=h(a,c)),a.push(b.type===k.GeneratorExpression?')':']'),a},ComprehensionBlock:function(b,c,d){var a;return b.left.type===k.VariableDeclaration?a=[b.left.kind,v(),this.generateStatement(b.left.declarations[0],K)]:a=this.generateExpression(b.left,e.Call,g),a=h(a,b.of?'of':'in'),a=h(a,this.generateExpression(b.right,e.Sequence,g)),['for'+f+'(',a,')']},SpreadElement:function(a,b,c){return['...',this.generateExpression(a.argument,e.Assignment,g)]},TaggedTemplateExpression:function(b,d,f){var a=P;f&E||(a=R);var c=[this.generateExpression(b.tag,e.Call,a),this.generateExpression(b.quasi,e.Primary,a6)];return s(c,e.TaggedTemplate,d)},TemplateElement:function(a,b,c){return a.value.raw},TemplateLiteral:function(c,h,i){var a,b,d;for(a=['`'],b=0,d=c.quasis.length;b<d;++b)a.push(this.generateExpression(c.quasis[b],e.Primary,g)),b+1<d&&(a.push('${'+f),a.push(this.generateExpression(c.expressions[b],e.Sequence,g)),a.push(f+'}'));return a.push('`'),a},ModuleSpecifier:function(a,b,c){return this.Literal(a,b,c)}},a0(o.prototype,o.Expression),o.prototype.generateExpression=function(a,c,e){var b,d;return d=a.type||k.Property,t.verbatim&&a.hasOwnProperty(t.verbatim)?an(a,c):(b=this[d](a,c,e),t.comment&&(b=$(a,b)),j(b,a))},o.prototype.generateStatement=function(b,d){var a,c;return a=this[b.type](b,d),t.comment&&(a=$(b,a)),c=j(a).toString(),b.type===k.Program&&!L&&i===''&&c.charAt(c.length-1)==='\n'&&(a=B?j(a).replaceRight(/\s+$/,''):c.replace(/\s+$/,'')),j(a,b)},a9={indent:{style:'',base:0},renumber:!0,hexadecimal:!0,quotes:'auto',escapeless:!0,compact:!0,parentheses:!1,semicolons:!1},a7=a2().format,c.version=a('/package.json',d).version,c.generate=al,c.attachComments=_.attachComments,c.Precedence=T({},e),c.browser=!1,c.FORMAT_MINIFY=a9,c.FORMAT_DEFAULTS=a7}()}),a.define('/package.json',function(a,b,c,d){a.exports={name:'escodegen',description:'ECMAScript code generator',homepage:'http://github.com/estools/escodegen',main:'escodegen.js',bin:{esgenerate:'./bin/esgenerate.js',escodegen:'./bin/escodegen.js'},files:['LICENSE.BSD','LICENSE.source-map','README.md','bin','escodegen.js','package.json'],version:'1.8.1',engines:{node:'>=0.12.0'},maintainers:[{name:'Yusuke Suzuki',email:'utatane.tea@gmail.com',web:'http://github.com/Constellation'}],repository:{type:'git',url:'http://github.com/estools/escodegen.git'},dependencies:{estraverse:'^1.9.1',esutils:'^2.0.2',esprima:'^2.7.1',optionator:'^0.8.1'},optionalDependencies:{'source-map':'~0.2.0'},devDependencies:{acorn:'^2.7.0',bluebird:'^2.3.11','bower-registry-client':'^0.2.1',chai:'^1.10.0','commonjs-everywhere':'^0.9.7',gulp:'^3.8.10','gulp-eslint':'^0.2.0','gulp-mocha':'^2.0.0',semver:'^5.1.0'},license:'BSD-2-Clause',scripts:{test:'gulp travis','unit-test':'gulp test',lint:'gulp lint',release:'node tools/release.js','build-min':'./node_modules/.bin/cjsify -ma path: tools/entry-point.js > escodegen.browser.min.js',build:'./node_modules/.bin/cjsify -a path: tools/entry-point.js > escodegen.browser.js'}}}),a.define('/node_modules/source-map/lib/source-map.js',function(b,c,d,e){c.SourceMapGenerator=a('/node_modules/source-map/lib/source-map/source-map-generator.js',b).SourceMapGenerator,c.SourceMapConsumer=a('/node_modules/source-map/lib/source-map/source-map-consumer.js',b).SourceMapConsumer,c.SourceNode=a('/node_modules/source-map/lib/source-map/source-node.js',b).SourceNode}),a.define('/node_modules/source-map/lib/source-map/source-node.js',function(c,d,e,f){if(typeof b!=='function')var b=a('/node_modules/amdefine/amdefine.js',c)(c,a);b(function(d,i,e){function a(a,c,d,e,f){this.children=[],this.sourceContents={},this.line=a==null?null:a,this.column=c==null?null:c,this.source=d==null?null:d,this.name=f==null?null:f,this[b]=!0,e!=null&&this.add(e)}var f=d('/node_modules/source-map/lib/source-map/source-map-generator.js',e).SourceMapGenerator,c=d('/node_modules/source-map/lib/source-map/util.js',e),g=/(\r?\n)/,h=10,b='$$$isSourceNode$$$';a.fromStringWithSourceMap=function b(n,m,j){function l(b,d){if(b===null||b.source===undefined)e.add(d);else{var f=j?c.join(j,b.source):b.source;e.add(new a(b.originalLine,b.originalColumn,f,d,b.name))}}var e=new a,d=n.split(g),k=function(){var a=d.shift(),b=d.shift()||'';return a+b},i=1,h=0,f=null;return m.eachMapping(function(a){if(f!==null)if(i<a.generatedLine){var c='';l(f,k()),i++,h=0}else{var b=d[0],c=b.substr(0,a.generatedColumn-h);d[0]=b.substr(a.generatedColumn-h),h=a.generatedColumn,l(f,c),f=a;return}while(i<a.generatedLine)e.add(k()),i++;if(h<a.generatedColumn){var b=d[0];e.add(b.substr(0,a.generatedColumn)),d[0]=b.substr(a.generatedColumn),h=a.generatedColumn}f=a},this),d.length>0&&(f&&l(f,k()),e.add(d.join(''))),m.sources.forEach(function(a){var b=m.sourceContentFor(a);b!=null&&(j!=null&&(a=c.join(j,a)),e.setSourceContent(a,b))}),e},a.prototype.add=function a(c){if(Array.isArray(c))c.forEach(function(a){this.add(a)},this);else if(c[b]||typeof c==='string')c&&this.children.push(c);else throw new TypeError('Expected a SourceNode, string, or an array of SourceNodes and strings. Got '+c);return this},a.prototype.prepend=function a(c){if(Array.isArray(c))for(var d=c.length-1;d>=0;d--)this.prepend(c[d]);else if(c[b]||typeof c==='string')this.children.unshift(c);else throw new TypeError('Expected a SourceNode, string, or an array of SourceNodes and strings. Got '+c);return this},a.prototype.walk=function a(e){var c;for(var d=0,f=this.children.length;d<f;d++)c=this.children[d],c[b]?c.walk(e):c!==''&&e(c,{source:this.source,line:this.line,column:this.column,name:this.name})},a.prototype.join=function a(e){var b,c,d=this.children.length;if(d>0){for(b=[],c=0;c<d-1;c++)b.push(this.children[c]),b.push(e);b.push(this.children[c]),this.children=b}return this},a.prototype.replaceRight=function a(d,e){var c=this.children[this.children.length-1];return c[b]?c.replaceRight(d,e):typeof c==='string'?this.children[this.children.length-1]=c.replace(d,e):this.children.push(''.replace(d,e)),this},a.prototype.setSourceContent=function a(b,d){this.sourceContents[c.toSetString(b)]=d},a.prototype.walkSourceContents=function a(g){for(var d=0,e=this.children.length;d<e;d++)this.children[d][b]&&this.children[d].walkSourceContents(g);var f=Object.keys(this.sourceContents);for(var d=0,e=f.length;d<e;d++)g(c.fromSetString(f[d]),this.sourceContents[f[d]])},a.prototype.toString=function a(){var b='';return this.walk(function(a){b+=a}),b},a.prototype.toStringWithSourceMap=function a(k){var b={code:'',line:1,column:0},c=new f(k),d=!1,e=null,g=null,i=null,j=null;return this.walk(function(k,a){b.code+=k,a.source!==null&&a.line!==null&&a.column!==null?((e!==a.source||g!==a.line||i!==a.column||j!==a.name)&&c.addMapping({source:a.source,original:{line:a.line,column:a.column},generated:{line:b.line,column:b.column},name:a.name}),e=a.source,g=a.line,i=a.column,j=a.name,d=!0):d&&(c.addMapping({generated:{line:b.line,column:b.column}}),e=null,d=!1);for(var f=0,l=k.length;f<l;f++)k.charCodeAt(f)===h?(b.line++,b.column=0,f+1===l?(e=null,d=!1):d&&c.addMapping({source:a.source,original:{line:a.line,column:a.column},generated:{line:b.line,column:b.column},name:a.name})):b.column++}),this.walkSourceContents(function(a,b){c.setSourceContent(a,b)}),{code:b.code,map:c}},i.SourceNode=a})}),a.define('/node_modules/source-map/lib/source-map/util.js',function(c,d,e,f){if(typeof b!=='function')var b=a('/node_modules/amdefine/amdefine.js',c)(c,a);b(function(o,a,p){function m(b,a,c){if(a in b)return b[a];else if(arguments.length===3)return c;else throw new Error('"'+a+'" is a required argument.')}function b(b){var a=b.match(f);return a?{scheme:a[1],auth:a[2],host:a[3],port:a[4],path:a[5]}:null}function c(a){var b='';return a.scheme&&(b+=a.scheme+':'),b+='//',a.auth&&(b+=a.auth+'@'),a.host&&(b+=a.host),a.port&&(b+=':'+a.port),a.path&&(b+=a.path),b}function g(i){var a=i,d=b(i);if(d){if(!d.path)return i;a=d.path}var j=a.charAt(0)==='/',e=a.split(/\/+/);for(var h,g=0,f=e.length-1;f>=0;f--)h=e[f],h==='.'?e.splice(f,1):h==='..'?g++:g>0&&(h===''?(e.splice(f+1,g),g=0):(e.splice(f,2),g--));return a=e.join('/'),a===''&&(a=j?'/':'.'),d?(d.path=a,c(d)):a}function h(h,d){h===''&&(h='.'),d===''&&(d='.');var f=b(d),a=b(h);if(a&&(h=a.path||'/'),f&&!f.scheme)return a&&(f.scheme=a.scheme),c(f);if(f||d.match(e))return d;if(a&&!a.host&&!a.path)return a.host=d,c(a);var i=d.charAt(0)==='/'?d:g(h.replace(/\/+$/,'')+'/'+d);return a?(a.path=i,c(a)):i}function j(a,c){a===''&&(a='.'),a=a.replace(/\/$/,'');var d=b(a);return c.charAt(0)=='/'&&d&&d.path=='/'?c.slice(1):c.indexOf(a+'/')===0?c.substr(a.length+1):c}function k(a){return'$'+a}function l(a){return a.substr(1)}function d(c,d){var a=c||'',b=d||'';return(a>b)-(a<b)}function n(b,c,e){var a;return a=d(b.source,c.source),a?a:(a=b.originalLine-c.originalLine,a?a:(a=b.originalColumn-c.originalColumn,a||e?a:(a=d(b.name,c.name),a?a:(a=b.generatedLine-c.generatedLine,a?a:b.generatedColumn-c.generatedColumn))))}function i(b,c,e){var a;return a=b.generatedLine-c.generatedLine,a?a:(a=b.generatedColumn-c.generatedColumn,a||e?a:(a=d(b.source,c.source),a?a:(a=b.originalLine-c.originalLine,a?a:(a=b.originalColumn-c.originalColumn,a?a:d(b.name,c.name)))))}a.getArg=m;var f=/^(?:([\w+\-.]+):)?\/\/(?:(\w+:\w+)@)?([\w.]*)(?::(\d+))?(\S*)$/,e=/^data:.+\,.+$/;a.urlParse=b,a.urlGenerate=c,a.normalize=g,a.join=h,a.relative=j,a.toSetString=k,a.fromSetString=l,a.compareByOriginalPositions=n,a.compareByGeneratedPositions=i})}),a.define('/node_modules/amdefine/amdefine.js',function(b,f,g,d){'use strict';function e(e,i){'use strict';function q(b){var a,c;for(a=0;b[a];a+=1)if(c=b[a],c==='.')b.splice(a,1),a-=1;else if(c==='..')if(a===1&&(b[2]==='..'||b[0]==='..'))break;else a>0&&(b.splice(a-1,2),a-=2)}function j(b,c){var a;return b&&b.charAt(0)==='.'&&c&&(a=c.split('/'),a=a.slice(0,a.length-1),a=a.concat(b.split('/')),q(a),b=a.join('/')),b}function p(a){return function(b){return j(b,a)}}function o(c){function a(a){b[c]=a}return a.fromText=function(a,b){throw new Error('amdefine does not implement load.fromText')},a}function m(c,h,l){var m,f,a,j;if(c)f=b[c]={},a={id:c,uri:d,exports:f},m=g(i,f,a,c);else{if(k)throw new Error('amdefine with no module ID cannot be called more than once per file.');k=!0,f=e.exports,a=e,m=g(i,f,a,e.id)}h&&(h=h.map(function(a){return m(a)})),typeof l==='function'?j=l.apply(a.exports,h):j=l,j!==undefined&&(a.exports=j,c&&(b[c]=a.exports))}function l(b,a,c){Array.isArray(b)?(c=a,a=b,b=undefined):typeof b!=='string'&&(c=b,b=a=undefined),a&&!Array.isArray(a)&&(c=a,a=undefined),a||(a=['require','exports','module']),b?f[b]=[b,a,c]:m(b,a,c)}var f={},b={},k=!1,n=a('path',e),g,h;return g=function(b,d,a,e){function f(f,g){if(typeof f==='string')return h(b,d,a,f,e);f=f.map(function(c){return h(b,d,a,c,e)}),g&&c.nextTick(function(){g.apply(null,f)})}return f.toUrl=function(b){return b.indexOf('.')===0?j(b,n.dirname(a.filename)):b},f},i=i||function a(){return e.require.apply(e,arguments)},h=function(d,e,i,a,c){var k=a.indexOf('!'),n=a,q,l;if(k===-1)if(a=j(a,c),a==='require')return g(d,e,i,c);else if(a==='exports')return e;else if(a==='module')return i;else if(b.hasOwnProperty(a))return b[a];else if(f[a])return m.apply(null,f[a]),b[a];else if(d)return d(n);else throw new Error('No module with ID: '+a);else return q=a.substring(0,k),a=a.substring(k+1,a.length),l=h(d,e,i,q,c),l.normalize?a=l.normalize(a,p(c)):a=j(a,c),b[a]?b[a]:(l.load(a,g(d,e,i,c),o(a),{}),b[a])},l.require=function(a){return b[a]?b[a]:f[a]?(m.apply(null,f[a]),b[a]):void 0},l.amd={},l}b.exports=e}),a.define('/node_modules/source-map/lib/source-map/source-map-generator.js',function(c,d,e,f){if(typeof b!=='function')var b=a('/node_modules/amdefine/amdefine.js',c)(c,a);b(function(e,h,f){function b(b){b||(b={}),this._file=a.getArg(b,'file',null),this._sourceRoot=a.getArg(b,'sourceRoot',null),this._skipValidation=a.getArg(b,'skipValidation',!1),this._sources=new d,this._names=new d,this._mappings=new g,this._sourcesContents=null}var c=e('/node_modules/source-map/lib/source-map/base64-vlq.js',f),a=e('/node_modules/source-map/lib/source-map/util.js',f),d=e('/node_modules/source-map/lib/source-map/array-set.js',f).ArraySet,g=e('/node_modules/source-map/lib/source-map/mapping-list.js',f).MappingList;b.prototype._version=3,b.fromSourceMap=function c(d){var e=d.sourceRoot,f=new b({file:d.file,sourceRoot:e});return d.eachMapping(function(b){var c={generated:{line:b.generatedLine,column:b.generatedColumn}};b.source!=null&&(c.source=b.source,e!=null&&(c.source=a.relative(e,c.source)),c.original={line:b.originalLine,column:b.originalColumn},b.name!=null&&(c.name=b.name)),f.addMapping(c)}),d.sources.forEach(function(b){var a=d.sourceContentFor(b);a!=null&&f.setSourceContent(b,a)}),f},b.prototype.addMapping=function b(f){var g=a.getArg(f,'generated'),c=a.getArg(f,'original',null),d=a.getArg(f,'source',null),e=a.getArg(f,'name',null);this._skipValidation||this._validateMapping(g,c,d,e),d!=null&&!this._sources.has(d)&&this._sources.add(d),e!=null&&!this._names.has(e)&&this._names.add(e),this._mappings.add({generatedLine:g.line,generatedColumn:g.column,originalLine:c!=null&&c.line,originalColumn:c!=null&&c.column,source:d,name:e})},b.prototype.setSourceContent=function b(e,d){var c=e;this._sourceRoot!=null&&(c=a.relative(this._sourceRoot,c)),d!=null?(this._sourcesContents||(this._sourcesContents={}),this._sourcesContents[a.toSetString(c)]=d):this._sourcesContents&&(delete this._sourcesContents[a.toSetString(c)],Object.keys(this._sourcesContents).length===0&&(this._sourcesContents=null))},b.prototype.applySourceMap=function b(e,j,g){var f=j;if(j==null){if(e.file==null)throw new Error('SourceMapGenerator.prototype.applySourceMap requires either an explicit source file, or the source map\'s "file" property. Both were omitted.');f=e.file}var c=this._sourceRoot;c!=null&&(f=a.relative(c,f));var h=new d,i=new d;this._mappings.unsortedForEach(function(b){if(b.source===f&&b.originalLine!=null){var d=e.originalPositionFor({line:b.originalLine,column:b.originalColumn});d.source!=null&&(b.source=d.source,g!=null&&(b.source=a.join(g,b.source)),c!=null&&(b.source=a.relative(c,b.source)),b.originalLine=d.line,b.originalColumn=d.column,d.name!=null&&(b.name=d.name))}var j=b.source;j!=null&&!h.has(j)&&h.add(j);var k=b.name;k!=null&&!i.has(k)&&i.add(k)},this),this._sources=h,this._names=i,e.sources.forEach(function(b){var d=e.sourceContentFor(b);d!=null&&(g!=null&&(b=a.join(g,b)),c!=null&&(b=a.relative(c,b)),this.setSourceContent(b,d))},this)},b.prototype._validateMapping=function a(b,c,d,e){if(b&&'line'in b&&'column'in b&&b.line>0&&b.column>=0&&!c&&!d&&!e)return;else if(b&&'line'in b&&'column'in b&&c&&'line'in c&&'column'in c&&b.line>0&&b.column>=0&&c.line>0&&c.column>=0&&d)return;else throw new Error('Invalid mapping: '+JSON.stringify({generated:b,source:d,original:c,name:e}))},b.prototype._serializeMappings=function b(){var h=0,g=1,k=0,l=0,m=0,j=0,e='',d,i=this._mappings.toArray();for(var f=0,n=i.length;f<n;f++){if(d=i[f],d.generatedLine!==g){h=0;while(d.generatedLine!==g)e+=';',g++}else if(f>0){if(!a.compareByGeneratedPositions(d,i[f-1]))continue;e+=','}e+=c.encode(d.generatedColumn-h),h=d.generatedColumn,d.source!=null&&(e+=c.encode(this._sources.indexOf(d.source)-j),j=this._sources.indexOf(d.source),e+=c.encode(d.originalLine-1-l),l=d.originalLine-1,e+=c.encode(d.originalColumn-k),k=d.originalColumn,d.name!=null&&(e+=c.encode(this._names.indexOf(d.name)-m),m=this._names.indexOf(d.name)))}return e},b.prototype._generateSourcesContent=function b(d,c){return d.map(function(b){if(!this._sourcesContents)return null;c!=null&&(b=a.relative(c,b));var d=a.toSetString(b);return Object.prototype.hasOwnProperty.call(this._sourcesContents,d)?this._sourcesContents[d]:null},this)},b.prototype.toJSON=function a(){var b={version:this._version,sources:this._sources.toArray(),names:this._names.toArray(),mappings:this._serializeMappings()};return this._file!=null&&(b.file=this._file),this._sourceRoot!=null&&(b.sourceRoot=this._sourceRoot),this._sourcesContents&&(b.sourcesContent=this._generateSourcesContent(b.sources,b.sourceRoot)),b},b.prototype.toString=function a(){return JSON.stringify(this)},h.SourceMapGenerator=b})}),a.define('/node_modules/source-map/lib/source-map/mapping-list.js',function(c,d,e,f){if(typeof b!=='function')var b=a('/node_modules/amdefine/amdefine.js',c)(c,a);b(function(c,d,e){function f(a,c){var d=a.generatedLine,e=c.generatedLine,f=a.generatedColumn,g=c.generatedColumn;return e>d||e==d&&g>=f||b.compareByGeneratedPositions(a,c)<=0}function a(){this._array=[],this._sorted=!0,this._last={generatedLine:-1,generatedColumn:0}}var b=c('/node_modules/source-map/lib/source-map/util.js',e);a.prototype.unsortedForEach=function a(b,c){this._array.forEach(b,c)},a.prototype.add=function a(b){f(this._last,b)?(this._last=b,this._array.push(b)):(this._sorted=!1,this._array.push(b))},a.prototype.toArray=function a(){return this._sorted||(this._array.sort(b.compareByGeneratedPositions),this._sorted=!0),this._array},d.MappingList=a})}),a.define('/node_modules/source-map/lib/source-map/array-set.js',function(c,d,e,f){if(typeof b!=='function')var b=a('/node_modules/amdefine/amdefine.js',c)(c,a);b(function(c,d,e){function a(){this._array=[],this._set={}}var b=c('/node_modules/source-map/lib/source-map/util.js',e);a.fromArray=function b(e,g){var d=new a;for(var c=0,f=e.length;c<f;c++)d.add(e[c],g);return d},a.prototype.add=function a(c,f){var d=this.has(c),e=this._array.length;(!d||f)&&this._array.push(c),d||(this._set[b.toSetString(c)]=e)},a.prototype.has=function a(c){return Object.prototype.hasOwnProperty.call(this._set,b.toSetString(c))},a.prototype.indexOf=function a(c){if(this.has(c))return this._set[b.toSetString(c)];throw new Error('"'+c+'" is not in the set.')},a.prototype.at=function a(b){if(b>=0&&b<this._array.length)return this._array[b];throw new Error('No element indexed by '+b)},a.prototype.toArray=function a(){return this._array.slice()},d.ArraySet=a})}),a.define('/node_modules/source-map/lib/source-map/base64-vlq.js',function(c,d,e,f){if(typeof b!=='function')var b=a('/node_modules/amdefine/amdefine.js',c)(c,a);b(function(j,f,h){function i(a){return a<0?(-a<<1)+1:(a<<1)+0}function g(b){var c=(b&1)===1,a=b>>1;return c?-a:a}var c=j('/node_modules/source-map/lib/source-map/base64.js',h),a=5,d=1<<a,e=d-1,b=d;f.encode=function d(j){var g='',h,f=i(j);do h=f&e,f>>>=a,f>0&&(h|=b),g+=c.encode(h);while(f>0);return g},f.decode=function d(i,l){var f=0,m=i.length,j=0,k=0,n,h;do{if(f>=m)throw new Error('Expected more digits in base 64 VLQ value.');h=c.decode(i.charAt(f++)),n=!!(h&b),h&=e,j+=h<<k,k+=a}while(n);l.value=g(j),l.rest=i.slice(f)}})}),a.define('/node_modules/source-map/lib/source-map/base64.js',function(c,d,e,f){if(typeof b!=='function')var b=a('/node_modules/amdefine/amdefine.js',c)(c,a);b(function(d,c,e){var a={},b={};'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'.split('').forEach(function(c,d){a[c]=d,b[d]=c}),c.encode=function a(c){if(c in b)return b[c];throw new TypeError('Must be between 0 and 63: '+c)},c.decode=function b(c){if(c in a)return a[c];throw new TypeError('Not a valid base 64 digit: '+c)}})}),a.define('/node_modules/source-map/lib/source-map/source-map-consumer.js',function(c,d,e,f){if(typeof b!=='function')var b=a('/node_modules/amdefine/amdefine.js',c)(c,a);b(function(c,e,d){function a(b){var a=b;if(typeof b==='string'&&(a=JSON.parse(b.replace(/^\)\]\}'/,''))),a.sections!=null){var e=c('/node_modules/source-map/lib/source-map/indexed-source-map-consumer.js',d);return new e.IndexedSourceMapConsumer(a)}else{var f=c('/node_modules/source-map/lib/source-map/basic-source-map-consumer.js',d);return new f.BasicSourceMapConsumer(a)}}var b=c('/node_modules/source-map/lib/source-map/util.js',d);a.fromSourceMap=function(b){var a=c('/node_modules/source-map/lib/source-map/basic-source-map-consumer.js',d);return a.BasicSourceMapConsumer.fromSourceMap(b)},a.prototype._version=3,a.prototype.__generatedMappings=null,Object.defineProperty(a.prototype,'_generatedMappings',{get:function(){return this.__generatedMappings||(this.__generatedMappings=[],this.__originalMappings=[],this._parseMappings(this._mappings,this.sourceRoot)),this.__generatedMappings}}),a.prototype.__originalMappings=null,Object.defineProperty(a.prototype,'_originalMappings',{get:function(){return this.__originalMappings||(this.__generatedMappings=[],this.__originalMappings=[],this._parseMappings(this._mappings,this.sourceRoot)),this.__originalMappings}}),a.prototype._nextCharIsMappingSeparator=function a(c){var b=c.charAt(0);return b===';'||b===','},a.prototype._parseMappings=function a(b,c){throw new Error('Subclasses must implement _parseMappings')},a.GENERATED_ORDER=1,a.ORIGINAL_ORDER=2,a.prototype.eachMapping=function c(h,i,j){var f=i||null,g=j||a.GENERATED_ORDER,d;switch(g){case a.GENERATED_ORDER:d=this._generatedMappings;break;case a.ORIGINAL_ORDER:d=this._originalMappings;break;default:throw new Error('Unknown order of iteration.')}var e=this.sourceRoot;d.map(function(a){var c=a.source;return c!=null&&e!=null&&(c=b.join(e,c)),{source:c,generatedLine:a.generatedLine,generatedColumn:a.generatedColumn,originalLine:a.originalLine,originalColumn:a.originalColumn,name:a.name}}).forEach(h,f)},a.prototype.allGeneratedPositionsFor=function a(g){var d={source:b.getArg(g,'source'),originalLine:b.getArg(g,'line'),originalColumn:Infinity};this.sourceRoot!=null&&(d.source=b.relative(this.sourceRoot,d.source));var f=[],e=this._findMapping(d,this._originalMappings,'originalLine','originalColumn',b.compareByOriginalPositions);if(e>=0){var c=this._originalMappings[e];while(c&&c.originalLine===d.originalLine)f.push({line:b.getArg(c,'generatedLine',null),column:b.getArg(c,'generatedColumn',null),lastColumn:b.getArg(c,'lastGeneratedColumn',null)}),c=this._originalMappings[--e]}return f.reverse()},e.SourceMapConsumer=a})}),a.define('/node_modules/source-map/lib/source-map/basic-source-map-consumer.js',function(c,d,e,f){if(typeof b!=='function')var b=a('/node_modules/amdefine/amdefine.js',c)(c,a);b(function(d,i,e){function b(d){var b=d;typeof d==='string'&&(b=JSON.parse(d.replace(/^\)\]\}'/,'')));var e=a.getArg(b,'version'),c=a.getArg(b,'sources'),g=a.getArg(b,'names',[]),h=a.getArg(b,'sourceRoot',null),i=a.getArg(b,'sourcesContent',null),j=a.getArg(b,'mappings'),k=a.getArg(b,'file',null);if(e!=this._version)throw new Error('Unsupported version: '+e);c=c.map(a.normalize),this._names=f.fromArray(g,!0),this._sources=f.fromArray(c,!0),this.sourceRoot=h,this.sourcesContent=i,this._mappings=j,this.file=k}var a=d('/node_modules/source-map/lib/source-map/util.js',e),h=d('/node_modules/source-map/lib/source-map/binary-search.js',e),f=d('/node_modules/source-map/lib/source-map/array-set.js',e).ArraySet,c=d('/node_modules/source-map/lib/source-map/base64-vlq.js',e),g=d('/node_modules/source-map/lib/source-map/source-map-consumer.js',e).SourceMapConsumer;b.prototype=Object.create(g.prototype),b.prototype.consumer=g,b.fromSourceMap=function c(e){var d=Object.create(b.prototype);return d._names=f.fromArray(e._names.toArray(),!0),d._sources=f.fromArray(e._sources.toArray(),!0),d.sourceRoot=e._sourceRoot,d.sourcesContent=e._generateSourcesContent(d._sources.toArray(),d.sourceRoot),d.file=e._file,d.__generatedMappings=e._mappings.toArray().slice(),d.__originalMappings=e._mappings.toArray().slice().sort(a.compareByOriginalPositions),d},b.prototype._version=3,Object.defineProperty(b.prototype,'sources',{get:function(){return this._sources.toArray().map(function(b){return this.sourceRoot!=null?a.join(this.sourceRoot,b):b},this)}}),b.prototype._parseMappings=function b(m,n){var j=1,g=0,i=0,h=0,k=0,l=0,d=m,e={},f;while(d.length>0)if(d.charAt(0)===';')j++,d=d.slice(1),g=0;else if(d.charAt(0)===',')d=d.slice(1);else{if(f={},f.generatedLine=j,c.decode(d,e),f.generatedColumn=g+e.value,g=f.generatedColumn,d=e.rest,d.length>0&&!this._nextCharIsMappingSeparator(d)){if(c.decode(d,e),f.source=this._sources.at(k+e.value),k+=e.value,d=e.rest,d.length===0||this._nextCharIsMappingSeparator(d))throw new Error('Found a source, but no line and column');if(c.decode(d,e),f.originalLine=i+e.value,i=f.originalLine,f.originalLine+=1,d=e.rest,d.length===0||this._nextCharIsMappingSeparator(d))throw new Error('Found a source and line, but no column');c.decode(d,e),f.originalColumn=h+e.value,h=f.originalColumn,d=e.rest,d.length>0&&!this._nextCharIsMappingSeparator(d)&&(c.decode(d,e),f.name=this._names.at(l+e.value),l+=e.value,d=e.rest)}this.__generatedMappings.push(f),typeof f.originalLine==='number'&&this.__originalMappings.push(f)}this.__generatedMappings.sort(a.compareByGeneratedPositions),this.__originalMappings.sort(a.compareByOriginalPositions)},b.prototype._findMapping=function a(b,e,c,d,f){if(b[c]<=0)throw new TypeError('Line must be greater than or equal to 1, got '+b[c]);if(b[d]<0)throw new TypeError('Column must be greater than or equal to 0, got '+b[d]);return h.search(b,e,f)},b.prototype.computeColumnSpans=function a(){for(var b=0;b<this._generatedMappings.length;++b){var c=this._generatedMappings[b];if(b+1<this._generatedMappings.length){var d=this._generatedMappings[b+1];if(c.generatedLine===d.generatedLine){c.lastGeneratedColumn=d.generatedColumn-1;continue}}c.lastGeneratedColumn=Infinity}},b.prototype.originalPositionFor=function b(g){var e={generatedLine:a.getArg(g,'line'),generatedColumn:a.getArg(g,'column')},f=this._findMapping(e,this._generatedMappings,'generatedLine','generatedColumn',a.compareByGeneratedPositions);if(f>=0){var c=this._generatedMappings[f];if(c.generatedLine===e.generatedLine){var d=a.getArg(c,'source',null);return d!=null&&this.sourceRoot!=null&&(d=a.join(this.sourceRoot,d)),{source:d,line:a.getArg(c,'originalLine',null),column:a.getArg(c,'originalColumn',null),name:a.getArg(c,'name',null)}}}return{source:null,line:null,column:null,name:null}},b.prototype.sourceContentFor=function b(c,f){if(!this.sourcesContent)return null;if(this.sourceRoot!=null&&(c=a.relative(this.sourceRoot,c)),this._sources.has(c))return this.sourcesContent[this._sources.indexOf(c)];var d;if(this.sourceRoot!=null&&(d=a.urlParse(this.sourceRoot))){var e=c.replace(/^file:\/\//,'');if(d.scheme=='file'&&this._sources.has(e))return this.sourcesContent[this._sources.indexOf(e)];if((!d.path||d.path=='/')&&this._sources.has('/'+c))return this.sourcesContent[this._sources.indexOf('/'+c)]}if(f)return null;else throw new Error('"'+c+'" is not in the SourceMap.')},b.prototype.generatedPositionFor=function b(e){var c={source:a.getArg(e,'source'),originalLine:a.getArg(e,'line'),originalColumn:a.getArg(e,'column')};this.sourceRoot!=null&&(c.source=a.relative(this.sourceRoot,c.source));var f=this._findMapping(c,this._originalMappings,'originalLine','originalColumn',a.compareByOriginalPositions);if(f>=0){var d=this._originalMappings[f];return{line:a.getArg(d,'generatedLine',null),column:a.getArg(d,'generatedColumn',null),lastColumn:a.getArg(d,'lastGeneratedColumn',null)}}return{line:null,column:null,lastColumn:null}},i.BasicSourceMapConsumer=b})}),a.define('/node_modules/source-map/lib/source-map/binary-search.js',function(c,d,e,f){if(typeof b!=='function')var b=a('/node_modules/amdefine/amdefine.js',c)(c,a);b(function(c,b,d){function a(c,d,e,f,g){var b=Math.floor((d-c)/2)+c,h=g(e,f[b],!0);return h===0?b:h>0?d-b>1?a(b,d,e,f,g):b:b-c>1?a(c,b,e,f,g):c<0?-1:c}b.search=function b(d,c,e){return c.length===0?-1:a(-1,c.length,d,c,e)}})}),a.define('/node_modules/source-map/lib/source-map/indexed-source-map-consumer.js',function(c,d,e,f){if(typeof b!=='function')var b=a('/node_modules/amdefine/amdefine.js',c)(c,a);b(function(c,g,d){function b(d){var c=d;typeof d==='string'&&(c=JSON.parse(d.replace(/^\)\]\}'/,'')));var f=a.getArg(c,'version'),g=a.getArg(c,'sections');if(f!=this._version)throw new Error('Unsupported version: '+f);var b={line:-1,column:0};this._sections=g.map(function(f){if(f.url)throw new Error('Support for url field in sections not implemented.');var c=a.getArg(f,'offset'),d=a.getArg(c,'line'),g=a.getArg(c,'column');if(d<b.line||d===b.line&&g<b.column)throw new Error('Section offsets must be ordered and non-overlapping.');return b=c,{generatedOffset:{generatedLine:d+1,generatedColumn:g+1},consumer:new e(a.getArg(f,'map'))}})}var a=c('/node_modules/source-map/lib/source-map/util.js',d),f=c('/node_modules/source-map/lib/source-map/binary-search.js',d),e=c('/node_modules/source-map/lib/source-map/source-map-consumer.js',d).SourceMapConsumer,h=c('/node_modules/source-map/lib/source-map/basic-source-map-consumer.js',d).BasicSourceMapConsumer;b.prototype=Object.create(e.prototype),b.prototype.constructor=e,b.prototype._version=3,Object.defineProperty(b.prototype,'sources',{get:function(){var c=[];for(var a=0;a<this._sections.length;a++)for(var b=0;b<this._sections[a].consumer.sources.length;b++)c.push(this._sections[a].consumer.sources[b]);return c}}),b.prototype.originalPositionFor=function b(e){var d={generatedLine:a.getArg(e,'line'),generatedColumn:a.getArg(e,'column')},g=f.search(d,this._sections,function(b,c){var a=b.generatedLine-c.generatedOffset.generatedLine;return a?a:b.generatedColumn-c.generatedOffset.generatedColumn}),c=this._sections[g];return c?c.consumer.originalPositionFor({line:d.generatedLine-(c.generatedOffset.generatedLine-1),column:d.generatedColumn-(c.generatedOffset.generatedLine===d.generatedLine?c.generatedOffset.generatedColumn-1:0)}):{source:null,line:null,column:null,name:null}},b.prototype.sourceContentFor=function a(d,f){for(var b=0;b<this._sections.length;b++){var e=this._sections[b],c=e.consumer.sourceContentFor(d,!0);if(c)return c}if(f)return null;else throw new Error('"'+d+'" is not in the SourceMap.')},b.prototype.generatedPositionFor=function b(f){for(var e=0;e<this._sections.length;e++){var c=this._sections[e];if(c.consumer.sources.indexOf(a.getArg(f,'source'))===-1)continue;var d=c.consumer.generatedPositionFor(f);if(d){var g={line:d.line+(c.generatedOffset.generatedLine-1),column:d.column+(c.generatedOffset.generatedLine===d.line?c.generatedOffset.generatedColumn-1:0)};return g}}return{line:null,column:null}},b.prototype._parseMappings=function b(k,l){this.__generatedMappings=[],this.__originalMappings=[];for(var e=0;e<this._sections.length;e++){var d=this._sections[e],h=d.consumer._generatedMappings;for(var i=0;i<h.length;i++){var c=h[e],f=c.source,j=d.consumer.sourceRoot;f!=null&&j!=null&&(f=a.join(j,f));var g={source:f,generatedLine:c.generatedLine+(d.generatedOffset.generatedLine-1),generatedColumn:c.column+(d.generatedOffset.generatedLine===c.generatedLine)?d.generatedOffset.generatedColumn-1:0,originalLine:c.originalLine,originalColumn:c.originalColumn,name:c.name};this.__generatedMappings.push(g),typeof g.originalLine==='number'&&this.__originalMappings.push(g)}}this.__generatedMappings.sort(a.compareByGeneratedPositions),this.__originalMappings.sort(a.compareByOriginalPositions)},g.IndexedSourceMapConsumer=b})}),a.define('/node_modules/esutils/lib/utils.js',function(b,c,d,e){!function(){'use strict';c.ast=a('/node_modules/esutils/lib/ast.js',b),c.code=a('/node_modules/esutils/lib/code.js',b),c.keyword=a('/node_modules/esutils/lib/keyword.js',b)}()}),a.define('/node_modules/esutils/lib/keyword.js',function(b,c,d,e){!function(c){'use strict';function m(a){switch(a){case'implements':case'interface':case'package':case'private':case'protected':case'public':case'static':case'let':return!0;default:return!1}}function f(a,b){return!b&&a==='yield'?!1:d(a,b)}function d(a,b){if(b&&m(a))return!0;switch(a.length){case 2:return a==='if'||a==='in'||a==='do';case 3:return a==='var'||a==='for'||a==='new'||a==='try';case 4:return a==='this'||a==='else'||a==='case'||a==='void'||a==='with'||a==='enum';case 5:return a==='while'||a==='break'||a==='catch'||a==='throw'||a==='const'||a==='yield'||a==='class'||a==='super';case 6:return a==='return'||a==='typeof'||a==='delete'||a==='switch'||a==='export'||a==='import';case 7:return a==='default'||a==='finally'||a==='extends';case 8:return a==='function'||a==='continue'||a==='debugger';case 10:return a==='instanceof';default:return!1}}function g(a,b){return a==='null'||a==='true'||a==='false'||f(a,b)}function e(a,b){return a==='null'||a==='true'||a==='false'||d(a,b)}function j(a){return a==='eval'||a==='arguments'}function h(a){var b,e,d;if(a.length===0)return!1;if(d=a.charCodeAt(0),!c.isIdentifierStartES5(d))return!1;for(b=1,e=a.length;b<e;++b)if(d=a.charCodeAt(b),!c.isIdentifierPartES5(d))return!1;return!0}function l(a,b){return(a-55296)*1024+(b-56320)+65536}function i(d){var a,f,b,e,g;if(d.length===0)return!1;for(g=c.isIdentifierStartES6,a=0,f=d.length;a<f;++a){if(b=d.charCodeAt(a),55296<=b&&b<=56319){if(++a,a>=f)return!1;if(e=d.charCodeAt(a),!(56320<=e&&e<=57343))return!1;b=l(b,e)}if(!g(b))return!1;g=c.isIdentifierPartES6}return!0}function n(a,b){return h(a)&&!g(a,b)}function k(a,b){return i(a)&&!e(a,b)}c=a('/node_modules/esutils/lib/code.js',b),b.exports={isKeywordES5:f,isKeywordES6:d,isReservedWordES5:g,isReservedWordES6:e,isRestrictedWord:j,isIdentifierNameES5:h,isIdentifierNameES6:i,isIdentifierES5:n,isIdentifierES6:k}}()}),a.define('/node_modules/esutils/lib/code.js',function(a,b,c,d){!function(g,f,h,c,d,b){'use strict';function n(a){return 48<=a&&a<=57}function i(a){return 48<=a&&a<=57||97<=a&&a<=102||65<=a&&a<=70}function k(a){return a>=48&&a<=55}function l(a){return a===32||a===9||a===11||a===12||a===160||a>=5760&&h.indexOf(a)>=0}function m(a){return a===10||a===13||a===8232||a===8233}function e(a){if(a<=65535)return String.fromCharCode(a);var b=String.fromCharCode(Math.floor((a-65536)/1024)+55296),c=String.fromCharCode((a-65536)%1024+56320);return b+c}function o(a){return a<128?c[a]:f.NonAsciiIdentifierStart.test(e(a))}function p(a){return a<128?d[a]:f.NonAsciiIdentifierPart.test(e(a))}function q(a){return a<128?c[a]:g.NonAsciiIdentifierStart.test(e(a))}function j(a){return a<128?d[a]:g.NonAsciiIdentifierPart.test(e(a))}for(f={NonAsciiIdentifierStart:/[\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u048A-\u052F\u0531-\u0556\u0559\u0561-\u0587\u05D0-\u05EA\u05F0-\u05F2\u0620-\u064A\u066E\u066F\u0671-\u06D3\u06D5\u06E5\u06E6\u06EE\u06EF\u06FA-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07CA-\u07EA\u07F4\u07F5\u07FA\u0800-\u0815\u081A\u0824\u0828\u0840-\u0858\u08A0-\u08B2\u0904-\u0939\u093D\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BD\u09CE\u09DC\u09DD\u09DF-\u09E1\u09F0\u09F1\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABD\u0AD0\u0AE0\u0AE1\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3D\u0B5C\u0B5D\u0B5F-\u0B61\u0B71\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BD0\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D\u0C58\u0C59\u0C60\u0C61\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD\u0CDE\u0CE0\u0CE1\u0CF1\u0CF2\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D\u0D4E\u0D60\u0D61\u0D7A-\u0D7F\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0E01-\u0E30\u0E32\u0E33\u0E40-\u0E46\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB0\u0EB2\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6\u0EDC-\u0EDF\u0F00\u0F40-\u0F47\u0F49-\u0F6C\u0F88-\u0F8C\u1000-\u102A\u103F\u1050-\u1055\u105A-\u105D\u1061\u1065\u1066\u106E-\u1070\u1075-\u1081\u108E\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is upstream source code licensed under BSD 2-clause. The same goes for the esprima.js in this same directory.

Keeping track of changes to these dependencies over time worries me; we'll need to think more about how to do this. Fauxton uses npm to pull the latest, but so far, we've managed to avoid that for core CouchDB itself.

At a minimum, we need to disclose this in the top-level NOTICE file. It would be best to link there to the original source locations for these.

@janl any advice as our resident JS ecosystem expert?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, the esprima.js that's included here is actually patched from the upstream version (because it implements the spec precisely which we don't want). So we'll always have a slight fork there (two lines if memory serves).

This escodegen.js bit is annoying. I spent some time awhile back trying to figure out how to get a version that's not minified so that tracking changes would be much easier. However I couldn't figure out the JS build system for getting a single file version of it. Any help from resident JS experts there would be quite helpful.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's going to be difficult to maintain. It would be best if, before we merge this, we have at least a README that contains the diffs we apply to esprima.js and a method for applying them, if not a Makefile target (possibly supplemented by npm/webpack/etc tooling that can pull the latest code, apply patches, and build a minified version.

He's probably not yet caught up on email but @janl might be best, or maybe @garrensmith knows someone in the Fauxton team who could help?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @wohali and @davisp. I discussed with Paul, and tried to use 88f8b06 to add necessary information for reference of esprima.js and escodegen.js. Just let me know whether this is fine or anything else to follow?

@wohali
Copy link
Member

wohali commented Dec 12, 2019

@jiangphcn Sounds like we agree on this.

I will review the code more closely tomorrow; I want to understand how sandboxing is affected by the move to SM60, and I want to get some more hands-on time with the code.

@jiangphcn
Copy link
Contributor Author

Sure, thanks @wohali

@wohali
Copy link
Member

wohali commented Dec 13, 2019

@jiangphcn on Debian Buster, I did the following:

sudo apt install libmozjs-60-0 libmozjs-60-dev
git clone https://github.com/apache/couchdb
cd couchdb
git checkout sm60-davisp
./configure --spidermonkey-version 60 -c
make couch

This results in the following warnings at build time:

Compiling priv/couch_js/60/http.cpp
Compiling priv/couch_js/60/main.cpp
In file included from /usr/include/time.h:29,
                 from /usr/include/pthread.h:24,
                 from /usr/include/x86_64-linux-gnu/c++/8/bits/gthr-default.h:35,
                 from /usr/include/x86_64-linux-gnu/c++/8/bits/gthr.h:148,
                 from /usr/include/c++/8/ext/atomicity.h:35,
                 from /usr/include/c++/8/bits/basic_string.h:39,
                 from /usr/include/c++/8/string:52,
                 from /usr/include/c++/8/stdexcept:39,
                 from /usr/include/c++/8/array:39,
                 from /usr/include/mozjs-60/mozilla/Span.h:32,
                 from /usr/include/mozjs-60/mozilla/Range.h:12,
                 from /usr/include/mozjs-60/jsapi.h:15,
                 from priv/couch_js/60/main.cpp:23:
/usr/include/mozjs-60/js/Proxy.h: In static member function 'static size_t js::BaseProxyHandler::offsetOfFamily()':
/usr/include/mozjs-60/js/Proxy.h:212:25: warning: offsetof within non-standard-layout type 'js::BaseProxyHandler' is conditionally-supported [-Winvalid-offsetof]
         return offsetof(BaseProxyHandler, mFamily);
                         ^
priv/couch_js/60/main.cpp: In function 'bool req_ctor(JSContext*, unsigned int, JS::Value*)':
priv/couch_js/60/main.cpp:90:32: warning: too many arguments for format [-Wformat-extra-args]
         JS_ReportErrorUTF8(cx, "Failed to create CouchHTTP instance.\n", NULL);
                                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Compiling priv/couch_js/60/utf8.cpp
In file included from /usr/include/strings.h:23,
                 from /usr/include/string.h:431,
                 from /usr/include/c++/8/cstring:42,
                 from /usr/include/mozjs-60/mozilla/Span.h:33,
                 from /usr/include/mozjs-60/mozilla/Range.h:12,
                 from /usr/include/mozjs-60/jsapi.h:15,
                 from priv/couch_js/60/utf8.cpp:13:
/usr/include/mozjs-60/js/Proxy.h: In static member function 'static size_t js::BaseProxyHandler::offsetOfFamily()':
/usr/include/mozjs-60/js/Proxy.h:212:25: warning: offsetof within non-standard-layout type 'js::BaseProxyHandler' is conditionally-supported [-Winvalid-offsetof]
         return offsetof(BaseProxyHandler, mFamily);
                         ^

Do you see these as well?

I do see that make javascript passes, which is good. Next step for me is to read the code a bit more closely. @davisp if you're able to describe the changes you're making to the upstream JS libraries that'd be most useful.

I have asked @tilgovi to look at the sandboxing for this code and SM60. He says he hopes to have time this weekend for a code review.

@jiangphcn
Copy link
Contributor Author

Thanks Joan @wohali. I only saw two of them before.

In file included from priv/couch_js/main.cpp:26:
In file included from /usr/local/include/mozjs-60/js/Wrapper.h:12:
/usr/local/include/mozjs-60/js/Proxy.h:212:16: warning: offset of on non-standard-layout type 'js::BaseProxyHandler' [-Winvalid-offsetof]
        return offsetof(BaseProxyHandler, mFamily);

In file included from priv/couch_js/utf8.cpp:16:
In file included from /usr/local/include/mozjs-60/js/Wrapper.h:12:
/usr/local/include/mozjs-60/js/Proxy.h:212:16: warning: offset of on non-standard-layout type 'js::BaseProxyHandler' [-Winvalid-offsetof]
        return offsetof(BaseProxyHandler, mFamily);
                       ^

Above looks to be related to spidermonkey so I leave them for now.

However, I addressed the second one in your list using f6830c9.

Also, thank you for involving more people on this PR.

Copy link
Member

@davisp davisp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall this looks good. I had a few comments and questions inline.

One thing I'm not seeing is where you moved the 1.8.5 JS files. I may be missing them in the diff but it looks like maybe they're missing from this PR? Also do we actually need two versions of those? If memory serves the changes were minimal and were just slightly different syntactically. Can we not just tweak the few places to run on both 1.8.5 and 60 both?


JS::CompileOptions opts(cx);
JS::RootedValue rval(cx);
opts.setFileAndLine(__FILE__, __LINE__);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is wrong. You're setting the filename and line number of the javascript code to "main.cpp", 258. With 1.8.5 we would set this to an optional second paramter and hard code the start line to 1 (which is appropriate when you're doing the equivalent of evaling a whole file.

Copy link
Contributor Author

@jiangphcn jiangphcn Dec 17, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, as you mentioned, there is different parameters for eval in spidermonkey 6.0. I replaced it with "<unknown>", 1


// Compile and run
JS::CompileOptions options(cx);
options.setFileAndLine(__FILE__, __LINE__);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as above about setting file/line numbers.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here the __FILE__ should be args->scripts[i] which is easier. __LINE__ should still be 1.

@@ -215,11 +215,6 @@ couchTests.reader_acl = function(debug) {
);

usersDb.deleteDb();
// have to delete the backside version now too :(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we removing these cleanup bits in tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We used 15986 here. As you suggested, I changed to _node instead.

@@ -154,7 +154,7 @@ couchTests.view_errors = function(debug) {
db.view("infinite/infinite_loop");
T(0 == 1);
} catch(e) {
T(e.error == "os_process_error");

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this removed? If this test passes then we should be asserting that we have the expected error here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is different error generated for spidermonkey 6.0. I added both for that now 9d1cb18#diff-4aba4f69c2f30c9686f1c16ea474a9ddR157

@davisp
Copy link
Member

davisp commented Dec 16, 2019

I'll compile and run make javascript on both 1.8.5 and 60 and report back.

@jiangphcn
Copy link
Contributor Author

thanks @davisp. The javascript layout for spidermonkey 1.8.5 and 60 can be seen from https://github.com/apache/couchdb/pull/2345/files#diff-a28dc96b01dfdd66c40acdcc4704ea16R44. In general, there are 3 files to be changed in 1.8.5 for 60. They are not missing. I will try to see whether we can unify them today. Of course, esprima.js and escodegen.js are only for spidermonkey 60.

@jiangphcn jiangphcn force-pushed the sm60-davisp branch 4 times, most recently from ab0f573 to 9d1cb18 Compare December 17, 2019 10:05
@jiangphcn
Copy link
Contributor Author

hey Paul, @davisp I think that I addressed all existing comments from your side. Would you please take another look at them when getting time? The left is esprima.js and escodegen.js.

@jiangphcn jiangphcn force-pushed the sm60-davisp branch 3 times, most recently from cdf82ea to f0f583a Compare December 17, 2019 15:31
Copy link
Member

@wohali wohali left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very minor changes; I will approve (since I won't be back to look at this again until after 12/25) but please review my comments.

@@ -850,6 +850,61 @@ FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
OTHER DEALINGS IN THE FONT SOFTWARE.


for share/server/60/esprima.js
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good.

We still need to place a copy of these upstream dependencies untouched into an Apache repository, as @janl said on IRC. If we made modifications, we should track those in a branch in that repo as well. If we can't solve the build problem now (how to generate these files from those repos), please open a new ticket and mention Jan and Garren in it so we can look at fixing that for the future.

I want to be sure that if these libraries change in the future, we can easily absorb the fixes and improvements into our code, especially if they're security-related patches.

@davisp can help you with the repo importation into Apache, he's done it recently for part of the 4.0 libraries.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your suggestions, @wohali I created #2372 for now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wohali @jiangphcn Yap, will do that in a few minute after I finish testing this PR.

"@
$InstallMk | Out-File "$rootdir\install.mk" -encoding ascii

$lowercurl = "$WithCurl".ToLower()
$ConfigERL = @"
{with_curl, $lowercurl}.
{spidermonkey_version, "$SpiderMonkeyVersion"}.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for doing both configure and configure.ps1.

" default is 64 MiB\n"
" -u FILE path to a .uri file containing the address\n"
" (or addresses) of one or more servers\n"
" --eval Enable runtime code evaluation (dangerous!)\n"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally we should manually test -S <size> and --eval as I know multiple users who need these options immediately. I don't think we a test case set up for either of these, unfortunately, because changing launch options isn't easy. Sorry that I ran out of time for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for your tip. I will test them manually at least.

{
"-DHAVE_CURL",
"-DHAVE_CURL -lcurl"
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes look right. If we've broken a platform we haven't tested (like freebsd) we can fix it before we release.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, currently, I tested against

  • xenial for linux
  • MacOS
  • Windows 10

We can react if there is more issue before release.

@@ -154,7 +154,7 @@ couchTests.view_errors = function(debug) {
db.view("infinite/infinite_loop");
T(0 == 1);
} catch(e) {
T(e.error == "os_process_error");
T(e.error == "os_process_error" || e.error == "unnamed_error");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a difference between 1.8.5 and 60? If so, is there any better error message we can emit? unnamed_error is a bit worrying, but if we really don't know, there's not much we can do.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, they are different. For 1.8.5, we have os_process_error while it is unnamed_error in 6.0. Took some time to get better error message, but don't get bottom yet. So stayed with this for now.

@wohali
Copy link
Member

wohali commented Dec 18, 2019

Thanks again @jiangphcn .

@tilgovi
Copy link
Contributor

tilgovi commented Dec 18, 2019

Apologies, but I've not gotten to this yet. I plan to do so this week.

@jiangphcn
Copy link
Contributor Author

jiangphcn commented Dec 18, 2019

Thanks again @wohali and @tilgovi. I will take care of these comments. And enjoy your coming holidays.

// If we have a function declaration without an Id, wrap it
// in an ExpressionStatement and change it into
// a FuntionExpression
if (decl.type == "FunctionDeclaration" && decl.id == null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm trying to reproduce such a parse tree with the esprima online parser, and I just get errors for things like this:

function(doc) {}

Here's a link: https://esprima.org/demo/parse.html?code=function(doc)%20%7B%7D

Does this actually parse both forms we want it to?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks that the esprima online parser doesn't like function(doc) {}. Using esprima in this PR, we can have output. I tried both (function (doc) {emit(doc._id, doc._id);}); and function (doc) {emit(doc._id, doc._id);}. The result are listed below respectively.

(function (doc) {emit(doc._id, doc._id);});

{"type":"Program","body":[{"type":"ExpressionStatement","expression":{"type":"FunctionExpression","id":null,"params":[{"type":"Identifier","name":"doc"}],"body":{"type":"BlockStatement","body":[{"type":"ExpressionStatement","expression":{"type":"CallExpression","callee":{"type":"Identifier","name":"emit"},"arguments":[{"type":"MemberExpression","computed":false,"object":{"type":"Identifier","name":"doc"},"property":{"type":"Identifier","name":"_id"}},{"type":"MemberExpression","computed":false,"object":{"type":"Identifier","name":"doc"},"property":{"type":"Identifier","name":"_id"}}]}}]},"generator":false,"expression":false,"async":false}}],"sourceType":"script"}

function (doc) {emit(doc._id, doc._id);}

{"type":"Program","body":[{"type":"FunctionDeclaration","id":null,"params":[{"type":"Identifier","name":"doc"}],"body":{"type":"BlockStatement","body":[{"type":"ExpressionStatement","expression":{"type":"CallExpression","callee":{"type":"Identifier","name":"emit"},"arguments":[{"type":"MemberExpression","computed":false,"object":{"type":"Identifier","name":"doc"},"property":{"type":"Identifier","name":"_id"}},{"type":"MemberExpression","computed":false,"object":{"type":"Identifier","name":"doc"},"property":{"type":"Identifier","name":"_id"}}]}}]},"generator":false,"expression":false,"async":false}],"sourceType":"script"}

One is ExpressionStatement while another is FunctionDeclaration

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tilgovi The esprima used by this PR is patched to avoid that error so that we can rewrite it. Basically we have to violate the spec as existed in old SpiderMonkey so we can tweak the AST so that it conforms. One of the to-do items we have is to extract that patch so we can apply it to a standard esprima.js to show the diff better.

If memory serves it's something like two lines to remove a boolean check for that "anonymous function at global scope" error.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, that's the context I was forgetting. Thank you, both!

share/server/dreyfus.js Outdated Show resolved Hide resolved
share/server/views.js Outdated Show resolved Hide resolved
@tilgovi
Copy link
Contributor

tilgovi commented Dec 18, 2019

I'll pick up more review tomorrow. This is looking good!

@davisp
Copy link
Member

davisp commented Dec 18, 2019

I've tested make javascript on both ./configure --dev and ./configure --dev --spidermonkey-version=1.8.5 and that passes. Having moved on to using --spidermonkey-version=60 I'm getting these errors consistently:

Error: chttpd_view_test:chttpd_view_test:75 should_succeed_on_view_with_queries_keys

::in function lists:nth/2 (lists.erl, line 170)
  called as nth(1,undefined)
in call from chttpd_view_test:'-should_succeed_on_view_with_queries_keys/1-fun-2-'/1 (test/eunit/chttpd_view_test.erl, line 85)
**error:function_clause

Error: chttpd_view_test:chttpd_view_test:91 should_succeed_on_view_with_queries_limit_skip

::in function chttpd_view_test:'-should_succeed_on_view_with_queries_limit_skip/1-fun-1-'/1 (test/eunit/chttpd_view_test.erl, line 98)
in call from chttpd_view_test:'-should_succeed_on_view_with_queries_limit_skip/1-fun-4-'/1 (test/eunit/chttpd_view_test.erl, line 98)
**error:{assertEqual,[{module,chttpd_view_test},
              {line,98},
              {expression,"RC"},
              {expected,200},
              {value,404}]}

Error: chttpd_view_test:chttpd_view_test:108 should_succeed_on_view_with_multiple_queries

::in function chttpd_view_test:'-should_succeed_on_view_with_multiple_queries/1-fun-1-'/1 (test/eunit/chttpd_view_test.erl, line 116)
in call from chttpd_view_test:'-should_succeed_on_view_with_multiple_queries/1-fun-5-'/1 (test/eunit/chttpd_view_test.erl, line 116)
**error:{assertEqual,[{module,chttpd_view_test},
              {line,116},
              {expression,"RC"},
              {expected,200},
              {value,404}]}

Error: chttpd_security_tests:fixture setup [39,1,1,14]

::in function chttpd_security_tests:create_user/4 (test/eunit/chttpd_security_tests.erl, line 91)
in call from chttpd_security_tests:setup/0 (test/eunit/chttpd_security_tests.erl, line 51)
**error:{badmatch,{ok,500,
              [{"Cache-Control","must-revalidate"},
               {"Content-Length","5555"},
               {"Content-Type","application/json"},
               {"Date","Wed, 18 Dec 2019 16:07:37 GMT"},
               {"Server","CouchDB/3.0.0-61486a5e4 (Erlang OTP/20)"},
               {"X-Couch-Request-ID","7707c95a33"},
               {"X-CouchDB-Body-Time","0"}],
              <<"{\"error\":\"compilation_error\",\"reason\":\"(new SyntaxError(\\\"function statement requires a name\\\", \\\"<unknown>\\\", 2)) (\\n    function(newDoc, oldDoc, userCtx, secObj) {\\n        if (newDoc._deleted === true) {\\n            // allow deletes by admins and matching users\\n            // without checking the other fields\\n            if ((userCtx.roles.indexOf('_admin') !== -1"...>>}}

I haven't looked at them in any depth. That last one is obviously us missing a call to rewriteFun somewhere though.

@davisp
Copy link
Member

davisp commented Dec 18, 2019

Also we should rebase this against master which includes those fixes for JavaScript tests.

@davisp
Copy link
Member

davisp commented Dec 18, 2019

I've created the requested mirrors:

https://github.com/apache/couchdb-esprima
https://github.com/apache/couchdb-escodegen

The esprima repo in particular is nearly 60MiB so we'll want to figure out some sort of script to avoid having to download that for every build. Not sure how all the JS tooling works for that sort of thing.

@davisp
Copy link
Member

davisp commented Dec 18, 2019

Finally managed to get the esprima.js thing "compiled" and importable into SpiderMonkey. In the couchdb-esprima repo you can do this (assuming you have TypeScript and webpack installed, both available in Homebrew):

tsc -p src/
webpack --mode none

This gives a human readable dist/esprima.js

The patch that CouchDB needs to make this work is:

--- esprima.js	2019-12-18 12:59:30.000000000 -0600
+++ esprima.couchdb.js	2019-12-18 13:05:04.000000000 -0600
@@ -7,7 +7,7 @@
 		exports["esprima"] = factory();
 	else
 		root["esprima"] = factory();
-})(window, function() {
+})(this, function() {
 return /******/ (function(modules) { // webpackBootstrap
 /******/ 	// The module cache
 /******/ 	var installedModules = {};
@@ -3468,7 +3468,9 @@
                     statement = this.parseLexicalDeclaration({ inFor: false });
                     break;
                 case 'function':
-                    statement = this.parseFunctionDeclaration();
+                    // Apache CouchDB modification: add true to tolerate
+                    // missing function identifiers.
+                    statement = this.parseFunctionDeclaration(true);
                     break;
                 case 'class':
                     statement = this.parseClassDeclaration();

@davisp
Copy link
Member

davisp commented Dec 18, 2019

I can't figure out how to get a standalone escodegen.js as it has commonjs stuff and the npm run release script fails. If any JS folks want to take a look at that I'd be much obliged.

@jiangphcn
Copy link
Contributor Author

jiangphcn commented Dec 19, 2019

@davisp Hey Paul, regarding #2345 (comment), it is due to our refactoring of bffa5e6 this week. Removing this line will resolve issue. I also rebased from master along with this change.

@jiangphcn jiangphcn force-pushed the sm60-davisp branch 2 times, most recently from a79cedf to bffa5e6 Compare December 19, 2019 00:33
Copy link
Member

@davisp davisp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 Awesome work @jiangphcn!

This passes all of the test suite including the sandboxing tests. Given that its not the default yet and everything passes I think its fine to go ahead and merge.

@jiangphcn
Copy link
Contributor Author

Thanks @davisp @wohali @janl @tilgovi @garrensmith and all who helped make this happen.

@jiangphcn jiangphcn merged commit 5c8e882 into master Dec 20, 2019
@jiangphcn jiangphcn deleted the sm60-davisp branch December 20, 2019 23:58
This was referenced Dec 23, 2019
@janl
Copy link
Member

janl commented Jan 3, 2020

great job everybody!

@jiangphcn
Copy link
Contributor Author

thanks @janl

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants