diff --git a/lib/_internal/libraries.dart b/lib/_internal/libraries.dart index ea6ddbfb488..1f90ddbd3aa 100644 --- a/lib/_internal/libraries.dart +++ b/lib/_internal/libraries.dart @@ -75,6 +75,9 @@ const Map LIBRARIES = const { "utf": const LibraryInfo( "utf/utf.dart"), + "web": const LibraryInfo( + "web/web.dart"), + "_js_helper": const LibraryInfo( "compiler/implementation/lib/js_helper.dart", category: "Internal", diff --git a/pkg/htmlescape/htmlescape.dart b/lib/web/web.dart similarity index 81% rename from pkg/htmlescape/htmlescape.dart rename to lib/web/web.dart index 6c5e4f85a14..58ce510857e 100644 --- a/pkg/htmlescape/htmlescape.dart +++ b/lib/web/web.dart @@ -2,11 +2,10 @@ // 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. -/** - * This library contains functions to escape strings for safe inclusion - * in HTML source. - */ -#library("htmlescape"); +#library("dart:web"); + +// Web related functions and data that are not specific to a single environment +// (e.g., only in a browser or only on a server). /** * Escapes HTML-special characters of [text] so that the result can be diff --git a/pkg/htmlescape/pubspec.yaml b/pkg/htmlescape/pubspec.yaml deleted file mode 100644 index 4ab6dc46f3e..00000000000 --- a/pkg/htmlescape/pubspec.yaml +++ /dev/null @@ -1,8 +0,0 @@ -name: htmlescape -description: > - Simple HTML utility for escapeing a String. - - -dependencies: - unittest: - sdk: unittest diff --git a/pkg/intl/intl.dart b/pkg/intl/intl.dart index d176e52862a..ad5803c4483 100644 --- a/pkg/intl/intl.dart +++ b/pkg/intl/intl.dart @@ -8,7 +8,7 @@ */ #library('intl'); -#import('../../pkg/htmlescape/htmlescape.dart'); +#import('dart:web'); #import('date_format.dart'); #source('intl_message.dart'); diff --git a/pkg/intl/pubspec.yaml b/pkg/intl/pubspec.yaml index 4b53267cf9e..975e9a1b278 100644 --- a/pkg/intl/pubspec.yaml +++ b/pkg/intl/pubspec.yaml @@ -6,5 +6,3 @@ description: > dependencies: unittest: sdk: unittest - htmlescape - sdk: htmlescape diff --git a/runtime/bin/bin.gypi b/runtime/bin/bin.gypi index 45d808c5a62..1872c3d073f 100644 --- a/runtime/bin/bin.gypi +++ b/runtime/bin/bin.gypi @@ -9,6 +9,7 @@ 'json_cc_file': '<(SHARED_INTERMEDIATE_DIR)/json_gen.cc', 'uri_cc_file': '<(SHARED_INTERMEDIATE_DIR)/uri_gen.cc', 'utf_cc_file': '<(SHARED_INTERMEDIATE_DIR)/utf_gen.cc', + 'web_cc_file': '<(SHARED_INTERMEDIATE_DIR)/web_gen.cc', 'builtin_in_cc_file': 'builtin_in.cc', 'builtin_cc_file': '<(SHARED_INTERMEDIATE_DIR)/builtin_gen.cc', 'snapshot_in_cc_file': 'snapshot_in.cc', @@ -215,6 +216,36 @@ }, ] }, + { + 'target_name': 'generate_web_cc_file', + 'type': 'none', + 'includes': [ + 'web_sources.gypi', + ], + 'actions': [ + { + 'action_name': 'generate_web_cc', + 'inputs': [ + '../tools/create_string_literal.py', + '<(builtin_in_cc_file)', + '<@(_sources)', + ], + 'outputs': [ + '<(web_cc_file)', + ], + 'action': [ + 'python', + 'tools/create_string_literal.py', + '--output', '<(web_cc_file)', + '--input_cc', '<(builtin_in_cc_file)', + '--include', 'bin/builtin.h', + '--var_name', 'Builtin::web_source_', + '<@(_sources)', + ], + 'message': 'Generating ''<(web_cc_file)'' file.' + }, + ] + }, { 'target_name': 'libdart_builtin', 'type': 'static_library', @@ -225,6 +256,7 @@ 'generate_json_cc_file', 'generate_uri_cc_file', 'generate_utf_cc_file', + 'generate_web_cc_file', ], 'include_dirs': [ '..', @@ -307,6 +339,7 @@ '<(json_cc_file)', '<(uri_cc_file)', '<(utf_cc_file)', + '<(web_cc_file)', ], 'conditions': [ ['OS=="win"', { @@ -389,6 +422,7 @@ 'main.cc', 'builtin_nolib.cc', '<(snapshot_cc_file)', + '<(web_cc_file)', ], 'conditions': [ ['OS=="win"', { @@ -426,6 +460,7 @@ '<(json_cc_file)', '<(uri_cc_file)', '<(utf_cc_file)', + '<(web_cc_file)', 'snapshot_empty.cc', ], 'conditions': [ @@ -464,6 +499,7 @@ '<(json_cc_file)', '<(uri_cc_file)', '<(utf_cc_file)', + '<(web_cc_file)', ], 'includes': [ 'builtin_impl_sources.gypi', diff --git a/runtime/bin/builtin.cc b/runtime/bin/builtin.cc index c42c3c3776a..83b2847959b 100644 --- a/runtime/bin/builtin.cc +++ b/runtime/bin/builtin.cc @@ -17,7 +17,8 @@ Builtin::builtin_lib_props Builtin::builtin_libraries_[] = { { DartUtils::kUriLibURL, uri_source_, false }, { DartUtils::kCryptoLibURL, crypto_source_, false }, { DartUtils::kIOLibURL, io_source_, true }, - { DartUtils::kUtfLibURL, utf_source_, false } + { DartUtils::kUtfLibURL, utf_source_, false }, + { DartUtils::kWebLibURL, web_source_, false } }; diff --git a/runtime/bin/builtin.h b/runtime/bin/builtin.h index 2b954a6affe..2e8f8df1c5a 100644 --- a/runtime/bin/builtin.h +++ b/runtime/bin/builtin.h @@ -30,6 +30,7 @@ class Builtin { kCryptoLibrary, kIOLibrary, kUtfLibrary, + kWebLibrary, kInvalidLibrary, }; diff --git a/runtime/bin/builtin_nolib.cc b/runtime/bin/builtin_nolib.cc index 58f81332964..91c3ce38403 100644 --- a/runtime/bin/builtin_nolib.cc +++ b/runtime/bin/builtin_nolib.cc @@ -17,14 +17,16 @@ Builtin::builtin_lib_props Builtin::builtin_libraries_[] = { { DartUtils::kUriLibURL, NULL, false }, { DartUtils::kCryptoLibURL, NULL, false }, { DartUtils::kIOLibURL, NULL, true }, - { DartUtils::kUtfLibURL, NULL, false } + { DartUtils::kUtfLibURL, NULL, false }, + { DartUtils::kWebLibURL, web_source_, false } }; Dart_Handle Builtin::Source(BuiltinLibraryId id) { ASSERT((sizeof(builtin_libraries_) / sizeof(builtin_lib_props)) == kInvalidLibrary); - return Dart_NewApiError("Unreachable code in Builtin::Source (%d).", id); + ASSERT(id == kWebLibrary); + return Dart_NewString(builtin_libraries_[id].source_); } diff --git a/runtime/bin/dartutils.cc b/runtime/bin/dartutils.cc index 57f70069f0b..8223b9f633f 100644 --- a/runtime/bin/dartutils.cc +++ b/runtime/bin/dartutils.cc @@ -23,6 +23,7 @@ const char* DartUtils::kJsonLibURL = "dart:json"; const char* DartUtils::kUriLibURL = "dart:uri"; const char* DartUtils::kUtfLibURL = "dart:utf"; const char* DartUtils::kIsolateLibURL = "dart:isolate"; +const char* DartUtils::kWebLibURL = "dart:web"; const char* DartUtils::kIdFieldName = "_id"; @@ -165,6 +166,11 @@ bool DartUtils::IsDartUtfLibURL(const char* url_name) { } +bool DartUtils::IsDartWebLibURL(const char* url_name) { + return (strcmp(url_name, kWebLibURL) == 0); +} + + Dart_Handle DartUtils::CanonicalizeURL(CommandLineOptions* url_mapping, Dart_Handle library, const char* url_str) { @@ -300,6 +306,8 @@ Dart_Handle DartUtils::LibraryTagHandler(Dart_LibraryTag tag, id = Builtin::kUriLibrary; } else if (DartUtils::IsDartUtfLibURL(url_string)) { id = Builtin::kUtfLibrary; + } else if (DartUtils::IsDartWebLibURL(url_string)) { + id = Builtin::kWebLibrary; } else { return Dart_Error("Do not know how to load '%s'", url_string); } diff --git a/runtime/bin/dartutils.h b/runtime/bin/dartutils.h index 723c191ada1..880e4794069 100644 --- a/runtime/bin/dartutils.h +++ b/runtime/bin/dartutils.h @@ -85,6 +85,7 @@ class DartUtils { static bool IsDartJsonLibURL(const char* url_name); static bool IsDartUriLibURL(const char* url_name); static bool IsDartUtfLibURL(const char* url_name); + static bool IsDartWebLibURL(const char* url_name); static Dart_Handle CanonicalizeURL(CommandLineOptions* url_mapping, Dart_Handle library, const char* url_str); diff --git a/runtime/bin/web_sources.gypi b/runtime/bin/web_sources.gypi new file mode 100644 index 00000000000..e9a063d4bc6 --- /dev/null +++ b/runtime/bin/web_sources.gypi @@ -0,0 +1,10 @@ +# Copyright (c) 2012, 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. + +# This file contains all sources for the dart:web library. +{ + 'sources': [ + '../../lib/web/web.dart', + ], +} diff --git a/runtime/vm/unit_test.cc b/runtime/vm/unit_test.cc index e1105a5de56..c10cbbae2c3 100644 --- a/runtime/vm/unit_test.cc +++ b/runtime/vm/unit_test.cc @@ -86,6 +86,8 @@ static Dart_Handle LibraryTagHandler(Dart_LibraryTag tag, return Builtin::LoadAndCheckLibrary(Builtin::kUtfLibrary); } else if (DartUtils::IsDartCryptoLibURL(url_chars)) { return Builtin::LoadAndCheckLibrary(Builtin::kCryptoLibrary); + } else if (DartUtils::IsDartWebLibURL(url_chars)) { + return Builtin::LoadAndCheckLibrary(Builtin::kWebLibrary); } else { return Dart_Error("Do not know how to load '%s'", url_chars); } diff --git a/tools/create_sdk.py b/tools/create_sdk.py index 2ea8fe8443a..7bdd755d92c 100755 --- a/tools/create_sdk.py +++ b/tools/create_sdk.py @@ -55,10 +55,11 @@ # ......uri/ # ........uri.dart # ......utf/ +# ......web/ +# ........web.dart # ....pkg/ # ......args/ # ......dartdoc/ -#.......htmlescape/ # ......intl/ # ......logging/ # ......(more will come here) @@ -299,9 +300,8 @@ def Main(argv): # Create and populate lib/{core, crypto, isolate, json, uri, utf, ...}. # - # TODO: Take this data from lib/_internal/libraries.dart! for library in ['_internal', 'core', 'coreimpl', 'crypto', 'isolate', 'json', - 'math', 'mirrors', 'uri', 'utf']: + 'math', 'mirrors', 'uri', 'utf', 'web']: src_dir = join(HOME, 'lib', library) dest_dir = join(LIB, library) os.makedirs(dest_dir) @@ -318,7 +318,7 @@ def Main(argv): # Create and populate pkg/{args, intl, logging, unittest} # - for library in ['args', 'htmlescape', 'intl', 'logging', 'unittest']: + for library in ['args', 'intl', 'logging', 'unittest']: src_dir = join(HOME, 'pkg', library) dest_dir = join(PKG, library) os.makedirs(dest_dir)