OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "include/dart_api.h" | 5 #include "include/dart_api.h" |
6 | 6 |
7 #include "platform/assert.h" | 7 #include "platform/assert.h" |
8 #include "vm/bigint_operations.h" | 8 #include "vm/bigint_operations.h" |
9 #include "vm/class_finalizer.h" | 9 #include "vm/class_finalizer.h" |
10 #include "vm/compiler.h" | 10 #include "vm/compiler.h" |
(...skipping 4274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4285 | 4285 |
4286 const Script& script = Script::Handle( | 4286 const Script& script = Script::Handle( |
4287 isolate, Script::New(url_str, source_str, RawScript::kScriptTag)); | 4287 isolate, Script::New(url_str, source_str, RawScript::kScriptTag)); |
4288 script.SetLocationOffset(line_offset, col_offset); | 4288 script.SetLocationOffset(line_offset, col_offset); |
4289 Dart_Handle result; | 4289 Dart_Handle result; |
4290 CompileSource(isolate, library, script, &result); | 4290 CompileSource(isolate, library, script, &result); |
4291 return result; | 4291 return result; |
4292 } | 4292 } |
4293 | 4293 |
4294 | 4294 |
4295 DART_EXPORT Dart_Handle Dart_LoadScriptFromSnapshot(const uint8_t* buffer) { | 4295 DART_EXPORT Dart_Handle Dart_LoadScriptFromSnapshot(const uint8_t* buffer, |
| 4296 intptr_t buffer_len) { |
4296 Isolate* isolate = Isolate::Current(); | 4297 Isolate* isolate = Isolate::Current(); |
4297 DARTSCOPE(isolate); | 4298 DARTSCOPE(isolate); |
4298 TIMERSCOPE(time_script_loading); | 4299 TIMERSCOPE(time_script_loading); |
4299 if (buffer == NULL) { | 4300 if (buffer == NULL) { |
4300 RETURN_NULL_ERROR(buffer); | 4301 RETURN_NULL_ERROR(buffer); |
4301 } | 4302 } |
4302 const Snapshot* snapshot = Snapshot::SetupFromBuffer(buffer); | 4303 const Snapshot* snapshot = Snapshot::SetupFromBuffer(buffer); |
4303 if (!snapshot->IsScriptSnapshot()) { | 4304 if (!snapshot->IsScriptSnapshot()) { |
4304 return Api::NewError("%s expects parameter 'buffer' to be a script type" | 4305 return Api::NewError("%s expects parameter 'buffer' to be a script type" |
4305 " snapshot.", CURRENT_FUNC); | 4306 " snapshot.", CURRENT_FUNC); |
4306 } | 4307 } |
| 4308 if (snapshot->length() != buffer_len) { |
| 4309 return Api::NewError("%s: 'buffer_len' of %"Pd" is not equal to %d which" |
| 4310 " is the expected length in the snapshot.", |
| 4311 CURRENT_FUNC, buffer_len, snapshot->length()); |
| 4312 } |
4307 Library& library = | 4313 Library& library = |
4308 Library::Handle(isolate, isolate->object_store()->root_library()); | 4314 Library::Handle(isolate, isolate->object_store()->root_library()); |
4309 if (!library.IsNull()) { | 4315 if (!library.IsNull()) { |
4310 const String& library_url = String::Handle(isolate, library.url()); | 4316 const String& library_url = String::Handle(isolate, library.url()); |
4311 return Api::NewError("%s: A script has already been loaded from '%s'.", | 4317 return Api::NewError("%s: A script has already been loaded from '%s'.", |
4312 CURRENT_FUNC, library_url.ToCString()); | 4318 CURRENT_FUNC, library_url.ToCString()); |
4313 } | 4319 } |
4314 CHECK_CALLBACK_STATE(isolate); | 4320 CHECK_CALLBACK_STATE(isolate); |
4315 | 4321 |
4316 SnapshotReader reader(snapshot->content(), | 4322 SnapshotReader reader(snapshot->content(), |
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4674 } | 4680 } |
4675 { | 4681 { |
4676 NoGCScope no_gc; | 4682 NoGCScope no_gc; |
4677 RawObject* raw_obj = obj.raw(); | 4683 RawObject* raw_obj = obj.raw(); |
4678 isolate->heap()->SetPeer(raw_obj, peer); | 4684 isolate->heap()->SetPeer(raw_obj, peer); |
4679 } | 4685 } |
4680 return Api::Success(isolate); | 4686 return Api::Success(isolate); |
4681 } | 4687 } |
4682 | 4688 |
4683 } // namespace dart | 4689 } // namespace dart |
OLD | NEW |