How to use getvalue method in avocado

Best Python code snippet using avocado_python

narcissus-exec.js

Source:narcissus-exec.js Github

copy

Full Screen

1/* ***** BEGIN LICENSE BLOCK *****2 * vim: set ts=4 sw=4 et tw=80:3 *4 * Version: MPL 1.1/GPL 2.0/LGPL 2.15 *6 * The contents of this file are subject to the Mozilla Public License Version7 * 1.1 (the "License"); you may not use this file except in compliance with8 * the License. You may obtain a copy of the License at9 * http://www.mozilla.org/MPL/10 *11 * Software distributed under the License is distributed on an "AS IS" basis,12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License13 * for the specific language governing rights and limitations under the14 * License.15 *16 * The Original Code is the Narcissus JavaScript engine.17 *18 * The Initial Developer of the Original Code is19 * Brendan Eich <brendan@mozilla.org>.20 * Portions created by the Initial Developer are Copyright (C) 200421 * the Initial Developer. All Rights Reserved.22 *23 * Contributor(s):24 *25 * Alternatively, the contents of this file may be used under the terms of26 * either the GNU General Public License Version 2 or later (the "GPL"), or27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),28 * in which case the provisions of the GPL or the LGPL are applicable instead29 * of those above. If you wish to allow use of your version of this file only30 * under the terms of either the GPL or the LGPL, and not to allow others to31 * use your version of this file under the terms of the MPL, indicate your32 * decision by deleting the provisions above and replace them with the notice33 * and other provisions required by the GPL or the LGPL. If you do not delete34 * the provisions above, a recipient may use your version of this file under35 * the terms of any one of the MPL, the GPL or the LGPL.36 *37 * ***** END LICENSE BLOCK ***** */38/*39 * Narcissus - JS implemented in JS.40 *41 * Execution of parse trees.42 *43 * Standard classes except for eval, Function, Array, and String are borrowed44 * from the host JS environment. Function is metacircular. Array and String45 * are reflected via wrapping the corresponding native constructor and adding46 * an extra level of prototype-based delegation.47 */48// jrh49//module('JS.Exec');50// end jrh51GLOBAL_CODE = 0; EVAL_CODE = 1; FUNCTION_CODE = 2;52function ExecutionContext(type) {53 this.type = type;54}55// jrh56var agenda = new Array();57var skip_setup = 0;58// end jrh59var global = {60 // Value properties.61 NaN: NaN, Infinity: Infinity, undefined: undefined,62 alert : function(msg) { alert(msg) },63 confirm : function(msg) { return confirm(msg) },64 document : document,65 window : window,66 // jrh67 //debug: window.open('','debugwindow','width=600,height=400,scrollbars=yes,resizable=yes'), 68 // end jrh69 navigator : navigator,70 XMLHttpRequest : function() { return new XMLHttpRequest() },71 // Function properties.72 eval: function(s) {73 if (typeof s != "string") {74 return s;75 }76 var x = ExecutionContext.current;77 var x2 = new ExecutionContext(EVAL_CODE);78 x2.thisObject = x.thisObject;79 x2.caller = x.caller;80 x2.callee = x.callee;81 x2.scope = x.scope;82 ExecutionContext.current = x2;83 try {84 execute(parse(s), x2);85 } catch (e) {86 x.result = x2.result;87 throw e;88 } finally {89 ExecutionContext.current = x;90 }91 return x2.result;92 },93 parseInt: parseInt, parseFloat: parseFloat,94 isNaN: isNaN, isFinite: isFinite,95 decodeURI: decodeURI, encodeURI: encodeURI,96 decodeURIComponent: decodeURIComponent,97 encodeURIComponent: encodeURIComponent,98 // Class constructors. Where ECMA-262 requires C.length == 1, we declare99 // a dummy formal parameter.100 Object: Object,101 Function: function(dummy) {102 var p = "", b = "", n = arguments.length;103 if (n) {104 var m = n - 1;105 if (m) {106 p += arguments[0];107 for (var k = 1; k < m; k++)108 p += "," + arguments[k];109 }110 b += arguments[m];111 }112 // XXX We want to pass a good file and line to the tokenizer.113 // Note the anonymous name to maintain parity with Spidermonkey.114 var t = new Tokenizer("anonymous(" + p + ") {" + b + "}");115 // NB: Use the STATEMENT_FORM constant since we don't want to push this116 // function onto the null compilation context.117 var f = FunctionDefinition(t, null, false, STATEMENT_FORM);118 var s = {object: global, parent: null};119 return new FunctionObject(f, s);120 },121 Array: function(dummy) {122 // Array when called as a function acts as a constructor.123 return GLOBAL.Array.apply(this, arguments);124 },125 String: function(s) {126 // Called as function or constructor: convert argument to string type.127 s = arguments.length ? "" + s : "";128 if (this instanceof String) {129 // Called as constructor: save the argument as the string value130 // of this String object and return this object.131 this.value = s;132 return this;133 }134 return s;135 },136 Boolean: Boolean, Number: Number, Date: Date, RegExp: RegExp,137 Error: Error, EvalError: EvalError, RangeError: RangeError,138 ReferenceError: ReferenceError, SyntaxError: SyntaxError,139 TypeError: TypeError, URIError: URIError,140 // Other properties.141 Math: Math,142 // Extensions to ECMA.143 //snarf: snarf,144 evaluate: evaluate,145 load: function(s) {146 if (typeof s != "string")147 return s;148 var req = new XMLHttpRequest();149 req.open('GET', s, false);150 req.send(null);151 evaluate(req.responseText, s, 1)152 },153 print: print, version: null154};155// jrh156//global.debug.document.body.innerHTML = ''157// end jrh158// Helper to avoid Object.prototype.hasOwnProperty polluting scope objects.159function hasDirectProperty(o, p) {160 return Object.prototype.hasOwnProperty.call(o, p);161}162// Reflect a host class into the target global environment by delegation.163function reflectClass(name, proto) {164 var gctor = global[name];165 gctor.prototype = proto;166 proto.constructor = gctor;167 return proto;168}169// Reflect Array -- note that all Array methods are generic.170reflectClass('Array', new Array);171// Reflect String, overriding non-generic methods.172var gSp = reflectClass('String', new String);173gSp.toSource = function () { return this.value.toSource(); };174gSp.toString = function () { return this.value; };175gSp.valueOf = function () { return this.value; };176global.String.fromCharCode = String.fromCharCode;177var XCp = ExecutionContext.prototype;178ExecutionContext.current = XCp.caller = XCp.callee = null;179XCp.scope = {object: global, parent: null};180XCp.thisObject = global;181XCp.result = undefined;182XCp.target = null;183XCp.ecmaStrictMode = false;184function Reference(base, propertyName, node) {185 this.base = base;186 this.propertyName = propertyName;187 this.node = node;188}189Reference.prototype.toString = function () { return this.node.getSource(); }190function getValue(v) {191 if (v instanceof Reference) {192 if (!v.base) {193 throw new ReferenceError(v.propertyName + " is not defined",194 v.node.filename(), v.node.lineno);195 }196 return v.base[v.propertyName];197 }198 return v;199}200function putValue(v, w, vn) {201 if (v instanceof Reference)202 return (v.base || global)[v.propertyName] = w;203 throw new ReferenceError("Invalid assignment left-hand side",204 vn.filename(), vn.lineno);205}206function isPrimitive(v) {207 var t = typeof v;208 return (t == "object") ? v === null : t != "function";209}210function isObject(v) {211 var t = typeof v;212 return (t == "object") ? v !== null : t == "function";213}214// If r instanceof Reference, v == getValue(r); else v === r. If passed, rn215// is the node whose execute result was r.216function toObject(v, r, rn) {217 switch (typeof v) {218 case "boolean":219 return new global.Boolean(v);220 case "number":221 return new global.Number(v);222 case "string":223 return new global.String(v);224 case "function":225 return v;226 case "object":227 if (v !== null)228 return v;229 }230 var message = r + " (type " + (typeof v) + ") has no properties";231 throw rn ? new TypeError(message, rn.filename(), rn.lineno)232 : new TypeError(message);233}234function execute(n, x) {235 if (!this.new_block)236 new_block = new Array();237 //alert (n)238 var a, f, i, j, r, s, t, u, v;239 switch (n.type) {240 case FUNCTION:241 if (n.functionForm != DECLARED_FORM) {242 if (!n.name || n.functionForm == STATEMENT_FORM) {243 v = new FunctionObject(n, x.scope);244 if (n.functionForm == STATEMENT_FORM)245 x.scope.object[n.name] = v;246 } else {247 t = new Object;248 x.scope = {object: t, parent: x.scope};249 try {250 v = new FunctionObject(n, x.scope);251 t[n.name] = v;252 } finally {253 x.scope = x.scope.parent;254 }255 }256 }257 break;258 case SCRIPT: 259 t = x.scope.object;260 a = n.funDecls;261 for (i = 0, j = a.length; i < j; i++) {262 s = a[i].name;263 f = new FunctionObject(a[i], x.scope);264 t[s] = f;265 }266 a = n.varDecls;267 for (i = 0, j = a.length; i < j; i++) {268 u = a[i];269 s = u.name;270 if (u.readOnly && hasDirectProperty(t, s)) {271 throw new TypeError("Redeclaration of const " + s,272 u.filename(), u.lineno);273 }274 if (u.readOnly || !hasDirectProperty(t, s)) {275 t[s] = null;276 }277 }278 // FALL THROUGH279 case BLOCK: 280 for (i = 0, j = n.$length; i < j; i++) { 281 //jrh282 //execute(n[i], x); 283 //new_block.unshift([n[i], x]); 284 new_block.push([n[i], x]); 285 }286 new_block.reverse(); 287 agenda = agenda.concat(new_block); 288 //agenda = new_block.concat(agenda)289 // end jrh290 break;291 case IF:292 if (getValue(execute(n.condition, x)))293 execute(n.thenPart, x);294 else if (n.elsePart)295 execute(n.elsePart, x);296 break;297 case SWITCH:298 s = getValue(execute(n.discriminant, x));299 a = n.cases;300 var matchDefault = false;301 switch_loop:302 for (i = 0, j = a.length; ; i++) {303 if (i == j) {304 if (n.defaultIndex >= 0) {305 i = n.defaultIndex - 1; // no case matched, do default306 matchDefault = true;307 continue;308 }309 break; // no default, exit switch_loop310 }311 t = a[i]; // next case (might be default!)312 if (t.type == CASE) {313 u = getValue(execute(t.caseLabel, x));314 } else {315 if (!matchDefault) // not defaulting, skip for now316 continue;317 u = s; // force match to do default318 }319 if (u === s) {320 for (;;) { // this loop exits switch_loop321 if (t.statements.length) {322 try {323 execute(t.statements, x);324 } catch (e) {325 if (!(e == BREAK && x.target == n)) { throw e }326 break switch_loop;327 }328 }329 if (++i == j)330 break switch_loop;331 t = a[i];332 }333 // NOT REACHED334 }335 }336 break;337 case FOR:338 // jrh339 // added "skip_setup" so initialization doesn't get called340 // on every call..341 if (!skip_setup)342 n.setup && getValue(execute(n.setup, x));343 // FALL THROUGH344 case WHILE:345 // jrh 346 //while (!n.condition || getValue(execute(n.condition, x))) {347 if (!n.condition || getValue(execute(n.condition, x))) {348 try {349 // jrh 350 //execute(n.body, x);351 new_block.push([n.body, x]);352 agenda.push([n.body, x])353 //agenda.unshift([n.body, x])354 // end jrh355 } catch (e) {356 if (e == BREAK && x.target == n) {357 break;358 } else if (e == CONTINUE && x.target == n) {359 // jrh360 // 'continue' is invalid inside an 'if' clause361 // I don't know what commenting this out will break!362 //continue;363 // end jrh364 365 } else {366 throw e;367 }368 } 369 n.update && getValue(execute(n.update, x));370 // jrh371 new_block.unshift([n, x])372 agenda.splice(agenda.length-1,0,[n, x])373 //agenda.splice(1,0,[n, x])374 skip_setup = 1375 // end jrh376 } else {377 skip_setup = 0378 }379 380 break;381 case FOR_IN:382 u = n.varDecl;383 if (u)384 execute(u, x);385 r = n.iterator;386 s = execute(n.object, x);387 v = getValue(s);388 // ECMA deviation to track extant browser JS implementation behavior.389 t = (v == null && !x.ecmaStrictMode) ? v : toObject(v, s, n.object);390 a = [];391 for (i in t)392 a.push(i);393 for (i = 0, j = a.length; i < j; i++) {394 putValue(execute(r, x), a[i], r);395 try {396 execute(n.body, x);397 } catch (e) {398 if (e == BREAK && x.target == n) {399 break;400 } else if (e == CONTINUE && x.target == n) {401 continue;402 } else {403 throw e;404 }405 }406 }407 break;408 case DO:409 do {410 try {411 execute(n.body, x);412 } catch (e) {413 if (e == BREAK && x.target == n) {414 break;415 } else if (e == CONTINUE && x.target == n) {416 continue;417 } else {418 throw e;419 }420 }421 } while (getValue(execute(n.condition, x)));422 break;423 case BREAK:424 case CONTINUE:425 x.target = n.target;426 throw n.type;427 case TRY:428 try {429 execute(n.tryBlock, x);430 } catch (e) {431 if (!(e == THROW && (j = n.catchClauses.length))) {432 throw e;433 }434 e = x.result;435 x.result = undefined;436 for (i = 0; ; i++) {437 if (i == j) {438 x.result = e;439 throw THROW;440 }441 t = n.catchClauses[i];442 x.scope = {object: {}, parent: x.scope};443 x.scope.object[t.varName] = e;444 try {445 if (t.guard && !getValue(execute(t.guard, x)))446 continue;447 execute(t.block, x);448 break;449 } finally {450 x.scope = x.scope.parent;451 }452 }453 } finally {454 if (n.finallyBlock)455 execute(n.finallyBlock, x);456 }457 break;458 case THROW:459 x.result = getValue(execute(n.exception, x));460 throw THROW;461 case RETURN:462 x.result = getValue(execute(n.value, x));463 throw RETURN;464 case WITH:465 r = execute(n.object, x);466 t = toObject(getValue(r), r, n.object);467 x.scope = {object: t, parent: x.scope};468 try {469 execute(n.body, x);470 } finally {471 x.scope = x.scope.parent;472 }473 break;474 case VAR:475 case CONST:476 for (i = 0, j = n.$length; i < j; i++) {477 u = n[i].initializer;478 if (!u)479 continue;480 t = n[i].name;481 for (s = x.scope; s; s = s.parent) {482 if (hasDirectProperty(s.object, t))483 break;484 }485 u = getValue(execute(u, x));486 if (n.type == CONST)487 s.object[t] = u;488 else489 s.object[t] = u;490 }491 break;492 case DEBUGGER:493 throw "NYI: " + tokens[n.type];494 case REQUIRE:495 var req = new XMLHttpRequest();496 req.open('GET', n.filename, 'false');497 case SEMICOLON:498 if (n.expression)499 // print debugging statements500 501 var the_start = n.start502 var the_end = n.end503 var the_statement = parse_result.tokenizer.source.slice(the_start,the_end)504 //global.debug.document.body.innerHTML += ('<pre>&gt;&gt;&gt; <b>' + the_statement + '</b></pre>')505 LOG.info('>>>' + the_statement)506 x.result = getValue(execute(n.expression, x)); 507 //if (x.result)508 //global.debug.document.body.innerHTML += ( '<pre>&gt;&gt;&gt; ' + x.result + '</pre>')509 510 break;511 case LABEL:512 try {513 execute(n.statement, x);514 } catch (e) {515 if (!(e == BREAK && x.target == n)) { throw e }516 }517 break;518 case COMMA:519 for (i = 0, j = n.$length; i < j; i++)520 v = getValue(execute(n[i], x));521 break;522 case ASSIGN:523 r = execute(n[0], x);524 t = n[0].assignOp;525 if (t)526 u = getValue(r);527 v = getValue(execute(n[1], x));528 if (t) {529 switch (t) {530 case BITWISE_OR: v = u | v; break;531 case BITWISE_XOR: v = u ^ v; break;532 case BITWISE_AND: v = u & v; break;533 case LSH: v = u << v; break;534 case RSH: v = u >> v; break;535 case URSH: v = u >>> v; break;536 case PLUS: v = u + v; break;537 case MINUS: v = u - v; break;538 case MUL: v = u * v; break;539 case DIV: v = u / v; break;540 case MOD: v = u % v; break;541 }542 }543 putValue(r, v, n[0]);544 break;545 case CONDITIONAL:546 v = getValue(execute(n[0], x)) ? getValue(execute(n[1], x))547 : getValue(execute(n[2], x));548 break;549 case OR:550 v = getValue(execute(n[0], x)) || getValue(execute(n[1], x));551 break;552 case AND:553 v = getValue(execute(n[0], x)) && getValue(execute(n[1], x));554 break;555 case BITWISE_OR:556 v = getValue(execute(n[0], x)) | getValue(execute(n[1], x));557 break;558 case BITWISE_XOR:559 v = getValue(execute(n[0], x)) ^ getValue(execute(n[1], x));560 break;561 case BITWISE_AND:562 v = getValue(execute(n[0], x)) & getValue(execute(n[1], x));563 break;564 case EQ:565 v = getValue(execute(n[0], x)) == getValue(execute(n[1], x));566 break;567 case NE:568 v = getValue(execute(n[0], x)) != getValue(execute(n[1], x));569 break;570 case STRICT_EQ:571 v = getValue(execute(n[0], x)) === getValue(execute(n[1], x));572 break;573 case STRICT_NE:574 v = getValue(execute(n[0], x)) !== getValue(execute(n[1], x));575 break;576 case LT:577 v = getValue(execute(n[0], x)) < getValue(execute(n[1], x));578 break;579 case LE:580 v = getValue(execute(n[0], x)) <= getValue(execute(n[1], x));581 break;582 case GE:583 v = getValue(execute(n[0], x)) >= getValue(execute(n[1], x));584 break;585 case GT:586 v = getValue(execute(n[0], x)) > getValue(execute(n[1], x));587 break;588 case IN:589 v = getValue(execute(n[0], x)) in getValue(execute(n[1], x));590 break;591 case INSTANCEOF:592 t = getValue(execute(n[0], x));593 u = getValue(execute(n[1], x));594 if (isObject(u) && typeof u.__hasInstance__ == "function")595 v = u.__hasInstance__(t);596 else597 v = t instanceof u;598 break;599 case LSH:600 v = getValue(execute(n[0], x)) << getValue(execute(n[1], x));601 break;602 case RSH:603 v = getValue(execute(n[0], x)) >> getValue(execute(n[1], x));604 break;605 case URSH:606 v = getValue(execute(n[0], x)) >>> getValue(execute(n[1], x));607 break;608 case PLUS:609 v = getValue(execute(n[0], x)) + getValue(execute(n[1], x));610 break;611 case MINUS:612 v = getValue(execute(n[0], x)) - getValue(execute(n[1], x));613 break;614 case MUL:615 v = getValue(execute(n[0], x)) * getValue(execute(n[1], x));616 break;617 case DIV:618 v = getValue(execute(n[0], x)) / getValue(execute(n[1], x));619 break;620 case MOD:621 v = getValue(execute(n[0], x)) % getValue(execute(n[1], x));622 break;623 case DELETE:624 t = execute(n[0], x);625 v = !(t instanceof Reference) || delete t.base[t.propertyName];626 break;627 case VOID:628 getValue(execute(n[0], x));629 break;630 case TYPEOF:631 t = execute(n[0], x);632 if (t instanceof Reference)633 t = t.base ? t.base[t.propertyName] : undefined;634 v = typeof t;635 break;636 case NOT:637 v = !getValue(execute(n[0], x));638 break;639 case BITWISE_NOT:640 v = ~getValue(execute(n[0], x));641 break;642 case UNARY_PLUS:643 v = +getValue(execute(n[0], x));644 break;645 case UNARY_MINUS:646 v = -getValue(execute(n[0], x));647 break;648 case INCREMENT:649 case DECREMENT:650 t = execute(n[0], x);651 u = Number(getValue(t));652 if (n.postfix)653 v = u;654 putValue(t, (n.type == INCREMENT) ? ++u : --u, n[0]);655 if (!n.postfix)656 v = u;657 break;658 case DOT:659 r = execute(n[0], x);660 t = getValue(r);661 u = n[1].value;662 v = new Reference(toObject(t, r, n[0]), u, n);663 break;664 case INDEX:665 r = execute(n[0], x);666 t = getValue(r);667 u = getValue(execute(n[1], x));668 v = new Reference(toObject(t, r, n[0]), String(u), n);669 break;670 case LIST:671 // Curse ECMA for specifying that arguments is not an Array object!672 v = {};673 for (i = 0, j = n.$length; i < j; i++) {674 u = getValue(execute(n[i], x));675 v[i] = u;676 }677 v.length = i;678 break;679 case CALL:680 r = execute(n[0], x);681 a = execute(n[1], x);682 f = getValue(r);683 if (isPrimitive(f) || typeof f.__call__ != "function") {684 throw new TypeError(r + " is not callable",685 n[0].filename(), n[0].lineno);686 }687 t = (r instanceof Reference) ? r.base : null;688 if (t instanceof Activation)689 t = null;690 v = f.__call__(t, a, x);691 break;692 case NEW:693 case NEW_WITH_ARGS:694 r = execute(n[0], x);695 f = getValue(r);696 if (n.type == NEW) {697 a = {};698 a.length = 0;699 } else {700 a = execute(n[1], x);701 }702 if (isPrimitive(f) || typeof f.__construct__ != "function") {703 throw new TypeError(r + " is not a constructor",704 n[0].filename(), n[0].lineno);705 }706 v = f.__construct__(a, x);707 break;708 case ARRAY_INIT:709 v = [];710 for (i = 0, j = n.$length; i < j; i++) {711 if (n[i])712 v[i] = getValue(execute(n[i], x));713 }714 v.length = j;715 break;716 case OBJECT_INIT:717 v = {};718 for (i = 0, j = n.$length; i < j; i++) {719 t = n[i];720 if (t.type == PROPERTY_INIT) {721 v[t[0].value] = getValue(execute(t[1], x));722 } else {723 f = new FunctionObject(t, x.scope);724 /*725 u = (t.type == GETTER) ? '__defineGetter__'726 : '__defineSetter__';727 v[u](t.name, thunk(f, x));728 */729 }730 }731 break;732 case NULL:733 v = null;734 break;735 case THIS:736 v = x.thisObject;737 break;738 case TRUE:739 v = true;740 break;741 case FALSE:742 v = false;743 break;744 case IDENTIFIER:745 for (s = x.scope; s; s = s.parent) {746 if (n.value in s.object)747 break;748 }749 v = new Reference(s && s.object, n.value, n);750 break;751 case NUMBER:752 case STRING:753 case REGEXP:754 v = n.value;755 break;756 case GROUP:757 v = execute(n[0], x);758 break;759 default:760 throw "PANIC: unknown operation " + n.type + ": " + uneval(n);761 }762 return v;763}764function Activation(f, a) {765 for (var i = 0, j = f.params.length; i < j; i++)766 this[f.params[i]] = a[i];767 this.arguments = a;768}769// Null Activation.prototype's proto slot so that Object.prototype.* does not770// pollute the scope of heavyweight functions. Also delete its 'constructor'771// property so that it doesn't pollute function scopes.772Activation.prototype.__proto__ = null;773delete Activation.prototype.constructor;774function FunctionObject(node, scope) {775 this.node = node;776 this.scope = scope;777 this.length = node.params.length;778 var proto = {};779 this.prototype = proto;780 proto.constructor = this;781}782var FOp = FunctionObject.prototype = {783 // Internal methods.784 __call__: function (t, a, x) {785 var x2 = new ExecutionContext(FUNCTION_CODE);786 x2.thisObject = t || global;787 x2.caller = x;788 x2.callee = this;789 a.callee = this;790 var f = this.node;791 x2.scope = {object: new Activation(f, a), parent: this.scope};792 ExecutionContext.current = x2;793 try {794 execute(f.body, x2);795 } catch (e) {796 if (!(e == RETURN)) { throw e } else if (e == RETURN) {797 return x2.result;798 }799 if (e != THROW) { throw e }800 x.result = x2.result;801 throw THROW;802 } finally {803 ExecutionContext.current = x;804 }805 return undefined;806 },807 __construct__: function (a, x) {808 var o = new Object;809 var p = this.prototype;810 if (isObject(p))811 o.__proto__ = p;812 // else o.__proto__ defaulted to Object.prototype813 var v = this.__call__(o, a, x);814 if (isObject(v))815 return v;816 return o;817 },818 __hasInstance__: function (v) {819 if (isPrimitive(v))820 return false;821 var p = this.prototype;822 if (isPrimitive(p)) {823 throw new TypeError("'prototype' property is not an object",824 this.node.filename(), this.node.lineno);825 }826 var o;827 while ((o = v.__proto__)) {828 if (o == p)829 return true;830 v = o;831 }832 return false;833 },834 // Standard methods.835 toString: function () {836 return this.node.getSource();837 },838 apply: function (t, a) {839 // Curse ECMA again!840 if (typeof this.__call__ != "function") {841 throw new TypeError("Function.prototype.apply called on" +842 " uncallable object");843 }844 if (t === undefined || t === null)845 t = global;846 else if (typeof t != "object")847 t = toObject(t, t);848 if (a === undefined || a === null) {849 a = {};850 a.length = 0;851 } else if (a instanceof Array) {852 var v = {};853 for (var i = 0, j = a.length; i < j; i++)854 v[i] = a[i];855 v.length = i;856 a = v;857 } else if (!(a instanceof Object)) {858 // XXX check for a non-arguments object859 throw new TypeError("Second argument to Function.prototype.apply" +860 " must be an array or arguments object",861 this.node.filename(), this.node.lineno);862 }863 return this.__call__(t, a, ExecutionContext.current);864 },865 call: function (t) {866 // Curse ECMA a third time!867 var a = Array.prototype.splice.call(arguments, 1);868 return this.apply(t, a);869 }870};871// Connect Function.prototype and Function.prototype.constructor in global.872reflectClass('Function', FOp);873// Help native and host-scripted functions be like FunctionObjects.874var Fp = Function.prototype;875var REp = RegExp.prototype;876if (!('__call__' in Fp)) {877 Fp.__call__ = function (t, a, x) {878 // Curse ECMA yet again!879 a = Array.prototype.splice.call(a, 0, a.length);880 return this.apply(t, a);881 };882 REp.__call__ = function (t, a, x) {883 a = Array.prototype.splice.call(a, 0, a.length);884 return this.exec.apply(this, a);885 };886 Fp.__construct__ = function (a, x) {887 switch (a.length) {888 case 0:889 return new this();890 case 1:891 return new this(a[0]);892 case 2:893 return new this(a[0], a[1]);894 case 3:895 return new this(a[0], a[1], a[2]);896 case 4:897 return new this(a[0], a[1], a[2], a[3]);898 case 5:899 return new this(a[0], a[1], a[2], a[3], a[4]);900 case 6:901 return new this(a[0], a[1], a[2], a[3], a[4], a[5]);902 case 7:903 return new this(a[0], a[1], a[2], a[3], a[4], a[5], a[6]);904 }905 throw "PANIC: too many arguments to constructor";906 }907 // Since we use native functions such as Date along with host ones such908 // as global.eval, we want both to be considered instances of the native909 // Function constructor.910 Fp.__hasInstance__ = function (v) {911 return v instanceof Function || v instanceof global.Function;912 };913}914function thunk(f, x) {915 return function () { return f.__call__(this, arguments, x); };916}917function evaluate(s, f, l) {918 if (typeof s != "string")919 return s;920 var x = ExecutionContext.current;921 var x2 = new ExecutionContext(GLOBAL_CODE);922 ExecutionContext.current = x2;923 try {924 execute(parse(s, f, l), x2);925 } catch (e) {926 if (e != THROW) { throw e }927 if (x) {928 x.result = x2.result;929 throw(THROW);930 }931 throw x2.result;932 } finally {933 ExecutionContext.current = x;934 }935 return x2.result;...

Full Screen

Full Screen

sharer.js

Source:sharer.js Github

copy

Full Screen

1/**2 * @preserve3 * Sharer.js4 *5 * @description Create your own social share buttons6 * @version 0.4.07 * @author Ellison Leao <ellisonleao@gmail.com>8 * @license GPLv39 *10 */11(function (window, document) {12 'use strict';13 /**14 * @constructor15 */16 var Sharer = function (elem) {17 this.elem = elem;18 };19 /**20 * @function init21 * @description bind the events for multiple sharer elements22 * @returns {Empty}23 */24 Sharer.init = function () {25 var elems = document.querySelectorAll('[data-sharer]'),26 i,27 l = elems.length;28 for (i = 0; i < l; i++) {29 elems[i].addEventListener('click', Sharer.add);30 }31 };32 /**33 * @function add34 * @description bind the share event for a single dom element35 * @returns {Empty}36 */37 Sharer.add = function (elem) {38 var target = elem.currentTarget || elem.srcElement;39 var sharer = new Sharer(target);40 sharer.share();41 };42 // instance methods43 Sharer.prototype = {44 constructor: Sharer,45 /**46 * @function getValue47 * @description Helper to get the attribute of a DOM element48 * @param {String} attr DOM element attribute49 * @returns {String|Empty} returns the attr value or empty string50 */51 getValue: function (attr) {52 var val = this.elem.getAttribute('data-' + attr);53 // handing facebook hashtag attribute54 if (val && attr === 'hashtag') {55 if (!val.startsWith('#')) {56 val = '#' + val;57 }58 }59 return val;60 },61 /**62 * @event share63 * @description Main share event. Will pop a window or redirect to a link64 * based on the data-sharer attribute.65 */66 share: function () {67 var sharer = this.getValue('sharer').toLowerCase(),68 sharers = {69 facebook: {70 shareUrl: 'https://www.facebook.com/sharer/sharer.php',71 params: {72 u: this.getValue('url'),73 hashtag: this.getValue('hashtag')74 }75 },76 linkedin: {77 shareUrl: 'https://www.linkedin.com/shareArticle',78 params: {79 url: this.getValue('url'),80 mini: true81 }82 },83 twitter: {84 shareUrl: 'https://twitter.com/intent/tweet/',85 params: {86 text: this.getValue('title'),87 url: this.getValue('url'),88 hashtags: this.getValue('hashtags'),89 via: this.getValue('via')90 }91 },92 email: {93 shareUrl: 'mailto:' + this.getValue('to') || '',94 params: {95 subject: this.getValue('subject'),96 body: this.getValue('title') + '\n' + this.getValue('url')97 },98 isLink: true99 },100 whatsapp: {101 shareUrl: this.getValue('web') !== null ? 'https://api.whatsapp.com/send' : 'whatsapp://send',102 params: {103 text: this.getValue('title') + ' ' + this.getValue('url')104 },105 isLink: true106 },107 telegram: {108 shareUrl: this.getValue('web') !== null ? 'https://telegram.me/share' : 'tg://msg_url',109 params: {110 text: this.getValue('title'),111 url: this.getValue('url'),112 to: this.getValue('to')113 },114 isLink: true115 },116 viber: {117 shareUrl: 'viber://forward',118 params: {119 text: this.getValue('title') + ' ' + this.getValue('url')120 },121 isLink: true122 },123 line: {124 shareUrl:125 'http://line.me/R/msg/text/?' + encodeURIComponent(this.getValue('title') + ' ' + this.getValue('url')),126 isLink: true127 },128 pinterest: {129 shareUrl: 'https://www.pinterest.com/pin/create/button/',130 params: {131 url: this.getValue('url'),132 media: this.getValue('image'),133 description: this.getValue('description')134 }135 },136 tumblr: {137 shareUrl: 'http://tumblr.com/widgets/share/tool',138 params: {139 canonicalUrl: this.getValue('url'),140 content: this.getValue('url'),141 posttype: 'link',142 title: this.getValue('title'),143 caption: this.getValue('caption'),144 tags: this.getValue('tags')145 }146 },147 hackernews: {148 shareUrl: 'https://news.ycombinator.com/submitlink',149 params: {150 u: this.getValue('url'),151 t: this.getValue('title')152 }153 },154 reddit: {155 shareUrl: 'https://www.reddit.com/submit',156 params: { url: this.getValue('url') }157 },158 vk: {159 shareUrl: 'http://vk.com/share.php',160 params: {161 url: this.getValue('url'),162 title: this.getValue('title'),163 description: this.getValue('caption'),164 image: this.getValue('image')165 }166 },167 xing: {168 shareUrl: 'https://www.xing.com/app/user',169 params: {170 op: 'share',171 url: this.getValue('url'),172 title: this.getValue('title')173 }174 },175 buffer: {176 shareUrl: 'https://buffer.com/add',177 params: {178 url: this.getValue('url'),179 title: this.getValue('title'),180 via: this.getValue('via'),181 picture: this.getValue('picture')182 }183 },184 instapaper: {185 shareUrl: 'http://www.instapaper.com/edit',186 params: {187 url: this.getValue('url'),188 title: this.getValue('title'),189 description: this.getValue('description')190 }191 },192 pocket: {193 shareUrl: 'https://getpocket.com/save',194 params: {195 url: this.getValue('url')196 }197 },198 digg: {199 shareUrl: 'http://www.digg.com/submit',200 params: {201 url: this.getValue('url')202 }203 },204 stumbleupon: {205 // Usage deprecated, leaving for backwards compatibility.206 shareUrl: 'http://www.stumbleupon.com/submit',207 params: {208 url: this.getValue('url'),209 title: this.getValue('title')210 }211 },212 mashable: {213 shareUrl: 'https://mashable.com/submit',214 params: {215 url: this.getValue('url'),216 title: this.getValue('title')217 }218 },219 mix: {220 shareUrl: 'https://mix.com/add',221 params: {222 url: this.getValue('url')223 }224 },225 flipboard: {226 shareUrl: 'https://share.flipboard.com/bookmarklet/popout',227 params: {228 v: 2,229 title: this.getValue('title'),230 url: this.getValue('url'),231 t: Date.now()232 }233 },234 weibo: {235 shareUrl: 'http://service.weibo.com/share/share.php',236 params: {237 url: this.getValue('url'),238 title: this.getValue('title'),239 pic: this.getValue('image'),240 appkey: this.getValue('appkey'),241 ralateUid: this.getValue('ralateuid'),242 language: 'zh_cn'243 }244 },245 renren: {246 shareUrl: 'http://share.renren.com/share/buttonshare',247 params: {248 link: this.getValue('url')249 }250 },251 myspace: {252 shareUrl: 'https://myspace.com/post',253 params: {254 u: this.getValue('url'),255 t: this.getValue('title'),256 c: this.getValue('description')257 }258 },259 blogger: {260 shareUrl: 'https://www.blogger.com/blog-this.g',261 params: {262 u: this.getValue('url'),263 n: this.getValue('title'),264 t: this.getValue('description')265 }266 },267 baidu: {268 shareUrl: 'http://cang.baidu.com/do/add',269 params: {270 it: this.getValue('title'),271 iu: this.getValue('url')272 }273 },274 douban: {275 shareUrl: 'https://www.douban.com/share/service',276 params: {277 name: this.getValue('title'),278 href: this.getValue('url'),279 image: this.getValue('image')280 }281 },282 okru: {283 shareUrl: 'https://connect.ok.ru/dk',284 params: {285 'st.cmd': 'WidgetSharePreview',286 'st.shareUrl': this.getValue('url'),287 title: this.getValue('title')288 }289 },290 mailru: {291 shareUrl: 'http://connect.mail.ru/share',292 params: {293 share_url: this.getValue('url'),294 linkname: this.getValue('title'),295 linknote: this.getValue('description'),296 type: 'page'297 }298 },299 evernote: {300 shareUrl: 'http://www.evernote.com/clip.action',301 params: {302 url: this.getValue('url'),303 title: this.getValue('title')304 }305 },306 skype: {307 shareUrl: 'https://web.skype.com/share',308 params: {309 url: this.getValue('url'),310 title: this.getValue('title')311 }312 },313 quora: {314 shareUrl: 'https://www.quora.com/share',315 params: {316 url: this.getValue('url'),317 title: this.getValue('title')318 }319 },320 delicious: {321 shareUrl: 'https://del.icio.us/post',322 params: {323 url: this.getValue('url'),324 title: this.getValue('title')325 }326 },327 sms: {328 shareUrl: 'sms://',329 params: {330 body: this.getValue('body')331 }332 },333 trello: {334 shareUrl: 'https://trello.com/add-card',335 params: {336 url: this.getValue('url'),337 name: this.getValue('title'),338 desc: this.getValue('description'),339 mode: 'popup'340 }341 },342 messenger: {343 shareUrl: 'fb-messenger://share',344 params: {345 link: this.getValue('url')346 }347 },348 odnoklassniki: {349 shareUrl: 'https://connect.ok.ru/dk',350 params: {351 st: {352 cmd: 'WidgetSharePreview',353 deprecated: 1,354 shareUrl: this.getValue('url')355 }356 }357 },358 meneame: {359 shareUrl: 'https://www.meneame.net/submit',360 params: {361 url: this.getValue('url')362 }363 },364 diaspora: {365 shareUrl: 'https://share.diasporafoundation.org',366 params: {367 title: this.getValue('title'),368 url: this.getValue('url')369 }370 },371 googlebookmarks: {372 shareUrl: 'https://www.google.com/bookmarks/mark',373 params: {374 op: 'edit',375 bkmk: this.getValue('url'),376 title: this.getValue('title')377 }378 },379 qzone: {380 shareUrl: 'https://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey',381 params: {382 url: this.getValue('url')383 }384 },385 refind: {386 shareUrl: 'https://refind.com',387 params: {388 url: this.getValue('url')389 }390 },391 surfingbird: {392 shareUrl: 'https://surfingbird.ru/share',393 params: {394 url: this.getValue('url'),395 title: this.getValue('title'),396 description: this.getValue('description')397 }398 },399 yahoomail: {400 shareUrl: 'http://compose.mail.yahoo.com',401 params: {402 to: this.getValue('to'),403 subject: this.getValue('subject'),404 body: this.getValue('body')405 }406 },407 wordpress: {408 shareUrl: 'https://wordpress.com/wp-admin/press-this.php',409 params: {410 u: this.getValue('url'),411 t: this.getValue('title'),412 s: this.getValue('title')413 }414 },415 amazon: {416 shareUrl: 'https://www.amazon.com/gp/wishlist/static-add',417 params: {418 u: this.getValue('url'),419 t: this.getValue('title')420 }421 },422 pinboard: {423 shareUrl: 'https://pinboard.in/add',424 params: {425 url: this.getValue('url'),426 title: this.getValue('title'),427 description: this.getValue('description')428 }429 },430 threema: {431 shareUrl: 'threema://compose',432 params: {433 text: this.getValue('text'),434 id: this.getValue('id')435 }436 },437 kakaostory: {438 shareUrl: 'https://story.kakao.com/share',439 params: {440 url: this.getValue('url')441 }442 }443 },444 s = sharers[sharer];445 // custom popups sizes446 if (s) {447 s.width = this.getValue('width');448 s.height = this.getValue('height');449 }450 return s !== undefined ? this.urlSharer(s) : false;451 },452 /**453 * @event urlSharer454 * @param {Object} sharer455 */456 urlSharer: function (sharer) {457 var p = sharer.params || {},458 keys = Object.keys(p),459 i,460 str = keys.length > 0 ? '?' : '';461 for (i = 0; i < keys.length; i++) {462 if (str !== '?') {463 str += '&';464 }465 if (p[keys[i]]) {466 str += keys[i] + '=' + encodeURIComponent(p[keys[i]]);467 }468 }469 sharer.shareUrl += str;470 if (!sharer.isLink) {471 var popWidth = sharer.width || 600,472 popHeight = sharer.height || 480,473 left = window.innerWidth / 2 - popWidth / 2 + window.screenX,474 top = window.innerHeight / 2 - popHeight / 2 + window.screenY,475 popParams = 'scrollbars=no, width=' + popWidth + ', height=' + popHeight + ', top=' + top + ', left=' + left,476 newWindow = window.open(sharer.shareUrl, '', popParams);477 if (window.focus) {478 newWindow.focus();479 }480 } else {481 window.location.href = sharer.shareUrl;482 }483 }484 };485 // adding sharer events on domcontentload486 if (document.readyState === 'complete' || document.readyState !== 'loading') {487 Sharer.init();488 } else {489 document.addEventListener('DOMContentLoaded', Sharer.init);490 }491 // turbolinks 3 compatibility492 window.addEventListener('page:load', Sharer.init);493 // turbolinks 5 compatibility494 window.addEventListener('turbolinks:load', Sharer.init);495 // exporting sharer for external usage496 window.Sharer = Sharer;...

Full Screen

Full Screen

document_test.js

Source:document_test.js Github

copy

Full Screen

1/* ***** BEGIN LICENSE BLOCK *****2 * Version: MPL 1.1/GPL 2.0/LGPL 2.13 *4 * The contents of this file are subject to the Mozilla Public License Version5 * 1.1 (the "License"); you may not use this file except in compliance with6 * the License. You may obtain a copy of the License at7 * http://www.mozilla.org/MPL/8 *9 * Software distributed under the License is distributed on an "AS IS" basis,10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License11 * for the specific language governing rights and limitations under the12 * License.13 *14 * The Original Code is Ajax.org Code Editor (ACE).15 *16 * The Initial Developer of the Original Code is17 * Ajax.org B.V.18 * Portions created by the Initial Developer are Copyright (C) 201019 * the Initial Developer. All Rights Reserved.20 *21 * Contributor(s):22 * Fabian Jakobs <fabian AT ajax DOT org>23 * Julian Viereck <julian.viereck@gmail.com>24 *25 * Alternatively, the contents of this file may be used under the terms of26 * either the GNU General Public License Version 2 or later (the "GPL"), or27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),28 * in which case the provisions of the GPL or the LGPL are applicable instead29 * of those above. If you wish to allow use of your version of this file only30 * under the terms of either the GPL or the LGPL, and not to allow others to31 * use your version of this file under the terms of the MPL, indicate your32 * decision by deleting the provisions above and replace them with the notice33 * and other provisions required by the GPL or the LGPL. If you do not delete34 * the provisions above, a recipient may use your version of this file under35 * the terms of any one of the MPL, the GPL or the LGPL.36 *37 * ***** END LICENSE BLOCK ***** */38if (typeof process !== "undefined") {39 require("../../support/paths");40 require("ace/test/mockdom");41}42define(function(require, exports, module) {43 44var Document = require("ace/document").Document;45var Range = require("ace/range").Range;46var assert = require("ace/test/assertions");47module.exports = {48 "test: insert text in line" : function() {49 var doc = new Document(["12", "34"]);50 var deltas = [];51 doc.on("change", function(e) { deltas.push(e.data); });52 doc.insert({row: 0, column: 1}, "juhu");53 assert.equal(doc.getValue(), ["1juhu2", "34"].join("\n"));54 var d = deltas.concat();55 doc.revertDeltas(d);56 assert.equal(doc.getValue(), ["12", "34"].join("\n"));57 doc.applyDeltas(d);58 assert.equal(doc.getValue(), ["1juhu2", "34"].join("\n"));59 },60 "test: insert new line" : function() {61 var doc = new Document(["12", "34"]);62 var deltas = [];63 doc.on("change", function(e) { deltas.push(e.data); });64 doc.insertNewLine({row: 0, column: 1});65 assert.equal(doc.getValue(), ["1", "2", "34"].join("\n"));66 var d = deltas.concat();67 doc.revertDeltas(d);68 assert.equal(doc.getValue(), ["12", "34"].join("\n"));69 doc.applyDeltas(d);70 assert.equal(doc.getValue(), ["1", "2", "34"].join("\n"));71 },72 "test: insert lines at the beginning" : function() {73 var doc = new Document(["12", "34"]);74 var deltas = [];75 doc.on("change", function(e) { deltas.push(e.data); });76 doc.insertLines(0, ["aa", "bb"]);77 assert.equal(doc.getValue(), ["aa", "bb", "12", "34"].join("\n"));78 var d = deltas.concat();79 doc.revertDeltas(d);80 assert.equal(doc.getValue(), ["12", "34"].join("\n"));81 doc.applyDeltas(d);82 assert.equal(doc.getValue(), ["aa", "bb", "12", "34"].join("\n"));83 },84 "test: insert lines at the end" : function() {85 var doc = new Document(["12", "34"]);86 var deltas = [];87 doc.on("change", function(e) { deltas.push(e.data); });88 doc.insertLines(2, ["aa", "bb"]);89 assert.equal(doc.getValue(), ["12", "34", "aa", "bb"].join("\n"));90 },91 "test: insert lines in the middle" : function() {92 var doc = new Document(["12", "34"]);93 var deltas = [];94 doc.on("change", function(e) { deltas.push(e.data); });95 doc.insertLines(1, ["aa", "bb"]);96 assert.equal(doc.getValue(), ["12", "aa", "bb", "34"].join("\n"));97 var d = deltas.concat();98 doc.revertDeltas(d);99 assert.equal(doc.getValue(), ["12", "34"].join("\n"));100 doc.applyDeltas(d);101 assert.equal(doc.getValue(), ["12", "aa", "bb", "34"].join("\n"));102 },103 "test: insert multi line string at the start" : function() {104 var doc = new Document(["12", "34"]);105 var deltas = [];106 doc.on("change", function(e) { deltas.push(e.data); });107 doc.insert({row: 0, column: 0}, "aa\nbb\ncc");108 assert.equal(doc.getValue(), ["aa", "bb", "cc12", "34"].join("\n"));109 var d = deltas.concat();110 doc.revertDeltas(d);111 assert.equal(doc.getValue(), ["12", "34"].join("\n"));112 doc.applyDeltas(d);113 assert.equal(doc.getValue(), ["aa", "bb", "cc12", "34"].join("\n"));114 },115 "test: insert multi line string at the end" : function() {116 var doc = new Document(["12", "34"]);117 var deltas = [];118 doc.on("change", function(e) { deltas.push(e.data); });119 doc.insert({row: 2, column: 0}, "aa\nbb\ncc");120 assert.equal(doc.getValue(), ["12", "34aa", "bb", "cc"].join("\n"));121 var d = deltas.concat();122 doc.revertDeltas(d);123 assert.equal(doc.getValue(), ["12", "34"].join("\n"));124 doc.applyDeltas(d);125 assert.equal(doc.getValue(), ["12", "34aa", "bb", "cc"].join("\n"));126 },127 "test: insert multi line string in the middle" : function() {128 var doc = new Document(["12", "34"]);129 var deltas = [];130 doc.on("change", function(e) { deltas.push(e.data); });131 doc.insert({row: 0, column: 1}, "aa\nbb\ncc");132 assert.equal(doc.getValue(), ["1aa", "bb", "cc2", "34"].join("\n"));133 var d = deltas.concat();134 doc.revertDeltas(d);135 assert.equal(doc.getValue(), ["12", "34"].join("\n"));136 doc.applyDeltas(d);137 assert.equal(doc.getValue(), ["1aa", "bb", "cc2", "34"].join("\n"));138 },139 "test: delete in line" : function() {140 var doc = new Document(["1234", "5678"]);141 var deltas = [];142 doc.on("change", function(e) { deltas.push(e.data); });143 doc.remove(new Range(0, 1, 0, 3));144 assert.equal(doc.getValue(), ["14", "5678"].join("\n"));145 var d = deltas.concat();146 doc.revertDeltas(d);147 assert.equal(doc.getValue(), ["1234", "5678"].join("\n"));148 doc.applyDeltas(d);149 assert.equal(doc.getValue(), ["14", "5678"].join("\n"));150 },151 "test: delete new line" : function() {152 var doc = new Document(["1234", "5678"]);153 var deltas = [];154 doc.on("change", function(e) { deltas.push(e.data); });155 doc.remove(new Range(0, 4, 1, 0));156 assert.equal(doc.getValue(), ["12345678"].join("\n"));157 var d = deltas.concat();158 doc.revertDeltas(d);159 assert.equal(doc.getValue(), ["1234", "5678"].join("\n"));160 doc.applyDeltas(d);161 assert.equal(doc.getValue(), ["12345678"].join("\n"));162 },163 "test: delete multi line range line" : function() {164 var doc = new Document(["1234", "5678", "abcd"]);165 var deltas = [];166 doc.on("change", function(e) { deltas.push(e.data); });167 doc.remove(new Range(0, 2, 2, 2));168 assert.equal(doc.getValue(), ["12cd"].join("\n"));169 var d = deltas.concat();170 doc.revertDeltas(d);171 assert.equal(doc.getValue(), ["1234", "5678", "abcd"].join("\n"));172 doc.applyDeltas(d);173 assert.equal(doc.getValue(), ["12cd"].join("\n"));174 },175 "test: delete full lines" : function() {176 var doc = new Document(["1234", "5678", "abcd"]);177 var deltas = [];178 doc.on("change", function(e) { deltas.push(e.data); });179 doc.remove(new Range(1, 0, 3, 0));180 assert.equal(doc.getValue(), ["1234", ""].join("\n"));181 },182 "test: remove lines should return the removed lines" : function() {183 var doc = new Document(["1234", "5678", "abcd"]);184 var removed = doc.removeLines(1, 2);185 assert.equal(removed.join("\n"), ["5678", "abcd"].join("\n"));186 },187 "test: should handle unix style new lines" : function() {188 var doc = new Document(["1", "2", "3"]);189 assert.equal(doc.getValue(), ["1", "2", "3"].join("\n"));190 },191 "test: should handle windows style new lines" : function() {192 var doc = new Document(["1", "2", "3"].join("\r\n"));193 doc.setNewLineMode("unix");194 assert.equal(doc.getValue(), ["1", "2", "3"].join("\n"));195 },196 "test: set new line mode to 'windows' should use '\\r\\n' as new lines": function() {197 var doc = new Document(["1", "2", "3"].join("\n"));198 doc.setNewLineMode("windows");199 assert.equal(doc.getValue(), ["1", "2", "3"].join("\r\n"));200 },201 "test: set new line mode to 'unix' should use '\\n' as new lines": function() {202 var doc = new Document(["1", "2", "3"].join("\r\n"));203 doc.setNewLineMode("unix");204 assert.equal(doc.getValue(), ["1", "2", "3"].join("\n"));205 },206 "test: set new line mode to 'auto' should detect the incoming nl type": function() {207 var doc = new Document(["1", "2", "3"].join("\n"));208 doc.setNewLineMode("auto");209 assert.equal(doc.getValue(), ["1", "2", "3"].join("\n"));210 var doc = new Document(["1", "2", "3"].join("\r\n"));211 doc.setNewLineMode("auto");212 assert.equal(doc.getValue(), ["1", "2", "3"].join("\r\n"));213 doc.replace(new Range(0, 0, 2, 1), ["4", "5", "6"].join("\n"));214 assert.equal(["4", "5", "6"].join("\n"), doc.getValue());215 },216 "test: set value": function() {217 var doc = new Document("1");218 assert.equal("1", doc.getValue());219 doc.setValue(doc.getValue());220 assert.equal("1", doc.getValue());221 var doc = new Document("1\n2");222 assert.equal("1\n2", doc.getValue());223 doc.setValue(doc.getValue());224 assert.equal("1\n2", doc.getValue());225 },226 "test: empty document has to contain one line": function() {227 var doc = new Document("");228 assert.equal(doc.$lines.length, 1);229 }230};231});232if (typeof module !== "undefined" && module === require.main) {233 require("asyncjs").test.testcase(module.exports).exec()...

Full Screen

Full Screen

Current.js

Source:Current.js Github

copy

Full Screen

1/**2 * WeatherAPILib3 *4 * This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ).5 */6'use strict';7const BaseModel = require('./BaseModel');8/**9 * Creates an instance of Current10 */11class Current extends BaseModel {12 /**13 * @constructor14 * @param {Object} obj The object passed to constructor15 */16 constructor(obj) {17 super(obj);18 if (obj === undefined || obj === null) return;19 this.lastUpdatedEpoch =20 this.constructor.getValue(obj.lastUpdatedEpoch21 || obj.last_updated_epoch);22 this.lastUpdated = this.constructor.getValue(obj.lastUpdated || obj.last_updated);23 this.tempC = this.constructor.getValue(obj.tempC || obj.temp_c);24 this.tempF = this.constructor.getValue(obj.tempF || obj.temp_f);25 this.isDay = this.constructor.getValue(obj.isDay || obj.is_day);26 this.condition = this.constructor.getValue(obj.condition);27 this.windMph = this.constructor.getValue(obj.windMph || obj.wind_mph);28 this.windKph = this.constructor.getValue(obj.windKph || obj.wind_kph);29 this.windDegree = this.constructor.getValue(obj.windDegree || obj.wind_degree);30 this.windDir = this.constructor.getValue(obj.windDir || obj.wind_dir);31 this.pressureMb = this.constructor.getValue(obj.pressureMb || obj.pressure_mb);32 this.pressureIn = this.constructor.getValue(obj.pressureIn || obj.pressure_in);33 this.precipMm = this.constructor.getValue(obj.precipMm || obj.precip_mm);34 this.precipIn = this.constructor.getValue(obj.precipIn || obj.precip_in);35 this.humidity = this.constructor.getValue(obj.humidity);36 this.cloud = this.constructor.getValue(obj.cloud);37 this.feelslikeC = this.constructor.getValue(obj.feelslikeC || obj.feelslike_c);38 this.feelslikeF = this.constructor.getValue(obj.feelslikeF || obj.feelslike_f);39 this.visKm = this.constructor.getValue(obj.visKm || obj.vis_km);40 this.visMiles = this.constructor.getValue(obj.visMiles || obj.vis_miles);41 this.uv = this.constructor.getValue(obj.uv);42 this.gustMph = this.constructor.getValue(obj.gustMph || obj.gust_mph);43 this.gustKph = this.constructor.getValue(obj.gustKph || obj.gust_kph);44 }45 /**46 * Function containing information about the fields of this model47 * @return {array} Array of objects containing information about the fields48 */49 static mappingInfo() {50 return super.mappingInfo().concat([51 { name: 'lastUpdatedEpoch', realName: 'last_updated_epoch' },52 { name: 'lastUpdated', realName: 'last_updated' },53 { name: 'tempC', realName: 'temp_c' },54 { name: 'tempF', realName: 'temp_f' },55 { name: 'isDay', realName: 'is_day' },56 { name: 'condition', realName: 'condition', type: 'Condition' },57 { name: 'windMph', realName: 'wind_mph' },58 { name: 'windKph', realName: 'wind_kph' },59 { name: 'windDegree', realName: 'wind_degree' },60 { name: 'windDir', realName: 'wind_dir' },61 { name: 'pressureMb', realName: 'pressure_mb' },62 { name: 'pressureIn', realName: 'pressure_in' },63 { name: 'precipMm', realName: 'precip_mm' },64 { name: 'precipIn', realName: 'precip_in' },65 { name: 'humidity', realName: 'humidity' },66 { name: 'cloud', realName: 'cloud' },67 { name: 'feelslikeC', realName: 'feelslike_c' },68 { name: 'feelslikeF', realName: 'feelslike_f' },69 { name: 'visKm', realName: 'vis_km' },70 { name: 'visMiles', realName: 'vis_miles' },71 { name: 'uv', realName: 'uv' },72 { name: 'gustMph', realName: 'gust_mph' },73 { name: 'gustKph', realName: 'gust_kph' },74 ]);75 }76 /**77 * Function containing information about discriminator values78 * mapped with their corresponding model class names79 *80 * @return {object} Object containing Key-Value pairs mapping discriminator81 * values with their corresponding model classes82 */83 static discriminatorMap() {84 return {};85 }86}...

Full Screen

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 avocado 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