Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 the V8 project authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 print("Tests that CommandLineAPI is presented only while evaluation."); | |
| 6 | |
| 7 InspectorTest.evaluateInPage( | |
| 8 ` | |
| 9 var methods = ["dir","dirxml","profile","profileEnd","clear","table","keys","val ues","debug","undebug","monitor","unmonitor","inspect","copy"]; | |
| 10 var window = this; | |
| 11 function presentedAPIMethods() | |
| 12 { | |
| 13 var methodCount = 0; | |
| 14 for (var method of methods) { | |
| 15 try { | |
| 16 if (eval("window." + method + "&&" + method + ".toString ? " + metho d + ".toString().indexOf(\\"[Command Line API]\\") !== -1 : false")) | |
| 17 ++methodCount; | |
| 18 } catch (e) { | |
| 19 } | |
| 20 } | |
| 21 methodCount += eval("\\"$_\\" in window ? $_ === 239 : false") ? 1 : 0; | |
| 22 return methodCount; | |
| 23 } | |
| 24 | |
| 25 function setPropertyForMethod() | |
| 26 { | |
| 27 window.dir = 42; | |
| 28 } | |
| 29 | |
| 30 function defineValuePropertyForMethod() | |
| 31 { | |
| 32 Object.defineProperty(window, "dir", { value: 42 }); | |
| 33 } | |
| 34 | |
| 35 function defineAccessorPropertyForMethod() | |
| 36 { | |
| 37 Object.defineProperty(window, "dir", { set: function() {}, get: function(){ return 42 } }); | |
| 38 } | |
| 39 | |
| 40 function definePropertiesForMethod() | |
| 41 { | |
| 42 Object.defineProperties(window, { "dir": { set: function() {}, get: function (){ return 42 } }}); | |
| 43 } | |
| 44 | |
| 45 var builtinGetOwnPropertyDescriptorOnObject; | |
| 46 var builtinGetOwnPropertyDescriptorOnObjectPrototype; | |
| 47 var builtinGetOwnPropertyDescriptorOnWindow; | |
| 48 | |
| 49 function redefineGetOwnPropertyDescriptors() | |
| 50 { | |
| 51 builtinGetOwnPropertyDescriptorOnObject = Object.getOwnPropertyDescriptor; | |
| 52 Object.getOwnPropertyDescriptor = function() {} | |
| 53 builtinGetOwnPropertyDescriptorOnObjectPrototype = Object.prototype.getOwnPr opertyDescriptor; | |
| 54 Object.prototype.getOwnPropertyDescriptor = function() {} | |
| 55 builtinGetOwnPropertyDescriptorOnWindow = window.getOwnPropertyDescriptor; | |
| 56 window.getOwnPropertyDescriptor = function() {} | |
| 57 } | |
| 58 | |
| 59 function restoreGetOwnPropertyDescriptors() | |
| 60 { | |
| 61 Object.getOwnPropertyDescriptor = builtinGetOwnPropertyDescriptorOnObject; | |
| 62 Object.prototype.getOwnPropertyDescriptor = builtinGetOwnPropertyDescriptorO nObjectPrototype; | |
| 63 window.getOwnPropertyDescriptor = builtinGetOwnPropertyDescriptorOnWindow; | |
| 64 }`); | |
| 65 | |
| 66 runExpressionAndDumpPresentedMethods("") | |
| 67 .then(() => dumpLeftMethods()) | |
|
alph
2016/09/30 01:48:33
nit: .then(dumpLeftMethod)
kozy
2016/09/30 02:01:59
Done.
| |
| 68 .then(() => runExpressionAndDumpPresentedMethods("setPropertyForMethod()")) | |
| 69 .then(() => dumpLeftMethods()) | |
| 70 .then(() => dumpDir()) | |
| 71 .then(() => runExpressionAndDumpPresentedMethods("defineValuePropertyForMethod ()")) | |
| 72 .then(() => dumpLeftMethods()) | |
| 73 .then(() => dumpDir()) | |
| 74 .then(() => runExpressionAndDumpPresentedMethods("definePropertiesForMethod()" )) | |
| 75 .then(() => dumpLeftMethods()) | |
| 76 .then(() => dumpDir()) | |
| 77 .then(() => runExpressionAndDumpPresentedMethods("defineAccessorPropertyForMet hod()")) | |
| 78 .then(() => dumpLeftMethods()) | |
| 79 .then(() => dumpDir()) | |
| 80 .then(() => runExpressionAndDumpPresentedMethods("redefineGetOwnPropertyDescri ptors()")) | |
| 81 .then(() => dumpLeftMethods()) | |
| 82 .then(() => dumpDir()) | |
| 83 .then(() => evaluate("restoreGetOwnPropertyDescriptors()", false)) | |
| 84 .then(() => InspectorTest.completeTest()); | |
| 85 | |
| 86 function evaluate(expression, includeCommandLineAPI) | |
| 87 { | |
| 88 var cb; | |
| 89 var p = new Promise(resolver => cb = resolver); | |
| 90 InspectorTest.sendCommandOrDie("Runtime.evaluate", { expression: expression, o bjectGroup: "console", includeCommandLineAPI: includeCommandLineAPI }, cb); | |
| 91 return p; | |
| 92 } | |
| 93 | |
| 94 function setLastEvaluationResultTo239() | |
| 95 { | |
| 96 return evaluate("239", false); | |
| 97 } | |
| 98 | |
| 99 function runExpressionAndDumpPresentedMethods(expression) | |
| 100 { | |
| 101 InspectorTest.log(expression); | |
| 102 return setLastEvaluationResultTo239() | |
| 103 .then(() => evaluate(expression + "; var a = presentedAPIMethods(); a", true )) | |
| 104 .then((result) => InspectorTest.logObject(result)); | |
| 105 } | |
| 106 | |
| 107 function dumpLeftMethods() | |
| 108 { | |
| 109 // Should always be zero. | |
| 110 return setLastEvaluationResultTo239() | |
| 111 .then(() => evaluate("presentedAPIMethods()", false)) | |
| 112 .then((result) => InspectorTest.logObject(result)); | |
| 113 } | |
| 114 | |
| 115 function dumpDir() | |
| 116 { | |
| 117 // Should always be presented. | |
| 118 return evaluate("dir", false) | |
| 119 .then((result) => InspectorTest.logObject(result)); | |
| 120 } | |
| OLD | NEW |