Skip to content

Instantly share code, notes, and snippets.

@abarth
Created June 26, 2018 20:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abarth/b4fc909d83be5133cd7a5af209757e96 to your computer and use it in GitHub Desktop.
Save abarth/b4fc909d83be5133cd7a5af209757e96 to your computer and use it in GitHub Desktop.
diff --git a/Source/JavaScriptCore/Configurations/FeatureDefines.xcconfig b/Source/JavaScriptCore/Configurations/FeatureDefines.xcconfig
index 53aab1db3949..8c8471842198 100644
--- a/Source/JavaScriptCore/Configurations/FeatureDefines.xcconfig
+++ b/Source/JavaScriptCore/Configurations/FeatureDefines.xcconfig
@@ -200,4 +200,4 @@ ENABLE_FTL_JIT[sdk=iphoneos*] = ENABLE_FTL_JIT;
ENABLE_CUSTOM_ELEMENTS = ENABLE_CUSTOM_ELEMENTS;
-FEATURE_DEFINES = $(ENABLE_3D_TRANSFORMS) $(ENABLE_ACCELERATED_2D_CANVAS) $(ENABLE_ACCELERATED_OVERFLOW_SCROLLING) $(ENABLE_APPLE_PAY) $(ENABLE_ATTACHMENT_ELEMENT) $(ENABLE_AVF_CAPTIONS) $(ENABLE_CACHE_PARTITIONING) $(ENABLE_CANVAS_PATH) $(ENABLE_CANVAS_PROXY) $(ENABLE_CHANNEL_MESSAGING) $(ENABLE_CONTENT_FILTERING) $(ENABLE_CSP_NEXT) $(ENABLE_CSS_ANIMATIONS_LEVEL_2) $(ENABLE_CSS_BOX_DECORATION_BREAK) $(ENABLE_CSS_COMPOSITING) $(ENABLE_CSS_DEVICE_ADAPTATION) $(ENABLE_CSS_GRID_LAYOUT) $(ENABLE_CSS_IMAGE_ORIENTATION) $(ENABLE_CSS_IMAGE_RESOLUTION) $(ENABLE_CSS_REGIONS) $(ENABLE_CSS_SCROLL_SNAP) $(ENABLE_CSS_SELECTORS_LEVEL4) $(ENABLE_CSS_SHAPES) $(ENABLE_CSS_TRAILING_WORD) $(ENABLE_CSS3_TEXT) $(ENABLE_CURSOR_VISIBILITY) $(ENABLE_CUSTOM_ELEMENTS) $(ENABLE_CUSTOM_SCHEME_HANDLER) $(ENABLE_DASHBOARD_SUPPORT) $(ENABLE_DATA_TRANSFER_ITEMS) $(ENABLE_DATACUE_VALUE) $(ENABLE_DATALIST_ELEMENT) $(ENABLE_DETAILS_ELEMENT) $(ENABLE_DEVICE_ORIENTATION) $(ENABLE_DOM4_EVENTS_CONSTRUCTOR) $(ENABLE_ENCRYPTED_MEDIA_V2) $(ENABLE_ES6_MODULES) $(ENABLE_ES2017_ASYNCFUNCTION_SYNTAX) $(ENABLE_FETCH_API) $(ENABLE_FILTERS_LEVEL_2) $(ENABLE_FONT_LOAD_EVENTS) $(ENABLE_FTL_JIT) $(ENABLE_FULLSCREEN_API) $(ENABLE_GAMEPAD_DEPRECATED) $(ENABLE_GAMEPAD) $(ENABLE_GEOLOCATION) $(ENABLE_ICONDATABASE) $(ENABLE_INDEXED_DATABASE_IN_WORKERS) $(ENABLE_INDEXED_DATABASE) $(ENABLE_INDIE_UI) $(ENABLE_INPUT_TYPE_COLOR_POPOVER) $(ENABLE_INPUT_TYPE_COLOR) $(ENABLE_INPUT_TYPE_DATE) $(ENABLE_INPUT_TYPE_DATETIME_INCOMPLETE) $(ENABLE_INPUT_TYPE_DATETIMELOCAL) $(ENABLE_INPUT_TYPE_MONTH) $(ENABLE_INPUT_TYPE_TIME) $(ENABLE_INPUT_TYPE_WEEK) $(ENABLE_INTL) $(ENABLE_IOS_GESTURE_EVENTS) $(ENABLE_IOS_TOUCH_EVENTS) $(ENABLE_JIT) $(ENABLE_LEGACY_CSS_VENDOR_PREFIXES) $(ENABLE_LEGACY_NOTIFICATIONS) $(ENABLE_LEGACY_VENDOR_PREFIXES) $(ENABLE_LETTERPRESS) $(ENABLE_LINK_PREFETCH) $(ENABLE_MAC_GESTURE_EVENTS) $(ENABLE_MATHML) $(ENABLE_MEDIA_CAPTURE) $(ENABLE_MEDIA_CONTROLS_SCRIPT) $(ENABLE_MEDIA_SESSION) $(ENABLE_MEDIA_SOURCE) $(ENABLE_MEDIA_STATISTICS) $(ENABLE_MEDIA_STREAM) $(ENABLE_METER_ELEMENT) $(ENABLE_MHTML) $(ENABLE_MOUSE_CURSOR_SCALE) $(ENABLE_NAVIGATOR_CONTENT_UTILS) $(ENABLE_NAVIGATOR_HWCONCURRENCY) $(ENABLE_NOTIFICATIONS) $(ENABLE_PDFKIT_PLUGIN) $(ENABLE_POINTER_LOCK) $(ENABLE_PROXIMITY_EVENTS) $(ENABLE_PUBLIC_SUFFIX_LIST) $(ENABLE_QUOTA) $(ENABLE_READABLE_STREAM_API) $(ENABLE_REMOTE_INSPECTOR) $(ENABLE_REQUEST_ANIMATION_FRAME) $(ENABLE_REQUEST_AUTOCOMPLETE) $(ENABLE_RESOLUTION_MEDIA_QUERY) $(ENABLE_RESOURCE_USAGE) $(ENABLE_RUBBER_BANDING) $(ENABLE_SERVICE_CONTROLS) $(ENABLE_SPEECH_SYNTHESIS) $(ENABLE_SUBTLE_CRYPTO) $(ENABLE_SVG_FONTS) $(ENABLE_TELEPHONE_NUMBER_DETECTION) $(ENABLE_TEXT_AUTOSIZING) $(ENABLE_TOUCH_EVENTS) $(ENABLE_TOUCH_ICON_LOADING) $(ENABLE_USERSELECT_ALL) $(ENABLE_VIDEO_PRESENTATION_MODE) $(ENABLE_VIDEO_TRACK) $(ENABLE_VIDEO) $(ENABLE_VIEW_MODE_CSS_MEDIA) $(ENABLE_WEB_ANIMATIONS) $(ENABLE_WEB_AUDIO) $(ENABLE_WEB_REPLAY) $(ENABLE_WEB_SOCKETS) $(ENABLE_WEB_TIMING) $(ENABLE_WEBASSEMBLY) $(ENABLE_WEBGL) $(ENABLE_WEBGL2) $(ENABLE_WIRELESS_PLAYBACK_TARGET) $(ENABLE_WRITABLE_STREAM_API) $(ENABLE_XSLT);
+FEATURE_DEFINES = $(ENABLE_3D_TRANSFORMS) $(ENABLE_ACCELERATED_2D_CANVAS) $(ENABLE_ACCELERATED_OVERFLOW_SCROLLING) $(ENABLE_ATTACHMENT_ELEMENT) $(ENABLE_AVF_CAPTIONS) $(ENABLE_CACHE_PARTITIONING) $(ENABLE_CANVAS_PATH) $(ENABLE_CANVAS_PROXY) $(ENABLE_CHANNEL_MESSAGING) $(ENABLE_CONTENT_FILTERING) $(ENABLE_CSP_NEXT) $(ENABLE_CSS_ANIMATIONS_LEVEL_2) $(ENABLE_CSS_BOX_DECORATION_BREAK) $(ENABLE_CSS_COMPOSITING) $(ENABLE_CSS_DEVICE_ADAPTATION) $(ENABLE_CSS_GRID_LAYOUT) $(ENABLE_CSS_IMAGE_ORIENTATION) $(ENABLE_CSS_IMAGE_RESOLUTION) $(ENABLE_CSS_REGIONS) $(ENABLE_CSS_SCROLL_SNAP) $(ENABLE_CSS_SELECTORS_LEVEL4) $(ENABLE_CSS_SHAPES) $(ENABLE_CSS_TRAILING_WORD) $(ENABLE_CSS3_TEXT) $(ENABLE_CURSOR_VISIBILITY) $(ENABLE_CUSTOM_ELEMENTS) $(ENABLE_CUSTOM_SCHEME_HANDLER) $(ENABLE_DASHBOARD_SUPPORT) $(ENABLE_DATA_TRANSFER_ITEMS) $(ENABLE_DATACUE_VALUE) $(ENABLE_DATALIST_ELEMENT) $(ENABLE_DETAILS_ELEMENT) $(ENABLE_DEVICE_ORIENTATION) $(ENABLE_DOM4_EVENTS_CONSTRUCTOR) $(ENABLE_ENCRYPTED_MEDIA_V2) $(ENABLE_ES6_MODULES) $(ENABLE_ES2017_ASYNCFUNCTION_SYNTAX) $(ENABLE_FETCH_API) $(ENABLE_FILTERS_LEVEL_2) $(ENABLE_FONT_LOAD_EVENTS) $(ENABLE_FTL_JIT) $(ENABLE_FULLSCREEN_API) $(ENABLE_GAMEPAD_DEPRECATED) $(ENABLE_GAMEPAD) $(ENABLE_GEOLOCATION) $(ENABLE_ICONDATABASE) $(ENABLE_INDEXED_DATABASE_IN_WORKERS) $(ENABLE_INDEXED_DATABASE) $(ENABLE_INDIE_UI) $(ENABLE_INPUT_TYPE_COLOR_POPOVER) $(ENABLE_INPUT_TYPE_COLOR) $(ENABLE_INPUT_TYPE_DATE) $(ENABLE_INPUT_TYPE_DATETIME_INCOMPLETE) $(ENABLE_INPUT_TYPE_DATETIMELOCAL) $(ENABLE_INPUT_TYPE_MONTH) $(ENABLE_INPUT_TYPE_TIME) $(ENABLE_INPUT_TYPE_WEEK) $(ENABLE_INTL) $(ENABLE_IOS_GESTURE_EVENTS) $(ENABLE_IOS_TOUCH_EVENTS) $(ENABLE_JIT) $(ENABLE_LEGACY_CSS_VENDOR_PREFIXES) $(ENABLE_LEGACY_NOTIFICATIONS) $(ENABLE_LEGACY_VENDOR_PREFIXES) $(ENABLE_LETTERPRESS) $(ENABLE_LINK_PREFETCH) $(ENABLE_MAC_GESTURE_EVENTS) $(ENABLE_MATHML) $(ENABLE_MEDIA_CAPTURE) $(ENABLE_MEDIA_CONTROLS_SCRIPT) $(ENABLE_MEDIA_SESSION) $(ENABLE_MEDIA_SOURCE) $(ENABLE_MEDIA_STATISTICS) $(ENABLE_MEDIA_STREAM) $(ENABLE_METER_ELEMENT) $(ENABLE_MHTML) $(ENABLE_MOUSE_CURSOR_SCALE) $(ENABLE_NAVIGATOR_CONTENT_UTILS) $(ENABLE_NAVIGATOR_HWCONCURRENCY) $(ENABLE_NOTIFICATIONS) $(ENABLE_PDFKIT_PLUGIN) $(ENABLE_POINTER_LOCK) $(ENABLE_PROXIMITY_EVENTS) $(ENABLE_PUBLIC_SUFFIX_LIST) $(ENABLE_QUOTA) $(ENABLE_READABLE_STREAM_API) $(ENABLE_REMOTE_INSPECTOR) $(ENABLE_REQUEST_ANIMATION_FRAME) $(ENABLE_REQUEST_AUTOCOMPLETE) $(ENABLE_RESOLUTION_MEDIA_QUERY) $(ENABLE_RESOURCE_USAGE) $(ENABLE_RUBBER_BANDING) $(ENABLE_SERVICE_CONTROLS) $(ENABLE_SPEECH_SYNTHESIS) $(ENABLE_SUBTLE_CRYPTO) $(ENABLE_SVG_FONTS) $(ENABLE_TELEPHONE_NUMBER_DETECTION) $(ENABLE_TEXT_AUTOSIZING) $(ENABLE_TOUCH_EVENTS) $(ENABLE_TOUCH_ICON_LOADING) $(ENABLE_USERSELECT_ALL) $(ENABLE_VIDEO_PRESENTATION_MODE) $(ENABLE_VIDEO_TRACK) $(ENABLE_VIDEO) $(ENABLE_VIEW_MODE_CSS_MEDIA) $(ENABLE_WEB_ANIMATIONS) $(ENABLE_WEB_AUDIO) $(ENABLE_WEB_REPLAY) $(ENABLE_WEB_SOCKETS) $(ENABLE_WEB_TIMING) $(ENABLE_WEBASSEMBLY) $(ENABLE_WEBGL) $(ENABLE_WEBGL2) $(ENABLE_WIRELESS_PLAYBACK_TARGET) $(ENABLE_WRITABLE_STREAM_API) $(ENABLE_XSLT);
diff --git a/Source/JavaScriptCore/PlatformFuchsia.cmake b/Source/JavaScriptCore/PlatformFuchsia.cmake
new file mode 100644
index 000000000000..8380b659bc72
--- /dev/null
+++ b/Source/JavaScriptCore/PlatformFuchsia.cmake
@@ -0,0 +1,6 @@
+add_definitions(-DSTATICALLY_LINKED_WITH_WTF)
+
+list(APPEND JavaScriptCore_INCLUDE_DIRECTORIES
+ "${WTF_DIR}"
+)
+
diff --git a/Source/JavaScriptCore/assembler/ARM64Assembler.h b/Source/JavaScriptCore/assembler/ARM64Assembler.h
index 28b9fd73be08..049aa4445fdc 100644
--- a/Source/JavaScriptCore/assembler/ARM64Assembler.h
+++ b/Source/JavaScriptCore/assembler/ARM64Assembler.h
@@ -35,6 +35,10 @@
#include <wtf/Vector.h>
#include <stdint.h>
+#if OS(FUCHSIA)
+#include <zircon/syscalls.h>
+#endif
+
#define CHECK_DATASIZE_OF(datasize) ASSERT(datasize == 32 || datasize == 64)
#define DATASIZE_OF(datasize) ((datasize == 64) ? Datasize_64 : Datasize_32)
#define MEMOPSIZE_OF(datasize) ((datasize == 8 || datasize == 128) ? MemOpSize_8_or_128 : (datasize == 16) ? MemOpSize_16 : (datasize == 32) ? MemOpSize_32 : MemOpSize_64)
@@ -2707,7 +2711,7 @@ public:
unsigned debugOffset() { return m_buffer.debugOffset(); }
#if OS(LINUX) && COMPILER(GCC_OR_CLANG)
- static inline void linuxPageFlush(uintptr_t begin, uintptr_t end)
+ static inline void builtinPageFlush(uintptr_t begin, uintptr_t end)
{
__builtin___clear_cache(reinterpret_cast<char*>(begin), reinterpret_cast<char*>(end));
}
@@ -2717,6 +2721,8 @@ public:
{
#if OS(IOS)
sys_cache_control(kCacheFunctionPrepareForExecution, code, size);
+#elif OS(FUCHSIA)
+ zx_cache_flush(code, size, ZX_CACHE_FLUSH_INSN);
#elif OS(LINUX)
size_t page = pageSize();
uintptr_t current = reinterpret_cast<uintptr_t>(code);
@@ -2724,16 +2730,16 @@ public:
uintptr_t firstPageEnd = (current & ~(page - 1)) + page;
if (end <= firstPageEnd) {
- linuxPageFlush(current, end);
+ builtinPageFlush(current, end);
return;
}
- linuxPageFlush(current, firstPageEnd);
+ builtinPageFlush(current, firstPageEnd);
for (current = firstPageEnd; current + page < end; current += page)
- linuxPageFlush(current, current + page);
+ builtinPageFlush(current, current + page);
- linuxPageFlush(current, end);
+ builtinPageFlush(current, end);
#else
#error "The cacheFlush support is missing on this platform."
#endif
diff --git a/Source/JavaScriptCore/heap/HeapStatistics.cpp b/Source/JavaScriptCore/heap/HeapStatistics.cpp
index 1afa098f3782..7e351cc3e81e 100644
--- a/Source/JavaScriptCore/heap/HeapStatistics.cpp
+++ b/Source/JavaScriptCore/heap/HeapStatistics.cpp
@@ -37,7 +37,7 @@
#include <wtf/DataLog.h>
#include <wtf/StdLibExtras.h>
-#if OS(UNIX)
+#if OS(UNIX) && !defined(__Fuchsia__)
#include <sys/resource.h>
#endif
@@ -48,7 +48,7 @@ double HeapStatistics::s_endTime = 0.0;
Vector<double>* HeapStatistics::s_pauseTimeStarts = 0;
Vector<double>* HeapStatistics::s_pauseTimeEnds = 0;
-#if OS(UNIX)
+#if OS(UNIX) && !defined(__Fuchsia__)
void HeapStatistics::initialize()
{
diff --git a/Source/JavaScriptCore/heap/MachineStackMarker.cpp b/Source/JavaScriptCore/heap/MachineStackMarker.cpp
index a1fc3063a7ea..0d16c04bc196 100644
--- a/Source/JavaScriptCore/heap/MachineStackMarker.cpp
+++ b/Source/JavaScriptCore/heap/MachineStackMarker.cpp
@@ -323,6 +323,7 @@ MachineThreads::Thread::Thread(const PlatformThread& platThread, void* base, voi
&platformThreadHandle, 0, FALSE, DUPLICATE_SAME_ACCESS);
RELEASE_ASSERT(isSuccessful);
#elif USE(PTHREADS) && !OS(DARWIN)
+#if !OS(FUCHSIA)
threadLocalCurrentThread.store(this);
// Signal handlers are process global configuration.
@@ -346,6 +347,7 @@ MachineThreads::Thread::Thread(const PlatformThread& platThread, void* base, voi
sem_init(&semaphoreForSuspendResume, /* Only available in this process. */ 0, /* Initial value for the semaphore. */ 0);
#endif
+#endif
}
MachineThreads::Thread::~Thread()
diff --git a/Source/JavaScriptCore/jsc.cpp b/Source/JavaScriptCore/jsc.cpp
index 8ba4d207760f..3ffe090974c6 100644
--- a/Source/JavaScriptCore/jsc.cpp
+++ b/Source/JavaScriptCore/jsc.cpp
@@ -2305,6 +2305,269 @@ static bool runWithScripts(GlobalObject* globalObject, const Vector<Script>& scr
#define RUNNING_FROM_XCODE 0
+#if OS(FUCHSIA)
+
+#include <lib/fdio/io.h>
+#include <zircon/listnode.h>
+
+static bool interactive = false;
+
+void cputc(uint8_t ch) {
+ write(1, &ch, 1);
+}
+
+void cputs(const char* s, size_t len) {
+ write(1, s, len);
+}
+
+int cgetc(void) {
+ uint8_t ch;
+ for (;;) {
+ fdio_wait_fd(0, FDIO_EVT_READABLE, NULL, ZX_TIME_INFINITE);
+ int r = read(0, &ch, 1);
+ if (r < 0) {
+ return r;
+ }
+ if (r == 1) {
+ return ch;
+ }
+ }
+}
+
+void beep(void) {
+}
+
+#define CTRL_C 3
+#define BACKSPACE 8
+#define NL 10
+#define CTRL_L 12
+#define CR 13
+#define ESC 27
+#define DELETE 127
+
+#define EXT_UP 'A'
+#define EXT_DOWN 'B'
+#define EXT_RIGHT 'C'
+#define EXT_LEFT 'D'
+
+typedef struct {
+ list_node_t node;
+ int len;
+ char line[LINE_MAX];
+} hitem;
+
+list_node_t history = LIST_INITIAL_VALUE(history);
+
+static const char nl[2] = {'\r', '\n'};
+static const char bs[3] = {8, ' ', 8};
+static const char erase_line[5] = {ESC, '[', '2', 'K', '\r'};
+static const char cursor_left[3] = {ESC, '[', 'D'};
+static const char cursor_right[3] = {ESC, '[', 'C'};
+
+typedef struct {
+ int pos;
+ int len;
+ int save_len;
+ hitem* item;
+ char save[LINE_MAX];
+ char line[LINE_MAX + 1];
+} editstate;
+
+void history_add(editstate* es) {
+ hitem* item;
+ if (es->len && ((item = reinterpret_cast<hitem*>(malloc(sizeof(hitem)))) != NULL)) {
+ item->len = es->len;
+ memset(item->line, 0, sizeof(item->line));
+ memcpy(item->line, es->line, es->len);
+ list_add_tail(&history, &item->node);
+ }
+}
+
+int history_up(editstate* es) {
+ hitem* next;
+ if (es->item) {
+ next = list_prev_type(&history, &es->item->node, hitem, node);
+ if (next != NULL) {
+ es->item = next;
+ memcpy(es->line, es->item->line, es->item->len);
+ es->pos = es->len = es->item->len;
+ cputs(erase_line, sizeof(erase_line));
+ return 1;
+ } else {
+ beep();
+ return 0;
+ }
+ } else {
+ next = list_peek_tail_type(&history, hitem, node);
+ if (next != NULL) {
+ es->item = next;
+ memset(es->save, 0, sizeof(es->save));
+ memcpy(es->save, es->line, es->len);
+ es->save_len = es->len;
+ es->pos = es->len = es->item->len;
+ memcpy(es->line, es->item->line, es->len);
+ cputs(erase_line, sizeof(erase_line));
+ return 1;
+ } else {
+ return 0;
+ }
+ }
+}
+
+int history_down(editstate* es) {
+ if (es->item == NULL) {
+ beep();
+ return 0;
+ }
+ hitem* next = list_next_type(&history, &es->item->node, hitem, node);
+ if (next != NULL) {
+ es->item = next;
+ es->pos = es->len = es->item->len;
+ memcpy(es->line, es->item->line, es->len);
+ } else {
+ memcpy(es->line, es->save, es->save_len);
+ es->pos = es->len = es->save_len;
+ es->item = NULL;
+ }
+ cputs(erase_line, sizeof(erase_line));
+ return 1;
+}
+
+void settitle(const char* title) {
+ if (!interactive) {
+ return;
+ }
+ char str[16];
+ int n = snprintf(str, sizeof(str) - 1, "\033]2;%s", title);
+ if (n < 0) {
+ return; // error
+ } else if ((size_t)n >= sizeof(str) - 1) {
+ n = sizeof(str) - 2; // truncated
+ }
+ str[n] = '\007';
+ str[n+1] = '\0';
+ cputs(str, n + 1);
+}
+
+int readline(editstate* es, char prompt) {
+ int a, b, c;
+ es->len = 0;
+ es->pos = 0;
+ es->save_len = 0;
+ es->item = NULL;
+again:
+ cputc(prompt);
+ cputc(prompt);
+ cputc(prompt);
+ cputc(' ');
+ if (es->len) {
+ cputs(es->line, es->len);
+ }
+ if (es->len != es->pos) {
+ char tmp[16];
+ sprintf(tmp, "%c[%dG", ESC, es->pos + 3);
+ cputs(tmp, strlen(tmp));
+ }
+ for (;;) {
+ if ((c = cgetc()) < 0) {
+ es->item = NULL;
+ return c;
+ }
+ if ((c >= ' ') && (c < 127)) {
+ if (es->len < LINE_MAX) {
+ if (es->pos != es->len) {
+ memmove(es->line + es->pos + 1, es->line + es->pos, es->len - es->pos);
+ // expensive full redraw of line
+ es->len++;
+ es->line[es->pos++] = c;
+ es->item = NULL;
+ cputs(erase_line, sizeof(erase_line));
+ goto again;
+ }
+ es->len++;
+ es->line[es->pos++] = c;
+ cputc(c);
+ }
+ beep();
+ continue;
+ }
+ switch (c) {
+ case CTRL_C:
+ es->len = 0;
+ es->pos = 0;
+ es->item = NULL;
+ cputs(nl, sizeof(nl));
+ goto again;
+ case CTRL_L:
+ cputs(erase_line, sizeof(erase_line));
+ goto again;
+ case BACKSPACE:
+ case DELETE:
+ backspace:
+ if (es->pos > 0) {
+ es->pos--;
+ es->len--;
+ memmove(es->line + es->pos, es->line + es->pos + 1, es->len - es->pos);
+ // expensive full redraw of line
+ es->item = NULL;
+ cputs(erase_line, sizeof(erase_line));
+ goto again;
+ } else {
+ beep();
+ }
+ es->item = NULL;
+ continue;
+ case NL:
+ case CR:
+ es->line[es->len] = 0;
+ cputs(nl, sizeof(nl));
+ history_add(es);
+ return 0;
+ case ESC:
+ if ((a = cgetc()) < 0) {
+ return a;
+ }
+ if ((b = cgetc()) < 0) {
+ return b;
+ }
+ if (a != '[') {
+ break;
+ }
+ switch (b) {
+ case EXT_UP:
+ if (history_up(es)) {
+ goto again;
+ }
+ break;
+ case EXT_DOWN:
+ if (history_down(es)) {
+ goto again;
+ }
+ break;
+ case EXT_RIGHT:
+ if (es->pos < es->len) {
+ es->pos++;
+ cputs(cursor_right, sizeof(cursor_right));
+ } else {
+ beep();
+ }
+ break;
+ case EXT_LEFT:
+ if (es->pos > 0) {
+ es->pos--;
+ cputs(cursor_left, sizeof(cursor_left));
+ } else {
+ beep();
+ }
+ break;
+ }
+ }
+ beep();
+ }
+}
+#endif
+
+
static void runInteractive(GlobalObject* globalObject)
{
VM& vm = globalObject->vm();
@@ -2314,7 +2577,32 @@ static void runInteractive(GlobalObject* globalObject)
bool shouldQuit = false;
while (!shouldQuit) {
-#if HAVE(READLINE) && !RUNNING_FROM_XCODE
+#if OS(FUCHSIA)
+ editstate es = {};
+ ParserError error;
+ String source;
+ const char* continuationPrompt = "... ";
+ do {
+ error = ParserError();
+ int result = readline(&es, source.isEmpty() ? '>' : '.');
+ if (result != 0)
+ break;
+ source = source + es.line;
+ source = source + '\n';
+ checkSyntax(globalObject->vm(), makeSource(source, interpreterName), error);
+ if (!es.line[0])
+ break;
+ } while (error.syntaxErrorType() == ParserError::SyntaxErrorRecoverable);
+
+ if (error.isValid()) {
+ printf("%s:%d\n", error.message().utf8().data(), error.line());
+ continue;
+ }
+
+
+ NakedPtr<Exception> evaluationException;
+ JSValue returnValue = evaluate(globalObject->globalExec(), makeSource(source, interpreterName), JSValue(), evaluationException);
+#elif HAVE(READLINE) && !RUNNING_FROM_XCODE
ParserError error;
String source;
do {
diff --git a/Source/JavaScriptCore/shell/PlatformFuchsia.cmake b/Source/JavaScriptCore/shell/PlatformFuchsia.cmake
new file mode 100644
index 000000000000..9a3a0a4bcf32
--- /dev/null
+++ b/Source/JavaScriptCore/shell/PlatformFuchsia.cmake
@@ -0,0 +1,3 @@
+# list(APPEND JSC_LIBRARIES
+# $ENV{HOME}/fuchsia/lib/libicudata.a
+# )
diff --git a/Source/WTF/wtf/FastMalloc.cpp b/Source/WTF/wtf/FastMalloc.cpp
index dd6bab412a6c..59bfbfb7ebb5 100644
--- a/Source/WTF/wtf/FastMalloc.cpp
+++ b/Source/WTF/wtf/FastMalloc.cpp
@@ -36,8 +36,10 @@
#include <windows.h>
#else
#include <pthread.h>
+#ifndef __Fuchsia__
#include <sys/resource.h>
#endif
+#endif
#if OS(DARWIN)
#include <mach/mach_init.h>
diff --git a/Source/WTF/wtf/FeatureDefines.h b/Source/WTF/wtf/FeatureDefines.h
index 004fba1ae055..fe72abbdaafd 100644
--- a/Source/WTF/wtf/FeatureDefines.h
+++ b/Source/WTF/wtf/FeatureDefines.h
@@ -318,6 +318,17 @@ the public iOS SDK. We will also need to update the FeatureDefines.xcconfig file
#if PLATFORM(GTK)
#endif /* PLATFORM(GTK) */
+/* --------- Fuchsia port --------- */
+#if PLATFORM(FUCHSIA)
+#if !defined(ENABLE_TEXT_CARET)
+#define ENABLE_TEXT_CARET 1
+#endif
+
+#if !defined(ENABLE_TEXT_SELECTION)
+#define ENABLE_TEXT_SELECTION 1
+#endif
+#endif /* PLATFORM(FUCHSIA) */
+
/* ENABLE macro defaults for WebCore */
/* Do not use PLATFORM() tests in this section ! */
diff --git a/Source/WTF/wtf/InlineASM.h b/Source/WTF/wtf/InlineASM.h
index d440bda3d6e5..195dff07edda 100644
--- a/Source/WTF/wtf/InlineASM.h
+++ b/Source/WTF/wtf/InlineASM.h
@@ -64,6 +64,7 @@
#define HIDE_SYMBOL(name) ".lglobl " #name
#elif OS(LINUX) \
|| OS(FREEBSD) \
+ || OS(FUCHSIA) \
|| OS(OPENBSD) \
|| OS(SOLARIS) \
|| (OS(HPUX) && CPU(IA64)) \
@@ -81,6 +82,7 @@
#define LOCAL_LABEL_STRING(name) "L" #name
#elif OS(LINUX) \
|| OS(FREEBSD) \
+ || OS(FUCHSIA) \
|| OS(OPENBSD) \
|| OS(HURD) \
|| OS(NETBSD)
diff --git a/Source/WTF/wtf/OSRandomSource.cpp b/Source/WTF/wtf/OSRandomSource.cpp
index 378795dc7780..00db140ab297 100644
--- a/Source/WTF/wtf/OSRandomSource.cpp
+++ b/Source/WTF/wtf/OSRandomSource.cpp
@@ -44,6 +44,10 @@
#include "CommonCryptoSPI.h"
#endif
+#if OS(FUCHSIA)
+#include <zircon/syscalls.h>
+#endif
+
namespace WTF {
#if !OS(DARWIN) && OS(UNIX)
@@ -62,6 +66,8 @@ void cryptographicallyRandomValuesFromOS(unsigned char* buffer, size_t length)
{
#if OS(DARWIN)
RELEASE_ASSERT(!CCRandomCopyBytes(kCCRandomDefault, buffer, length));
+#elif OS(FUCHSIA)
+ zx_cprng_draw(buffer, length);
#elif OS(UNIX)
int fd = open("/dev/urandom", O_RDONLY, 0);
if (fd < 0)
diff --git a/Source/WTF/wtf/Platform.h b/Source/WTF/wtf/Platform.h
index 77bf8f941672..a6b5b7f21447 100644
--- a/Source/WTF/wtf/Platform.h
+++ b/Source/WTF/wtf/Platform.h
@@ -373,6 +373,11 @@
#define WTF_OS_MAC_OS_X 1
#endif
+/* OS(Fuchsia) - Fuchsia */
+#if defined(OS_FUCHSIA)
+#define WTF_OS_FUCHSIA 1
+#endif
+
/* OS(FREEBSD) - FreeBSD */
#if defined(__FreeBSD__) || defined(__DragonFly__) || defined(__FreeBSD_kernel__)
#define WTF_OS_FREEBSD 1
@@ -415,6 +420,7 @@
#if OS(AIX) \
|| OS(DARWIN) \
|| OS(FREEBSD) \
+ || OS(FUCHSIA) \
|| OS(HURD) \
|| OS(LINUX) \
|| OS(NETBSD) \
@@ -454,6 +460,8 @@
#endif
#elif OS(WINDOWS)
#define WTF_PLATFORM_WIN 1
+#elif OS(FUCHSIA)
+#define WTF_PLATFORM_FUCHSIA 1
#endif
/* PLATFORM(COCOA) */
@@ -605,7 +613,7 @@
#endif
#endif /* !defined(HAVE_ACCESSIBILITY) */
-#if OS(UNIX)
+#if OS(UNIX) && !OS(FUCHSIA)
#define HAVE_ERRNO_H 1
#define HAVE_LANGINFO_H 1
#define HAVE_MMAP 1
@@ -616,6 +624,19 @@
#define USE_PTHREADS 1
#endif /* OS(UNIX) */
+#if OS(FUCHSIA)
+#define HAVE_ERRNO_H 1
+#define HAVE_LANGINFO_H 1
+#define HAVE_MMAP 1
+#define HAVE_SIGNAL_H 1
+#define HAVE_STRINGS_H 1
+#define HAVE_SYS_PARAM_H 1
+#define HAVE_SYS_TIME_H 1
+#define USE_PTHREADS 1
+#define USE_CAIRO 1
+#define USE_FREETYPE 1
+#endif /* OS(FUCHSIA) */
+
#if (OS(FREEBSD) || OS(OPENBSD)) && !defined(__GLIBC__)
#define HAVE_PTHREAD_NP_H 1
#endif
@@ -685,7 +706,7 @@
/* Include feature macros */
#include <wtf/FeatureDefines.h>
-#if OS(WINDOWS)
+#if OS(WINDOWS) || OS(FUCHSIA)
#define USE_SYSTEM_MALLOC 1
#endif
diff --git a/Source/WTF/wtf/PlatformFuchsia.cmake b/Source/WTF/wtf/PlatformFuchsia.cmake
new file mode 100644
index 000000000000..679fb2b7a7d6
--- /dev/null
+++ b/Source/WTF/wtf/PlatformFuchsia.cmake
@@ -0,0 +1,32 @@
+list(APPEND WTF_SOURCES
+ PlatformUserPreferredLanguagesUnix.cpp
+
+ text/jsconly/TextBreakIteratorInternalICUJSCOnly.cpp
+)
+
+if (LOWERCASE_EVENT_LOOP_TYPE STREQUAL "glib")
+ list(APPEND WTF_SOURCES
+ glib/GRefPtr.cpp
+ glib/MainThreadGLib.cpp
+ glib/RunLoopGLib.cpp
+ glib/WorkQueueGLib.cpp
+ )
+ list(APPEND WTF_SYSTEM_INCLUDE_DIRECTORIES
+ ${GLIB_INCLUDE_DIRS}
+ )
+ list(APPEND WTF_LIBRARIES
+ ${GLIB_GIO_LIBRARIES}
+ ${GLIB_GOBJECT_LIBRARIES}
+ ${GLIB_LIBRARIES}
+ )
+else ()
+ list(APPEND WTF_SOURCES
+ generic/MainThreadGeneric.cpp
+ generic/RunLoopGeneric.cpp
+ generic/WorkQueueGeneric.cpp
+ )
+endif ()
+
+list(APPEND WTF_LIBRARIES
+ ${CMAKE_THREAD_LIBS_INIT}
+)
diff --git a/Source/WTF/wtf/ThreadingPthreads.cpp b/Source/WTF/wtf/ThreadingPthreads.cpp
index 705f36def67c..4c2532fa41a4 100644
--- a/Source/WTF/wtf/ThreadingPthreads.cpp
+++ b/Source/WTF/wtf/ThreadingPthreads.cpp
@@ -203,6 +203,7 @@ void initializeCurrentThreadInternal(const char* threadName)
void changeThreadPriority(ThreadIdentifier threadID, int delta)
{
+#if !PLATFORM(FUCHSIA)
pthread_t pthreadHandle;
ASSERT(threadID);
@@ -221,6 +222,7 @@ void changeThreadPriority(ThreadIdentifier threadID, int delta)
param.sched_priority += delta;
pthread_setschedparam(pthreadHandle, policy, &param);
+#endif
}
int waitForThreadCompletion(ThreadIdentifier threadID)
diff --git a/Source/WTF/wtf/text/TextBreakIterator.cpp b/Source/WTF/wtf/text/TextBreakIterator.cpp
index fc70a777e37d..83eeec61df8e 100644
--- a/Source/WTF/wtf/text/TextBreakIterator.cpp
+++ b/Source/WTF/wtf/text/TextBreakIterator.cpp
@@ -798,7 +798,9 @@ TextBreakIterator* openLineBreakIterator(const AtomicString& locale, LineBreakIt
}
if (U_FAILURE(openStatus)) {
+#if !PLATFORM(FUCHSIA)
LOG_ERROR("ubrk_open failed with status %d", openStatus);
+#endif
return nullptr;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment