Skip to content

Commit c0e90cb

Browse files
committed
Version 1.11.0-dev.5.3
Cherry-pick 19bb19d to dev Cherry-pick d5a34bd to dev Cherry-pick bbdc57e to dev Cherry-pick bd25e64 to dev Cherry-pick 5cc8fca to dev Cherry-pick ed72caa to dev Cherry-pick 82535a6 to dev Cherry-pick c05c8c6 to dev Cherry-pick f9e8852 to dev Cherry-pick 9a01a22 to dev Cherry-pick 3c85970 to dev
2 parents 23736d3 + 7a01514 commit c0e90cb

File tree

14 files changed

+100
-51
lines changed

14 files changed

+100
-51
lines changed

runtime/bin/io_natives.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ namespace bin {
4040
V(Platform_PathSeparator, 0) \
4141
V(Platform_LocalHostname, 0) \
4242
V(Platform_ExecutableName, 0) \
43+
V(Platform_ResolvedExecutableName, 0) \
4344
V(Platform_Environment, 0) \
4445
V(Platform_ExecutableArguments, 0) \
4546
V(Platform_PackageRoot, 0) \

runtime/bin/platform.cc

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace dart {
1313
namespace bin {
1414

1515
const char* Platform::executable_name_ = NULL;
16-
bool Platform::executable_name_resolved_ = false;
16+
const char* Platform::resolved_executable_name_ = NULL;
1717
const char* Platform::package_root_ = NULL;
1818
int Platform::script_index_ = 1;
1919
char** Platform::argv_ = NULL;
@@ -51,6 +51,16 @@ void FUNCTION_NAME(Platform_ExecutableName)(Dart_NativeArguments args) {
5151
}
5252

5353

54+
void FUNCTION_NAME(Platform_ResolvedExecutableName)(Dart_NativeArguments args) {
55+
if (Platform::GetResolvedExecutableName() != NULL) {
56+
Dart_SetReturnValue(
57+
args, Dart_NewStringFromCString(Platform::GetResolvedExecutableName()));
58+
} else {
59+
Dart_SetReturnValue(args, Dart_Null());
60+
}
61+
}
62+
63+
5464
void FUNCTION_NAME(Platform_ExecutableArguments)(Dart_NativeArguments args) {
5565
int end = Platform::GetScriptIndex();
5666
char** argv = Platform::GetArgv();

runtime/bin/platform.h

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,14 @@ class Platform {
4646
executable_name_ = executable_name;
4747
}
4848
static const char* GetExecutableName() {
49-
if (!executable_name_resolved_) {
49+
return executable_name_;
50+
}
51+
static const char* GetResolvedExecutableName() {
52+
if (resolved_executable_name_ == NULL) {
5053
// Try to resolve the executable path using platform specific APIs.
51-
char* path = Platform::ResolveExecutablePath();
52-
if (path != NULL) {
53-
executable_name_ = path;
54-
}
55-
executable_name_resolved_ = true;
54+
resolved_executable_name_ = Platform::ResolveExecutablePath();
5655
}
57-
return executable_name_;
56+
return resolved_executable_name_;
5857
}
5958

6059
// Stores and gets the package root.
@@ -80,8 +79,8 @@ class Platform {
8079
private:
8180
// The path to the executable.
8281
static const char* executable_name_;
83-
// State to indicate whether the executable name has been resolved.
84-
static bool executable_name_resolved_;
82+
// The path to the resolved executable.
83+
static const char* resolved_executable_name_;
8584

8685
static const char* package_root_;
8786
static int script_index_;

runtime/bin/platform_macos.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#include <mach-o/dyld.h>
99

10+
#include "bin/file.h"
1011
#include "bin/platform.h"
1112

1213
#include <crt_externs.h> // NOLINT
@@ -91,7 +92,10 @@ char* Platform::ResolveExecutablePath() {
9192
free(path);
9293
return NULL;
9394
}
94-
return path;
95+
// Return the canonical path as the returned path might contain symlinks.
96+
char* canon_path = File::GetCanonicalPath(path);
97+
free(path);
98+
return canon_path;
9599
}
96100

97101
} // namespace bin

runtime/bin/platform_patch.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ patch class _Platform {
1010
native "Platform_OperatingSystem";
1111
/* patch */ static _localHostname() native "Platform_LocalHostname";
1212
/* patch */ static _executable() native "Platform_ExecutableName";
13+
/* patch */ static _resolvedExecutable()
14+
native "Platform_ResolvedExecutableName";
1315
/* patch */ static _environment() native "Platform_Environment";
1416
/* patch */ static List<String> _executableArguments()
1517
native "Platform_ExecutableArguments";

runtime/bin/platform_win.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "platform/globals.h"
66
#if defined(TARGET_OS_WINDOWS)
77

8+
#include "bin/file.h"
89
#include "bin/platform.h"
910
#include "bin/log.h"
1011
#include "bin/socket.h"
@@ -97,7 +98,10 @@ char* Platform::ResolveExecutablePath() {
9798
}
9899
char* path = StringUtils::WideToUtf8(tmp_buffer);
99100
free(tmp_buffer);
100-
return path;
101+
// Return the canonical path as the returned path might contain symlinks.
102+
char* canon_path = File::GetCanonicalPath(path);
103+
free(path);
104+
return canon_path;
101105
}
102106

103107
} // namespace bin

runtime/vm/dart_api_impl.cc

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3182,10 +3182,20 @@ DART_EXPORT Dart_TypedData_Type Dart_GetTypeOfExternalTypedData(
31823182
Dart_Handle object) {
31833183
TRACE_API_CALL(CURRENT_FUNC);
31843184
intptr_t class_id = Api::ClassId(object);
3185-
if (RawObject::IsExternalTypedDataClassId(class_id) ||
3186-
RawObject::IsTypedDataViewClassId(class_id)) {
3185+
if (RawObject::IsExternalTypedDataClassId(class_id)) {
31873186
return GetType(class_id);
31883187
}
3188+
if (RawObject::IsTypedDataViewClassId(class_id)) {
3189+
// Check if data object of the view is external.
3190+
Isolate* isolate = Isolate::Current();
3191+
const Instance& view_obj = Api::UnwrapInstanceHandle(isolate, object);
3192+
ASSERT(!view_obj.IsNull());
3193+
const Instance& data_obj =
3194+
Instance::Handle(isolate, TypedDataView::Data(view_obj));
3195+
if (ExternalTypedData::IsExternalTypedData(data_obj)) {
3196+
return GetType(class_id);
3197+
}
3198+
}
31893199
return Dart_TypedData_kInvalid;
31903200
}
31913201

sdk/lib/_internal/compiler/js_lib/io_patch.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,10 @@ class _Platform {
221221
throw new UnsupportedError("Platform._executable");
222222
}
223223
@patch
224+
static _resolvedExecutable() {
225+
throw new UnsupportedError("Platform._resolvedExecutable");
226+
}
227+
@patch
224228
static List<String> _executableArguments() {
225229
throw new UnsupportedError("Platform._executableArguments");
226230
}

sdk/lib/io/platform.dart

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,13 +131,24 @@ class Platform {
131131
* Returns the path of the executable used to run the script in this
132132
* isolate.
133133
*
134-
* If supported by the platform the returned path will be absolute.
134+
* The path returned is the literal path used to run the script. This
135+
* path might be relative or just be a name from which the executable
136+
* was found by searching the `PATH`.
135137
*
136-
* If the execution environment does not support [executable] an empty
137-
* string is returned.
138+
* To get the absolute path to the resolved executable use
139+
* [resolvedExecutable].
138140
*/
139141
static String get executable => _Platform.executable;
140142

143+
/**
144+
* Returns the path of the executable used to run the script in this
145+
* isolate after it has been resolved by the OS.
146+
*
147+
* This is the absolute path, with all symlinks resolved, to the
148+
* executable used to run the script.
149+
*/
150+
static String get resolvedExecutable => _Platform.resolvedExecutable;
151+
141152
/**
142153
* Returns the absolute URI of the script being run in this
143154
* isolate.

sdk/lib/io/platform_impl.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class _Platform {
1010
external static String _operatingSystem();
1111
external static _localHostname();
1212
external static _executable();
13+
external static _resolvedExecutable();
1314
/**
1415
* Retrieve the entries of the process environment.
1516
*
@@ -31,6 +32,7 @@ class _Platform {
3132
external static String _version();
3233

3334
static String executable = _executable();
35+
static String resolvedExecutable = _resolvedExecutable();
3436
static String packageRoot = _packageRoot();
3537

3638
// Cache the OS environemnt. This can be an OSError instance if

0 commit comments

Comments
 (0)