VM: remove service_object_patch.dart and all associated code.

This deletion has several reasons:

- This code is broken and refers to non-existant private parts of dart:io
(e.g. `_NativeSocket._sockets`, `_ProcessImpl._processes`, `_RandomAccessFile._files`).

- This code is not reachable through the service protocol. `_serviceObjectHandler` uses
`paths` to fetch the right handler from `_servicePathMap` but caller `ServiceGetIOHandler`
always passes empty paths.

- The only test that was attempting to test some of this code through mirrors (sic!)
has been disabled since January 2015.

After deletion all tests continue to pass meaning that nobody really relies on this
broken code in any way.

BUG=https://github.com/dart-lang/sdk/issues/28882
R=johnmccutchan@google.com

Review-Url: https://codereview.chromium.org/2715253002 .
This commit is contained in:
Vyacheslav Egorov 2017-02-27 16:08:16 +01:00
parent c4045d4ce8
commit 1c7cb7c5e9
7 changed files with 0 additions and 342 deletions

View file

@ -14,7 +14,6 @@
'io_service_patch.dart',
'platform_patch.dart',
'process_patch.dart',
'service_object_patch.dart',
'socket_patch.dart',
'stdio_patch.dart',
'secure_socket_patch.dart',

View file

@ -1156,78 +1156,6 @@ static void ShutdownIsolate(void* callback_data) {
}
static const char* InternalJsonRpcError(Dart_Handle error) {
TextBuffer buffer(128);
buffer.Printf(
"{\"code\":-32603,"
"\"message\":\"Internal error\","
"\"details\": \"%s\"}",
Dart_GetError(error));
return buffer.Steal();
}
class DartScope {
public:
DartScope() { Dart_EnterScope(); }
~DartScope() { Dart_ExitScope(); }
};
static bool ServiceGetIOHandler(const char* method,
const char** param_keys,
const char** param_values,
intptr_t num_params,
void* user_data,
const char** response) {
DartScope scope;
// TODO(ajohnsen): Store the library/function in isolate data or user_data.
Dart_Handle dart_io_str = Dart_NewStringFromCString("dart:io");
if (Dart_IsError(dart_io_str)) {
*response = InternalJsonRpcError(dart_io_str);
return false;
}
Dart_Handle io_lib = Dart_LookupLibrary(dart_io_str);
if (Dart_IsError(io_lib)) {
*response = InternalJsonRpcError(io_lib);
return false;
}
Dart_Handle handler_function_name =
Dart_NewStringFromCString("_serviceObjectHandler");
if (Dart_IsError(handler_function_name)) {
*response = InternalJsonRpcError(handler_function_name);
return false;
}
// TODO(johnmccutchan): paths is no longer used. Update the io
// _serviceObjectHandler function to use json rpc.
Dart_Handle paths = Dart_NewList(0);
Dart_Handle keys = Dart_NewList(num_params);
Dart_Handle values = Dart_NewList(num_params);
for (int i = 0; i < num_params; i++) {
Dart_ListSetAt(keys, i, Dart_NewStringFromCString(param_keys[i]));
Dart_ListSetAt(values, i, Dart_NewStringFromCString(param_values[i]));
}
Dart_Handle args[] = {paths, keys, values};
Dart_Handle result = Dart_Invoke(io_lib, handler_function_name, 3, args);
if (Dart_IsError(result)) {
*response = InternalJsonRpcError(result);
return false;
}
const char* json;
result = Dart_StringToCString(result, &json);
if (Dart_IsError(result)) {
*response = InternalJsonRpcError(result);
return false;
}
*response = strdup(json);
return true;
}
static const char* kStdoutStreamId = "Stdout";
static const char* kStderrStreamId = "Stderr";
@ -1701,8 +1629,6 @@ void main(int argc, char** argv) {
Platform::Exit(kErrorExitCode);
}
Dart_RegisterIsolateServiceRequestCallback("getIO", &ServiceGetIOHandler,
NULL);
Dart_SetServiceStreamCallbacks(&ServiceStreamListenCallback,
&ServiceStreamCancelCallback);
Dart_SetFileModifiedCallback(&FileModifiedCallback);

View file

@ -1,164 +0,0 @@
// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
final Map _servicePathMap = {
'http' : {
'servers' : _httpServersServiceObject,
'serverconnections' : _httpServerConnectionsServiceObject,
},
'sockets' : _socketsServiceObject,
'websockets' : _webSocketsServiceObject,
'file' : {
'randomaccessfiles' : _randomAccessFilesServiceObject
},
'processes' : _processesServiceObject,
};
String _getServicePath(obj) => obj._servicePath;
String _serviceObjectHandler(List<String> paths,
List<String> keys,
List<String> values) {
assert(keys.length == values.length);
if (paths.isEmpty) {
return JSON.encode(_ioServiceObject());
}
int i = 0;
var current = _servicePathMap;
do {
current = current[paths[i]];
i++;
} while (i < paths.length && current is Map);
if (current is! Function) {
return JSON.encode(_makeServiceError('Unrecognized path', paths, keys,
values));
}
var query = new Map();
for (int i = 0; i < keys.length; i++) {
query[keys[i]] = values[i];
}
return JSON.encode(current(paths.sublist(i)));
}
Map _makeServiceError(String message,
List<String> paths,
List<String> keys,
List<String> values,
[String kind]) {
var error = {
'type': 'Error',
'id': '',
'message': message,
'request': {
'arguments': paths,
'option_keys': keys,
'option_values': values,
}
};
if (kind != null) {
error['kind'] = kind;
}
return error;
}
Map _ioServiceObject() {
return {
'id': 'io',
'type': 'IO',
'name': 'io',
'user_name': 'io',
};
}
Map _httpServersServiceObject(args) {
if (args.length == 1) {
var server = _HttpServer._servers[int.parse(args.first)];
if (server == null) {
return {};
}
return server._toJSON(false);
}
return {
'id': 'io/http/servers',
'type': 'HttpServerList',
'members': _HttpServer._servers.values
.map((server) => server._toJSON(true)).toList(),
};
}
Map _httpServerConnectionsServiceObject(args) {
if (args.length == 1) {
var connection = _HttpConnection._connections[int.parse(args.first)];
if (connection == null) {
return {};
}
return connection._toJSON(false);
}
return _makeServiceError("http/serverconnections can not be listed");
}
Map _socketsServiceObject(args) {
if (args.length == 1) {
var socket = _NativeSocket._sockets[int.parse(args.first)];
if (socket == null) {
return {};
}
return socket._toJSON(false);
}
return {
'id': 'io/sockets',
'type': 'SocketList',
'members': _NativeSocket._sockets.values
.map((socket) => socket._toJSON(true)).toList(),
};
}
Map _webSocketsServiceObject(args) {
if (args.length == 1) {
var webSocket = _WebSocketImpl._webSockets[int.parse(args.first)];
if (webSocket == null) {
return {};
}
return webSocket._toJSON(false);
}
return {
'id': 'io/websockets',
'type': 'WebSocketList',
'members': _WebSocketImpl._webSockets.values
.map((webSocket) => webSocket._toJSON(true)).toList(),
};
}
Map _randomAccessFilesServiceObject(args) {
if (args.length == 1) {
var raf = _RandomAccessFile._files[int.parse(args.first)];
if (raf == null) {
return {};
}
return raf._toJSON(false);
}
return {
'id': 'io/file/randomaccessfiles',
'type': 'RandomAccessFileList',
'members': _RandomAccessFile._files.values
.map((raf) => raf._toJSON(true)).toList(),
};
}
Map _processesServiceObject(args) {
if (args.length == 1) {
var process = _ProcessImpl._processes[int.parse(args.first)];
if (process == null) {
return {};
}
return process._toJSON(false);
}
return {
'id': 'io/processes',
'type': 'ProcessList',
'members': _ProcessImpl._processes.values
.map((p) => p._toJSON(true)).toList(),
};
}

View file

@ -124,7 +124,6 @@
"io_service_patch.dart",
"platform_patch.dart",
"process_patch.dart",
"service_object_patch.dart",
"socket_patch.dart",
"stdio_patch.dart",
"secure_socket_patch.dart"

View file

@ -153,7 +153,6 @@ io:
- io_service_patch.dart
- platform_patch.dart
- process_patch.dart
- service_object_patch.dart
- socket_patch.dart
- stdio_patch.dart
- secure_socket_patch.dart

View file

@ -1,99 +0,0 @@
// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'dart:async';
import 'dart:convert';
import 'dart:io';
import 'dart:mirrors';
import 'package:expect/expect.dart';
import 'package:async_helper/async_helper.dart';
Map lookupServiceObject(String path) {
var io = currentMirrorSystem().findLibrary(const Symbol('dart.io'));
var m = MirrorSystem.getSymbol('_serviceObjectHandler', io);
var paths = Uri.parse(path).pathSegments;
Expect.equals('io', paths.first);
return JSON.decode(
io.invoke(m, [paths.sublist(1), [], []]).reflectee);
}
String getServicePath(obj) {
var io = currentMirrorSystem().findLibrary(const Symbol('dart.io'));
var m = MirrorSystem.getSymbol('_getServicePath', io);
return io.invoke(m, [obj]).reflectee;
}
Future testHttpServer1() {
return HttpServer.bind('localhost', 0).then((server) {
var path = getServicePath(server);
var map = lookupServiceObject(path);
Expect.equals(map['type'], 'HttpServer');
Expect.equals(map['id'], path);
Expect.equals(map['address'], 'localhost');
Expect.equals(map['port'], server.port);
Expect.equals(map['closed'], false);
Expect.listEquals(map['idle'], []);
Expect.listEquals(map['active'], []);
var socket = map['socket'];
Expect.equals(socket['type'], '@Socket');
Expect.equals(socket['kind'], 'Listening');
// Validate owner back-ref.
socket = lookupServiceObject(socket['id']);
Expect.equals(socket['owner']['id'], path);
return server.close();
});
}
Future testHttpServerConnection1() {
return HttpServer.bind('localhost', 0).then((server) {
server.listen((request) {
var map = lookupServiceObject(getServicePath(server));
Expect.listEquals(map['idle'], []);
Expect.equals(map['active'].length, 1);
var active = map['active'].first;
Expect.equals(active['type'], '@HttpServerConnection');
var path = active['id'];
map = lookupServiceObject(path);
Expect.equals(map['type'], 'HttpServerConnection');
var socket = map['socket'];
Expect.equals(socket['type'], '@Socket');
Expect.equals(socket['kind'], 'Normal');
// Validate owner back-ref.
socket = lookupServiceObject(socket['id']);
Expect.equals(socket['owner']['id'], path);
request.response.close();
});
var client = new HttpClient();
return client.get('localhost', server.port, '/')
.then((request) => request.close())
.then((response) => response.drain())
.then((_) {
// The connection should be idle now.
var map = lookupServiceObject(getServicePath(server));
Expect.equals(map['idle'].length, 1);
Expect.listEquals(map['active'], []);
return server.close();
});
});
}
void main() {
final tests = [
testHttpServer1(),
testHttpServerConnection1(),
];
asyncStart();
// Run one test at a time.
Future.forEach(tests, (f) => f)
.then((_) {
asyncEnd();
});
}

View file

@ -30,7 +30,6 @@ env_test: Skip # This is testing a vm command line parsing scenario.
[ $runtime == vm || $runtime == dart_precompiled ]
package/package_isolate_test: Fail # Issue 12474
io/observatory_test: Fail
package/scenarios/invalid/same_package_twice_test: Pass # Issue 24119
# This test checks that the test runner correctly detects and reports non-utf8
# output from a test.
@ -159,7 +158,6 @@ medium_integer_test: Pass # The test only fails at runtime, not at compilation.
oom_error_stacktrace_test: Pass # The test only fails at runtime.
[ $compiler == dart2js && $fast_startup ]
io/observatory_test: Fail # mirrors not supported.
io/skipping_dart2js_compilations_test: CompileTimeError # Imports dart:mirrors
io/test_harness_analyzer_test: CompileTimeError # Imports dart:mirrors
io/test_runner_test: CompileTimeError # Imports dart:mirrors