Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(84)

Side by Side Diff: sdk/lib/_internal/js_runtime/lib/native_helper.dart

Issue 2383273002: Revert "Add native_testing library to mock @Native classes" (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 part of _js_helper; 5 part of _js_helper;
6 6
7 7
8 // TODO(ngeoffray): stop using this method once our optimizers can 8 // TODO(ngeoffray): stop using this method once our optimizers can
9 // change str1.contains(str2) into str1.indexOf(str2) != -1. 9 // change str1.contains(str2) into str1.indexOf(str2) != -1.
10 bool contains(String userAgent, String name) { 10 bool contains(String userAgent, String name) {
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 // JavaScript code fragments. 442 // JavaScript code fragments.
443 // 443 //
444 // This is a temporary place for the JavaScript code. 444 // This is a temporary place for the JavaScript code.
445 // 445 //
446 // TODO(sra): These code fragments are not minified. They could be generated by 446 // TODO(sra): These code fragments are not minified. They could be generated by
447 // the code emitter, or JS_CONST could be improved to parse entire functions and 447 // the code emitter, or JS_CONST could be improved to parse entire functions and
448 // take care of the minification. 448 // take care of the minification.
449 449
450 const _baseHooks = const JS_CONST(r''' 450 const _baseHooks = const JS_CONST(r'''
451 function() { 451 function() {
452 var toStringFunction = Object.prototype.toString; 452 function typeNameInChrome(o) {
453 function getTag(o) { 453 var constructor = o.constructor;
454 var s = toStringFunction.call(o); 454 if (constructor) {
455 var name = constructor.name;
456 if (name) return name;
457 }
458 var s = Object.prototype.toString.call(o);
455 return s.substring(8, s.length - 1); 459 return s.substring(8, s.length - 1);
456 } 460 }
457 function getUnknownTag(object, tag) { 461 function getUnknownTag(object, tag) {
458 // This code really belongs in [getUnknownTagGenericBrowser] but having it 462 // This code really belongs in [getUnknownTagGenericBrowser] but having it
459 // here allows [getUnknownTag] to be tested on d8. 463 // here allows [getUnknownTag] to be tested on d8.
460 if (/^HTML[A-Z].*Element$/.test(tag)) { 464 if (/^HTML[A-Z].*Element$/.test(tag)) {
461 // Check that it is not a simple JavaScript object. 465 // Check that it is not a simple JavaScript object.
462 var name = toStringFunction.call(object); 466 var name = Object.prototype.toString.call(object);
463 if (name == "[object Object]") return null; 467 if (name == "[object Object]") return null;
464 return "HTMLElement"; 468 return "HTMLElement";
465 } 469 }
466 } 470 }
467 function getUnknownTagGenericBrowser(object, tag) { 471 function getUnknownTagGenericBrowser(object, tag) {
468 if (self.HTMLElement && object instanceof HTMLElement) return "HTMLElement"; 472 if (self.HTMLElement && object instanceof HTMLElement) return "HTMLElement";
469 return getUnknownTag(object, tag); 473 return getUnknownTag(object, tag);
470 } 474 }
471 function prototypeForTag(tag) { 475 function prototypeForTag(tag) {
472 if (typeof window == "undefined") return null; 476 if (typeof window == "undefined") return null;
473 if (typeof window[tag] == "undefined") return null; 477 if (typeof window[tag] == "undefined") return null;
474 var constructor = window[tag]; 478 var constructor = window[tag];
475 if (typeof constructor != "function") return null; 479 if (typeof constructor != "function") return null;
476 return constructor.prototype; 480 return constructor.prototype;
477 } 481 }
478 function discriminator(tag) { return null; } 482 function discriminator(tag) { return null; }
479 483
480 var isBrowser = typeof navigator == "object"; 484 var isBrowser = typeof navigator == "object";
481 485
482 return { 486 return {
483 getTag: getTag, 487 getTag: typeNameInChrome,
484 getUnknownTag: isBrowser ? getUnknownTagGenericBrowser : getUnknownTag, 488 getUnknownTag: isBrowser ? getUnknownTagGenericBrowser : getUnknownTag,
485 prototypeForTag: prototypeForTag, 489 prototypeForTag: prototypeForTag,
486 discriminator: discriminator }; 490 discriminator: discriminator };
487 }'''); 491 }''');
488 492
489 493
490 /** 494 /**
491 * Returns the name of the constructor function for browsers where 495 * Returns the name of the constructor function for browsers where
492 * `object.constructor.name` is not reliable. 496 * `object.constructor.name` is not reliable.
493 * 497 *
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
645 const _safariHooksTransformer = const JS_CONST(r''' 649 const _safariHooksTransformer = const JS_CONST(r'''
646 function(hooks) { return hooks; } 650 function(hooks) { return hooks; }
647 '''); 651 ''');
648 652
649 653
650 const _dartExperimentalFixupGetTagHooksTransformer = const JS_CONST(r''' 654 const _dartExperimentalFixupGetTagHooksTransformer = const JS_CONST(r'''
651 function(hooks) { 655 function(hooks) {
652 if (typeof dartExperimentalFixupGetTag != "function") return hooks; 656 if (typeof dartExperimentalFixupGetTag != "function") return hooks;
653 hooks.getTag = dartExperimentalFixupGetTag(hooks.getTag); 657 hooks.getTag = dartExperimentalFixupGetTag(hooks.getTag);
654 }'''); 658 }''');
OLDNEW
« no previous file with comments | « sdk/lib/_internal/js_runtime/lib/interceptors.dart ('k') | tests/compiler/dart2js_native/abstract_class_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698