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

Unified Diff: Source/bindings/dart/DartDebugHooks.js

Issue 18169002: Improve Dart Debugger performance and robustness by creating Dart wrappers using the standard SetNa… (Closed) Base URL: svn://svn.chromium.org/multivm/trunk/webkit
Patch Set: code review fixes Created 7 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: Source/bindings/dart/DartDebugHooks.js
diff --git a/Source/bindings/dart/DartDebugHooks.js b/Source/bindings/dart/DartDebugHooks.js
index 5dd0ef5f03b0da7240b9c68ac6602b2134ffb257..f964c48d1c2683fdfdc2ab7e3aab95078b2396a5 100644
--- a/Source/bindings/dart/DartDebugHooks.js
+++ b/Source/bindings/dart/DartDebugHooks.js
@@ -32,16 +32,6 @@
var DartDebug = {};
-function invokeDartCode(mirrorAPIFunction, proxy, memberName, args)
-{
- var unwrappedArgs = [];
- for (var i = 0; i < args.length; ++i)
- unwrappedArgs.push(DartDebug.unwrapValue(args[i]));
- var result = DartDebug.nativeCallbacks.invocationTrampoline(
- mirrorAPIFunction, [proxy, memberName, unwrappedArgs]);
- return DartDebug.wrapValue(result);
-}
-
DartDebug.ExecutionState = function(callFrames)
{
this._callFrames = [];
@@ -118,22 +108,8 @@ DartDebug.FrameMirror = function(callFrame)
this._functionName = callFrame.functionName;
this._scriptId = DartDebug.scriptURLToScriptId[callFrame.scriptURL];
this._lineNumber = callFrame.lineNumber;
-
- var localScopeObject = {}
- localScopeObject.__proto__ = null;
-
- for (var i = 0; i < callFrame.localVariables.length; i += 2) {
- var name = callFrame.localVariables[i];
- var value = callFrame.localVariables[i + 1];
- var suffixIndex = name.indexOf('@');
- if (suffixIndex != -1)
- name = name.substr(0, suffixIndex);
- localScopeObject[name] = value;
- }
- this._localScope = new DartDebug.ScopeMirror(localScopeObject, ScopeType.Local);
-
- var libraryScopeObject = DartDebug.buildLibraryScopeObject(callFrame.libraryProxy);
- this._globalScope = new DartDebug.ScopeMirror(libraryScopeObject, ScopeType.Global);
+ this._localScope = new DartDebug.ScopeMirror(callFrame.localScopeProxy, ScopeType.Local);
+ this._globalScope = new DartDebug.ScopeMirror(callFrame.libraryProxy, ScopeType.Global);
this._scopes = [this._localScope, this._globalScope];
};
@@ -169,17 +145,6 @@ DartDebug.FrameMirror.prototype = {
// FIXME: Dart VM doesn't currently support evaluations. Use
// JavaScript eval and 'with' statement to emulate evaluation on Dart
// call frame.
- var propertyMap = {};
- var scopes = [this._globalScope, this._localScope];
- for (var i = 0; i < scopes.length; ++i) {
- var scopeObject = scopes[i]._object;
- var propertyNames = Object.getOwnPropertyNames(scopeObject);
- for (var j = 0; j < propertyNames.length; ++j) {
- var name = propertyNames[j];
- if (name !== 'this')
- propertyMap[name] = scopeObject[name];
- }
- }
// FIXME: dartbug.com/10434 find a less fragile way to determine whether
// we need to strip off console API support added by InjectedScript.
@@ -189,7 +154,9 @@ DartDebug.FrameMirror.prototype = {
expression = expression.substr(expression.indexOf('\n') + 1);
expression = expression.substr(0, expression.lastIndexOf('\n'));
}
- var result = DartDebug.nativeCallbacks.evaluateInScope(expression, this._localScope.receiver(), propertyMap);
+
+ var result = DartDebug.nativeCallbacks.evaluateInScope(expression, this._localScope.receiver(),
+ this._globalScope._object, this._localScope._object);
return { value: function() { return result; } };
},
@@ -275,7 +242,7 @@ DartDebug.unregisterIsolate = function(isolateHandle)
// The page was destroyed.
DartDebug.scripts = {};
DartDebug.scriptURLToScriptId = {};
-
+ DartDebug.libraryScopeCache = {};
DartDebug.breakpoints = {};
};
@@ -328,311 +295,6 @@ DartDebug.updateExceptionPauseInfo = function()
DartDebug.nativeCallbacks.setExceptionPauseInfo(isolateHandle, Debug.isBreakOnException(), Debug.isBreakOnUncaughtException());
}
-DartDebug.wrapValue = function(value)
-{
- if (!value || !value.isProxy)
- return value;
- var wrapper = DartDebug.mirrorAPI.isList(value) ? DartDebug.wrapList(value) : DartDebug.wrapObject(value);
- DartDebug.nativeCallbacks.setHiddenValue(wrapper, 'proxy', value);
- return wrapper;
-}
-
-DartDebug.unwrapValue = function(value)
-{
- var proxy = DartDebug.nativeCallbacks.getHiddenValue(value, 'proxy');
- return proxy || value;
-}
-
-DartDebug.wrapList = function(arrayProxy)
-{
- function getter(index)
- {
- return DartDebug.wrapValue(DartDebug.mirrorAPI.listGetAt(arrayProxy, index));
- }
-
- function setter(index, value)
- {
- DartDebug.mirrorAPI.listSetAt(arrayProxy, index, value);
- }
-
- function enumerator()
- {
- var indices = [];
- var length = DartDebug.mirrorAPI.getField(arrayProxy, 'length');
- for (var i = 0; i < length; ++i)
- indices.push(i);
- return indices;
- }
-
- var array = DartDebug.nativeCallbacks.createArrayWithIndexedPropertyHandler(getter, setter, enumerator);
- array.length = DartDebug.mirrorAPI.getField(arrayProxy, 'length');
- return array;
-}
-
-DartDebug.installProxyFieldsAndFunctions = function(proxy, getContainer, getContainerProxy,
- filter, isLibrary, isClassDefinition)
-{
-
- function shouldInstallProperty(container, name)
- {
- if (!container || name in container)
- return false;
- return filter ? filter(name) : true;
- }
-
- function setAccessor(name, descriptor, hasGetter, hasSetter)
- {
- var container = getContainer(descriptor.isStatic);
- if (!shouldInstallProperty(container, name))
- return;
- var containerProxy = getContainerProxy(descriptor.isStatic);
- var getter;
- if (hasGetter) {
- getter = function()
- {
- return invokeDartCode(DartDebug.mirrorAPI.getField, containerProxy, name, []);
- };
- }
- var setter;
- if (hasSetter) {
- setter = function(value)
- {
- return invokeDartCode(DartDebug.mirrorAPI.setField, containerProxy, name, [value]);
- };
- }
- DartDebug.nativeCallbacks.setAccessor(container, name, getter, setter);
- }
-
- function setFunction(name, descriptor)
- {
- var container = getContainer(descriptor.isStatic);
- if (!shouldInstallProperty(container, name))
- return;
- var containerProxy = getContainerProxy(descriptor.isStatic);
- function invoke()
- {
- if (arguments.length < descriptor.fixedParameterCount ||
- arguments.length > descriptor.fixedParameterCount + descriptor.optionalParamerterCount)
- throw "NoSuchMethodException: incorrect number of arguments passed to function named '" + name + "'";
- return invokeDartCode(DartDebug.mirrorAPI.invoke, containerProxy, name, arguments);
- }
- Object.defineProperty(container, name, { value: invoke });
- }
-
- function setNamedConstructor(name, descriptor)
- {
- var container = getContainer(true);
- var indexFirstDot = name.indexOf(".");
- // Not a named constructor.
- if (indexFirstDot == -1)
- return;
-
- var nameWithoutDot = name.substr(indexFirstDot + 1);
- if (!shouldInstallProperty(container, nameWithoutDot))
- return;
- var containerProxy = getContainerProxy(descriptor.isStatic);
- function invoke()
- {
- // FIXME: display the actual number of arguments and allowed range of number of arguments.
- if (arguments.length < descriptor.fixedParameterCount ||
- arguments.length > descriptor.fixedParameterCount + descriptor.optionalParamerterCount)
- throw "NoSuchMethodException: incorrect number of arguments passed to constructor '" + nameWithoutDot + "'";
- return invokeDartCode(DartDebug.mirrorAPI.dartNew, containerProxy, nameWithoutDot, arguments);
- }
- Object.defineProperty(container, nameWithoutDot, { value: invoke });
- }
-
- function setClass(name, descriptor)
- {
- var container = getContainer(true);
- if (!shouldInstallProperty(container, name))
- return;
- var classProxy = DartDebug.createClassProxy(null, descriptor, name, proxy);
- Object.defineProperty(container, name, { value: classProxy });
- }
-
- var variableNames = DartDebug.mirrorAPI.getVariableNames(proxy);
- for (var i = 0; i < variableNames.length; ++i) {
- var variableName = variableNames[i];
- var variable = DartDebug.mirrorAPI.lookupVariable(proxy, variableName);
- if (isClassDefinition && !variable.isStatic) continue;
- setAccessor(variableName, variable, true, !variable.isFinal);
- }
-
- var functionNames = DartDebug.mirrorAPI.getFunctionNames(proxy);
-
- var accessors = {};
- for (var i = 0; i < functionNames.length; ++i) {
- var functionName = functionNames[i];
- var func = DartDebug.mirrorAPI.lookupFunction(proxy, functionName);
- if (isClassDefinition && !func.isStatic && !func.isConstructor)
- continue;
-
- if (func.isAbstract)
- continue;
-
- if (func.isGetter) {
- if (!accessors[functionName])
- accessors[functionName] = {};
- accessors[functionName].getter = func;
- } else if (func.isSetter) {
- // Remove trailing '='.
- functionName = functionName.substr(0, functionName.length - 1);
- if (!accessors[functionName])
- accessors[functionName] = {};
- accessors[functionName].setter = func;
- } else if (!func.isConstructor) {
- setFunction(functionName, func);
- } else if (isClassDefinition && func.isConstructor){
- setNamedConstructor(functionName, func);
- }
- }
-
- if (isLibrary && !isClassDefinition) {
- var classNames = DartDebug.mirrorAPI.getClassNames(proxy);
- for (var i = 0; i < classNames.length; ++i) {
- var className = classNames[i];
- var clazz = DartDebug.mirrorAPI.lookupClass(proxy, className);
- setClass(className, clazz);
- }
- }
-
- for (var functionName in accessors) {
- var accessor = accessors[functionName];
- var func = accessor.getter || accessor.setter;
- setAccessor(functionName, func, !!accessor.getter, !!accessor.setter);
- }
-}
-
-DartDebug.wrapObject = function(objectProxy)
-{
- var classProxy = DartDebug.mirrorAPI.instanceGetClass(objectProxy);
- var className = DartDebug.mirrorAPI.className(classProxy);
- return DartDebug.createClassProxy(objectProxy, classProxy, className);
-}
-
-DartDebug.createClassProxy = function(objectProxy, classProxy, className, opt_libraryProxy)
-{
- // Create a fake constructor to set wrapper's class name.
- var object;
- if (objectProxy) {
- // This is a class instance not a class definition object.
- try {
- fakeConstructor = eval('(function ' + className + '() {})');
- object = new fakeConstructor();
- } catch(e) {
- object = {};
- }
- object.__proto__ = null;
- } else {
- // This is a class definition object.
- // We need to wire up a default constructor if one exists.
- // TODO(jacobr): there is some duplicated code here and for the named constructor case.
- var myConstructor = null;
- var functionNames = DartDebug.mirrorAPI.getFunctionNames(classProxy);
- for (var i = 0; i < functionNames.length; ++i) {
- var functionName = functionNames[i];
- if (functionName != className)
- continue;
-
- var func = DartDebug.mirrorAPI.lookupFunction(classProxy, functionName);
-
- if (func.isConstructor) {
- myConstructor = func;
- break;
- }
- }
-
- var constructorStatement;
- if (myConstructor != null) {
- // FIXME: reduce duplicate code handling constructor invocation.
- constructorStatement = '(function(invokeDartCode, DartDebug, classProxy, myConstructor) {' +
- 'return (function ' + className + '() {' +
- 'if (arguments.length < myConstructor.fixedParameterCount || ' +
- 'arguments.length > (myConstructor.fixedParameterCount + myConstructor.optionalParamerterCount)) ' +
- 'throw "NoSuchMethodException: incorrect number of arguments passed to default constructor";' +
- 'return invokeDartCode(DartDebug.mirrorAPI.dartNew, classProxy, "", arguments);' +
- '})})';
- } else {
- // FIXME: throw a better error message.
- constructorStatement = '(function() { return (function ' + className + '() { throw "' + className + ' does not have a constructor"})})';
- }
- try {
- // FIXME: avoid using eval.
- object = (eval(constructorStatement))(invokeDartCode, DartDebug, classProxy, myConstructor);
- } catch(e) {
- object = {};
- object['@ERROR'] = e;
- object['@SOURCE'] = constructorStatement;
- object.__proto__ = null;
- }
- object.toString = function() { return className + " [Dart Class]"; };
- }
-
- var classInfo = {};
- classInfo.__proto__ = null;
- classInfo['class'] = className;
- var libraryProxy = opt_libraryProxy || DartDebug.mirrorAPI.classGetLibrary(classProxy);
- classInfo['library'] = DartDebug.mirrorAPI.libraryUrl(libraryProxy);
- Object.defineProperty(object, '@classInfo', { value: classInfo });
-
- var staticFields = objectProxy != null ? {} : object;
- staticFields.__proto__ = null;
-
- function getContainer(isStatic) { return isStatic ? staticFields : object; }
- function getContainerProxy(isStatic) { return isStatic ? classProxy : objectProxy || classProxy; }
-
- while (classProxy) {
- DartDebug.installProxyFieldsAndFunctions(
- classProxy, getContainer, getContainerProxy, null, false, !objectProxy);
- if (!objectProxy)
- break; // Static methods from parent classes should not be wired up to subclasses.
- classProxy = DartDebug.mirrorAPI.getSuperclass(classProxy);
- }
-
- if (objectProxy != null) {
- Object.defineProperty(object, '@staticFields', { value: staticFields });
- }
-
- return object;
-}
-
-DartDebug.buildLibraryScopeObject = function(libraryProxy)
-{
- var libraryScopeObject = {};
- libraryScopeObject.__proto__ = null;
-
- DartDebug.installProxyFieldsAndFunctions(
- libraryProxy,
- function() { return libraryScopeObject; },
- function() { return libraryProxy; },
- null,
- true);
-
- var imports = DartDebug.mirrorAPI.libraryImports(libraryProxy);
- for (var i = 0; i < imports.length; i += 2) {
- var prefix = imports[i];
- var importedLibraryProxy = imports[i + 1];
- var scopeObject = libraryScopeObject;
- if (prefix) {
- // Remove trailing '.'.
- prefix = prefix.substr(0, prefix.length - 1);
- // FIXME: remove the check below once dartbug.com/6131 is fixed.
- if (!(prefix in libraryScopeObject)) {
- scopeObject = {};
- scopeObject.__proto__ = null;
- Object.defineProperty(libraryScopeObject, prefix, { value: scopeObject });
- }
- }
- var filter = function(name) { return name[0] != '_'; };
- var getContainer = function() { return scopeObject};
- var getContainerProxy = function() { return importedLibraryProxy};
- DartDebug.installProxyFieldsAndFunctions(importedLibraryProxy, getContainer, getContainerProxy, filter, true);
- }
-
- return libraryScopeObject;
-}
-
var originals = {};
originals.scripts = Debug.scripts;

Powered by Google App Engine
This is Rietveld 408576698