How to use write method in stryker-parent

Best JavaScript code snippet using stryker-parent

ParseTreeWriter.js

Source:ParseTreeWriter.js Github

copy

Full Screen

1// Copyright 2011 Google Inc.2//3// Licensed under the Apache License, Version 2.0 (the 'License');4// you may not use this file except in compliance with the License.5// You may obtain a copy of the License at6//7// http://www.apache.org/licenses/LICENSE-2.08//9// Unless required by applicable law or agreed to in writing, software10// distributed under the License is distributed on an 'AS IS' BASIS,11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12// See the License for the specific language governing permissions and13// limitations under the License.14traceur.define('outputgeneration', function() {15 'use strict';16 var ParseTreeVisitor = traceur.syntax.ParseTreeVisitor;17 var PredefinedName = traceur.syntax.PredefinedName;18 var Keywords = traceur.syntax.Keywords;19 var TokenType = traceur.syntax.TokenType;20 var StringBuilder = traceur.util.StringBuilder;21 /**22 * Converts a ParseTree to text.23 * @param {ParseTree} highlighted24 * @param {boolean} showLineNumbers25 * @constructor26 */27 function ParseTreeWriter(highlighted, showLineNumbers) {28 ParseTreeVisitor.call(this);29 this.highlighted_ = highlighted;30 this.showLineNumbers_ = showLineNumbers;31 this.result_ = new StringBuilder();32 this.currentLine_ = new StringBuilder();33 }34 // constants35 var NEW_LINE = '\n';36 var PRETTY_PRINT = true;37 ParseTreeWriter.prototype = traceur.createObject(38 ParseTreeVisitor.prototype, {39 /**40 * @type {string}41 * @private42 */43 currentLineComment_: null,44 /**45 * @type {number}46 * @private47 */48 indentDepth_: 0,49 /**50 * @param {ParseTree} tree51 */52 visitAny: function(tree) {53 if (!tree) {54 return;55 }56 57 // set background color to red if tree is highlighted58 if (tree === this.highlighted_) {59 this.write_('\x1B[41m');60 }61 if (tree.location !== null &&62 tree.location.start !== null && this.showLineNumbers_) {63 var line = tree.location.start.line + 1;64 var column = tree.location.start.column;65 this.currentLineComment_ = 'Line: ' + line + '.' + column;66 }67 68 this.currentLocation = tree.location;69 70 ParseTreeVisitor.prototype.visitAny.call(this, tree);71 // set background color to normal72 if (tree === this.highlighted_) {73 this.write_('\x1B[0m');74 }75 },76 /**77 * @param {ArgumentList} tree78 */79 visitArgumentList: function(tree) {80 this.write_(TokenType.OPEN_PAREN);81 this.writeList_(tree.args, TokenType.COMMA, false);82 this.write_(TokenType.CLOSE_PAREN);83 },84 visitArrayComprehension: function(tree) {85 this.write_(TokenType.OPEN_SQUARE);86 this.visitAny(tree.expression);87 this.visitList(tree.comprehensionForList);88 if (tree.ifExpression) {89 this.write_(TokenType.IF);90 this.visitAny(tree.ifExpression);91 }92 this.write_(TokenType.CLOSE_SQUARE);93 },94 /**95 * @param {ArrayLiteralExpression} tree96 */97 visitArrayLiteralExpression: function(tree) {98 this.write_(TokenType.OPEN_SQUARE);99 this.writeList_(tree.elements, TokenType.COMMA, false);100 this.write_(TokenType.CLOSE_SQUARE);101 },102 /**103 * @param {ArrayPattern} tree104 */105 visitArrayPattern: function(tree) {106 this.write_(TokenType.OPEN_SQUARE);107 this.writeList_(tree.elements, TokenType.COMMA, false);108 this.write_(TokenType.CLOSE_SQUARE);109 },110 /**111 * @param {traceur.syntax.trees.ArrowFunctionExpression} tree112 */113 visitArrowFunctionExpression: function(tree) {114 this.write_(TokenType.OPEN_PAREN);115 this.visitAny(tree.formalParameters);116 this.write_(TokenType.CLOSE_PAREN);117 this.write_(TokenType.ARROW);118 this.visitAny(tree.functionBody);119 },120 /**121 * @param {AwaitStatement} tree122 */123 visitAwaitStatement: function(tree) {124 this.write_(TokenType.AWAIT);125 if (tree.identifier !== null) {126 this.write_(tree.identifier);127 this.write_(TokenType.EQUAL);128 }129 this.visitAny(tree.expression);130 this.write_(TokenType.SEMI_COLON);131 },132 /**133 * @param {BinaryOperator} tree134 */135 visitBinaryOperator: function(tree) {136 this.visitAny(tree.left);137 this.write_(tree.operator);138 this.visitAny(tree.right);139 },140 /**141 * @param {BindThisParameter} tree142 */143 visitBindThisParameter: function(tree) {144 this.write_(TokenType.THIS);145 this.write_(TokenType.EQUAL);146 this.visitAny(tree.expression);147 },148 /**149 * @param {BindingElement} tree150 */151 visitBindingElement: function(tree) {152 this.visitAny(tree.binding);153 if (tree.initializer) {154 this.write_(TokenType.EQUAL);155 this.visitAny(tree.initializer);156 }157 },158 /**159 * @param {BindingIdentifier} tree160 */161 visitBindingIdentifier: function(tree) {162 this.write_(tree.identifierToken);163 },164 /**165 * @param {Block} tree166 */167 visitBlock: function(tree) {168 this.write_(TokenType.OPEN_CURLY);169 this.writelnList_(tree.statements);170 this.write_(TokenType.CLOSE_CURLY);171 },172 /**173 * @param {BreakStatement} tree174 */175 visitBreakStatement: function(tree) {176 this.write_(TokenType.BREAK);177 if (tree.name !== null) {178 this.write_(tree.name);179 }180 this.write_(TokenType.SEMI_COLON);181 },182 /**183 * @param {CallExpression} tree184 */185 visitCallExpression: function(tree) {186 this.visitAny(tree.operand);187 this.visitAny(tree.args);188 },189 /**190 * @param {CaseClause} tree191 */192 visitCaseClause: function(tree) {193 this.write_(TokenType.CASE);194 this.visitAny(tree.expression);195 this.write_(TokenType.COLON);196 this.indentDepth_++;197 this.writelnList_(tree.statements);198 this.indentDepth_--;199 },200 /**201 * @param {Catch} tree202 */203 visitCatch: function(tree) {204 this.write_(TokenType.CATCH);205 this.write_(TokenType.OPEN_PAREN);206 this.visitAny(tree.binding);207 this.write_(TokenType.CLOSE_PAREN);208 this.visitAny(tree.catchBody);209 },210 /**211 * @param {ChaineExpression} tree212 */213 visitCascadeExpression: function(tree) {214 this.visitAny(tree.operand);215 this.write_(TokenType.PERIOD_OPEN_CURLY);216 this.writelnList_(tree.expressions, TokenType.SEMI_COLON, false);217 this.write_(TokenType.CLOSE_CURLY);218 },219 visitClassShared_: function(tree) {220 this.write_(TokenType.CLASS);221 if (tree.name) 222 this.write_(tree.name);223 if (tree.superClass !== null) {224 this.write_(TokenType.EXTENDS);225 this.visitAny(tree.superClass);226 }227 this.write_(TokenType.OPEN_CURLY);228 this.writelnList_(tree.elements);229 this.write_(TokenType.CLOSE_CURLY);230 },231 /**232 * @param {ClassDeclaration} tree233 */234 visitClassDeclaration: function(tree) {235 this.visitClassShared_(tree);236 },237 /**238 * @param {ClassExpression} tree239 */240 visitClassExpression: function(tree) {241 this.visitClassShared_(tree);242 },243 /**244 * @param {CommaExpression} tree245 */246 visitCommaExpression: function(tree) {247 this.writeList_(tree.expressions, TokenType.COMMA, false);248 },249 visitComprehensionFor: function(tree) {250 this.write_(TokenType.FOR);251 this.visitAny(tree.left);252 this.write_(PredefinedName.OF);253 this.visitAny(tree.iterator);254 },255 /**256 * @param {ConditionalExpression} tree257 */258 visitConditionalExpression: function(tree) {259 this.visitAny(tree.condition);260 this.write_(TokenType.QUESTION);261 this.visitAny(tree.left);262 this.write_(TokenType.COLON);263 this.visitAny(tree.right);264 },265 /**266 * @param {ContinueStatement} tree267 */268 visitContinueStatement: function(tree) {269 this.write_(TokenType.CONTINUE);270 if (tree.name !== null) {271 this.write_(tree.name);272 }273 this.write_(TokenType.SEMI_COLON);274 },275 /**276 * @param {DebuggerStatement} tree277 */278 visitDebuggerStatement: function(tree) {279 this.write_(TokenType.DEBUGGER);280 this.write_(TokenType.SEMI_COLON);281 },282 /**283 * @param {DefaultClause} tree284 */285 visitDefaultClause: function(tree) {286 this.write_(TokenType.DEFAULT);287 this.write_(TokenType.COLON);288 this.indentDepth_++;289 this.writelnList_(tree.statements);290 this.indentDepth_--;291 },292 /**293 * @param {DoWhileStatement} tree294 */295 visitDoWhileStatement: function(tree) {296 this.write_(TokenType.DO);297 this.visitAny(tree.body);298 this.write_(TokenType.WHILE);299 this.write_(TokenType.OPEN_PAREN);300 this.visitAny(tree.condition);301 this.write_(TokenType.CLOSE_PAREN);302 this.write_(TokenType.SEMI_COLON);303 },304 /**305 * @param {EmptyStatement} tree306 */307 visitEmptyStatement: function(tree) {308 this.write_(TokenType.SEMI_COLON);309 },310 /**311 * @param {ExportDeclaration} tree312 */313 visitExportDeclaration: function(tree) {314 this.write_(TokenType.EXPORT);315 this.visitAny(tree.declaration);316 },317 /**318 * @param {traceur.syntax.trees.ExportMappingList} tree319 */320 visitExportMappingList: function(tree) {321 this.writeList_(tree.paths, TokenType.COMMA, false);322 },323 /**324 * @param {traceur.syntax.trees.ExportMapping} tree325 */326 visitExportMapping: function(tree) {327 this.visitAny(tree.specifierSet);328 if (tree.moduleExpression) {329 this.write_(PredefinedName.FROM);330 this.visitAny(tree.moduleExpression);331 }332 },333 /**334 * @param {traceur.syntax.trees.ExportSpecifier} tree335 */336 visitExportSpecifier: function(tree) {337 this.write_(tree.lhs);338 if (tree.rhs) {339 this.write_(TokenType.COLON);340 this.write_(tree.rhs);341 }342 },343 /**344 * @param {traceur.syntax.trees.ExportSpecifierSet} tree345 */346 visitExportSpecifierSet: function(tree) {347 this.write_(TokenType.OPEN_CURLY);348 this.writeList_(tree.specifiers, TokenType.COMMA, false);349 this.write_(TokenType.CLOSE_CURLY);350 },351 /**352 * @param {ExpressionStatement} tree353 */354 visitExpressionStatement: function(tree) {355 this.visitAny(tree.expression);356 this.write_(TokenType.SEMI_COLON);357 },358 /**359 * @param {Finally} tree360 */361 visitFinally: function(tree) {362 this.write_(TokenType.FINALLY);363 this.visitAny(tree.block);364 },365 /**366 * @param {ForOfStatement} tree367 */368 visitForOfStatement: function(tree) {369 this.write_(TokenType.FOR);370 this.write_(TokenType.OPEN_PAREN);371 this.visitAny(tree.initializer);372 this.write_(PredefinedName.OF);373 this.visitAny(tree.collection);374 this.write_(TokenType.CLOSE_PAREN);375 this.visitAny(tree.body);376 },377 /**378 * @param {ForInStatement} tree379 */380 visitForInStatement: function(tree) {381 this.write_(TokenType.FOR);382 this.write_(TokenType.OPEN_PAREN);383 this.visitAny(tree.initializer);384 this.write_(TokenType.IN);385 this.visitAny(tree.collection);386 this.write_(TokenType.CLOSE_PAREN);387 this.visitAny(tree.body);388 },389 /**390 * @param {ForStatement} tree391 */392 visitForStatement: function(tree) {393 this.write_(TokenType.FOR);394 this.write_(TokenType.OPEN_PAREN);395 this.visitAny(tree.initializer);396 this.write_(TokenType.SEMI_COLON);397 this.visitAny(tree.condition);398 this.write_(TokenType.SEMI_COLON);399 this.visitAny(tree.increment);400 this.write_(TokenType.CLOSE_PAREN);401 this.visitAny(tree.body);402 },403 /**404 * @param {FormalParameterList} tree405 */406 visitFormalParameterList: function(tree) {407 var first = true;408 for (var i = 0; i < tree.parameters.length; i++) {409 var parameter = tree.parameters[i];410 if (first) {411 first = false;412 } else {413 this.write_(TokenType.COMMA);414 }415 this.visitAny(parameter);416 }417 },418 /**419 * @param {FunctionDeclaration} tree420 */421 visitFunctionDeclaration: function(tree) {422 this.write_(Keywords.FUNCTION);423 if (tree.isGenerator) {424 this.write_(TokenType.STAR);425 }426 this.visitAny(tree.name);427 this.write_(TokenType.OPEN_PAREN);428 this.visitAny(tree.formalParameterList);429 this.write_(TokenType.CLOSE_PAREN);430 this.visitAny(tree.functionBody);431 },432 visitGeneratorComprehension: function(tree) {433 this.write_(TokenType.OPEN_PAREN);434 this.visitAny(tree.expression);435 this.visitList(tree.comprehensionForList);436 if (tree.ifExpression) {437 this.write_(TokenType.IF);438 this.visitAny(tree.ifExpression);439 }440 this.write_(TokenType.CLOSE_PAREN);441 },442 /**443 * @param {GetAccessor} tree444 */445 visitGetAccessor: function(tree) {446 this.write_(PredefinedName.GET);447 this.write_(tree.propertyName);448 this.write_(TokenType.OPEN_PAREN);449 this.write_(TokenType.CLOSE_PAREN);450 this.visitAny(tree.body);451 },452 /**453 * @param {IdentifierExpression} tree454 */455 visitIdentifierExpression: function(tree) {456 this.write_(tree.identifierToken);457 },458 /**459 * @param {IfStatement} tree460 */461 visitIfStatement: function(tree) {462 this.write_(TokenType.IF);463 this.write_(TokenType.OPEN_PAREN);464 this.visitAny(tree.condition);465 this.write_(TokenType.CLOSE_PAREN);466 this.visitAny(tree.ifClause);467 if (tree.elseClause) {468 this.write_(TokenType.ELSE);469 this.visitAny(tree.elseClause);470 }471 },472 /**473 * @param {ImportDeclaration} tree474 */475 visitImportDeclaration: function(tree) {476 this.write_(TokenType.IMPORT);477 this.writeList_(tree.importPathList, TokenType.COMMA, false);478 this.write_(TokenType.SEMI_COLON);479 },480 /**481 * @param {ImportBinding} tree482 */483 visitImportBinding: function(tree) {484 this.visitAny(tree.importSpecifierSet);485 if (tree.moduleExpression) {486 this.write_(PredefinedName.FROM);487 this.visitAny(tree.moduleExpression);488 }489 },490 /**491 * @param {ImportSpecifier} tree492 */493 visitImportSpecifier: function(tree) {494 this.write_(tree.importedName);495 if (tree.destinationName !== null) {496 this.write_(TokenType.COLON);497 this.write_(tree.destinationName);498 }499 },500 visitImportSpecifierSet: function(tree) {501 if (tree.specifiers.type == TokenType.STAR)502 this.write_(TokenType.STAR);503 else504 this.visitList(tree.specifiers);505 },506 /**507 * @param {LabelledStatement} tree508 */509 visitLabelledStatement: function(tree) {510 this.write_(tree.name);511 this.write_(TokenType.COLON);512 this.visitAny(tree.statement);513 },514 /**515 * @param {LiteralExpression} tree516 */517 visitLiteralExpression: function(tree) {518 this.write_(tree.literalToken);519 },520 /**521 * @param {MemberExpression} tree522 */523 visitMemberExpression: function(tree) {524 this.visitAny(tree.operand);525 this.write_(TokenType.PERIOD);526 this.write_(tree.memberName);527 },528 /**529 * @param {MemberLookupExpression} tree530 */531 visitMemberLookupExpression: function(tree) {532 this.visitAny(tree.operand);533 this.write_(TokenType.OPEN_SQUARE);534 this.visitAny(tree.memberExpression);535 this.write_(TokenType.CLOSE_SQUARE);536 },537 /**538 * @param {MissingPrimaryExpression} tree539 */540 visitMissingPrimaryExpression: function(tree) {541 this.write_('MissingPrimaryExpression');542 },543 /**544 * @param {ModuleDeclarationfinitionTree} tree545 */546 visitModuleDeclaration: function(tree) {547 this.write_(PredefinedName.MODULE);548 this.writeList_(tree.specifiers, TokenType.COMMA, false);549 this.write_(TokenType.SEMI_COLON);550 },551 /**552 * @param {ModuleDefinition} tree553 */554 visitModuleDefinition: function(tree) {555 this.write_(PredefinedName.MODULE);556 this.write_(tree.name);557 this.write_(TokenType.OPEN_CURLY);558 this.writeln_();559 this.writeList_(tree.elements, null, true);560 this.write_(TokenType.CLOSE_CURLY);561 this.writeln_();562 },563 /**564 * @param {ModuleExpression} tree565 */566 visitModuleExpression: function(tree) {567 this.visitAny(tree.reference);568 for (var i = 0; i < tree.identifiers.length; i++) {569 this.write_(TokenType.PERIOD);570 this.write_(tree.identifiers[i]);571 }572 },573 /**574 * @param {ModuleRequire} tree575 */576 visitModuleRequire: function(tree) {577 this.write_(tree.url);578 },579 /**580 * @param {ModuleSpecifier} tree581 */582 visitModuleSpecifier: function(tree) {583 this.write_(tree.identifier);584 this.write_(PredefinedName.FROM);585 this.visitAny(tree.expression);586 },587 /**588 * @param {NewExpression} tree589 */590 visitNewExpression: function(tree) {591 this.write_(TokenType.NEW);592 this.visitAny(tree.operand);593 this.visitAny(tree.args);594 },595 /**596 * @param {NullTree} tree597 */598 visitNullTree: function(tree) {599 },600 /**601 * @param {ObjectLiteralExpression} tree602 */603 visitObjectLiteralExpression: function(tree) {604 this.write_(TokenType.OPEN_CURLY);605 if (tree.propertyNameAndValues.length > 1)606 this.writeln_();607 this.writelnList_(tree.propertyNameAndValues, TokenType.COMMA);608 if (tree.propertyNameAndValues.length > 1)609 this.writeln_();610 this.write_(TokenType.CLOSE_CURLY);611 },612 /**613 * @param {ObjectPattern} tree614 */615 visitObjectPattern: function(tree) {616 this.write_(TokenType.OPEN_CURLY);617 this.writelnList_(tree.fields, TokenType.COMMA);618 this.write_(TokenType.CLOSE_CURLY);619 },620 /**621 * @param {ObjectPatternField} tree622 */623 visitObjectPatternField: function(tree) {624 this.write_(tree.identifier);625 if (tree.element !== null) {626 this.write_(TokenType.COLON);627 this.visitAny(tree.element);628 }629 },630 /**631 * @param {ParenExpression} tree632 */633 visitParenExpression: function(tree) {634 this.write_(TokenType.OPEN_PAREN);635 ParseTreeVisitor.prototype.visitParenExpression.call(this, tree);636 this.write_(TokenType.CLOSE_PAREN);637 },638 /**639 * @param {PostfixExpression} tree640 */641 visitPostfixExpression: function(tree) {642 this.visitAny(tree.operand);643 this.write_(tree.operator);644 },645 /**646 * @param {Program} tree647 */648 visitProgram: function(tree) {649 this.writelnList_(tree.programElements);650 },651 /**652 * @param {PropertyMethodAssignment} tree653 */654 visitPropertyMethodAssignment: function(tree) {655 if (tree.isGenerator)656 this.write_(TokenType.STAR);657 this.write_(tree.name);658 this.write_(TokenType.OPEN_PAREN);659 this.visitAny(tree.formalParameterList);660 this.write_(TokenType.CLOSE_PAREN);661 this.visitAny(tree.functionBody);662 },663 /**664 * @param {PropertyNameAssignment} tree665 */666 visitPropertyNameAssignment: function(tree) {667 this.write_(tree.name);668 this.write_(TokenType.COLON);669 this.visitAny(tree.value);670 },671 /**672 * @param {PropertyNameShorthand} tree673 */674 visitPropertyNameShorthand: function(tree) {675 this.write_(tree.name);676 },677 /**678 * @param {traceur.syntax.trees.QuasiLiteralExpression} tree679 */680 visitQuasiLiteralExpression: function(tree) {681 // Quasi Literals have important whitespace semantics.682 this.visitAny(tree.operand);683 this.writeRaw_(TokenType.BACK_QUOTE);684 this.visitList(tree.elements);685 this.writeRaw_(TokenType.BACK_QUOTE);686 },687 /**688 * @param {traceur.syntax.trees.QuasiLiteralPortion} tree689 */690 visitQuasiLiteralPortion: function(tree) {691 this.writeRaw_(tree.value);692 },693 /**694 * @param {traceur.syntax.trees.QuasiSubstitution} tree695 */696 visitQuasiSubstitution: function(tree) {697 this.writeRaw_(TokenType.DOLLAR);698 this.writeRaw_(TokenType.OPEN_CURLY);699 this.visitAny(tree.expression);700 this.writeRaw_(TokenType.CLOSE_CURLY);701 },702 /*703 * @param {RequiresMember} tree704 */705 visitRequiresMember: function(tree) {706 this.write_(PredefinedName.REQUIRES);707 this.write_(tree.name);708 this.write_(TokenType.SEMI_COLON);709 },710 /**711 * @param {ReturnStatement} tree712 */713 visitReturnStatement: function(tree) {714 this.write_(TokenType.RETURN);715 this.visitAny(tree.expression);716 this.write_(TokenType.SEMI_COLON);717 },718 /**719 * @param {RestParameter} tree720 */721 visitRestParameter: function(tree) {722 this.write_(TokenType.DOT_DOT_DOT);723 this.write_(tree.identifier);724 },725 /**726 * @param {SetAccessor} tree727 */728 visitSetAccessor: function(tree) {729 this.write_(PredefinedName.SET);730 this.write_(tree.propertyName);731 this.write_(TokenType.OPEN_PAREN);732 this.visitAny(tree.parameter);733 this.write_(TokenType.CLOSE_PAREN);734 this.visitAny(tree.body);735 },736 /**737 * @param {SpreadExpression} tree738 */739 visitSpreadExpression: function(tree) {740 this.write_(TokenType.DOT_DOT_DOT);741 this.visitAny(tree.expression);742 },743 /**744 * @param {SpreadPatternElement} tree745 */746 visitSpreadPatternElement: function(tree) {747 this.write_(TokenType.DOT_DOT_DOT);748 this.visitAny(tree.lvalue);749 },750 /**751 * @param {StateMachine} tree752 */753 visitStateMachine: function(tree) {754 throw new Error('State machines cannot be converted to source');755 },756 /**757 * @param {SuperExpression} tree758 */759 visitSuperExpression: function(tree) {760 this.write_(TokenType.SUPER);761 },762 /**763 * @param {SwitchStatement} tree764 */765 visitSwitchStatement: function(tree) {766 this.write_(TokenType.SWITCH);767 this.write_(TokenType.OPEN_PAREN);768 this.visitAny(tree.expression);769 this.write_(TokenType.CLOSE_PAREN);770 this.write_(TokenType.OPEN_CURLY);771 this.writelnList_(tree.caseClauses);772 this.write_(TokenType.CLOSE_CURLY);773 },774 /**775 * @param {ThisExpression} tree776 */777 visitThisExpression: function(tree) {778 this.write_(TokenType.THIS);779 },780 /**781 * @param {ThrowStatement} tree782 */783 visitThrowStatement: function(tree) {784 this.write_(TokenType.THROW);785 this.visitAny(tree.value);786 this.write_(TokenType.SEMI_COLON);787 },788 /**789 * @param {TryStatement} tree790 */791 visitTryStatement: function(tree) {792 this.write_(TokenType.TRY);793 this.visitAny(tree.body);794 this.visitAny(tree.catchBlock);795 this.visitAny(tree.finallyBlock);796 },797 /**798 * @param {UnaryExpression} tree799 */800 visitUnaryExpression: function(tree) {801 this.write_(tree.operator);802 this.visitAny(tree.operand);803 },804 /**805 * @param {VariableDeclarationList} tree806 */807 visitVariableDeclarationList: function(tree) {808 this.write_(tree.declarationType);809 this.writeList_(tree.declarations, TokenType.COMMA, false);810 },811 /**812 * @param {VariableDeclaration} tree813 */814 visitVariableDeclaration: function(tree) {815 this.visitAny(tree.lvalue);816 if (tree.initializer !== null) {817 this.write_(TokenType.EQUAL);818 this.visitAny(tree.initializer);819 }820 },821 /**822 * @param {VariableStatement} tree823 */824 visitVariableStatement: function(tree) {825 ParseTreeVisitor.prototype.visitVariableStatement.call(this, tree);826 this.write_(TokenType.SEMI_COLON);827 },828 /**829 * @param {WhileStatement} tree830 */831 visitWhileStatement: function(tree) {832 this.write_(TokenType.WHILE);833 this.write_(TokenType.OPEN_PAREN);834 this.visitAny(tree.condition);835 this.write_(TokenType.CLOSE_PAREN);836 this.visitAny(tree.body);837 },838 /**839 * @param {WithStatement} tree840 */841 visitWithStatement: function(tree) {842 this.write_(TokenType.WITH);843 this.write_(TokenType.OPEN_PAREN);844 this.visitAny(tree.expression);845 this.write_(TokenType.CLOSE_PAREN);846 this.visitAny(tree.body);847 },848 /**849 * @param {YieldStatement} tree850 */851 visitYieldStatement: function(tree) {852 this.write_(TokenType.YIELD);853 if (tree.isYieldFor) {854 this.write_(TokenType.STAR);855 }856 this.visitAny(tree.expression);857 this.write_(TokenType.SEMI_COLON);858 },859 writeln_: function() {860 if (this.currentLineComment_ !== null) {861 while (this.currentLine_.length < 80) {862 this.currentLine_.append(' ');863 }864 this.currentLine_.append(' // ').append(this.currentLineComment_);865 this.currentLineComment_ = null;866 }867 this.result_.append(this.currentLine_.toString());868 this.result_.append(NEW_LINE);869 this.outputLineCount++;870 this.currentLine_ = new StringBuilder();871 },872 /**873 * @param {Array.<ParseTree>} list874 * @param {TokenType} delimiter875 * @private876 */877 writelnList_: function(list, delimiter) {878 if (delimiter) {879 this.writeList_(list, delimiter, true);880 } else {881 if (list.length > 0)882 this.writeln_();883 this.writeList_(list, null, true);884 if (list.length > 0)885 this.writeln_();886 }887 },888 /**889 * @param {Array.<ParseTree>} list890 * @param {TokenType} delimiter891 * @param {boolean} writeNewLine892 * @private893 */894 writeList_: function(list, delimiter, writeNewLine) {895 var first = true;896 for (var i = 0; i < list.length; i++) {897 var element = list[i];898 if (first) {899 first = false;900 } else {901 if (delimiter !== null) {902 this.write_(delimiter);903 }904 if (writeNewLine) {905 this.writeln_();906 }907 }908 this.visitAny(element);909 }910 },911 912 // TODO(jjb) not called 913 writeTokenList_: function(list, delimiter, writeNewLine) {914 var first = true;915 for (var i = 0; i < list.length; i++) {916 var element = list[i];917 if (first) {918 first = false;919 } else {920 if (delimiter !== null) {921 this.write_(delimiter);922 }923 if (writeNewLine) {924 this.writeln_();925 }926 }927 this.write_(element);928 }929 },930 /**931 * @param {string|Token|TokenType|Keywords} value932 * @private933 */934 writeRaw_: function(value) {935 if (value !== null) {936 this.currentLine_.append(value.toString());937 }938 },939 /**940 * @param {string|Token|TokenType|Keywords} value941 * @private942 */943 write_: function(value) {944 if (value === TokenType.CLOSE_CURLY) {945 this.indentDepth_--;946 }947 // Imperfect but good enough spacing rules to make output readable.948 var spaceBefore = true;949 var spaceAfter = true;950 switch (value) {951 case TokenType.PERIOD:952 case TokenType.OPEN_SQUARE:953 case TokenType.OPEN_PAREN:954 case TokenType.CLOSE_SQUARE:955 spaceBefore = false;956 spaceAfter = false;957 break;958 case TokenType.COLON:959 case TokenType.COMMA:960 case TokenType.SEMI_COLON:961 case TokenType.CLOSE_PAREN:962 spaceBefore = false;963 break;964 }965 if (value !== null) {966 if (PRETTY_PRINT) {967 if (this.currentLine_.length === 0) {968 for (var i = 0, indent = this.indentDepth_ * 2; i < indent; ++i) {969 this.currentLine_.append(' ');970 }971 } else {972 if (spaceBefore === false && this.currentLine_.lastChar() === ' ') {973 this.currentLine_.deleteLastChar();974 }975 }976 }977 this.currentLine_.append(value.toString());978 if (spaceAfter) {979 this.currentLine_.append(' ');980 }981 }982 if (value === TokenType.OPEN_CURLY) {983 this.indentDepth_++;984 }985 }986 987 });988 989 return {990 ParseTreeWriter: ParseTreeWriter991 };...

Full Screen

Full Screen

jpeg_encoder_basic.js

Source:jpeg_encoder_basic.js Github

copy

Full Screen

1goog.provide('goog.crypt.JpegEncoder'); 2goog.require('goog.crypt.base64'); 3goog.crypt.JpegEncoder = function(opt_quality) { 4 var self = this; 5 var fround = Math.round; 6 var ffloor = Math.floor; 7 var YTable = new Array(64); 8 var UVTable = new Array(64); 9 var fdtbl_Y = new Array(64); 10 var fdtbl_UV = new Array(64); 11 var YDC_HT; 12 var UVDC_HT; 13 var YAC_HT; 14 var UVAC_HT; 15 var bitcode = new Array(65535); 16 var category = new Array(65535); 17 var outputfDCTQuant = new Array(64); 18 var DU = new Array(64); 19 var byteout =[]; 20 var bytenew = 0; 21 var bytepos = 7; 22 var YDU = new Array(64); 23 var UDU = new Array(64); 24 var VDU = new Array(64); 25 var clt = new Array(256); 26 var RGB_YUV_TABLE = new Array(2048); 27 var currentQuality; 28 var ZigZag =[0, 1, 5, 6, 14, 15, 27, 28, 2, 4, 7, 13, 16, 26, 29, 42, 3, 8, 12, 17, 25, 30, 41, 43, 9, 11, 18, 24, 31, 40, 44, 53, 10, 19, 23, 32, 39, 45, 52, 54, 20, 22, 33, 38, 46, 51, 55, 60, 21, 34, 37, 47, 50, 56, 59, 61, 35, 36, 48, 49, 57, 58, 62, 63]; 29 var std_dc_luminance_nrcodes =[0, 0, 1, 5, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0]; 30 var std_dc_luminance_values =[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]; 31 var std_ac_luminance_nrcodes =[0, 0, 2, 1, 3, 3, 2, 4, 3, 5, 5, 4, 4, 0, 0, 1, 0x7d]; 32 var std_ac_luminance_values =[0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12, 0x21, 0x31, 0x41, 0x06, 0x13, 0x51, 0x61, 0x07, 0x22, 0x71, 0x14, 0x32, 0x81, 0x91, 0xa1, 0x08, 0x23, 0x42, 0xb1, 0xc1, 0x15, 0x52, 0xd1, 0xf0, 0x24, 0x33, 0x62, 0x72, 0x82, 0x09, 0x0a, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa]; 33 var std_dc_chrominance_nrcodes =[0, 0, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0]; 34 var std_dc_chrominance_values =[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]; 35 var std_ac_chrominance_nrcodes =[0, 0, 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0, 1, 2, 0x77]; 36 var std_ac_chrominance_values =[0x00, 0x01, 0x02, 0x03, 0x11, 0x04, 0x05, 0x21, 0x31, 0x06, 0x12, 0x41, 0x51, 0x07, 0x61, 0x71, 0x13, 0x22, 0x32, 0x81, 0x08, 0x14, 0x42, 0x91, 0xa1, 0xb1, 0xc1, 0x09, 0x23, 0x33, 0x52, 0xf0, 0x15, 0x62, 0x72, 0xd1, 0x0a, 0x16, 0x24, 0x34, 0xe1, 0x25, 0xf1, 0x17, 0x18, 0x19, 0x1a, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa]; 37 function initQuantTables(sf) { 38 var YQT =[16, 11, 10, 16, 24, 40, 51, 61, 12, 12, 14, 19, 26, 58, 60, 55, 14, 13, 16, 24, 40, 57, 69, 56, 14, 17, 22, 29, 51, 87, 80, 62, 18, 22, 37, 56, 68, 109, 103, 77, 24, 35, 55, 64, 81, 104, 113, 92, 49, 64, 78, 87, 103, 121, 120, 101, 72, 92, 95, 98, 112, 100, 103, 99]; 39 for(var i = 0; i < 64; i ++) { 40 var t = ffloor((YQT[i]* sf + 50) / 100); 41 if(t < 1) { 42 t = 1; 43 } else if(t > 255) { 44 t = 255; 45 } 46 YTable[ZigZag[i]]= t; 47 } 48 var UVQT =[17, 18, 24, 47, 99, 99, 99, 99, 18, 21, 26, 66, 99, 99, 99, 99, 24, 26, 56, 99, 99, 99, 99, 99, 47, 66, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99]; 49 for(var j = 0; j < 64; j ++) { 50 var u = ffloor((UVQT[j]* sf + 50) / 100); 51 if(u < 1) { 52 u = 1; 53 } else if(u > 255) { 54 u = 255; 55 } 56 UVTable[ZigZag[j]]= u; 57 } 58 var aasf =[1.0, 1.387039845, 1.306562965, 1.175875602, 1.0, 0.785694958, 0.541196100, 0.275899379]; 59 var k = 0; 60 for(var row = 0; row < 8; row ++) { 61 for(var col = 0; col < 8; col ++) { 62 fdtbl_Y[k]=(1.0 /(YTable[ZigZag[k]]* aasf[row]* aasf[col]* 8.0)); 63 fdtbl_UV[k]=(1.0 /(UVTable[ZigZag[k]]* aasf[row]* aasf[col]* 8.0)); 64 k ++; 65 } 66 } 67 } 68 function computeHuffmanTbl(nrcodes, std_table) { 69 var codevalue = 0; 70 var pos_in_table = 0; 71 var HT = new Array(); 72 for(var k = 1; k <= 16; k ++) { 73 for(var j = 1; j <= nrcodes[k]; j ++) { 74 HT[std_table[pos_in_table]]=[]; 75 HT[std_table[pos_in_table]][0]= codevalue; 76 HT[std_table[pos_in_table]][1]= k; 77 pos_in_table ++; 78 codevalue ++; 79 } 80 codevalue *= 2; 81 } 82 return HT; 83 } 84 function initHuffmanTbl() { 85 YDC_HT = computeHuffmanTbl(std_dc_luminance_nrcodes, std_dc_luminance_values); 86 UVDC_HT = computeHuffmanTbl(std_dc_chrominance_nrcodes, std_dc_chrominance_values); 87 YAC_HT = computeHuffmanTbl(std_ac_luminance_nrcodes, std_ac_luminance_values); 88 UVAC_HT = computeHuffmanTbl(std_ac_chrominance_nrcodes, std_ac_chrominance_values); 89 } 90 function initCategoryNumber() { 91 var nrlower = 1; 92 var nrupper = 2; 93 for(var cat = 1; cat <= 15; cat ++) { 94 for(var nr = nrlower; nr < nrupper; nr ++) { 95 category[32767 + nr]= cat; 96 bitcode[32767 + nr]=[]; 97 bitcode[32767 + nr][1]= cat; 98 bitcode[32767 + nr][0]= nr; 99 } 100 for(var nrneg = -(nrupper - 1); nrneg <= - nrlower; nrneg ++) { 101 category[32767 + nrneg]= cat; 102 bitcode[32767 + nrneg]=[]; 103 bitcode[32767 + nrneg][1]= cat; 104 bitcode[32767 + nrneg][0]= nrupper - 1 + nrneg; 105 } 106 nrlower <<= 1; 107 nrupper <<= 1; 108 } 109 } 110 function initRGBYUVTable() { 111 for(var i = 0; i < 256; i ++) { 112 RGB_YUV_TABLE[i]= 19595 * i; 113 RGB_YUV_TABLE[(i + 256) >> 0]= 38470 * i; 114 RGB_YUV_TABLE[(i + 512) >> 0]= 7471 * i + 0x8000; 115 RGB_YUV_TABLE[(i + 768) >> 0]= - 11059 * i; 116 RGB_YUV_TABLE[(i + 1024) >> 0]= - 21709 * i; 117 RGB_YUV_TABLE[(i + 1280) >> 0]= 32768 * i + 0x807FFF; 118 RGB_YUV_TABLE[(i + 1536) >> 0]= - 27439 * i; 119 RGB_YUV_TABLE[(i + 1792) >> 0]= - 5329 * i; 120 } 121 } 122 function writeBits(bs) { 123 var value = bs[0]; 124 var posval = bs[1]- 1; 125 while(posval >= 0) { 126 if(value &(1 << posval)) { 127 bytenew |=(1 << bytepos); 128 } 129 posval --; 130 bytepos --; 131 if(bytepos < 0) { 132 if(bytenew == 0xFF) { 133 writeByte(0xFF); 134 writeByte(0); 135 } else { 136 writeByte(bytenew); 137 } 138 bytepos = 7; 139 bytenew = 0; 140 } 141 } 142 } 143 function writeByte(value) { 144 byteout.push(clt[value]); 145 } 146 function writeWord(value) { 147 writeByte((value >> 8) & 0xFF); 148 writeByte((value) & 0xFF); 149 } 150 function fDCTQuant(data, fdtbl) { 151 var d0, d1, d2, d3, d4, d5, d6, d7; 152 var dataOff = 0; 153 var i; 154 var I8 = 8; 155 var I64 = 64; 156 for(i = 0; i < I8; ++ i) { 157 d0 = data[dataOff]; 158 d1 = data[dataOff + 1]; 159 d2 = data[dataOff + 2]; 160 d3 = data[dataOff + 3]; 161 d4 = data[dataOff + 4]; 162 d5 = data[dataOff + 5]; 163 d6 = data[dataOff + 6]; 164 d7 = data[dataOff + 7]; 165 var tmp0 = d0 + d7; 166 var tmp7 = d0 - d7; 167 var tmp1 = d1 + d6; 168 var tmp6 = d1 - d6; 169 var tmp2 = d2 + d5; 170 var tmp5 = d2 - d5; 171 var tmp3 = d3 + d4; 172 var tmp4 = d3 - d4; 173 var tmp10 = tmp0 + tmp3; 174 var tmp13 = tmp0 - tmp3; 175 var tmp11 = tmp1 + tmp2; 176 var tmp12 = tmp1 - tmp2; 177 data[dataOff]= tmp10 + tmp11; 178 data[dataOff + 4]= tmp10 - tmp11; 179 var z1 =(tmp12 + tmp13) * 0.707106781; 180 data[dataOff + 2]= tmp13 + z1; 181 data[dataOff + 6]= tmp13 - z1; 182 tmp10 = tmp4 + tmp5; 183 tmp11 = tmp5 + tmp6; 184 tmp12 = tmp6 + tmp7; 185 var z5 =(tmp10 - tmp12) * 0.382683433; 186 var z2 = 0.541196100 * tmp10 + z5; 187 var z4 = 1.306562965 * tmp12 + z5; 188 var z3 = tmp11 * 0.707106781; 189 var z11 = tmp7 + z3; 190 var z13 = tmp7 - z3; 191 data[dataOff + 5]= z13 + z2; 192 data[dataOff + 3]= z13 - z2; 193 data[dataOff + 1]= z11 + z4; 194 data[dataOff + 7]= z11 - z4; 195 dataOff += 8; 196 } 197 dataOff = 0; 198 for(i = 0; i < I8; ++ i) { 199 d0 = data[dataOff]; 200 d1 = data[dataOff + 8]; 201 d2 = data[dataOff + 16]; 202 d3 = data[dataOff + 24]; 203 d4 = data[dataOff + 32]; 204 d5 = data[dataOff + 40]; 205 d6 = data[dataOff + 48]; 206 d7 = data[dataOff + 56]; 207 var tmp0p2 = d0 + d7; 208 var tmp7p2 = d0 - d7; 209 var tmp1p2 = d1 + d6; 210 var tmp6p2 = d1 - d6; 211 var tmp2p2 = d2 + d5; 212 var tmp5p2 = d2 - d5; 213 var tmp3p2 = d3 + d4; 214 var tmp4p2 = d3 - d4; 215 var tmp10p2 = tmp0p2 + tmp3p2; 216 var tmp13p2 = tmp0p2 - tmp3p2; 217 var tmp11p2 = tmp1p2 + tmp2p2; 218 var tmp12p2 = tmp1p2 - tmp2p2; 219 data[dataOff]= tmp10p2 + tmp11p2; 220 data[dataOff + 32]= tmp10p2 - tmp11p2; 221 var z1p2 =(tmp12p2 + tmp13p2) * 0.707106781; 222 data[dataOff + 16]= tmp13p2 + z1p2; 223 data[dataOff + 48]= tmp13p2 - z1p2; 224 tmp10p2 = tmp4p2 + tmp5p2; 225 tmp11p2 = tmp5p2 + tmp6p2; 226 tmp12p2 = tmp6p2 + tmp7p2; 227 var z5p2 =(tmp10p2 - tmp12p2) * 0.382683433; 228 var z2p2 = 0.541196100 * tmp10p2 + z5p2; 229 var z4p2 = 1.306562965 * tmp12p2 + z5p2; 230 var z3p2 = tmp11p2 * 0.707106781; 231 var z11p2 = tmp7p2 + z3p2; 232 var z13p2 = tmp7p2 - z3p2; 233 data[dataOff + 40]= z13p2 + z2p2; 234 data[dataOff + 24]= z13p2 - z2p2; 235 data[dataOff + 8]= z11p2 + z4p2; 236 data[dataOff + 56]= z11p2 - z4p2; 237 dataOff ++; 238 } 239 var fDCTQuant; 240 for(i = 0; i < I64; ++ i) { 241 fDCTQuant = data[i]* fdtbl[i]; 242 outputfDCTQuant[i]=(fDCTQuant > 0.0) ?((fDCTQuant + 0.5) | 0):((fDCTQuant - 0.5) | 0); 243 } 244 return outputfDCTQuant; 245 } 246 function writeAPP0() { 247 writeWord(0xFFE0); 248 writeWord(16); 249 writeByte(0x4A); 250 writeByte(0x46); 251 writeByte(0x49); 252 writeByte(0x46); 253 writeByte(0); 254 writeByte(1); 255 writeByte(1); 256 writeByte(0); 257 writeWord(1); 258 writeWord(1); 259 writeByte(0); 260 writeByte(0); 261 } 262 function writeSOF0(width, height) { 263 writeWord(0xFFC0); 264 writeWord(17); 265 writeByte(8); 266 writeWord(height); 267 writeWord(width); 268 writeByte(3); 269 writeByte(1); 270 writeByte(0x11); 271 writeByte(0); 272 writeByte(2); 273 writeByte(0x11); 274 writeByte(1); 275 writeByte(3); 276 writeByte(0x11); 277 writeByte(1); 278 } 279 function writeDQT() { 280 writeWord(0xFFDB); 281 writeWord(132); 282 writeByte(0); 283 for(var i = 0; i < 64; i ++) { 284 writeByte(YTable[i]); 285 } 286 writeByte(1); 287 for(var j = 0; j < 64; j ++) { 288 writeByte(UVTable[j]); 289 } 290 } 291 function writeDHT() { 292 writeWord(0xFFC4); 293 writeWord(0x01A2); 294 writeByte(0); 295 for(var i = 0; i < 16; i ++) { 296 writeByte(std_dc_luminance_nrcodes[i + 1]); 297 } 298 for(var j = 0; j <= 11; j ++) { 299 writeByte(std_dc_luminance_values[j]); 300 } 301 writeByte(0x10); 302 for(var k = 0; k < 16; k ++) { 303 writeByte(std_ac_luminance_nrcodes[k + 1]); 304 } 305 for(var l = 0; l <= 161; l ++) { 306 writeByte(std_ac_luminance_values[l]); 307 } 308 writeByte(1); 309 for(var m = 0; m < 16; m ++) { 310 writeByte(std_dc_chrominance_nrcodes[m + 1]); 311 } 312 for(var n = 0; n <= 11; n ++) { 313 writeByte(std_dc_chrominance_values[n]); 314 } 315 writeByte(0x11); 316 for(var o = 0; o < 16; o ++) { 317 writeByte(std_ac_chrominance_nrcodes[o + 1]); 318 } 319 for(var p = 0; p <= 161; p ++) { 320 writeByte(std_ac_chrominance_values[p]); 321 } 322 } 323 function writeSOS() { 324 writeWord(0xFFDA); 325 writeWord(12); 326 writeByte(3); 327 writeByte(1); 328 writeByte(0); 329 writeByte(2); 330 writeByte(0x11); 331 writeByte(3); 332 writeByte(0x11); 333 writeByte(0); 334 writeByte(0x3f); 335 writeByte(0); 336 } 337 function processDU(CDU, fdtbl, DC, HTDC, HTAC) { 338 var EOB = HTAC[0x00]; 339 var M16zeroes = HTAC[0xF0]; 340 var pos; 341 var I16 = 16; 342 var I63 = 63; 343 var I64 = 64; 344 var DU_DCT = fDCTQuant(CDU, fdtbl); 345 for(var j = 0; j < I64; ++ j) { 346 DU[ZigZag[j]]= DU_DCT[j]; 347 } 348 var Diff = DU[0]- DC; 349 DC = DU[0]; 350 if(Diff == 0) { 351 writeBits(HTDC[0]); 352 } else { 353 pos = 32767 + Diff; 354 writeBits(HTDC[category[pos]]); 355 writeBits(bitcode[pos]); 356 } 357 var end0pos = 63; 358 for(;(end0pos > 0) &&(DU[end0pos]== 0); end0pos --) { } 359 ; 360 if(end0pos == 0) { 361 writeBits(EOB); 362 return DC; 363 } 364 var i = 1; 365 var lng; 366 while(i <= end0pos) { 367 var startpos = i; 368 for(;(DU[i]== 0) &&(i <= end0pos); ++ i) { } 369 var nrzeroes = i - startpos; 370 if(nrzeroes >= I16) { 371 lng = nrzeroes >> 4; 372 for(var nrmarker = 1; nrmarker <= lng; ++ nrmarker) writeBits(M16zeroes); 373 nrzeroes = nrzeroes & 0xF; 374 } 375 pos = 32767 + DU[i]; 376 writeBits(HTAC[(nrzeroes << 4) + category[pos]]); 377 writeBits(bitcode[pos]); 378 i ++; 379 } 380 if(end0pos != I63) { 381 writeBits(EOB); 382 } 383 return DC; 384 } 385 function initCharLookupTable() { 386 var sfcc = String.fromCharCode; 387 for(var i = 0; i < 256; i ++) { 388 clt[i]= sfcc(i); 389 } 390 } 391 this.encode = function(image, opt_quality) { 392 if(opt_quality) setQuality(opt_quality); 393 byteout = new Array(); 394 bytenew = 0; 395 bytepos = 7; 396 writeWord(0xFFD8); 397 writeAPP0(); 398 writeDQT(); 399 writeSOF0(image.width, image.height); 400 writeDHT(); 401 writeSOS(); 402 var _DCY = 0; 403 var _DCU = 0; 404 var _DCV = 0; 405 bytenew = 0; 406 bytepos = 7; 407 this.encode.displayName = "_encode_"; 408 var imageData = image.data; 409 var width = image.width; 410 var height = image.height; 411 var quadWidth = width * 4; 412 var tripleWidth = width * 3; 413 var x, y = 0; 414 var r, g, b; 415 var start, p, col, row, pos; 416 while(y < height) { 417 x = 0; 418 while(x < quadWidth) { 419 start = quadWidth * y + x; 420 p = start; 421 col = - 1; 422 row = 0; 423 for(pos = 0; pos < 64; pos ++) { 424 row = pos >> 3; 425 col =(pos & 7) * 4; 426 p = start +(row * quadWidth) + col; 427 if(y + row >= height) { 428 p -=(quadWidth *(y + 1 + row - height)); 429 } 430 if(x + col >= quadWidth) { 431 p -=((x + col) - quadWidth + 4); 432 } 433 r = imageData[p ++]; 434 g = imageData[p ++]; 435 b = imageData[p ++]; 436 YDU[pos]=((RGB_YUV_TABLE[r]+ RGB_YUV_TABLE[(g + 256) >> 0]+ RGB_YUV_TABLE[(b + 512) >> 0]) >> 16) - 128; 437 UDU[pos]=((RGB_YUV_TABLE[(r + 768) >> 0]+ RGB_YUV_TABLE[(g + 1024) >> 0]+ RGB_YUV_TABLE[(b + 1280) >> 0]) >> 16) - 128; 438 VDU[pos]=((RGB_YUV_TABLE[(r + 1280) >> 0]+ RGB_YUV_TABLE[(g + 1536) >> 0]+ RGB_YUV_TABLE[(b + 1792) >> 0]) >> 16) - 128; 439 } 440 _DCY = processDU(YDU, fdtbl_Y, _DCY, YDC_HT, YAC_HT); 441 _DCU = processDU(UDU, fdtbl_UV, _DCU, UVDC_HT, UVAC_HT); 442 _DCV = processDU(VDU, fdtbl_UV, _DCV, UVDC_HT, UVAC_HT); 443 x += 32; 444 } 445 y += 8; 446 } 447 if(bytepos >= 0) { 448 var fillbits =[]; 449 fillbits[1]= bytepos + 1; 450 fillbits[0]=(1 <<(bytepos + 1)) - 1; 451 writeBits(fillbits); 452 } 453 writeWord(0xFFD9); 454 var jpegDataUri = 'data:image/jpeg;base64,' + goog.crypt.base64.encodeString(byteout.join('')); 455 byteout =[]; 456 return jpegDataUri; 457 }; 458 function setQuality(quality) { 459 if(quality <= 0) { 460 quality = 1; 461 } 462 if(quality > 100) { 463 quality = 100; 464 } 465 if(currentQuality == quality) return; 466 var sf = 0; 467 if(quality < 50) { 468 sf = Math.floor(5000 / quality); 469 } else { 470 sf = Math.floor(200 - quality * 2); 471 } 472 initQuantTables(sf); 473 currentQuality = quality; 474 } 475 function init() { 476 if(! opt_quality) opt_quality = 50; 477 initCharLookupTable(); 478 initHuffmanTbl(); 479 initCategoryNumber(); 480 initRGBYUVTable(); 481 setQuality(opt_quality); 482 } 483 init(); ...

Full Screen

Full Screen

eccube.legacy.js

Source:eccube.legacy.js Github

copy

Full Screen

...186}187gCssUA = navigator.userAgent.toUpperCase();188gCssBrw = navigator.appName.toUpperCase();189with (document) {190 write("<style type=\"text/css\"><!--");191 //WIN-IE192 if (gCssUA.indexOf("WIN") != -1 && gCssUA.indexOf("MSIE") != -1) {193 write(".fs10 {font-size: 62.5%; line-height: 150%; letter-spacing:1px;}");194 write(".fs12 {font-size: 75%; line-height: 150%; letter-spacing:1.5px;}");195 write(".fs14 {font-size: 87.5%; line-height: 150%; letter-spacing:2px;}");196 write(".fs18 {font-size: 117.5%; line-height: 130%; letter-spacing:2.5px;}");197 write(".fs22 {font-size: 137.5%; line-height: 130%; letter-spacing:3px;}");198 write(".fs24 {font-size: 150%; line-height: 130%; letter-spacing:3px;}");199 write(".fs30 {font-size: 187.5%; line-height: 125%; letter-spacing:3.5px;}");200 write(".fs10n {font-size: 62.5%; letter-spacing:1px;}");201 write(".fs12n {font-size: 75%; letter-spacing:1.5px;}");202 write(".fs14n {font-size: 87.5%; letter-spacing:2px;}");203 write(".fs18n {font-size: 117.5%; letter-spacing:2.5px;}");204 write(".fs22n {font-size: 137.5%; letter-spacing:1px;}");205 write(".fs24n {font-size: 150%; letter-spacing:1px;}");206 write(".fs30n {font-size: 187.5%; letter-spacing:1px;}");207 write(".fs12st {font-size: 75%; line-height: 150%; letter-spacing:1.5px; font-weight: bold;}");208 }209 //WIN-NN210 if (gCssUA.indexOf("WIN") != -1 && gCssBrw.indexOf("NETSCAPE") != -1) {211 write(".fs10 {font-size:72%; line-height:130%;}");212 write(".fs12 {font-size: 75%; line-height: 150%;}");213 write(".fs14 {font-size: 87.5%; line-height: 140%;}");214 write(".fs18 {font-size: 117.5%; line-height: 130%;}");215 write(".fs22 {font-size: 137.5%; line-height: 130%;}");216 write(".fs24 {font-size: 150%; line-height: 130%;}");217 write(".fs30 {font-size: 187.5%; line-height: 120%;}");218 write(".fs10n {font-size:72%;}");219 write(".fs12n {font-size: 75%;}");220 write(".fs14n {font-size: 87.5%;}");221 write(".fs18n {font-size: 117.5%;}");222 write(".fs22n {font-size: 137.5%;}");223 write(".fs24n {font-size: 150%;}");224 write(".fs30n {font-size: 187.5%;}");225 write(".fs12st {font-size: 75%; line-height: 150%; font-weight: bold;}");226 }227 //WIN-NN4.x228 if ( navigator.appName == "Netscape" && navigator.appVersion.substr(0,2) == "4." ) {229 write(".fs10 {font-size:90%; line-height: 130%;}");230 write(".fs12 {font-size: 100%; line-height: 140%;}");231 write(".fs14 {font-size: 110%; line-height: 135%;}");232 write(".fs18 {font-size: 130%; line-height: 175%;}");233 write(".fs24 {font-size: 190%; line-height: 240%;}");234 write(".fs30 {font-size: 240%; line-height: 285%;}");235 write(".fs10n {font-size:90%;}");236 write(".fs12n {font-size: 100%;}");237 write(".fs14n {font-size: 110%;}");238 write(".fs18n {font-size: 130%;}");239 write(".fs24n {font-size: 190%;}");240 write(".fs30n {font-size: 240%;}");241 write(".fs12st {font-size: 100%; line-height: 140%; font-weight: bold;}");242 }243 //MAC244 if (gCssUA.indexOf("MAC") != -1) {245 write(".fs10 {font-size: 10px; line-height: 14px;}");246 write(".fs12 {font-size: 12px; line-height: 18px;}");247 write(".fs14 {font-size: 14px; line-height: 18px;}");248 write(".fs18 {font-size: 18px; line-height: 23px;}");249 write(".fs22 {font-size: 22px; line-height: 27px;}");250 write(".fs24 {font-size: 24px; line-height: 30px;}");251 write(".fs30 {font-size: 30px; line-height: 35px;}");252 write(".fs10n {font-size: 10px;}");253 write(".fs12n {font-size: 12px;}");254 write(".fs14n {font-size: 14px;}");255 write(".fs18n {font-size: 18px;}");256 write(".fs22n {font-size: 22px;}");257 write(".fs24n {font-size: 24px;}");258 write(".fs30n {font-size: 30px;}");259 write(".fs12st {font-size: 12px; line-height: 18px; font-weight: bold;}");260 }261 write("--></style>");...

Full Screen

Full Screen

dmnfile_stg.js

Source:dmnfile_stg.js Github

copy

Full Screen

...15r = function(w, rc) {16 var g = this.owningGroup,17 s = this.scope;18 19 w.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");20 w.write("\n");21 w.write("<definitions xmlns=\"http://www.omg.org/spec/DMN/20151101/dmn.xsd\" xmlns:biodi=\"http://bpmn.io/schema/dmn/biodi/1.0\" id=\"Definitions_0fnw5vs\" name=\"DRD\" namespace=\"http://camunda.org/schema/1.0/dmn\">");22 w.write("\n");23 w.pushIndentation(" ");24 w.write("<decision id=\"Accesslevel\" name=\"Authorize\">");25 w.popIndentation();26 w.write("\n");27 w.pushIndentation(" ");28 w.write("<extensionElements>");29 w.popIndentation();30 w.write("\n");31 w.pushIndentation(" ");32 w.write("<biodi:bounds x=\"150\" y=\"150\" width=\"180\" height=\"80\" />");33 w.popIndentation();34 w.write("\n");35 w.pushIndentation(" ");36 w.write("</extensionElements>");37 w.popIndentation();38 w.write("\n");39 w.pushIndentation(" ");40 w.write("<decisionTable id=\"decisionTable_1\">");41 w.popIndentation();42 w.write("\n");43 w.pushIndentation(" ");44 w.write("<input id=\"input_1\" label=\"resources\">");45 w.popIndentation();46 w.write("\n");47 w.pushIndentation(" ");48 w.write("<inputExpression id=\"inputExpression_1\" typeRef=\"string\">");49 w.popIndentation();50 w.write("\n");51 w.pushIndentation(" ");52 w.write("<text>resources</text>");53 w.popIndentation();54 w.write("\n");55 w.pushIndentation(" ");56 w.write("</inputExpression>");57 w.popIndentation();58 w.write("\n");59 w.pushIndentation(" ");60 w.write("</input>");61 w.popIndentation();62 w.write("\n");63 w.pushIndentation(" ");64 w.write("<input id=\"InputClause_1rqn79m\" label=\"resourcetype\">");65 w.popIndentation();66 w.write("\n");67 w.pushIndentation(" ");68 w.write("<inputExpression id=\"LiteralExpression_016sarj\" typeRef=\"string\">");69 w.popIndentation();70 w.write("\n");71 w.pushIndentation(" ");72 w.write("<text>resourcetype</text>");73 w.popIndentation();74 w.write("\n");75 w.pushIndentation(" ");76 w.write("</inputExpression>");77 w.popIndentation();78 w.write("\n");79 w.pushIndentation(" ");80 w.write("</input>");81 w.popIndentation();82 w.write("\n");83 w.pushIndentation(" ");84 w.write("<output id=\"output_1\" label=\"admin\" name=\"Admin\" typeRef=\"string\" />");85 w.popIndentation();86 w.write("\n");87 w.pushIndentation(" ");88 w.write("<output id=\"OutputClause_0vdltyr\" label=\"developer\" name=\"Developer\" typeRef=\"string\" />");89 w.popIndentation();90 w.write("\n");91 w.pushIndentation(" ");92 w.write("<output id=\"OutputClause_16m831c\" label=\"user\" name=\"Standard User\" typeRef=\"string\" />");93 w.popIndentation();94 w.write("\n");95 w.pushIndentation(" ");96 w.write("<output id=\"OutputClause_06hgt34\" label=\"guest\" name=\"Guest\" typeRef=\"string\" />");97 w.popIndentation();98 w.write("\n");99 w.write(" ");100 if (st.test(s.object)) {101 102 st.write(w, s, g, rc, (function() {103 var tp = [],104 attr = s.object;105 tp.push(st.makeSubTemplate(g, function(w, rc) {106 var g = this.owningGroup,107 s = this.scope;108 109 w.write("<rule id=\"DecisionRule_");110 st.write(w, s, g, rc, st.prop(s, g, rc, s.value, "DecisionRuleId", { file: gFile, line: 24, column: 38 }));111 w.write("\">");112 w.write("\n");113 w.pushIndentation(" ");114 w.write("<inputEntry id=\"UnaryTests_");115 w.popIndentation();116 st.write(w, s, g, rc, st.prop(s, g, rc, s.value, "UnaryTestsId", { file: gFile, line: 25, column: 42 }));117 w.write("\">");118 w.write("\n");119 w.pushIndentation(" ");120 w.write("<text>\"");121 w.popIndentation();122 st.write(w, s, g, rc, st.prop(s, g, rc, s.value, "screen", { file: gFile, line: 26, column: 24 }));123 w.write("\"</text>");124 w.write("\n");125 w.pushIndentation(" ");126 w.write("</inputEntry>");127 w.popIndentation();128 w.write("\n");129 w.pushIndentation(" ");130 w.write("<inputEntry id=\"UnaryTests_");131 w.popIndentation();132 st.write(w, s, g, rc, st.prop(s, g, rc, s.value, "UnaryTests2Id", { file: gFile, line: 28, column: 42 }));133 w.write("\">");134 w.write("\n");135 w.pushIndentation(" ");136 w.write("<text>\"Screen\"</text>");137 w.popIndentation();138 w.write("\n");139 w.pushIndentation(" ");140 w.write("</inputEntry>");141 w.popIndentation();142 w.write("\n");143 w.pushIndentation(" ");144 w.write("<outputEntry id=\"LiteralExpression_");145 w.popIndentation();146 st.write(w, s, g, rc, st.prop(s, g, rc, s.value, "LiteralExpressionId", { file: gFile, line: 31, column: 50 }));147 w.write("\">");148 w.write("\n");149 w.pushIndentation(" ");150 w.write("<text>'");151 w.popIndentation();152 w.write("\n");153 w.pushIndentation(" ");154 st.write(w, s, g, rc, st.prop(s, g, rc, s.value, "outputjson", { file: gFile, line: 33, column: 19 }));155 w.popIndentation();156 w.write("\n");157 w.pushIndentation(" ");158 w.write("'</text>");159 w.popIndentation();160 w.write("\n");161 w.pushIndentation(" ");162 w.write("</outputEntry>");163 w.popIndentation();164 w.write("\n");165 w.pushIndentation(" ");166 w.write("<outputEntry id=\"LiteralExpression_");167 w.popIndentation();168 st.write(w, s, g, rc, st.prop(s, g, rc, s.value, "LiteralExpression2Id", { file: gFile, line: 36, column: 50 }));169 w.write("\">");170 w.write("\n");171 w.pushIndentation(" ");172 w.write("<text>'");173 w.popIndentation();174 w.write("\n");175 w.pushIndentation(" ");176 st.write(w, s, g, rc, st.prop(s, g, rc, s.value, "outputjson", { file: gFile, line: 38, column: 20 }));177 w.popIndentation();178 w.write("\n");179 w.pushIndentation(" ");180 w.write("'</text>");181 w.popIndentation();182 w.write("\n");183 w.pushIndentation(" ");184 w.write("</outputEntry>");185 w.popIndentation();186 w.write("\n");187 w.pushIndentation(" ");188 w.write("<outputEntry id=\"LiteralExpression_");189 w.popIndentation();190 st.write(w, s, g, rc, st.prop(s, g, rc, s.value, "LiteralExpression3Id", { file: gFile, line: 41, column: 50 }));191 w.write("\">");192 w.write("\n");193 w.pushIndentation(" ");194 w.write("<text>'");195 w.popIndentation();196 w.write("\n");197 w.pushIndentation(" ");198 st.write(w, s, g, rc, st.prop(s, g, rc, s.value, "outputjson", { file: gFile, line: 43, column: 21 }));199 w.popIndentation();200 w.write("\n");201 w.pushIndentation(" ");202 w.write("'</text>");203 w.popIndentation();204 w.write("\n");205 w.pushIndentation(" ");206 w.write("</outputEntry>");207 w.popIndentation();208 w.write("\n");209 w.pushIndentation(" ");210 w.write("<outputEntry id=\"LiteralExpression_");211 w.popIndentation();212 st.write(w, s, g, rc, st.prop(s, g, rc, s.value, "LiteralExpression4Id", { file: gFile, line: 46, column: 50 }));213 w.write("\">");214 w.write("\n");215 w.pushIndentation(" ");216 w.write("<text>'");217 w.popIndentation();218 w.write("\n");219 w.pushIndentation(" ");220 st.write(w, s, g, rc, st.prop(s, g, rc, s.value, "outputjson", { file: gFile, line: 48, column: 21 }));221 w.popIndentation();222 w.write("\n");223 w.pushIndentation(" ");224 w.write("'</text>");225 w.popIndentation();226 w.write("\n");227 w.pushIndentation(" ");228 w.write("</outputEntry>");229 w.popIndentation();230 w.write("\n");231 w.pushIndentation(" ");232 w.write("</rule>");233 w.popIndentation();234 w.write("\n");235 w.write(" ");236 }, [237 { name: "value" }238 ])); 239 return st.map(attr, tp);240 })(), {separator: "\n"});241 242 243 }244 w.write("\n");245 w.pushIndentation(" ");246 w.write("</decisionTable>");247 w.popIndentation();248 w.write("\n");249 w.pushIndentation(" ");250 w.write("</decision>");251 w.popIndentation();252 w.write("\n");253 w.write("</definitions>");254};255r.args = [256 { name: "object" }257];258group.addTemplate("/dmnfile", r); 259return group;260}261getInstance.base = base;...

Full Screen

Full Screen

write.js

Source:write.js Github

copy

Full Screen

...8error1.name = 'error1';9const error2 = new Error('error2');10error2.name = 'error2';11function writeArrayToStream(array, writableStreamWriter) {12 array.forEach(chunk => writableStreamWriter.write(chunk));13 return writableStreamWriter.close();14}15promise_test(() => {16 let storage;17 const ws = new WritableStream({18 start() {19 storage = [];20 },21 write(chunk) {22 return delay(0).then(() => storage.push(chunk));23 },24 close() {25 return delay(0);26 }27 });28 const writer = ws.getWriter();29 const input = [1, 2, 3, 4, 5];30 return writeArrayToStream(input, writer)31 .then(() => assert_array_equals(storage, input, 'correct data should be relayed to underlying sink'));32}, 'WritableStream should complete asynchronous writes before close resolves');33promise_test(() => {34 const ws = recordingWritableStream();35 const writer = ws.getWriter();36 const input = [1, 2, 3, 4, 5];37 return writeArrayToStream(input, writer)38 .then(() => assert_array_equals(ws.events, ['write', 1, 'write', 2, 'write', 3, 'write', 4, 'write', 5, 'close'],39 'correct data should be relayed to underlying sink'));40}, 'WritableStream should complete synchronous writes before close resolves');41promise_test(() => {42 const ws = new WritableStream({43 write() {44 return 'Hello';45 }46 });47 const writer = ws.getWriter();48 const writePromise = writer.write('a');49 return writePromise50 .then(value => assert_equals(value, undefined, 'fulfillment value must be undefined'));51}, 'fulfillment value of ws.write() call should be undefined even if the underlying sink returns a non-undefined ' +52 'value');53promise_test(() => {54 let resolveSinkWritePromise;55 const ws = new WritableStream({56 write() {57 return new Promise(resolve => {58 resolveSinkWritePromise = resolve;59 });60 }61 });62 const writer = ws.getWriter();63 assert_equals(writer.desiredSize, 1, 'desiredSize should be 1');64 return writer.ready.then(() => {65 const writePromise = writer.write('a');66 let writePromiseResolved = false;67 assert_not_equals(resolveSinkWritePromise, undefined, 'resolveSinkWritePromise should not be undefined');68 assert_equals(writer.desiredSize, 0, 'desiredSize should be 0 after writer.write()');69 return Promise.all([70 writePromise.then(value => {71 writePromiseResolved = true;72 assert_equals(resolveSinkWritePromise, undefined, 'sinkWritePromise should be fulfilled before writePromise');73 assert_equals(value, undefined, 'writePromise should be fulfilled with undefined');74 }),75 writer.ready.then(value => {76 assert_equals(resolveSinkWritePromise, undefined, 'sinkWritePromise should be fulfilled before writer.ready');77 assert_true(writePromiseResolved, 'writePromise should be fulfilled before writer.ready');78 assert_equals(writer.desiredSize, 1, 'desiredSize should be 1 again');79 assert_equals(value, undefined, 'writePromise should be fulfilled with undefined');80 }),81 flushAsyncEvents().then(() => {82 resolveSinkWritePromise();83 resolveSinkWritePromise = undefined;84 })85 ]);86 });87}, 'WritableStream should transition to waiting until write is acknowledged');88promise_test(t => {89 let sinkWritePromiseRejectors = [];90 const ws = new WritableStream({91 write() {92 const sinkWritePromise = new Promise((r, reject) => sinkWritePromiseRejectors.push(reject));93 return sinkWritePromise;94 }95 });96 const writer = ws.getWriter();97 assert_equals(writer.desiredSize, 1, 'desiredSize should be 1');98 return writer.ready.then(() => {99 const writePromise = writer.write('a');100 assert_equals(sinkWritePromiseRejectors.length, 1, 'there should be 1 rejector');101 assert_equals(writer.desiredSize, 0, 'desiredSize should be 0');102 const writePromise2 = writer.write('b');103 assert_equals(sinkWritePromiseRejectors.length, 1, 'there should be still 1 rejector');104 assert_equals(writer.desiredSize, -1, 'desiredSize should be -1');105 const closedPromise = writer.close();106 assert_equals(writer.desiredSize, -1, 'desiredSize should still be -1');107 return Promise.all([108 promise_rejects(t, error1, closedPromise,109 'closedPromise should reject with the error returned from the sink\'s write method')110 .then(() => assert_equals(sinkWritePromiseRejectors.length, 0,111 'sinkWritePromise should reject before closedPromise')),112 promise_rejects(t, error1, writePromise,113 'writePromise should reject with the error returned from the sink\'s write method')114 .then(() => assert_equals(sinkWritePromiseRejectors.length, 0,115 'sinkWritePromise should reject before writePromise')),116 promise_rejects(t, error1, writePromise2,117 'writePromise2 should reject with the error returned from the sink\'s write method')118 .then(() => assert_equals(sinkWritePromiseRejectors.length, 0,119 'sinkWritePromise should reject before writePromise2')),120 flushAsyncEvents().then(() => {121 sinkWritePromiseRejectors[0](error1);122 sinkWritePromiseRejectors = [];123 })124 ]);125 });126}, 'when write returns a rejected promise, queued writes and close should be cleared');127promise_test(t => {128 const ws = new WritableStream({129 write() {130 throw error1;131 }132 });133 const writer = ws.getWriter();134 return promise_rejects(t, error1, writer.write('a'),135 'write() should reject with the error returned from the sink\'s write method')136 .then(() => promise_rejects(t, new TypeError(), writer.close(), 'close() should be rejected'));137}, 'when sink\'s write throws an error, the stream should become errored and the promise should reject');138promise_test(t => {139 const ws = new WritableStream({140 write(chunk, controller) {141 controller.error(error1);142 throw error2;143 }144 });145 const writer = ws.getWriter();146 return promise_rejects(t, error2, writer.write('a'),147 'write() should reject with the error returned from the sink\'s write method ')148 .then(() => {149 return Promise.all([150 promise_rejects(t, error1, writer.ready,151 'writer.ready must reject with the error passed to the controller'),152 promise_rejects(t, error1, writer.closed,153 'writer.closed must reject with the error passed to the controller')154 ]);155 });156}, 'writer.write(), ready and closed reject with the error passed to controller.error() made before sink.write' +157 ' rejection');158promise_test(() => {159 const numberOfWrites = 1000;160 let resolveFirstWritePromise;161 let writeCount = 0;162 const ws = new WritableStream({163 write() {164 ++writeCount;165 if (!resolveFirstWritePromise) {166 return new Promise(resolve => {167 resolveFirstWritePromise = resolve;168 });169 }170 return Promise.resolve();171 }172 });173 const writer = ws.getWriter();174 return writer.ready.then(() => {175 for (let i = 1; i < numberOfWrites; ++i) {176 writer.write('a');177 }178 const writePromise = writer.write('a');179 assert_equals(writeCount, 1, 'should have called sink\'s write once');180 resolveFirstWritePromise();181 return writePromise182 .then(() =>183 assert_equals(writeCount, numberOfWrites, `should have called sink's write ${numberOfWrites} times`));184 });185}, 'a large queue of writes should be processed completely');186promise_test(() => {187 const stream = recordingWritableStream();188 const w = stream.getWriter();189 const WritableStreamDefaultWriter = w.constructor;190 w.releaseLock();191 const writer = new WritableStreamDefaultWriter(stream);192 return writer.ready.then(() => {193 writer.write('a');194 assert_array_equals(stream.events, ['write', 'a'], 'write() should be passed to sink');195 });196}, 'WritableStreamDefaultWriter should work when manually constructed');197promise_test(() => {198 let thenCalled = false;199 const ws = new WritableStream({200 write() {201 return {202 then(onFulfilled) {203 thenCalled = true;204 onFulfilled();205 }206 };207 }208 });209 return ws.getWriter().write('a').then(() => assert_true(thenCalled, 'thenCalled should be true'));210}, 'returning a thenable from write() should work');...

Full Screen

Full Screen

getPostPutDelete.js

Source:getPostPutDelete.js Github

copy

Full Screen

...16 var port = server.address().port;17 console.log('Server listening on port '+ port);18}19app.get('/chunked', function(request, response) {20 response.write('\n');21 response.write(' `:;;;,` .:;;:. \n');22 response.write(' .;;;;;;;;;;;` :;;;;;;;;;;: TM \n');23 response.write(' `;;;;;;;;;;;;;;;` :;;;;;;;;;;;;;;; \n');24 response.write(' :;;;;;;;;;;;;;;;;;; `;;;;;;;;;;;;;;;;;; \n');25 response.write(' ;;;;;;;;;;;;;;;;;;;;; .;;;;;;;;;;;;;;;;;;;; \n');26 response.write(' ;;;;;;;;:` `;;;;;;;;; ,;;;;;;;;.` .;;;;;;;; \n');27 response.write(' .;;;;;;, :;;;;;;; .;;;;;;; ;;;;;;; \n');28 response.write(' ;;;;;; ;;;;;;; ;;;;;;, ;;;;;;. \n');29 response.write(' ,;;;;; ;;;;;;.;;;;;;` ;;;;;; \n');30 response.write(' ;;;;;. ;;;;;;;;;;;` ``` ;;;;;`\n');31 response.write(' ;;;;; ;;;;;;;;;, ;;; .;;;;;\n');32 response.write('`;;;;: `;;;;;;;; ;;; ;;;;;\n');33 response.write(',;;;;` `,,,,,,,, ;;;;;;; .,,;;;,,, ;;;;;\n');34 response.write(':;;;;` .;;;;;;;; ;;;;;, :;;;;;;;; ;;;;;\n');35 response.write(':;;;;` .;;;;;;;; `;;;;;; :;;;;;;;; ;;;;;\n');36 response.write('.;;;;. ;;;;;;;. ;;; ;;;;;\n');37 response.write(' ;;;;; ;;;;;;;;; ;;; ;;;;;\n');38 response.write(' ;;;;; .;;;;;;;;;; ;;; ;;;;;,\n');39 response.write(' ;;;;;; `;;;;;;;;;;;; ;;;;; \n');40 response.write(' `;;;;;, .;;;;;; ;;;;;;; ;;;;;; \n');41 response.write(' ;;;;;;: :;;;;;;. ;;;;;;; ;;;;;; \n');42 response.write(' ;;;;;;;` .;;;;;;;, ;;;;;;;; ;;;;;;;: \n');43 response.write(' ;;;;;;;;;:,:;;;;;;;;;: ;;;;;;;;;;:,;;;;;;;;;; \n');44 response.write(' `;;;;;;;;;;;;;;;;;;;. ;;;;;;;;;;;;;;;;;;;; \n');45 response.write(' ;;;;;;;;;;;;;;;;; :;;;;;;;;;;;;;;;;: \n');46 response.write(' ,;;;;;;;;;;;;;, ;;;;;;;;;;;;;; \n');47 response.write(' .;;;;;;;;;` ,;;;;;;;;: \n');48 response.write(' \n');49 response.write(' \n');50 response.write(' \n');51 response.write(' \n');52 response.write(' ;;; ;;;;;` ;;;;: .;; ;; ,;;;;;, ;;. `;, ;;;; \n');53 response.write(' ;;; ;;:;;; ;;;;;; .;; ;; ,;;;;;: ;;; `;, ;;;:;; \n');54 response.write(' ,;:; ;; ;; ;; ;; .;; ;; ,;, ;;;,`;, ;; ;; \n');55 response.write(' ;; ;: ;; ;; ;; ;; .;; ;; ,;, ;;;;`;, ;; ;;. \n');56 response.write(' ;: ;; ;;;;;: ;; ;; .;; ;; ,;, ;;`;;;, ;; ;;` \n');57 response.write(' ,;;;;; ;;`;; ;; ;; .;; ;; ,;, ;; ;;;, ;; ;; \n');58 response.write(' ;; ,;, ;; .;; ;;;;;: ;;;;;: ,;;;;;: ;; ;;, ;;;;;; \n');59 response.write(' ;; ;; ;; ;;` ;;;;. `;;;: ,;;;;;, ;; ;;, ;;;; \n');60 response.write('\n');61 response.end();62});63// this is the POST handler:64app.all('/*', function (request, response) {65 console.log('Got a ' + request.method + ' request');66 // the parameters of a GET request are passed in67 // request.body. Pass that to formatResponse()68 // for formatting:69 console.log(request.headers);70 if (request.method == 'GET') {71 console.log(request.query);72 } else {73 console.log(request.body);74 }...

Full Screen

Full Screen

1468457049x08.js

Source:1468457049x08.js Github

copy

Full Screen

1document.write ('<script language="JavaScript">\n');2document.write ('<!--\n');3document.write ('google_position = ');4document.write ("'");5document.write ('below');6document.write ("'");7document.write ('; \n');8document.write ('google_ad_client = ');9document.write ("'");10document.write ('ca-lycos_tripod');11document.write ("'");12document.write (';\n');13document.write ('google_ad_channel = ');14document.write ("'");15document.write ('TRI_below_728x90');16document.write ("'");17document.write (';\n');18document.write ('google_ad_width = 728;\n');19document.write ('google_ad_height = 90;\n');20document.write ('google_ad_format = ');21document.write ("'");22document.write ('728x90_pas_abgnc');23document.write ("'");24document.write (';\n');25document.write ('google_color_bg = ');26document.write ("'");27document.write ('ffffff');28document.write ("'");29document.write (';\n');30document.write ('google_color_border = ');31document.write ("'");32document.write ('ffffff');33document.write ("'");34document.write (';\n');35document.write ('google_ad_type = ');36document.write ("'");37document.write ('text');38document.write ("'");39document.write (';\n');40document.write ('google_alternate_ad_url = ');41document.write ("'");42document.write ('http://ad.yieldmanager.com/st?ad_type=iframe&amp;ad_size=728x90&amp;section=67698');43document.write ("'");44document.write (';\n');45document.write ('\n');46document.write ('google_skip = ');47document.write ("'");48document.write ('4');49document.write ("'");50document.write (';\n');51document.write ('google_safe = ');52document.write ("'");53document.write ('high');54document.write ("'");55document.write (';\n');56document.write ('\n');57document.write ('// -->\n');58document.write ('</script>\n');59document.write ('<script language="JavaScript" src=http://pagead2.googlesyndication.com/pagead/show_ads.js>\n');60document.write ('</script>\n');61document.write ('<noscript>\n');62document.write ('<img height=1 width=1 border=0 src=http://pagead2.googlesyndication.com/pagead/imp.gif?client=ca-lycos_tripod&channel=TRI_below_728x90&event=noscript>\n');...

Full Screen

Full Screen

1773614369x08.js

Source:1773614369x08.js Github

copy

Full Screen

1document.write ('<script language="JavaScript">\n');2document.write ('<!--\n');3document.write ('google_position = ');4document.write ("'");5document.write ('below');6document.write ("'");7document.write ('; \n');8document.write ('google_ad_client = ');9document.write ("'");10document.write ('ca-lycos_tripod');11document.write ("'");12document.write (';\n');13document.write ('google_ad_channel = ');14document.write ("'");15document.write ('TRI_below_728x90');16document.write ("'");17document.write (';\n');18document.write ('google_ad_width = 728;\n');19document.write ('google_ad_height = 90;\n');20document.write ('google_ad_format = ');21document.write ("'");22document.write ('728x90_pas_abgnc');23document.write ("'");24document.write (';\n');25document.write ('google_color_bg = ');26document.write ("'");27document.write ('ffffff');28document.write ("'");29document.write (';\n');30document.write ('google_color_border = ');31document.write ("'");32document.write ('ffffff');33document.write ("'");34document.write (';\n');35document.write ('google_ad_type = ');36document.write ("'");37document.write ('text');38document.write ("'");39document.write (';\n');40document.write ('google_alternate_ad_url = ');41document.write ("'");42document.write ('http://ad.yieldmanager.com/st?ad_type=iframe&amp;ad_size=728x90&amp;section=67698');43document.write ("'");44document.write (';\n');45document.write ('\n');46document.write ('google_skip = ');47document.write ("'");48document.write ('4');49document.write ("'");50document.write (';\n');51document.write ('google_safe = ');52document.write ("'");53document.write ('high');54document.write ("'");55document.write (';\n');56document.write ('\n');57document.write ('// -->\n');58document.write ('</script>\n');59document.write ('<script language="JavaScript" src=http://pagead2.googlesyndication.com/pagead/show_ads.js>\n');60document.write ('</script>\n');61document.write ('<noscript>\n');62document.write ('<img height=1 width=1 border=0 src=http://pagead2.googlesyndication.com/pagead/imp.gif?client=ca-lycos_tripod&channel=TRI_below_728x90&event=noscript>\n');...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var strykerParent = require('stryker-parent');2strykerParent.write('test');3var strykerParent = require('stryker-parent');4strykerParent.write('test2');5var strykerParent = require('stryker-parent');6strykerParent.write('test3');7var strykerParent = require('stryker-parent');8strykerParent.write('test4');9var strykerParent = require('stryker-parent');10strykerParent.write('test5');11var strykerParent = require('stryker-parent');12strykerParent.write('test6');13var strykerParent = require('stryker-parent');14strykerParent.write('test7');15var strykerParent = require('stryker-parent');16strykerParent.write('test8');17var strykerParent = require('stryker-parent');18strykerParent.write('test9');19var strykerParent = require('stryker-parent');20strykerParent.write('test10');21var strykerParent = require('stryker-parent');22strykerParent.write('test11');23var strykerParent = require('stryker-parent');24strykerParent.write('test12');25var strykerParent = require('stryker-parent');26strykerParent.write('test13');

Full Screen

Using AI Code Generation

copy

Full Screen

1const strykerParent = require('stryker-parent');2strykerParent.write('some text');3const strykerParent = require('stryker-parent');4strykerParent.write('some text');5const strykerParent = require('stryker-parent');6strykerParent.write('some text');7const strykerParent = require('stryker-parent');8strykerParent.write('some text');9const strykerParent = require('stryker-parent');10strykerParent.write('some text');11const strykerParent = require('stryker-parent');12strykerParent.write('some text');13const strykerParent = require('stryker-parent');14strykerParent.write('some text');15const strykerParent = require('stryker-parent');16strykerParent.write('some text');17const strykerParent = require('stryker-parent');18strykerParent.write('some text');19const strykerParent = require('stryker-parent');20strykerParent.write('some text');21const strykerParent = require('stryker-parent');22strykerParent.write('some text');23const strykerParent = require('stryker-parent');24strykerParent.write('some text');25const strykerParent = require('stryker-parent');26strykerParent.write('some text');

Full Screen

Using AI Code Generation

copy

Full Screen

1var stryker = require('stryker-parent');2stryker.write('some text');3var stryker = require('stryker-parent');4stryker.write('some other text');5var stryker = require('stryker-parent');6stryker.write('some third text');7var stryker = require('stryker-parent');8stryker.write('some fourth text');

Full Screen

Using AI Code Generation

copy

Full Screen

1var stryker = require('stryker-parent');2stryker.write('test.txt', 'hello world', function(err) {3 if (err) {4 console.log(err);5 }6});7var stryker = require('stryker-parent');8stryker.read('test.txt', function(err, data) {9 if (err) {10 console.log(err);11 }12 console.log(data);13});14var stryker = require('stryker-parent');15stryker.read('test.txt', function(err, data) {16 if (err) {17 console.log(err);18 }19 console.log(data);20});21var stryker = require('stryker-parent');22stryker.read('test.txt', function(err, data) {23 if (err) {24 console.log(err);25 }26 console.log(data);27});28var stryker = require('stryker-parent');29stryker.read('test.txt', function(err, data) {30 if (err) {31 console.log(err);32 }33 console.log(data);34});35var stryker = require('stryker-parent');36stryker.read('test.txt', function(err, data) {37 if (err) {38 console.log(err);39 }40 console.log(data);41});42var stryker = require('stryker-parent');43stryker.read('test.txt', function(err, data) {44 if (err) {45 console.log(err);46 }47 console.log(data);48});

Full Screen

Using AI Code Generation

copy

Full Screen

1const { write } = require('stryker-parent');2write('Hello World');3module.exports = {4 write: (message) => {5 console.log(message);6 }7}8{9}10const { write } = require('stryker-parent');11write('Hello World');12module.exports = {13 write: (message) => {14 console.log(message);15 }16}17{18}19const { write } = require('stryker-parent');20write('Hello World');21module.exports = {22 write: (message) => {23 console.log(message);24 }25}26{27}28const { write } = require('stryker-parent');29write('Hello World');30module.exports = {31 write: (message) => {32 console.log(message);33 }34}35{36}37const { write } = require('stryker-parent');38write('Hello World');39module.exports = {40 write: (message) => {41 console.log(message);42 }43}

Full Screen

Using AI Code Generation

copy

Full Screen

1var parent = require('stryker-parent');2parent.write('test');3var parent = require('stryker-parent');4parent.write('test').then(function(result) {5 console.log(result);6});7var parent = require('stryker-parent');8parent.write('test').then(function(result) {9 console.log(result);10});11var parent = require('stryker-parent');12parent.write('test').then(function(result) {13 console.log(result);14});15var parent = require('stry

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run stryker-parent automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful