Import Cobalt 9.28152
diff --git a/src/base/base_paths_starboard.cc b/src/base/base_paths_starboard.cc index fbad177..15e7b20 100644 --- a/src/base/base_paths_starboard.cc +++ b/src/base/base_paths_starboard.cc
@@ -91,7 +91,6 @@ return PathProviderStarboard(base::DIR_CACHE, result); } - DLOG(ERROR) << "Could not resolve path for key = " << key; return false; }
diff --git a/src/base/rand_util.cc b/src/base/rand_util.cc index a9bc961..0810149 100644 --- a/src/base/rand_util.cc +++ b/src/base/rand_util.cc
@@ -11,6 +11,7 @@ #include "base/basictypes.h" #include "base/logging.h" #include "base/string_util.h" +#include "starboard/client_porting/poem/string_poem.h" namespace base {
diff --git a/src/cobalt/accessibility/accessibility.gyp b/src/cobalt/accessibility/accessibility.gyp index 149d26f..50de511 100644 --- a/src/cobalt/accessibility/accessibility.gyp +++ b/src/cobalt/accessibility/accessibility.gyp
@@ -21,8 +21,8 @@ 'internal/live_region.h', 'internal/text_alternative_helper.cc', 'internal/text_alternative_helper.h', - 'focus_observer.cc', - 'focus_observer.h', + 'screen_reader.cc', + 'screen_reader.h', 'starboard_tts_engine.cc', 'starboard_tts_engine.h', 'text_alternative.cc', @@ -32,6 +32,7 @@ ], 'dependencies': [ '<(DEPTH)/cobalt/base/base.gyp:base', + '<(DEPTH)/cobalt/dom/dom.gyp:dom', ], }, ]
diff --git a/src/cobalt/accessibility/accessibility_test.gyp b/src/cobalt/accessibility/accessibility_test.gyp index e28a8f1..8db8e78 100644 --- a/src/cobalt/accessibility/accessibility_test.gyp +++ b/src/cobalt/accessibility/accessibility_test.gyp
@@ -17,7 +17,7 @@ 'target_name': 'accessibility_test', 'type': '<(gtest_target_type)', 'sources': [ - 'text_alternative_tests.cc', + 'screen_reader_tests.cc', 'internal/live_region_test.cc', 'internal/text_alternative_helper_test.cc', ], @@ -41,7 +41,7 @@ 'input_files': [ '<(DEPTH)/cobalt/accessibility/testdata/', ], - 'output_dir': 'cobalt/accessibility_test', + 'output_dir': 'cobalt/accessibility/testdata/', }, 'includes': ['../build/copy_test_data.gypi'], }
diff --git a/src/cobalt/accessibility/focus_observer.cc b/src/cobalt/accessibility/focus_observer.cc deleted file mode 100644 index 4884a1f..0000000 --- a/src/cobalt/accessibility/focus_observer.cc +++ /dev/null
@@ -1,42 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "cobalt/accessibility/focus_observer.h" - -#include <string> - -#include "cobalt/accessibility/text_alternative.h" - -namespace cobalt { -namespace accessibility { -FocusObserver::FocusObserver(dom::Document* document, - scoped_ptr<TTSEngine> tts_engine) - : document_(document), tts_engine_(tts_engine.Pass()) { - document_->AddObserver(this); -} - -FocusObserver::~FocusObserver() { document_->RemoveObserver(this); } - -void FocusObserver::OnFocusChanged() { - // TODO: Only utter text if text-to-speech is enabled. - scoped_refptr<dom::Element> element = document_->active_element(); - if (element) { - std::string text_alternative = ComputeTextAlternative(element); - tts_engine_->SpeakNow(text_alternative); - } -} -} // namespace accessibility -} // namespace cobalt
diff --git a/src/cobalt/accessibility/focus_observer.h b/src/cobalt/accessibility/focus_observer.h deleted file mode 100644 index 7b0034f..0000000 --- a/src/cobalt/accessibility/focus_observer.h +++ /dev/null
@@ -1,50 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef COBALT_ACCESSIBILITY_FOCUS_OBSERVER_H_ -#define COBALT_ACCESSIBILITY_FOCUS_OBSERVER_H_ - -#include "base/memory/scoped_ptr.h" -#include "cobalt/accessibility/tts_engine.h" -#include "cobalt/dom/document.h" - -namespace cobalt { -namespace accessibility { -// FocusObserver registers an observer on the document such that it can be -// notified whenever the document's focused element changes. Upon change of the -// focused element, FocusObserver will calculate the text contents of the newly -// focused element and send that string to a TTSEngine. -class FocusObserver : public dom::DocumentObserver { - public: - FocusObserver(dom::Document* document, scoped_ptr<TTSEngine> tts_engine); - - protected: - ~FocusObserver(); - void OnLoad() OVERRIDE {} - void OnMutation() OVERRIDE {} - void OnFocusChanged() OVERRIDE; - - private: - dom::Document* document_; - scoped_ptr<TTSEngine> tts_engine_; - - friend class scoped_ptr<FocusObserver>; - DISALLOW_COPY_AND_ASSIGN(FocusObserver); -}; -} // namespace accessibility -} // namespace cobalt - -#endif // COBALT_ACCESSIBILITY_FOCUS_OBSERVER_H_
diff --git a/src/cobalt/accessibility/internal/live_region.cc b/src/cobalt/accessibility/internal/live_region.cc index fb9cb68..2b945b0 100644 --- a/src/cobalt/accessibility/internal/live_region.cc +++ b/src/cobalt/accessibility/internal/live_region.cc
@@ -1,18 +1,16 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #include "cobalt/accessibility/internal/live_region.h" @@ -22,6 +20,7 @@ #include "base/basictypes.h" #include "base/string_split.h" #include "cobalt/base/tokens.h" +#include "cobalt/dom/element.h" namespace cobalt { namespace accessibility { @@ -69,15 +68,16 @@ } // namespace // static -scoped_ptr<LiveRegion> LiveRegion::GetLiveRegionForElement( - const scoped_refptr<dom::Element>& element) { - if (!element) { +scoped_ptr<LiveRegion> LiveRegion::GetLiveRegionForNode( + const scoped_refptr<dom::Node>& node) { + if (!node) { return make_scoped_ptr<LiveRegion>(NULL); } - if (HasValidLiveRegionProperty(element)) { + scoped_refptr<dom::Element> element = node->AsElement(); + if (element && HasValidLiveRegionProperty(element)) { return make_scoped_ptr(new LiveRegion(element)); } - return GetLiveRegionForElement(element->parent_element()); + return GetLiveRegionForNode(node->parent_node()); } bool LiveRegion::IsAssertive() const { @@ -95,29 +95,31 @@ return bitset.test(mutation_type); } -bool LiveRegion::IsAtomic(const scoped_refptr<dom::Element>& element) const { +bool LiveRegion::IsAtomic(const scoped_refptr<dom::Node>& node) const { // Stop searching if we go past the live region's root node. The default is // non-atomic. - if (!element || element == root_->parent_element()) { + if (!node || node == root_->parent_node()) { return false; } - - // Search ancestors of the changed element to determine if this change is - // atomic or not, per the algorithm described in the spec. - // https://www.w3.org/TR/wai-aria/states_and_properties#aria-atomic - base::optional<std::string> aria_atomic_attribute = - element->GetAttribute(base::Tokens::aria_atomic().c_str()); - if (aria_atomic_attribute) { - if (*aria_atomic_attribute == base::Tokens::true_token()) { - return true; - } else if (*aria_atomic_attribute == base::Tokens::false_token()) { - return false; - } else { - DLOG(WARNING) << "Unexpected token for aria-atomic: " - << *aria_atomic_attribute; + if (node->IsElement()) { + scoped_refptr<dom::Element> element = node->AsElement(); + // Search ancestors of the changed element to determine if this change is + // atomic or not, per the algorithm described in the spec. + // https://www.w3.org/TR/wai-aria/states_and_properties#aria-atomic + base::optional<std::string> aria_atomic_attribute = + element->GetAttribute(base::Tokens::aria_atomic().c_str()); + if (aria_atomic_attribute) { + if (*aria_atomic_attribute == base::Tokens::true_token()) { + return true; + } else if (*aria_atomic_attribute == base::Tokens::false_token()) { + return false; + } else { + DLOG(WARNING) << "Unexpected token for aria-atomic: " + << *aria_atomic_attribute; + } } } - return IsAtomic(element->parent_element()); + return IsAtomic(node->parent_node()); } } // namespace internal
diff --git a/src/cobalt/accessibility/internal/live_region.h b/src/cobalt/accessibility/internal/live_region.h index d39ca2b..52d40ee 100644 --- a/src/cobalt/accessibility/internal/live_region.h +++ b/src/cobalt/accessibility/internal/live_region.h
@@ -1,18 +1,16 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #ifndef COBALT_ACCESSIBILITY_INTERNAL_LIVE_REGION_H_ #define COBALT_ACCESSIBILITY_INTERNAL_LIVE_REGION_H_ @@ -20,7 +18,7 @@ #include <string> #include "base/memory/scoped_ptr.h" -#include "cobalt/dom/element.h" +#include "cobalt/dom/node.h" namespace cobalt { namespace accessibility { @@ -45,8 +43,8 @@ // // Searches the element's ancestors looking for the first element with a // valid aria-live attribute. - static scoped_ptr<LiveRegion> GetLiveRegionForElement( - const scoped_refptr<dom::Element>& element); + static scoped_ptr<LiveRegion> GetLiveRegionForNode( + const scoped_refptr<dom::Node>& node); // Returns true if the value of aria-live is "assertive". // https://www.w3.org/TR/2011/CR-wai-aria-20110118/states_and_properties#aria-live @@ -58,12 +56,12 @@ // https://www.w3.org/TR/2011/CR-wai-aria-20110118/states_and_properties#aria-relevant bool IsMutationRelevant(MutationType mutation_type) const; - // Returns true if changes to this element should result in an atomic update + // Returns true if changes to this node should result in an atomic update // to its live region, according to the value of the aria-atomic property set - // on this element or its ancestors, up to and including the live region root. + // on this node or its ancestors, up to and including the live region root. // // https://www.w3.org/TR/2011/CR-wai-aria-20110118/states_and_properties#aria-atomic - bool IsAtomic(const scoped_refptr<dom::Element>& element) const; + bool IsAtomic(const scoped_refptr<dom::Node>& node) const; // Returns the root of the live region (i.e.) the element that has the // aria-live property set on it.
diff --git a/src/cobalt/accessibility/internal/live_region_test.cc b/src/cobalt/accessibility/internal/live_region_test.cc index cfb9230..6cb8c08 100644 --- a/src/cobalt/accessibility/internal/live_region_test.cc +++ b/src/cobalt/accessibility/internal/live_region_test.cc
@@ -1,22 +1,21 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" #include "cobalt/accessibility/internal/live_region.h" +#include "cobalt/dom/element.h" #include "cobalt/test/empty_document.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" @@ -45,21 +44,21 @@ CreateLiveRegion(base::Tokens::polite().c_str()); ASSERT_TRUE(live_region_element); - // GetLiveRegionForElement with the live region root. - live_region = LiveRegion::GetLiveRegionForElement(live_region_element); + // GetLiveRegionForNode with the live region root. + live_region = LiveRegion::GetLiveRegionForNode(live_region_element); ASSERT_TRUE(live_region); EXPECT_EQ(live_region->root(), live_region_element); - // GetLiveRegionForElement with a descendent node of a live region. + // GetLiveRegionForNode with a descendent node of a live region. scoped_refptr<dom::Element> child = document()->CreateElement("div"); live_region_element->AppendChild(child); - live_region = LiveRegion::GetLiveRegionForElement(child); + live_region = LiveRegion::GetLiveRegionForNode(child); ASSERT_TRUE(live_region); EXPECT_EQ(live_region->root(), live_region_element); // Element that is not in a live region. scoped_refptr<dom::Element> not_live = document()->CreateElement("div"); - live_region = LiveRegion::GetLiveRegionForElement(not_live); + live_region = LiveRegion::GetLiveRegionForNode(not_live); EXPECT_FALSE(live_region); } @@ -76,15 +75,14 @@ // The closest ancestor live region is this element's live region. scoped_refptr<dom::Element> child = document()->CreateElement("div"); nested_region_element->AppendChild(child); - scoped_ptr<LiveRegion> live_region = - LiveRegion::GetLiveRegionForElement(child); + scoped_ptr<LiveRegion> live_region = LiveRegion::GetLiveRegionForNode(child); ASSERT_TRUE(live_region); EXPECT_EQ(live_region->root(), nested_region_element); // Ignore live regions that are not active. nested_region_element->SetAttribute(base::Tokens::aria_live().c_str(), base::Tokens::off().c_str()); - live_region = LiveRegion::GetLiveRegionForElement(child); + live_region = LiveRegion::GetLiveRegionForNode(child); ASSERT_TRUE(live_region); EXPECT_EQ(live_region->root(), live_region_element); } @@ -96,7 +94,7 @@ scoped_refptr<dom::Element> polite_element = CreateLiveRegion(base::Tokens::polite().c_str()); ASSERT_TRUE(polite_element); - live_region = LiveRegion::GetLiveRegionForElement(polite_element); + live_region = LiveRegion::GetLiveRegionForNode(polite_element); ASSERT_TRUE(live_region); EXPECT_FALSE(live_region->IsAssertive()); @@ -104,7 +102,7 @@ scoped_refptr<dom::Element> assertive_element = CreateLiveRegion(base::Tokens::assertive().c_str()); ASSERT_TRUE(assertive_element); - live_region = LiveRegion::GetLiveRegionForElement(assertive_element); + live_region = LiveRegion::GetLiveRegionForNode(assertive_element); ASSERT_TRUE(live_region); EXPECT_TRUE(live_region->IsAssertive()); @@ -112,13 +110,13 @@ scoped_refptr<dom::Element> off_element = CreateLiveRegion(base::Tokens::off().c_str()); ASSERT_TRUE(off_element); - live_region = LiveRegion::GetLiveRegionForElement(off_element); + live_region = LiveRegion::GetLiveRegionForNode(off_element); EXPECT_FALSE(live_region); // aria-live=<invalid token> scoped_refptr<dom::Element> invalid_element = CreateLiveRegion("banana"); ASSERT_TRUE(invalid_element); - live_region = LiveRegion::GetLiveRegionForElement(invalid_element); + live_region = LiveRegion::GetLiveRegionForNode(invalid_element); EXPECT_FALSE(live_region); } @@ -127,9 +125,9 @@ CreateLiveRegion(base::Tokens::polite().c_str()); ASSERT_TRUE(live_region_element); - // GetLiveRegionForElement with the live region root. + // GetLiveRegionForNode with the live region root. scoped_ptr<LiveRegion> live_region = - LiveRegion::GetLiveRegionForElement(live_region_element); + LiveRegion::GetLiveRegionForNode(live_region_element); ASSERT_TRUE(live_region); // Default is that additions and text are relevant. EXPECT_TRUE( @@ -141,7 +139,7 @@ // Only removals are relevant. live_region_element->SetAttribute(base::Tokens::aria_relevant().c_str(), "removals"); - live_region = LiveRegion::GetLiveRegionForElement(live_region_element); + live_region = LiveRegion::GetLiveRegionForNode(live_region_element); ASSERT_TRUE(live_region); EXPECT_FALSE( live_region->IsMutationRelevant(LiveRegion::kMutationTypeAddition)); @@ -152,7 +150,7 @@ // Removals and additions are relevant. live_region_element->SetAttribute(base::Tokens::aria_relevant().c_str(), "removals additions"); - live_region = LiveRegion::GetLiveRegionForElement(live_region_element); + live_region = LiveRegion::GetLiveRegionForNode(live_region_element); ASSERT_TRUE(live_region); EXPECT_TRUE( live_region->IsMutationRelevant(LiveRegion::kMutationTypeAddition)); @@ -163,7 +161,7 @@ // An invalid token. live_region_element->SetAttribute(base::Tokens::aria_relevant().c_str(), "text dog additions"); - live_region = LiveRegion::GetLiveRegionForElement(live_region_element); + live_region = LiveRegion::GetLiveRegionForNode(live_region_element); ASSERT_TRUE(live_region); EXPECT_TRUE( live_region->IsMutationRelevant(LiveRegion::kMutationTypeAddition)); @@ -174,7 +172,7 @@ // "all" token. live_region_element->SetAttribute(base::Tokens::aria_relevant().c_str(), "all"); - live_region = LiveRegion::GetLiveRegionForElement(live_region_element); + live_region = LiveRegion::GetLiveRegionForNode(live_region_element); ASSERT_TRUE(live_region); EXPECT_TRUE( live_region->IsMutationRelevant(LiveRegion::kMutationTypeAddition)); @@ -191,21 +189,21 @@ ASSERT_TRUE(live_region_element); // Default is non-atomic. - live_region = LiveRegion::GetLiveRegionForElement(live_region_element); + live_region = LiveRegion::GetLiveRegionForNode(live_region_element); ASSERT_TRUE(live_region); EXPECT_FALSE(live_region->IsAtomic(live_region_element)); // aria-atomic=true live_region_element->SetAttribute(base::Tokens::aria_atomic().c_str(), "true"); - live_region = LiveRegion::GetLiveRegionForElement(live_region_element); + live_region = LiveRegion::GetLiveRegionForNode(live_region_element); ASSERT_TRUE(live_region); EXPECT_TRUE(live_region->IsAtomic(live_region_element)); // aria-atomic=false live_region_element->SetAttribute(base::Tokens::aria_atomic().c_str(), "false"); - live_region = LiveRegion::GetLiveRegionForElement(live_region_element); + live_region = LiveRegion::GetLiveRegionForNode(live_region_element); ASSERT_TRUE(live_region); EXPECT_FALSE(live_region->IsAtomic(live_region_element)); @@ -214,7 +212,7 @@ "true"); scoped_refptr<dom::Element> child = document()->CreateElement("div"); live_region_element->AppendChild(child); - live_region = LiveRegion::GetLiveRegionForElement(live_region_element); + live_region = LiveRegion::GetLiveRegionForNode(live_region_element); ASSERT_TRUE(live_region); EXPECT_TRUE(live_region->IsAtomic(child)); EXPECT_TRUE(live_region->IsAtomic(live_region_element)); @@ -223,7 +221,7 @@ live_region_element->SetAttribute(base::Tokens::aria_atomic().c_str(), "true"); child->SetAttribute(base::Tokens::aria_atomic().c_str(), "false"); - live_region = LiveRegion::GetLiveRegionForElement(live_region_element); + live_region = LiveRegion::GetLiveRegionForNode(live_region_element); ASSERT_TRUE(live_region); EXPECT_FALSE(live_region->IsAtomic(child)); EXPECT_TRUE(live_region->IsAtomic(live_region_element));
diff --git a/src/cobalt/accessibility/internal/text_alternative_helper.cc b/src/cobalt/accessibility/internal/text_alternative_helper.cc index 53aaa8d..c69cabd 100644 --- a/src/cobalt/accessibility/internal/text_alternative_helper.cc +++ b/src/cobalt/accessibility/internal/text_alternative_helper.cc
@@ -1,18 +1,16 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #include "cobalt/accessibility/internal/text_alternative_helper.h" @@ -81,8 +79,26 @@ } // namespace void TextAlternativeHelper::AppendTextAlternative( - const scoped_refptr<dom::Element>& element) { - DCHECK(element); + const scoped_refptr<dom::Node>& node) { + DCHECK(node); + // https://www.w3.org/TR/2014/REC-wai-aria-implementation-20140320/#mapping_additional_nd_te + // 5.6.1.3. Text Alternative Computation + + if (node->IsText()) { + // Rule 3D + // Get the contents of the text node. + if (node->text_content()) { + AppendTextIfNonEmpty(*node->text_content()); + } + return; + } + + scoped_refptr<dom::Element> element = node->AsElement(); + if (!element) { + // Since this is neither a Text or Element, ignore it. + return; + } + if (visited_element_ids_.find(element->id()) != visited_element_ids_.end()) { DLOG(INFO) << "Skipping element to prevent reference loop: " << element->id(); @@ -91,9 +107,6 @@ ScopedIdSetMember scoped_id_set_member(&visited_element_ids_, element->id()); - // https://www.w3.org/TR/2014/REC-wai-aria-implementation-20140320/#mapping_additional_nd_te - // 5.6.1.3. Text Alternative Computation - // Rule 1 // Skip hidden elements unless the author specifies to use them via an // aria-labelledby or aria-describedby being used in the current computation. @@ -165,15 +178,7 @@ scoped_refptr<dom::NodeList> children = element->child_nodes(); for (int i = 0; i < children->length(); ++i) { scoped_refptr<dom::Node> child = children->Item(i); - if (child->IsElement()) { - AppendTextAlternative(child->AsElement()); - } else if (child->IsText()) { - // Rule 3D - // Get the contents of the text node. - if (child->text_content()) { - AppendTextIfNonEmpty(*child->text_content()); - } - } + AppendTextAlternative(child); } }
diff --git a/src/cobalt/accessibility/internal/text_alternative_helper.h b/src/cobalt/accessibility/internal/text_alternative_helper.h index 8b935a4..721a589 100644 --- a/src/cobalt/accessibility/internal/text_alternative_helper.h +++ b/src/cobalt/accessibility/internal/text_alternative_helper.h
@@ -1,18 +1,16 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #ifndef COBALT_ACCESSIBILITY_INTERNAL_TEXT_ALTERNATIVE_HELPER_H_ #define COBALT_ACCESSIBILITY_INTERNAL_TEXT_ALTERNATIVE_HELPER_H_ @@ -34,7 +32,7 @@ class TextAlternativeHelper { public: TextAlternativeHelper() : in_labelled_by_(false) {} - void AppendTextAlternative(const scoped_refptr<dom::Element>& element); + void AppendTextAlternative(const scoped_refptr<dom::Node>& node); // Return the accumulated alternatives joined by a single space character. std::string GetTextAlternative();
diff --git a/src/cobalt/accessibility/internal/text_alternative_helper_test.cc b/src/cobalt/accessibility/internal/text_alternative_helper_test.cc index 1686df8..5ce980a 100644 --- a/src/cobalt/accessibility/internal/text_alternative_helper_test.cc +++ b/src/cobalt/accessibility/internal/text_alternative_helper_test.cc
@@ -1,18 +1,16 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h"
diff --git a/src/cobalt/accessibility/screen_reader.cc b/src/cobalt/accessibility/screen_reader.cc new file mode 100644 index 0000000..db4b5e5 --- /dev/null +++ b/src/cobalt/accessibility/screen_reader.cc
@@ -0,0 +1,157 @@ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "cobalt/accessibility/screen_reader.h" + +#include <string> + +#include "base/stringprintf.h" +#include "cobalt/accessibility/internal/live_region.h" +#include "cobalt/accessibility/text_alternative.h" +#include "cobalt/dom/element.h" +#include "cobalt/dom/html_body_element.h" +#include "cobalt/dom/node_list.h" + +namespace cobalt { +namespace accessibility { +namespace { +// When text is removed from a live region, add the word "Removed" to indicate +// that the text has been removed. +// TODO: Support other languages. +const char kRemovedFormatString[] = "Removed. %s"; +} + +ScreenReader::ScreenReader(dom::Document* document, TTSEngine* tts_engine, + dom::MutationObserverTaskManager* task_manager) + : document_(document), tts_engine_(tts_engine) { + document_->AddObserver(this); + live_region_observer_ = new dom::MutationObserver( + base::Bind(&ScreenReader::MutationObserverCallback, + base::Unretained(this)), + task_manager); +} + +ScreenReader::~ScreenReader() { + live_region_observer_->Disconnect(); + document_->RemoveObserver(this); +} + +void ScreenReader::OnLoad() { + dom::MutationObserverInit init; + init.set_subtree(true); + // Track character data and node addition/removal for live regions. + init.set_character_data(true); + init.set_child_list(true); + + live_region_observer_->Observe(document_->body(), init); +} + +void ScreenReader::OnFocusChanged() { + // TODO: Only utter text if text-to-speech is enabled. + scoped_refptr<dom::Element> element = document_->active_element(); + if (element) { + std::string text_alternative = ComputeTextAlternative(element); + tts_engine_->SpeakNow(text_alternative); + } +} + +// MutationObserver callback for tracking the creationg and destruction of +// live regions. +void ScreenReader::MutationObserverCallback( + const MutationRecordSequence& sequence, + const scoped_refptr<dom::MutationObserver>& observer) { + // TODO: Only check live regions if text-to-speech is enabled. + DCHECK_EQ(observer, live_region_observer_); + for (size_t i = 0; i < sequence.size(); ++i) { + scoped_refptr<dom::MutationRecord> record = sequence.at(i); + + // Check if the target node is part of a live region. + scoped_ptr<internal::LiveRegion> live_region = + internal::LiveRegion::GetLiveRegionForNode(record->target()); + if (!live_region) { + continue; + } + + const char* format_string = NULL; + // Get a list of changed nodes, based on the type of change this was and + // whether or not the live region cares about this type of change. + scoped_refptr<dom::NodeList> changed_nodes; + if (record->type() == base::Tokens::characterData() && + live_region->IsMutationRelevant( + internal::LiveRegion::kMutationTypeText)) { + changed_nodes = new dom::NodeList(); + changed_nodes->AppendNode(record->target()); + } else if (record->type() == base::Tokens::childList()) { + if (record->added_nodes() && + live_region->IsMutationRelevant( + internal::LiveRegion::kMutationTypeAddition)) { + changed_nodes = record->added_nodes(); + } + if (record->removed_nodes() && + live_region->IsMutationRelevant( + internal::LiveRegion::kMutationTypeRemoval)) { + changed_nodes = record->removed_nodes(); + format_string = kRemovedFormatString; + } + } + // If we don't have changed nodes, that means that the change was not + // relevant to this live region. + if (!changed_nodes || (changed_nodes->length() <= 0)) { + continue; + } + + // Check if any of the changed nodes should update the live region + // atomically. + bool is_atomic = false; + for (size_t i = 0; i < changed_nodes->length(); ++i) { + if (live_region->IsAtomic(changed_nodes->Item(i))) { + is_atomic = true; + break; + } + } + + std::string text_alternative; + if (is_atomic) { + // If the live region updates atomically, then ignore changed_nodes + // and just get the text alternative from the entire region. + text_alternative = ComputeTextAlternative(live_region->root()); + } else { + // Otherwise append all the text alternatives for each node. + for (size_t i = 0; i < changed_nodes->length(); ++i) { + text_alternative += ComputeTextAlternative(changed_nodes->Item(i)); + } + } + + // If we still don't have a text_alternative to speak, continue to the next + // mutation. + if (text_alternative.empty()) { + continue; + } + + // Provide additional context through a format string, if necessary. + if (format_string) { + text_alternative = StringPrintf(format_string, text_alternative.c_str()); + } + + // Utter the text according to whether this live region is assertive or not. + if (live_region->IsAssertive()) { + tts_engine_->SpeakNow(text_alternative); + } else { + tts_engine_->Speak(text_alternative); + } + } +} + +} // namespace accessibility +} // namespace cobalt
diff --git a/src/cobalt/accessibility/screen_reader.h b/src/cobalt/accessibility/screen_reader.h new file mode 100644 index 0000000..7f740ad --- /dev/null +++ b/src/cobalt/accessibility/screen_reader.h
@@ -0,0 +1,62 @@ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef COBALT_ACCESSIBILITY_SCREEN_READER_H_ +#define COBALT_ACCESSIBILITY_SCREEN_READER_H_ + +#include "base/memory/scoped_ptr.h" +#include "base/memory/scoped_vector.h" +#include "cobalt/accessibility/tts_engine.h" +#include "cobalt/dom/document.h" +#include "cobalt/dom/mutation_observer.h" +#include "cobalt/dom/mutation_observer_task_manager.h" + +namespace cobalt { +namespace accessibility { +// ScreenReader tracks changes in the state of the Document and provides speech +// utterances to a TTSEngine. The main use cases covered are when the document's +// focused element changes, usually in response to user input, or if there is +// an asynchronous change to "live region" that should be communicated to the +// user. +class ScreenReader : public dom::DocumentObserver { + public: + ScreenReader(dom::Document* document, TTSEngine* tts_engine, + dom::MutationObserverTaskManager* task_manager); + + protected: + ~ScreenReader(); + // dom::DocumentObserver overrides. + void OnLoad() OVERRIDE; + void OnMutation() OVERRIDE {} + void OnFocusChanged() OVERRIDE; + + private: + typedef script::Sequence<scoped_refptr<dom::MutationRecord> > + MutationRecordSequence; + // MutationObserver callback for tracking live regions. + void MutationObserverCallback( + const MutationRecordSequence& sequence, + const scoped_refptr<dom::MutationObserver>& observer); + + dom::Document* document_; + TTSEngine* tts_engine_; + scoped_refptr<dom::MutationObserver> live_region_observer_; + + friend class scoped_ptr<ScreenReader>; + DISALLOW_COPY_AND_ASSIGN(ScreenReader); +}; +} // namespace accessibility +} // namespace cobalt + +#endif // COBALT_ACCESSIBILITY_SCREEN_READER_H_
diff --git a/src/cobalt/accessibility/screen_reader_tests.cc b/src/cobalt/accessibility/screen_reader_tests.cc new file mode 100644 index 0000000..95a37eb --- /dev/null +++ b/src/cobalt/accessibility/screen_reader_tests.cc
@@ -0,0 +1,157 @@ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include <string> +#include <vector> + +#include "base/base_paths.h" +#include "base/file_path.h" +#include "base/file_util.h" +#include "base/memory/ref_counted.h" +#include "base/memory/scoped_ptr.h" +#include "base/path_service.h" +#include "cobalt/accessibility/text_alternative.h" +#include "cobalt/accessibility/tts_engine.h" +#include "cobalt/browser/web_module.h" +#include "cobalt/dom/element.h" +#include "cobalt/test/document_loader.h" +#include "testing/gmock/include/gmock/gmock.h" +#include "testing/gtest/include/gtest/gtest.h" + +using ::testing::_; + +namespace cobalt { +namespace accessibility { +namespace { +struct TestInfo { + TestInfo(const std::string& html_file_name, + const std::string& expected_result) + : html_file_name(html_file_name), expected_result(expected_result) {} + std::string html_file_name; + std::string expected_result; +}; + +// Enumerate the *.html files in the accessibility_test directory and build +// a list of input .html files and expected results. +std::vector<TestInfo> EnumerateTests(const std::string& subdir) { + std::vector<TestInfo> infos; + FilePath root_directory; + PathService::Get(base::DIR_SOURCE_ROOT, &root_directory); + root_directory = root_directory.Append("cobalt") + .Append("accessibility") + .Append("testdata") + .Append(subdir); + file_util::FileEnumerator enumerator(root_directory, false, + file_util::FileEnumerator::FILES); + for (FilePath html_file = enumerator.Next(); !html_file.empty(); + html_file = enumerator.Next()) { + if (html_file.Extension() == ".html") { + FilePath expected_results_file = html_file.ReplaceExtension(".expected"); + std::string results; + if (!file_util::ReadFileToString(expected_results_file, &results)) { + DLOG(WARNING) << "Failed to read results from file: " + << expected_results_file.value(); + continue; + } + TrimWhitespaceASCII(results, TRIM_ALL, &results); + infos.push_back(TestInfo(html_file.BaseName().value(), results)); + } + } + return infos; +} + +class MockTTSEngine : public TTSEngine { + public: + MOCK_METHOD1(Speak, void(const std::string&)); + MOCK_METHOD1(SpeakNow, void(const std::string&)); +}; + +class TextAlternativeTest : public ::testing::TestWithParam<TestInfo> { + protected: + test::DocumentLoader document_loader_; +}; + +class LiveRegionMutationTest : public ::testing::TestWithParam<TestInfo> { + public: + LiveRegionMutationTest() : quit_event_(true, false) {} + void OnError(const GURL&, const std::string& error) { + DLOG(ERROR) << error; + Quit(); + } + void Quit() { quit_event_.Signal(); } + static void OnRenderTreeProducedStub( + const browser::WebModule::LayoutResults&) {} + + protected: + MockTTSEngine tts_engine_; + base::WaitableEvent quit_event_; +}; +} // namespace + +TEST_P(TextAlternativeTest, TextAlternativeTest) { + GURL url( + std::string("file:///cobalt/accessibility/testdata/text_alternative/" + + GetParam().html_file_name)); + document_loader_.Load(url); + ASSERT_TRUE(document_loader_.document()); + scoped_refptr<dom::Element> element = + document_loader_.document()->GetElementById("element_to_test"); + ASSERT_TRUE(element); + EXPECT_EQ(GetParam().expected_result, ComputeTextAlternative(element)); +} + +TEST_P(LiveRegionMutationTest, LiveRegionMutationTest) { + GURL url(std::string("file:///cobalt/accessibility/testdata/live_region/" + + GetParam().html_file_name)); + const math::Size kDefaultViewportSize(1280, 720); + const float kRefreshRate = 60.0f; + + network::NetworkModule network_module((network::NetworkModule::Options())); + render_tree::ResourceProviderStub resource_provider; + + // Use test runner mode to allow the content itself to dictate when it is + // ready for layout should be performed. See cobalt/dom/test_runner.h. + browser::WebModule::Options web_module_options; + web_module_options.tts_engine = &tts_engine_; + + // Set expected result from mutation. + std::string expected_speech = GetParam().expected_result; + if (expected_speech.empty()) { + EXPECT_CALL(tts_engine_, Speak(_)).Times(0); + } else { + EXPECT_CALL(tts_engine_, Speak(expected_speech)); + } + + // Create the webmodule and let it run. + DLOG(INFO) << url.spec(); + browser::WebModule web_module( + url, base::Bind(&LiveRegionMutationTest::OnRenderTreeProducedStub), + base::Bind(&LiveRegionMutationTest::OnError, base::Unretained(this)), + base::Bind(&LiveRegionMutationTest::Quit, base::Unretained(this)), + NULL /* media_module */, &network_module, kDefaultViewportSize, + &resource_provider, NULL /* system_window */, kRefreshRate, + web_module_options); + + // Wait for the test to quit. + quit_event_.Wait(); +} + +INSTANTIATE_TEST_CASE_P( + TextAlternativeTest, TextAlternativeTest, + ::testing::ValuesIn(EnumerateTests("text_alternative"))); + +INSTANTIATE_TEST_CASE_P(LiveRegionMutationTest, LiveRegionMutationTest, + ::testing::ValuesIn(EnumerateTests("live_region"))); +} // namespace accessibility +} // namespace cobalt
diff --git a/src/cobalt/accessibility/starboard_tts_engine.cc b/src/cobalt/accessibility/starboard_tts_engine.cc index 09d717d..d2788fc 100644 --- a/src/cobalt/accessibility/starboard_tts_engine.cc +++ b/src/cobalt/accessibility/starboard_tts_engine.cc
@@ -1,18 +1,16 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #include "cobalt/accessibility/starboard_tts_engine.h"
diff --git a/src/cobalt/accessibility/starboard_tts_engine.h b/src/cobalt/accessibility/starboard_tts_engine.h index a559cf8..140df21 100644 --- a/src/cobalt/accessibility/starboard_tts_engine.h +++ b/src/cobalt/accessibility/starboard_tts_engine.h
@@ -1,24 +1,23 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #ifndef COBALT_ACCESSIBILITY_STARBOARD_TTS_ENGINE_H_ #define COBALT_ACCESSIBILITY_STARBOARD_TTS_ENGINE_H_ #include <string> +#include "base/compiler_specific.h" #include "cobalt/accessibility/tts_engine.h" namespace cobalt {
diff --git a/src/cobalt/accessibility/testdata/live_region/add-child.expected b/src/cobalt/accessibility/testdata/live_region/add-child.expected new file mode 100644 index 0000000..4706dc8 --- /dev/null +++ b/src/cobalt/accessibility/testdata/live_region/add-child.expected
@@ -0,0 +1 @@ +New child text contents
diff --git a/src/cobalt/accessibility/testdata/live_region/add-child.html b/src/cobalt/accessibility/testdata/live_region/add-child.html new file mode 100644 index 0000000..c22f5d2 --- /dev/null +++ b/src/cobalt/accessibility/testdata/live_region/add-child.html
@@ -0,0 +1,19 @@ +<html> +<head> +<script> +var doMutation = function() { + var region = document.getElementById("to_mutate"); + var new_child = document.createElement("div"); + new_child.appendChild(document.createTextNode("New child text contents")); + region.appendChild(new_child); + window.setTimeout(function() { window.close(); } ); +} +window.addEventListener("load", doMutation); +</script> +</head> +<body> +<div id="to_mutate" aria-live="polite" aria-relevant="additions" aria-atomic="false"> + Original contents. +</div> +</body> +</html>
diff --git a/src/cobalt/accessibility/testdata/live_region/atomic-update.expected b/src/cobalt/accessibility/testdata/live_region/atomic-update.expected new file mode 100644 index 0000000..c4395db --- /dev/null +++ b/src/cobalt/accessibility/testdata/live_region/atomic-update.expected
@@ -0,0 +1 @@ +Original contents. New child text contents
diff --git a/src/cobalt/accessibility/testdata/live_region/atomic-update.html b/src/cobalt/accessibility/testdata/live_region/atomic-update.html new file mode 100644 index 0000000..7e9a9cc --- /dev/null +++ b/src/cobalt/accessibility/testdata/live_region/atomic-update.html
@@ -0,0 +1,19 @@ +<html> +<head> +<script> +var doMutation = function() { + var region = document.getElementById("to_mutate"); + var new_child = document.createElement("div"); + new_child.appendChild(document.createTextNode("New child text contents")); + region.appendChild(new_child); + window.setTimeout(function() { window.close(); } ); +} +window.addEventListener("load", doMutation); +</script> +</head> +<body> +<div id="to_mutate" aria-live="polite" aria-relevant="additions" aria-atomic="true"> + Original contents. +</div> +</body> +</html>
diff --git a/src/cobalt/accessibility/testdata/live_region/mutate-text-contents.expected b/src/cobalt/accessibility/testdata/live_region/mutate-text-contents.expected new file mode 100644 index 0000000..8a1cd73 --- /dev/null +++ b/src/cobalt/accessibility/testdata/live_region/mutate-text-contents.expected
@@ -0,0 +1 @@ +New text contents
diff --git a/src/cobalt/accessibility/testdata/live_region/mutate-text-contents.html b/src/cobalt/accessibility/testdata/live_region/mutate-text-contents.html new file mode 100644 index 0000000..53e5afe --- /dev/null +++ b/src/cobalt/accessibility/testdata/live_region/mutate-text-contents.html
@@ -0,0 +1,18 @@ +<html> +<head> +<script> +var doMutation = function() { + var region = document.getElementById("to_mutate"); + region.firstChild.textContent = "New text contents"; + + window.setTimeout(function() { window.close(); } ); +} +window.addEventListener("load", doMutation); +</script> +</head> +<body> +<div id="to_mutate" aria-live="polite" aria-relevant="text" aria-atomic="false"> + Original contents. +</div> +</body> +</html>
diff --git a/src/third_party/protobuf-3/python/google/protobuf/internal/__init__.py b/src/cobalt/accessibility/testdata/live_region/non-relevant-mutations.expected old mode 100755 new mode 100644 similarity index 100% rename from src/third_party/protobuf-3/python/google/protobuf/internal/__init__.py rename to src/cobalt/accessibility/testdata/live_region/non-relevant-mutations.expected
diff --git a/src/cobalt/accessibility/testdata/live_region/non-relevant-mutations.html b/src/cobalt/accessibility/testdata/live_region/non-relevant-mutations.html new file mode 100644 index 0000000..f315236 --- /dev/null +++ b/src/cobalt/accessibility/testdata/live_region/non-relevant-mutations.html
@@ -0,0 +1,39 @@ +<html> +<head> +<script> +var doMutation = function() { + var text_only_region = document.getElementById("text_only"); + var to_remove = document.getElementById("text_only_to_remove"); + text_only_region.removeChild(to_remove); + text_only_region.appendChild(document.createTextNode("Irrelevant")) + + var additions_only_region = document.getElementById("additions_only"); + to_remove = document.getElementById("additions_only_to_remove"); + additions_only_region.removeChild(to_remove); + + var to_mutate = document.getElementById("additions_only_to_mutate"); + to_mutate.firstChild.textContent = "New Content"; + + window.setTimeout(function() { window.close(); } ); +} +window.addEventListener("load", doMutation); +</script> +</head> +<body> +<div id="text_only" aria-live="polite" aria-relevant="text" aria-atomic="false"> + Some contents + <div id="text_only_to_remove"> + Contents to be removed + </div> +<div> +<div id="additions_only" aria-live="polite" aria-relevant="additions" aria-atomic="false"> + Some contents + <div id="additions_only_to_remove"> + Contents to be removed + </div> + <div id="additions_only_to_mutate"> + Old text contents + </div> +<div> +</body> +</html>
diff --git a/src/cobalt/accessibility/testdata/live_region/remove-child.expected b/src/cobalt/accessibility/testdata/live_region/remove-child.expected new file mode 100644 index 0000000..c08dfdb --- /dev/null +++ b/src/cobalt/accessibility/testdata/live_region/remove-child.expected
@@ -0,0 +1 @@ +Removed. Contents to be removed
diff --git a/src/cobalt/accessibility/testdata/live_region/remove-child.html b/src/cobalt/accessibility/testdata/live_region/remove-child.html new file mode 100644 index 0000000..40727ec --- /dev/null +++ b/src/cobalt/accessibility/testdata/live_region/remove-child.html
@@ -0,0 +1,21 @@ +<html> +<head> +<script> +var doMutation = function() { + var region = document.getElementById("to_mutate"); + var to_remove = document.getElementById("to_remove"); + region.removeChild(to_remove); + window.setTimeout(function() { window.close(); } ); +} +window.addEventListener("load", doMutation); +</script> +</head> +<body> +<div id="to_mutate" aria-live="polite" aria-relevant="removals" aria-atomic="false"> + Some contents + <div id="to_remove"> + Contents to be removed + </div> +</div> +</body> +</html>
diff --git a/src/cobalt/accessibility/testdata/hidden-by-parent.expected b/src/cobalt/accessibility/testdata/text_alternative/hidden-by-parent.expected similarity index 100% rename from src/cobalt/accessibility/testdata/hidden-by-parent.expected rename to src/cobalt/accessibility/testdata/text_alternative/hidden-by-parent.expected
diff --git a/src/cobalt/accessibility/testdata/hidden-by-parent.html b/src/cobalt/accessibility/testdata/text_alternative/hidden-by-parent.html similarity index 100% rename from src/cobalt/accessibility/testdata/hidden-by-parent.html rename to src/cobalt/accessibility/testdata/text_alternative/hidden-by-parent.html
diff --git a/src/cobalt/accessibility/testdata/hidden-labelledby.expected b/src/cobalt/accessibility/testdata/text_alternative/hidden-labelledby.expected similarity index 100% rename from src/cobalt/accessibility/testdata/hidden-labelledby.expected rename to src/cobalt/accessibility/testdata/text_alternative/hidden-labelledby.expected
diff --git a/src/cobalt/accessibility/testdata/hidden-labelledby.html b/src/cobalt/accessibility/testdata/text_alternative/hidden-labelledby.html similarity index 100% rename from src/cobalt/accessibility/testdata/hidden-labelledby.html rename to src/cobalt/accessibility/testdata/text_alternative/hidden-labelledby.html
diff --git a/src/cobalt/accessibility/testdata/self-reference-labelledby.expected b/src/cobalt/accessibility/testdata/text_alternative/self-reference-labelledby.expected similarity index 100% rename from src/cobalt/accessibility/testdata/self-reference-labelledby.expected rename to src/cobalt/accessibility/testdata/text_alternative/self-reference-labelledby.expected
diff --git a/src/cobalt/accessibility/testdata/self-reference-labelledby.html b/src/cobalt/accessibility/testdata/text_alternative/self-reference-labelledby.html similarity index 100% rename from src/cobalt/accessibility/testdata/self-reference-labelledby.html rename to src/cobalt/accessibility/testdata/text_alternative/self-reference-labelledby.html
diff --git a/src/cobalt/accessibility/testdata/text-content.expected b/src/cobalt/accessibility/testdata/text_alternative/text-content.expected similarity index 100% rename from src/cobalt/accessibility/testdata/text-content.expected rename to src/cobalt/accessibility/testdata/text_alternative/text-content.expected
diff --git a/src/cobalt/accessibility/testdata/text-content.html b/src/cobalt/accessibility/testdata/text_alternative/text-content.html similarity index 100% rename from src/cobalt/accessibility/testdata/text-content.html rename to src/cobalt/accessibility/testdata/text_alternative/text-content.html
diff --git a/src/cobalt/accessibility/text_alternative.cc b/src/cobalt/accessibility/text_alternative.cc index 91c38dc..bca2187 100644 --- a/src/cobalt/accessibility/text_alternative.cc +++ b/src/cobalt/accessibility/text_alternative.cc
@@ -1,34 +1,34 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #include "cobalt/accessibility/text_alternative.h" #include "cobalt/accessibility/internal/text_alternative_helper.h" #include "cobalt/dom/document.h" +#include "cobalt/dom/element.h" +#include "cobalt/dom/text.h" namespace cobalt { namespace accessibility { -std::string ComputeTextAlternative(const scoped_refptr<dom::Element>& element) { +std::string ComputeTextAlternative(const scoped_refptr<dom::Node>& node) { // Update the computed styles first to ensure that any CSS that would modify // the text contents has been applied (such as :before and :after). - DCHECK(element->node_document()); - element->node_document()->UpdateComputedStyles(); - + if (node->node_document()) { + node->node_document()->UpdateComputedStyles(); + } internal::TextAlternativeHelper helper; - helper.AppendTextAlternative(element); + helper.AppendTextAlternative(node); return helper.GetTextAlternative(); } } // namespace accessibility
diff --git a/src/cobalt/accessibility/text_alternative.h b/src/cobalt/accessibility/text_alternative.h index ea4be8d..042908e 100644 --- a/src/cobalt/accessibility/text_alternative.h +++ b/src/cobalt/accessibility/text_alternative.h
@@ -1,32 +1,30 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #ifndef COBALT_ACCESSIBILITY_TEXT_ALTERNATIVE_H_ #define COBALT_ACCESSIBILITY_TEXT_ALTERNATIVE_H_ #include <string> -#include "cobalt/dom/element.h" +#include "cobalt/dom/node.h" namespace cobalt { namespace accessibility { -// Compute the Text Alternative for the element per the wai-aria specification: +// Compute the Text Alternative for the node per the wai-aria specification: // https://www.w3.org/TR/2014/REC-wai-aria-implementation-20140320/#mapping_additional_nd_te -std::string ComputeTextAlternative(const scoped_refptr<dom::Element>& element); +std::string ComputeTextAlternative(const scoped_refptr<dom::Node>& node); } // namespace accessibility } // namespace cobalt
diff --git a/src/cobalt/accessibility/text_alternative_tests.cc b/src/cobalt/accessibility/text_alternative_tests.cc deleted file mode 100644 index 5b2cb36..0000000 --- a/src/cobalt/accessibility/text_alternative_tests.cc +++ /dev/null
@@ -1,87 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include <string> -#include <vector> - -#include "base/base_paths.h" -#include "base/file_path.h" -#include "base/file_util.h" -#include "base/memory/ref_counted.h" -#include "base/memory/scoped_ptr.h" -#include "base/path_service.h" -#include "cobalt/accessibility/text_alternative.h" -#include "cobalt/test/document_loader.h" -#include "testing/gmock/include/gmock/gmock.h" -#include "testing/gtest/include/gtest/gtest.h" - -namespace cobalt { -namespace accessibility { -namespace { -struct TestInfo { - TestInfo(const std::string& html_file_name, - const std::string& expected_result) - : html_file_name(html_file_name), expected_result(expected_result) {} - std::string html_file_name; - std::string expected_result; -}; - -// Enumerate the *.html files in the accessibility_test directory and build -// a list of input .html files and expected results. -std::vector<TestInfo> EnumerateTests() { - std::vector<TestInfo> infos; - FilePath root_directory; - PathService::Get(base::DIR_SOURCE_ROOT, &root_directory); - root_directory = root_directory.Append("cobalt").Append("accessibility_test"); - file_util::FileEnumerator enumerator(root_directory, false, - file_util::FileEnumerator::FILES); - for (FilePath html_file = enumerator.Next(); !html_file.empty(); - html_file = enumerator.Next()) { - if (html_file.Extension() == ".html") { - FilePath expected_results_file = html_file.ReplaceExtension(".expected"); - std::string results; - if (!file_util::ReadFileToString(expected_results_file, &results)) { - DLOG(WARNING) << "Failed to read results from file: " - << expected_results_file.value(); - continue; - } - TrimWhitespaceASCII(results, TRIM_ALL, &results); - infos.push_back(TestInfo(html_file.BaseName().value(), results)); - } - } - return infos; -} - -class TextAlternativeTest : public ::testing::TestWithParam<TestInfo> { - protected: - test::DocumentLoader document_loader_; -}; -} // namespace - -TEST_P(TextAlternativeTest, TextAlternativeTest) { - GURL url(std::string("file:///cobalt/accessibility_test/" + - GetParam().html_file_name)); - document_loader_.Load(url); - ASSERT_TRUE(document_loader_.document()); - scoped_refptr<dom::Element> element = - document_loader_.document()->GetElementById("element_to_test"); - ASSERT_TRUE(element); - EXPECT_EQ(GetParam().expected_result, ComputeTextAlternative(element)); -} -INSTANTIATE_TEST_CASE_P(TextAlternativeTest, TextAlternativeTest, - ::testing::ValuesIn(EnumerateTests())); -} // namespace accessibility -} // namespace cobalt
diff --git a/src/cobalt/accessibility/tts_engine.h b/src/cobalt/accessibility/tts_engine.h index 1a9d141..f896330 100644 --- a/src/cobalt/accessibility/tts_engine.h +++ b/src/cobalt/accessibility/tts_engine.h
@@ -1,26 +1,22 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #ifndef COBALT_ACCESSIBILITY_TTS_ENGINE_H_ #define COBALT_ACCESSIBILITY_TTS_ENGINE_H_ #include <string> -#include "cobalt/dom/document.h" - namespace cobalt { namespace accessibility { // Interface for a TTS (text-to-speech) implementation.
diff --git a/src/cobalt/accessibility/tts_logger.h b/src/cobalt/accessibility/tts_logger.h index e48ac6c..9d9ea3a 100644 --- a/src/cobalt/accessibility/tts_logger.h +++ b/src/cobalt/accessibility/tts_logger.h
@@ -1,18 +1,16 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #ifndef COBALT_ACCESSIBILITY_TTS_LOGGER_H_ #define COBALT_ACCESSIBILITY_TTS_LOGGER_H_
diff --git a/src/cobalt/account/account_event.h b/src/cobalt/account/account_event.h index 37bcde8..629e5e5 100644 --- a/src/cobalt/account/account_event.h +++ b/src/cobalt/account/account_event.h
@@ -1,18 +1,16 @@ -/* - * Copyright 2015 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2015 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #ifndef COBALT_ACCOUNT_ACCOUNT_EVENT_H_ #define COBALT_ACCOUNT_ACCOUNT_EVENT_H_
diff --git a/src/cobalt/account/account_manager.h b/src/cobalt/account/account_manager.h index 3bddfea..6c5cd67 100644 --- a/src/cobalt/account/account_manager.h +++ b/src/cobalt/account/account_manager.h
@@ -1,18 +1,16 @@ -/* - * Copyright 2015 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2015 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #ifndef COBALT_ACCOUNT_ACCOUNT_MANAGER_H_ #define COBALT_ACCOUNT_ACCOUNT_MANAGER_H_
diff --git a/src/cobalt/account/account_manager_stub.cc b/src/cobalt/account/account_manager_stub.cc index 4634c8e..c1d182a 100644 --- a/src/cobalt/account/account_manager_stub.cc +++ b/src/cobalt/account/account_manager_stub.cc
@@ -1,18 +1,16 @@ -/* - * Copyright 2015 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2015 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #include "cobalt/account/account_manager_stub.h"
diff --git a/src/cobalt/account/account_manager_stub.h b/src/cobalt/account/account_manager_stub.h index ba1cdea..4955d12 100644 --- a/src/cobalt/account/account_manager_stub.h +++ b/src/cobalt/account/account_manager_stub.h
@@ -1,18 +1,16 @@ -/* - * Copyright 2015 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2015 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #ifndef COBALT_ACCOUNT_ACCOUNT_MANAGER_STUB_H_ #define COBALT_ACCOUNT_ACCOUNT_MANAGER_STUB_H_
diff --git a/src/cobalt/account/starboard/account_manager.cc b/src/cobalt/account/starboard/account_manager.cc index 3a546bb..292e568 100644 --- a/src/cobalt/account/starboard/account_manager.cc +++ b/src/cobalt/account/starboard/account_manager.cc
@@ -1,18 +1,16 @@ -/* - * Copyright 2016 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2016 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #include "cobalt/account/account_manager.h"
diff --git a/src/cobalt/account/win/account_manager.cc b/src/cobalt/account/win/account_manager.cc index 277a472..65225d3 100644 --- a/src/cobalt/account/win/account_manager.cc +++ b/src/cobalt/account/win/account_manager.cc
@@ -1,18 +1,16 @@ -/* - * Copyright 2015 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2015 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #include "cobalt/account/account_manager_stub.h"
diff --git a/src/cobalt/audio/AudioBuffer.idl b/src/cobalt/audio/AudioBuffer.idl deleted file mode 100644 index 8062932..0000000 --- a/src/cobalt/audio/AudioBuffer.idl +++ /dev/null
@@ -1,28 +0,0 @@ -/* - * Copyright 2015 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// https://www.w3.org/TR/webaudio/#AudioBuffer - -interface AudioBuffer { - readonly attribute float sampleRate; - readonly attribute long length; - - // in seconds - readonly attribute double duration; - readonly attribute long numberOfChannels; - - [RaisesException] Float32Array getChannelData(unsigned long channel); -};
diff --git a/src/cobalt/audio/AudioBufferSourceNode.idl b/src/cobalt/audio/AudioBufferSourceNode.idl deleted file mode 100644 index 890644f..0000000 --- a/src/cobalt/audio/AudioBufferSourceNode.idl +++ /dev/null
@@ -1,30 +0,0 @@ -/* - * Copyright 2015 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// https://www.w3.org/TR/webaudio/#AudioBufferSourceNode - -interface AudioBufferSourceNode : AudioNode { - attribute AudioBuffer? buffer; - - [RaisesException] void start(optional double when = 0, - optional double offset = 0, - optional double duration); - [RaisesException] void stop(optional double when = 0); - - attribute EventHandler onended; -}; - -typedef EventListener? EventHandler;
diff --git a/src/cobalt/audio/AudioContext.idl b/src/cobalt/audio/AudioContext.idl deleted file mode 100644 index 00a38e1..0000000 --- a/src/cobalt/audio/AudioContext.idl +++ /dev/null
@@ -1,34 +0,0 @@ -/* - * Copyright 2015 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// https://www.w3.org/TR/webaudio/#AudioContext-section - -[Constructor] -interface AudioContext : EventTarget { - readonly attribute AudioDestinationNode destination; - readonly attribute float sampleRate; - readonly attribute double currentTime; - - [CallWith=EnvironmentSettings] void decodeAudioData( - ArrayBuffer audioData, DecodeSuccessCallback successCallback, - optional DecodeErrorCallback errorCallback); - - // AudioNode creation - AudioBufferSourceNode createBufferSource(); -}; - -callback DecodeSuccessCallback = void(AudioBuffer decodedData); -callback DecodeErrorCallback = void();
diff --git a/src/cobalt/audio/AudioDestinationNode.idl b/src/cobalt/audio/AudioDestinationNode.idl deleted file mode 100644 index afcee3e..0000000 --- a/src/cobalt/audio/AudioDestinationNode.idl +++ /dev/null
@@ -1,21 +0,0 @@ -/* - * Copyright 2015 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// https://www.w3.org/TR/webaudio/#AudioDestinationNode - -interface AudioDestinationNode : AudioNode { - readonly attribute unsigned long maxChannelCount; -};
diff --git a/src/cobalt/audio/AudioNode.idl b/src/cobalt/audio/AudioNode.idl deleted file mode 100644 index 6e08c74..0000000 --- a/src/cobalt/audio/AudioNode.idl +++ /dev/null
@@ -1,44 +0,0 @@ -/* - * Copyright 2015 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// https://www.w3.org/TR/webaudio/#AudioNode-section - -enum ChannelCountMode { - "max", - "clamped-max", - "explicit" -}; - -enum ChannelInterpretation { - "speakers", - "discrete" -}; - -interface AudioNode : EventTarget { - [RaisesException] void connect(AudioNode destination, - optional unsigned long output = 0, - optional unsigned long input = 0); - [RaisesException] void disconnect(optional unsigned long output = 0); - - readonly attribute AudioContext context; - readonly attribute unsigned long numberOfInputs; - readonly attribute unsigned long numberOfOutputs; - - // Channel up-mixing and down-mixing rules for all inputs. - [RaisesException=Setter] attribute unsigned long channelCount; - attribute ChannelCountMode channelCountMode; - attribute ChannelInterpretation channelInterpretation; -};
diff --git a/src/cobalt/audio/async_audio_decoder.cc b/src/cobalt/audio/async_audio_decoder.cc index 2aa7a62..aac40c9 100644 --- a/src/cobalt/audio/async_audio_decoder.cc +++ b/src/cobalt/audio/async_audio_decoder.cc
@@ -1,18 +1,16 @@ -/* - * Copyright 2015 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2015 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #include "cobalt/audio/async_audio_decoder.h"
diff --git a/src/cobalt/audio/async_audio_decoder.h b/src/cobalt/audio/async_audio_decoder.h index 3827260..b82c0db 100644 --- a/src/cobalt/audio/async_audio_decoder.h +++ b/src/cobalt/audio/async_audio_decoder.h
@@ -1,18 +1,16 @@ -/* - * Copyright 2015 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2015 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #ifndef COBALT_AUDIO_ASYNC_AUDIO_DECODER_H_ #define COBALT_AUDIO_ASYNC_AUDIO_DECODER_H_
diff --git a/src/cobalt/audio/audio.gyp b/src/cobalt/audio/audio.gyp index 350a599..09fcbda 100644 --- a/src/cobalt/audio/audio.gyp +++ b/src/cobalt/audio/audio.gyp
@@ -58,8 +58,8 @@ 'audio_node_input_output_test.cc', ], 'dependencies': [ - '<(DEPTH)/base/base.gyp:run_all_unittests', '<(DEPTH)/cobalt/audio/audio.gyp:audio', + '<(DEPTH)/cobalt/test/test.gyp:run_all_unittests', '<(DEPTH)/testing/gmock.gyp:gmock', '<(DEPTH)/testing/gtest.gyp:gtest', ],
diff --git a/src/cobalt/audio/audio_buffer.cc b/src/cobalt/audio/audio_buffer.cc index a93eba2..38980c6 100644 --- a/src/cobalt/audio/audio_buffer.cc +++ b/src/cobalt/audio/audio_buffer.cc
@@ -1,18 +1,16 @@ -/* - * Copyright 2015 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2015 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #include "cobalt/audio/audio_buffer.h"
diff --git a/src/cobalt/audio/audio_buffer.h b/src/cobalt/audio/audio_buffer.h index c58fef5..0a9071c 100644 --- a/src/cobalt/audio/audio_buffer.h +++ b/src/cobalt/audio/audio_buffer.h
@@ -1,18 +1,16 @@ -/* - * Copyright 2015 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2015 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #ifndef COBALT_AUDIO_AUDIO_BUFFER_H_ #define COBALT_AUDIO_AUDIO_BUFFER_H_
diff --git a/src/cobalt/audio/audio_buffer.idl b/src/cobalt/audio/audio_buffer.idl new file mode 100644 index 0000000..53f9e09 --- /dev/null +++ b/src/cobalt/audio/audio_buffer.idl
@@ -0,0 +1,26 @@ +// Copyright 2015 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// https://www.w3.org/TR/webaudio/#AudioBuffer + +interface AudioBuffer { + readonly attribute float sampleRate; + readonly attribute long length; + + // in seconds + readonly attribute double duration; + readonly attribute long numberOfChannels; + + [RaisesException] Float32Array getChannelData(unsigned long channel); +};
diff --git a/src/cobalt/audio/audio_buffer_source_node.cc b/src/cobalt/audio/audio_buffer_source_node.cc index 222ab7a..e588651 100644 --- a/src/cobalt/audio/audio_buffer_source_node.cc +++ b/src/cobalt/audio/audio_buffer_source_node.cc
@@ -1,18 +1,16 @@ -/* - * Copyright 2015 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2015 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #include "cobalt/audio/audio_buffer_source_node.h"
diff --git a/src/cobalt/audio/audio_buffer_source_node.h b/src/cobalt/audio/audio_buffer_source_node.h index ce4f42f..137c95c 100644 --- a/src/cobalt/audio/audio_buffer_source_node.h +++ b/src/cobalt/audio/audio_buffer_source_node.h
@@ -1,18 +1,16 @@ -/* - * Copyright 2015 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2015 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #ifndef COBALT_AUDIO_AUDIO_BUFFER_SOURCE_NODE_H_ #define COBALT_AUDIO_AUDIO_BUFFER_SOURCE_NODE_H_ @@ -64,10 +62,10 @@ // dispatched to AudioBufferSourceNode node types. When the playback of the // buffer for an AudioBufferSourceNode is finished, an event of type Event // will be dispatched to the event handler. - const EventListenerScriptObject* onended() const { + const EventListenerScriptValue* onended() const { return GetAttributeEventListener(base::Tokens::ended()); } - void set_onended(const EventListenerScriptObject& event_listener) { + void set_onended(const EventListenerScriptValue& event_listener) { SetAttributeEventListener(base::Tokens::ended(), event_listener); }
diff --git a/src/cobalt/audio/audio_buffer_source_node.idl b/src/cobalt/audio/audio_buffer_source_node.idl new file mode 100644 index 0000000..60378fc --- /dev/null +++ b/src/cobalt/audio/audio_buffer_source_node.idl
@@ -0,0 +1,28 @@ +// Copyright 2015 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// https://www.w3.org/TR/webaudio/#AudioBufferSourceNode + +interface AudioBufferSourceNode : AudioNode { + attribute AudioBuffer? buffer; + + [RaisesException] void start(optional double when = 0, + optional double offset = 0, + optional double duration); + [RaisesException] void stop(optional double when = 0); + + attribute EventHandler onended; +}; + +typedef EventListener? EventHandler;
diff --git a/src/cobalt/audio/audio_context.cc b/src/cobalt/audio/audio_context.cc index 0962977..b0c2ddd 100644 --- a/src/cobalt/audio/audio_context.cc +++ b/src/cobalt/audio/audio_context.cc
@@ -1,18 +1,16 @@ -/* - * Copyright 2015 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2015 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #include "cobalt/audio/audio_context.h"
diff --git a/src/cobalt/audio/audio_context.h b/src/cobalt/audio/audio_context.h index 9b3ac6f..2fb310d 100644 --- a/src/cobalt/audio/audio_context.h +++ b/src/cobalt/audio/audio_context.h
@@ -1,18 +1,16 @@ -/* - * Copyright 2015 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2015 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #ifndef COBALT_AUDIO_AUDIO_CONTEXT_H_ #define COBALT_AUDIO_AUDIO_CONTEXT_H_ @@ -33,7 +31,7 @@ #include "cobalt/dom/event_target.h" #include "cobalt/script/callback_function.h" #include "cobalt/script/environment_settings.h" -#include "cobalt/script/script_object.h" +#include "cobalt/script/script_value.h" namespace cobalt { namespace audio { @@ -82,11 +80,11 @@ // The AudioBuffer is representing the decoded PCM audio data. typedef script::CallbackFunction<void( const scoped_refptr<AudioBuffer>& decoded_data)> DecodeSuccessCallback; - typedef script::ScriptObject<DecodeSuccessCallback> DecodeSuccessCallbackArg; + typedef script::ScriptValue<DecodeSuccessCallback> DecodeSuccessCallbackArg; typedef DecodeSuccessCallbackArg::Reference DecodeSuccessCallbackReference; typedef script::CallbackFunction<void()> DecodeErrorCallback; - typedef script::ScriptObject<DecodeErrorCallback> DecodeErrorCallbackArg; + typedef script::ScriptValue<DecodeErrorCallback> DecodeErrorCallbackArg; typedef DecodeErrorCallbackArg::Reference DecodeErrorCallbackReference; AudioContext();
diff --git a/src/cobalt/audio/audio_context.idl b/src/cobalt/audio/audio_context.idl new file mode 100644 index 0000000..ef3bf47 --- /dev/null +++ b/src/cobalt/audio/audio_context.idl
@@ -0,0 +1,32 @@ +// Copyright 2015 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// https://www.w3.org/TR/webaudio/#AudioContext-section + +[Constructor] +interface AudioContext : EventTarget { + readonly attribute AudioDestinationNode destination; + readonly attribute float sampleRate; + readonly attribute double currentTime; + + [CallWith=EnvironmentSettings] void decodeAudioData( + ArrayBuffer audioData, DecodeSuccessCallback successCallback, + optional DecodeErrorCallback errorCallback); + + // AudioNode creation + AudioBufferSourceNode createBufferSource(); +}; + +callback DecodeSuccessCallback = void(AudioBuffer decodedData); +callback DecodeErrorCallback = void();
diff --git a/src/cobalt/audio/audio_destination_node.cc b/src/cobalt/audio/audio_destination_node.cc index e0eda2b..78d414f 100644 --- a/src/cobalt/audio/audio_destination_node.cc +++ b/src/cobalt/audio/audio_destination_node.cc
@@ -1,18 +1,16 @@ -/* - * Copyright 2015 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2015 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #include "cobalt/audio/audio_destination_node.h"
diff --git a/src/cobalt/audio/audio_destination_node.h b/src/cobalt/audio/audio_destination_node.h index 50bfe7e..dfb3824 100644 --- a/src/cobalt/audio/audio_destination_node.h +++ b/src/cobalt/audio/audio_destination_node.h
@@ -1,18 +1,16 @@ -/* - * Copyright 2015 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2015 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #ifndef COBALT_AUDIO_AUDIO_DESTINATION_NODE_H_ #define COBALT_AUDIO_AUDIO_DESTINATION_NODE_H_
diff --git a/src/cobalt/audio/audio_destination_node.idl b/src/cobalt/audio/audio_destination_node.idl new file mode 100644 index 0000000..84cef00 --- /dev/null +++ b/src/cobalt/audio/audio_destination_node.idl
@@ -0,0 +1,19 @@ +// Copyright 2015 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// https://www.w3.org/TR/webaudio/#AudioDestinationNode + +interface AudioDestinationNode : AudioNode { + readonly attribute unsigned long maxChannelCount; +};
diff --git a/src/cobalt/audio/audio_device.cc b/src/cobalt/audio/audio_device.cc index e666970..205d3c6 100644 --- a/src/cobalt/audio/audio_device.cc +++ b/src/cobalt/audio/audio_device.cc
@@ -1,18 +1,16 @@ -/* - * Copyright 2015 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2015 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #include "cobalt/audio/audio_device.h"
diff --git a/src/cobalt/audio/audio_device.h b/src/cobalt/audio/audio_device.h index 6b75061..06e9469 100644 --- a/src/cobalt/audio/audio_device.h +++ b/src/cobalt/audio/audio_device.h
@@ -1,18 +1,16 @@ -/* - * Copyright 2015 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2015 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #ifndef COBALT_AUDIO_AUDIO_DEVICE_H_ #define COBALT_AUDIO_AUDIO_DEVICE_H_
diff --git a/src/cobalt/audio/audio_file_reader.cc b/src/cobalt/audio/audio_file_reader.cc index a858789..08ca2c3 100644 --- a/src/cobalt/audio/audio_file_reader.cc +++ b/src/cobalt/audio/audio_file_reader.cc
@@ -1,18 +1,16 @@ -/* - * Copyright 2015 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2015 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #include "cobalt/audio/audio_file_reader.h"
diff --git a/src/cobalt/audio/audio_file_reader.h b/src/cobalt/audio/audio_file_reader.h index 2d35a25..b7c95ca 100644 --- a/src/cobalt/audio/audio_file_reader.h +++ b/src/cobalt/audio/audio_file_reader.h
@@ -1,18 +1,16 @@ -/* - * Copyright 2015 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2015 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #ifndef COBALT_AUDIO_AUDIO_FILE_READER_H_ #define COBALT_AUDIO_AUDIO_FILE_READER_H_
diff --git a/src/cobalt/audio/audio_file_reader_wav.cc b/src/cobalt/audio/audio_file_reader_wav.cc index d0875f2..443c101 100644 --- a/src/cobalt/audio/audio_file_reader_wav.cc +++ b/src/cobalt/audio/audio_file_reader_wav.cc
@@ -1,18 +1,16 @@ -/* - * Copyright 2015 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2015 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #include "cobalt/audio/audio_file_reader_wav.h"
diff --git a/src/cobalt/audio/audio_file_reader_wav.h b/src/cobalt/audio/audio_file_reader_wav.h index dc3699a..2c7185e 100644 --- a/src/cobalt/audio/audio_file_reader_wav.h +++ b/src/cobalt/audio/audio_file_reader_wav.h
@@ -1,18 +1,16 @@ -/* - * Copyright 2015 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2015 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #ifndef COBALT_AUDIO_AUDIO_FILE_READER_WAV_H_ #define COBALT_AUDIO_AUDIO_FILE_READER_WAV_H_
diff --git a/src/cobalt/audio/audio_helpers.h b/src/cobalt/audio/audio_helpers.h index 2f0c06a..07b60c7 100644 --- a/src/cobalt/audio/audio_helpers.h +++ b/src/cobalt/audio/audio_helpers.h
@@ -1,18 +1,16 @@ -/* - * Copyright 2016 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2016 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #ifndef COBALT_AUDIO_AUDIO_HELPERS_H_ #define COBALT_AUDIO_AUDIO_HELPERS_H_
diff --git a/src/cobalt/audio/audio_node.cc b/src/cobalt/audio/audio_node.cc index a7478ca..961b862 100644 --- a/src/cobalt/audio/audio_node.cc +++ b/src/cobalt/audio/audio_node.cc
@@ -1,18 +1,16 @@ -/* - * Copyright 2015 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2015 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #include "cobalt/audio/audio_node.h"
diff --git a/src/cobalt/audio/audio_node.h b/src/cobalt/audio/audio_node.h index 01a578d..a69f5ba 100644 --- a/src/cobalt/audio/audio_node.h +++ b/src/cobalt/audio/audio_node.h
@@ -1,18 +1,16 @@ -/* - * Copyright 2015 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2015 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #ifndef COBALT_AUDIO_AUDIO_NODE_H_ #define COBALT_AUDIO_AUDIO_NODE_H_
diff --git a/src/cobalt/audio/audio_node.idl b/src/cobalt/audio/audio_node.idl new file mode 100644 index 0000000..afbb730 --- /dev/null +++ b/src/cobalt/audio/audio_node.idl
@@ -0,0 +1,42 @@ +// Copyright 2015 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// https://www.w3.org/TR/webaudio/#AudioNode-section + +enum ChannelCountMode { + "max", + "clamped-max", + "explicit" +}; + +enum ChannelInterpretation { + "speakers", + "discrete" +}; + +interface AudioNode : EventTarget { + [RaisesException] void connect(AudioNode destination, + optional unsigned long output = 0, + optional unsigned long input = 0); + [RaisesException] void disconnect(optional unsigned long output = 0); + + readonly attribute AudioContext context; + readonly attribute unsigned long numberOfInputs; + readonly attribute unsigned long numberOfOutputs; + + // Channel up-mixing and down-mixing rules for all inputs. + [RaisesException=Setter] attribute unsigned long channelCount; + attribute ChannelCountMode channelCountMode; + attribute ChannelInterpretation channelInterpretation; +};
diff --git a/src/cobalt/audio/audio_node_input.cc b/src/cobalt/audio/audio_node_input.cc index b7ac086..945fcb8 100644 --- a/src/cobalt/audio/audio_node_input.cc +++ b/src/cobalt/audio/audio_node_input.cc
@@ -1,18 +1,16 @@ -/* - * Copyright 2015 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2015 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #include "cobalt/audio/audio_node_input.h"
diff --git a/src/cobalt/audio/audio_node_input.h b/src/cobalt/audio/audio_node_input.h index 1ed3c21..ce1cda8 100644 --- a/src/cobalt/audio/audio_node_input.h +++ b/src/cobalt/audio/audio_node_input.h
@@ -1,18 +1,16 @@ -/* - * Copyright 2015 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2015 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #ifndef COBALT_AUDIO_AUDIO_NODE_INPUT_H_ #define COBALT_AUDIO_AUDIO_NODE_INPUT_H_
diff --git a/src/cobalt/audio/audio_node_input_output_test.cc b/src/cobalt/audio/audio_node_input_output_test.cc index 095217f..bff7de0 100644 --- a/src/cobalt/audio/audio_node_input_output_test.cc +++ b/src/cobalt/audio/audio_node_input_output_test.cc
@@ -1,18 +1,16 @@ -/* - * Copyright 2015 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2015 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #include "cobalt/audio/audio_buffer_source_node.h" #include "cobalt/audio/audio_context.h"
diff --git a/src/cobalt/audio/audio_node_output.cc b/src/cobalt/audio/audio_node_output.cc index 747bc01..43fb9ab 100644 --- a/src/cobalt/audio/audio_node_output.cc +++ b/src/cobalt/audio/audio_node_output.cc
@@ -1,18 +1,16 @@ -/* - * Copyright 2015 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2015 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #include "cobalt/audio/audio_node_output.h"
diff --git a/src/cobalt/audio/audio_node_output.h b/src/cobalt/audio/audio_node_output.h index decd54c..cbca442 100644 --- a/src/cobalt/audio/audio_node_output.h +++ b/src/cobalt/audio/audio_node_output.h
@@ -1,18 +1,16 @@ -/* - * Copyright 2015 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2015 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #ifndef COBALT_AUDIO_AUDIO_NODE_OUTPUT_H_ #define COBALT_AUDIO_AUDIO_NODE_OUTPUT_H_
diff --git a/src/cobalt/base/address_sanitizer.h b/src/cobalt/base/address_sanitizer.h index e443cc9..aef6a1f 100644 --- a/src/cobalt/base/address_sanitizer.h +++ b/src/cobalt/base/address_sanitizer.h
@@ -1,18 +1,16 @@ -/* - * Copyright 2016 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2016 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #ifndef COBALT_BASE_ADDRESS_SANITIZER_H_ #define COBALT_BASE_ADDRESS_SANITIZER_H_
diff --git a/src/cobalt/base/base.gyp b/src/cobalt/base/base.gyp index 81b0b0e..d453855 100644 --- a/src/cobalt/base/base.gyp +++ b/src/cobalt/base/base.gyp
@@ -104,7 +104,7 @@ ], 'dependencies': [ 'base', - '<(DEPTH)/base/base.gyp:run_all_unittests', + '<(DEPTH)/cobalt/test/test.gyp:run_all_unittests', '<(DEPTH)/testing/gmock.gyp:gmock', '<(DEPTH)/testing/gtest.gyp:gtest', ],
diff --git a/src/cobalt/base/c_val.cc b/src/cobalt/base/c_val.cc index 812433b..cc41ab8 100644 --- a/src/cobalt/base/c_val.cc +++ b/src/cobalt/base/c_val.cc
@@ -1,18 +1,16 @@ -/* - * Copyright 2015 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2015 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #include "cobalt/base/c_val.h" #include <sstream>
diff --git a/src/cobalt/base/c_val.h b/src/cobalt/base/c_val.h index e07b543..829e3d3 100644 --- a/src/cobalt/base/c_val.h +++ b/src/cobalt/base/c_val.h
@@ -1,18 +1,16 @@ -/* - * Copyright 2015 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2015 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #ifndef COBALT_BASE_C_VAL_H_ #define COBALT_BASE_C_VAL_H_
diff --git a/src/cobalt/base/c_val_collection_entry_stats.h b/src/cobalt/base/c_val_collection_entry_stats.h index c1dd807..28cd938 100644 --- a/src/cobalt/base/c_val_collection_entry_stats.h +++ b/src/cobalt/base/c_val_collection_entry_stats.h
@@ -1,18 +1,16 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #ifndef COBALT_BASE_C_VAL_COLLECTION_ENTRY_STATS_H_ #define COBALT_BASE_C_VAL_COLLECTION_ENTRY_STATS_H_
diff --git a/src/cobalt/base/c_val_collection_entry_stats_test.cc b/src/cobalt/base/c_val_collection_entry_stats_test.cc index 3a17189..c5871ad 100644 --- a/src/cobalt/base/c_val_collection_entry_stats_test.cc +++ b/src/cobalt/base/c_val_collection_entry_stats_test.cc
@@ -1,18 +1,16 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #include <string>
diff --git a/src/cobalt/base/c_val_collection_timer_stats.h b/src/cobalt/base/c_val_collection_timer_stats.h index aff2c02..eda96b9 100644 --- a/src/cobalt/base/c_val_collection_timer_stats.h +++ b/src/cobalt/base/c_val_collection_timer_stats.h
@@ -1,18 +1,16 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #ifndef COBALT_BASE_C_VAL_COLLECTION_TIMER_STATS_H_ #define COBALT_BASE_C_VAL_COLLECTION_TIMER_STATS_H_
diff --git a/src/cobalt/base/c_val_collection_timer_stats_test.cc b/src/cobalt/base/c_val_collection_timer_stats_test.cc index 8b0f6f3..b007d27 100644 --- a/src/cobalt/base/c_val_collection_timer_stats_test.cc +++ b/src/cobalt/base/c_val_collection_timer_stats_test.cc
@@ -1,18 +1,16 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #include <string>
diff --git a/src/cobalt/base/c_val_test.cc b/src/cobalt/base/c_val_test.cc index adfbb61..3dc416d 100644 --- a/src/cobalt/base/c_val_test.cc +++ b/src/cobalt/base/c_val_test.cc
@@ -1,18 +1,16 @@ -/* - * Copyright 2015 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2015 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #include <limits>
diff --git a/src/cobalt/base/c_val_time_interval_entry_stats.h b/src/cobalt/base/c_val_time_interval_entry_stats.h index d53b377..29705ce 100644 --- a/src/cobalt/base/c_val_time_interval_entry_stats.h +++ b/src/cobalt/base/c_val_time_interval_entry_stats.h
@@ -1,18 +1,16 @@ -/* - * Copyright 2016 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2016 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #ifndef COBALT_BASE_C_VAL_TIME_INTERVAL_ENTRY_STATS_H_ #define COBALT_BASE_C_VAL_TIME_INTERVAL_ENTRY_STATS_H_
diff --git a/src/cobalt/base/c_val_time_interval_entry_stats_test.cc b/src/cobalt/base/c_val_time_interval_entry_stats_test.cc index cd4cef0..c4a2efe 100644 --- a/src/cobalt/base/c_val_time_interval_entry_stats_test.cc +++ b/src/cobalt/base/c_val_time_interval_entry_stats_test.cc
@@ -1,18 +1,16 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #include <string>
diff --git a/src/cobalt/base/c_val_time_interval_timer_stats.h b/src/cobalt/base/c_val_time_interval_timer_stats.h index 00d992a..7ea2929 100644 --- a/src/cobalt/base/c_val_time_interval_timer_stats.h +++ b/src/cobalt/base/c_val_time_interval_timer_stats.h
@@ -1,18 +1,16 @@ -/* - * Copyright 2016 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2016 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #ifndef COBALT_BASE_C_VAL_TIME_INTERVAL_TIMER_STATS_H_ #define COBALT_BASE_C_VAL_TIME_INTERVAL_TIMER_STATS_H_
diff --git a/src/cobalt/base/c_val_time_interval_timer_stats_test.cc b/src/cobalt/base/c_val_time_interval_timer_stats_test.cc index 5ab0a67..4a66af8 100644 --- a/src/cobalt/base/c_val_time_interval_timer_stats_test.cc +++ b/src/cobalt/base/c_val_time_interval_timer_stats_test.cc
@@ -1,18 +1,16 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #include <string>
diff --git a/src/cobalt/base/clock.h b/src/cobalt/base/clock.h index 2b9b56d..01d5442 100644 --- a/src/cobalt/base/clock.h +++ b/src/cobalt/base/clock.h
@@ -1,18 +1,16 @@ -/* - * Copyright 2015 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2015 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #ifndef COBALT_BASE_CLOCK_H_ #define COBALT_BASE_CLOCK_H_
diff --git a/src/cobalt/base/cobalt_paths.h b/src/cobalt/base/cobalt_paths.h index 39709b5..f2f418c 100644 --- a/src/cobalt/base/cobalt_paths.h +++ b/src/cobalt/base/cobalt_paths.h
@@ -1,18 +1,16 @@ -/* - * Copyright 2014 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2014 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #ifndef COBALT_BASE_COBALT_PATHS_H_ #define COBALT_BASE_COBALT_PATHS_H_
diff --git a/src/cobalt/base/compiler.h b/src/cobalt/base/compiler.h index a7d7f9e..b9d9269 100644 --- a/src/cobalt/base/compiler.h +++ b/src/cobalt/base/compiler.h
@@ -1,18 +1,16 @@ -/* - * Copyright 2014 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2014 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #ifndef COBALT_BASE_COMPILER_H_ #define COBALT_BASE_COMPILER_H_
diff --git a/src/cobalt/base/console_commands.cc b/src/cobalt/base/console_commands.cc index 73e4f1b..9339f67 100644 --- a/src/cobalt/base/console_commands.cc +++ b/src/cobalt/base/console_commands.cc
@@ -1,18 +1,16 @@ -/* - * Copyright 2015 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2015 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #include "cobalt/base/console_commands.h"
diff --git a/src/cobalt/base/console_commands.h b/src/cobalt/base/console_commands.h index f12113e..4973a62 100644 --- a/src/cobalt/base/console_commands.h +++ b/src/cobalt/base/console_commands.h
@@ -1,18 +1,16 @@ -/* - * Copyright 2015 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2015 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #ifndef COBALT_BASE_CONSOLE_COMMANDS_H_ #define COBALT_BASE_CONSOLE_COMMANDS_H_
diff --git a/src/cobalt/base/deep_link_event.h b/src/cobalt/base/deep_link_event.h index b5c2afa..d70c7df 100644 --- a/src/cobalt/base/deep_link_event.h +++ b/src/cobalt/base/deep_link_event.h
@@ -1,18 +1,16 @@ -/* - * Copyright 2016 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2016 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #ifndef COBALT_BASE_DEEP_LINK_EVENT_H_ #define COBALT_BASE_DEEP_LINK_EVENT_H_
diff --git a/src/cobalt/base/enable_if.h b/src/cobalt/base/enable_if.h index c48a73b..c7fd510 100644 --- a/src/cobalt/base/enable_if.h +++ b/src/cobalt/base/enable_if.h
@@ -1,18 +1,16 @@ -/* - * Copyright 2015 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2015 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #ifndef COBALT_BASE_ENABLE_IF_H_ #define COBALT_BASE_ENABLE_IF_H_
diff --git a/src/cobalt/base/event.h b/src/cobalt/base/event.h index 721d1b0..b8ba6a6 100644 --- a/src/cobalt/base/event.h +++ b/src/cobalt/base/event.h
@@ -1,18 +1,16 @@ -/* - * Copyright 2015 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2015 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #ifndef COBALT_BASE_EVENT_H_ #define COBALT_BASE_EVENT_H_
diff --git a/src/cobalt/base/event_dispatcher.cc b/src/cobalt/base/event_dispatcher.cc index bea0c65..6ff6ab7 100644 --- a/src/cobalt/base/event_dispatcher.cc +++ b/src/cobalt/base/event_dispatcher.cc
@@ -1,18 +1,16 @@ -/* - * Copyright 2015 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2015 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #include "cobalt/base/event_dispatcher.h"
diff --git a/src/cobalt/base/event_dispatcher.h b/src/cobalt/base/event_dispatcher.h index 13fdda6..45179e4 100644 --- a/src/cobalt/base/event_dispatcher.h +++ b/src/cobalt/base/event_dispatcher.h
@@ -1,18 +1,16 @@ -/* - * Copyright 2015 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2015 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #ifndef COBALT_BASE_EVENT_DISPATCHER_H_ #define COBALT_BASE_EVENT_DISPATCHER_H_
diff --git a/src/cobalt/base/fixed_size_lru_cache.h b/src/cobalt/base/fixed_size_lru_cache.h index 17e53b8..8a1faa9 100644 --- a/src/cobalt/base/fixed_size_lru_cache.h +++ b/src/cobalt/base/fixed_size_lru_cache.h
@@ -1,18 +1,16 @@ -/* - * Copyright 2016 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2016 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #ifndef COBALT_BASE_FIXED_SIZE_LRU_CACHE_H_ #define COBALT_BASE_FIXED_SIZE_LRU_CACHE_H_
diff --git a/src/cobalt/base/fixed_size_lru_cache_test.cc b/src/cobalt/base/fixed_size_lru_cache_test.cc index 6fea17f..f11bf52 100644 --- a/src/cobalt/base/fixed_size_lru_cache_test.cc +++ b/src/cobalt/base/fixed_size_lru_cache_test.cc
@@ -1,18 +1,16 @@ -/* - * Copyright 2016 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2016 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #include "cobalt/base/fixed_size_lru_cache.h"
diff --git a/src/cobalt/base/generated_resources_types.h b/src/cobalt/base/generated_resources_types.h index fecb32c..6025c13 100644 --- a/src/cobalt/base/generated_resources_types.h +++ b/src/cobalt/base/generated_resources_types.h
@@ -1,18 +1,16 @@ -/* - * Copyright 2013 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2013 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #ifndef COBALT_BASE_GENERATED_RESOURCES_TYPES_H_ #define COBALT_BASE_GENERATED_RESOURCES_TYPES_H_
diff --git a/src/cobalt/base/init_cobalt.cc b/src/cobalt/base/init_cobalt.cc index 6806d29..d4af02e 100644 --- a/src/cobalt/base/init_cobalt.cc +++ b/src/cobalt/base/init_cobalt.cc
@@ -1,18 +1,16 @@ -/* - * Copyright 2014 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2014 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #include "cobalt/base/init_cobalt.h"
diff --git a/src/cobalt/base/init_cobalt.h b/src/cobalt/base/init_cobalt.h index 1ba9cdf..d73839a 100644 --- a/src/cobalt/base/init_cobalt.h +++ b/src/cobalt/base/init_cobalt.h
@@ -1,18 +1,16 @@ -/* - * Copyright 2014 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2014 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #ifndef COBALT_BASE_INIT_COBALT_H_ #define COBALT_BASE_INIT_COBALT_H_
diff --git a/src/cobalt/base/language.cc b/src/cobalt/base/language.cc index a681d7e..93869a1 100644 --- a/src/cobalt/base/language.cc +++ b/src/cobalt/base/language.cc
@@ -1,18 +1,16 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #include "cobalt/base/language.h"
diff --git a/src/cobalt/base/language.h b/src/cobalt/base/language.h index c4d3d25..174035f 100644 --- a/src/cobalt/base/language.h +++ b/src/cobalt/base/language.h
@@ -1,18 +1,16 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #ifndef COBALT_BASE_LANGUAGE_H_ #define COBALT_BASE_LANGUAGE_H_
diff --git a/src/cobalt/base/localized_strings.cc b/src/cobalt/base/localized_strings.cc index db65621..d601dcc 100644 --- a/src/cobalt/base/localized_strings.cc +++ b/src/cobalt/base/localized_strings.cc
@@ -1,18 +1,16 @@ -/* - * Copyright 2015 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2015 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #include "cobalt/base/localized_strings.h"
diff --git a/src/cobalt/base/localized_strings.h b/src/cobalt/base/localized_strings.h index cf78805..60fecae 100644 --- a/src/cobalt/base/localized_strings.h +++ b/src/cobalt/base/localized_strings.h
@@ -1,18 +1,16 @@ -/* - * Copyright 2015 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2015 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #ifndef COBALT_BASE_LOCALIZED_STRINGS_H_ #define COBALT_BASE_LOCALIZED_STRINGS_H_
diff --git a/src/cobalt/base/log_message_handler.cc b/src/cobalt/base/log_message_handler.cc index 45114db..2f06d00 100644 --- a/src/cobalt/base/log_message_handler.cc +++ b/src/cobalt/base/log_message_handler.cc
@@ -1,18 +1,16 @@ -/* - * Copyright 2015 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2015 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #include "cobalt/base/log_message_handler.h"
diff --git a/src/cobalt/base/log_message_handler.h b/src/cobalt/base/log_message_handler.h index d66599f..55a0dfa 100644 --- a/src/cobalt/base/log_message_handler.h +++ b/src/cobalt/base/log_message_handler.h
@@ -1,18 +1,16 @@ -/* - * Copyright 2015 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2015 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #ifndef COBALT_BASE_LOG_MESSAGE_HANDLER_H_ #define COBALT_BASE_LOG_MESSAGE_HANDLER_H_
diff --git a/src/cobalt/base/math.cc b/src/cobalt/base/math.cc index 9c6eccd..d335495 100644 --- a/src/cobalt/base/math.cc +++ b/src/cobalt/base/math.cc
@@ -1,18 +1,16 @@ -/* - * Copyright 2015 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2015 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #include "cobalt/base/math.h"
diff --git a/src/cobalt/base/math.h b/src/cobalt/base/math.h index 6a30314..7eb1f53 100644 --- a/src/cobalt/base/math.h +++ b/src/cobalt/base/math.h
@@ -1,18 +1,16 @@ -/* - * Copyright 2015 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2015 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #ifndef COBALT_BASE_MATH_H_ #define COBALT_BASE_MATH_H_
diff --git a/src/cobalt/base/message_queue.h b/src/cobalt/base/message_queue.h index 3c7ad78..26d0619 100644 --- a/src/cobalt/base/message_queue.h +++ b/src/cobalt/base/message_queue.h
@@ -1,18 +1,16 @@ -/* - * Copyright 2016 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2016 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #ifndef COBALT_BASE_MESSAGE_QUEUE_H_ #define COBALT_BASE_MESSAGE_QUEUE_H_
diff --git a/src/cobalt/base/path_provider.cc b/src/cobalt/base/path_provider.cc index 114717b..83031a1 100644 --- a/src/cobalt/base/path_provider.cc +++ b/src/cobalt/base/path_provider.cc
@@ -1,18 +1,16 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #include "cobalt/base/path_provider.h"
diff --git a/src/cobalt/base/path_provider.h b/src/cobalt/base/path_provider.h index 363e62c..5032fe5 100644 --- a/src/cobalt/base/path_provider.h +++ b/src/cobalt/base/path_provider.h
@@ -1,18 +1,16 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #ifndef COBALT_BASE_PATH_PROVIDER_H_ #define COBALT_BASE_PATH_PROVIDER_H_
diff --git a/src/cobalt/base/poller.h b/src/cobalt/base/poller.h index 8aadeb0..b63ff9c 100644 --- a/src/cobalt/base/poller.h +++ b/src/cobalt/base/poller.h
@@ -1,18 +1,16 @@ -/* - * Copyright 2015 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2015 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #ifndef COBALT_BASE_POLLER_H_ #define COBALT_BASE_POLLER_H_
diff --git a/src/cobalt/base/polymorphic_downcast.h b/src/cobalt/base/polymorphic_downcast.h index ad49257..c561cd5 100644 --- a/src/cobalt/base/polymorphic_downcast.h +++ b/src/cobalt/base/polymorphic_downcast.h
@@ -1,18 +1,16 @@ -/* - * Copyright 2014 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2014 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #ifndef COBALT_BASE_POLYMORPHIC_DOWNCAST_H_ #define COBALT_BASE_POLYMORPHIC_DOWNCAST_H_
diff --git a/src/cobalt/base/polymorphic_equatable.h b/src/cobalt/base/polymorphic_equatable.h index 42fe9a2..f74bb7c 100644 --- a/src/cobalt/base/polymorphic_equatable.h +++ b/src/cobalt/base/polymorphic_equatable.h
@@ -1,18 +1,16 @@ -/* - * Copyright 2015 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2015 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #ifndef COBALT_BASE_POLYMORPHIC_EQUATABLE_H_ #define COBALT_BASE_POLYMORPHIC_EQUATABLE_H_
diff --git a/src/cobalt/base/source_location.h b/src/cobalt/base/source_location.h index c725b38..1edd754 100644 --- a/src/cobalt/base/source_location.h +++ b/src/cobalt/base/source_location.h
@@ -1,18 +1,16 @@ -/* - * Copyright 2014 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2014 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #ifndef COBALT_BASE_SOURCE_LOCATION_H_ #define COBALT_BASE_SOURCE_LOCATION_H_
diff --git a/src/cobalt/base/stop_watch.cc b/src/cobalt/base/stop_watch.cc index d7814fe..d5da92b 100644 --- a/src/cobalt/base/stop_watch.cc +++ b/src/cobalt/base/stop_watch.cc
@@ -1,18 +1,16 @@ -/* - * Copyright 2016 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2016 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #include "cobalt/base/stop_watch.h"
diff --git a/src/cobalt/base/stop_watch.h b/src/cobalt/base/stop_watch.h index 97fefd3..59b6c72 100644 --- a/src/cobalt/base/stop_watch.h +++ b/src/cobalt/base/stop_watch.h
@@ -1,18 +1,16 @@ -/* - * Copyright 2016 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2016 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #ifndef COBALT_BASE_STOP_WATCH_H_ #define COBALT_BASE_STOP_WATCH_H_
diff --git a/src/cobalt/base/token.cc b/src/cobalt/base/token.cc index 5158a0b..ab3d2c9 100644 --- a/src/cobalt/base/token.cc +++ b/src/cobalt/base/token.cc
@@ -1,18 +1,16 @@ -/* - * Copyright 2016 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2016 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #include "cobalt/base/token.h"
diff --git a/src/cobalt/base/token.h b/src/cobalt/base/token.h index af0a6ca..09ab811 100644 --- a/src/cobalt/base/token.h +++ b/src/cobalt/base/token.h
@@ -1,18 +1,16 @@ -/* - * Copyright 2016 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2016 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #ifndef COBALT_BASE_TOKEN_H_ #define COBALT_BASE_TOKEN_H_
diff --git a/src/cobalt/base/token_test.cc b/src/cobalt/base/token_test.cc index 3fcb313..95666c3 100644 --- a/src/cobalt/base/token_test.cc +++ b/src/cobalt/base/token_test.cc
@@ -1,18 +1,16 @@ -/* - * Copyright 2016 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2016 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #include "cobalt/base/token.h"
diff --git a/src/cobalt/base/tokens.cc b/src/cobalt/base/tokens.cc index 26d8bd4..84fc9bc 100644 --- a/src/cobalt/base/tokens.cc +++ b/src/cobalt/base/tokens.cc
@@ -1,18 +1,16 @@ -/* - * Copyright 2016 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2016 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #include "cobalt/base/tokens.h"
diff --git a/src/cobalt/base/tokens.h b/src/cobalt/base/tokens.h index 3ae1cdc..e2be55a 100644 --- a/src/cobalt/base/tokens.h +++ b/src/cobalt/base/tokens.h
@@ -1,18 +1,16 @@ -/* - * Copyright 2016 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2016 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #ifndef COBALT_BASE_TOKENS_H_ #define COBALT_BASE_TOKENS_H_ @@ -25,16 +23,18 @@ // clang-format off #define TOKENS_FOR_EACH_WITH_NAME_ONLY(MacroOpWithNameOnly) \ MacroOpWithNameOnly(addsourcebuffer) \ + MacroOpWithNameOnly(addtrack) \ MacroOpWithNameOnly(abort) \ MacroOpWithNameOnly(additions) \ - MacroOpWithNameOnly(alt) \ MacroOpWithNameOnly(all) \ + MacroOpWithNameOnly(alt) \ MacroOpWithNameOnly(animationend) \ MacroOpWithNameOnly(assertive) \ - MacroOpWithNameOnly(attribute) \ + MacroOpWithNameOnly(attributes) \ MacroOpWithNameOnly(blur) \ MacroOpWithNameOnly(canplay) \ MacroOpWithNameOnly(canplaythrough) \ + MacroOpWithNameOnly(change) \ MacroOpWithNameOnly(characterData) \ MacroOpWithNameOnly(childList) \ MacroOpWithNameOnly(close) \ @@ -69,6 +69,7 @@ MacroOpWithNameOnly(readystatechange) \ MacroOpWithNameOnly(removals) \ MacroOpWithNameOnly(removesourcebuffer) \ + MacroOpWithNameOnly(removetrack) \ MacroOpWithNameOnly(result) \ MacroOpWithNameOnly(securitypolicyviolation) \ MacroOpWithNameOnly(seeked) \ @@ -86,6 +87,9 @@ MacroOpWithNameOnly(timeupdate) \ MacroOpWithNameOnly(transitionend) \ MacroOpWithNameOnly(unload) \ + MacroOpWithNameOnly(update) \ + MacroOpWithNameOnly(updateend) \ + MacroOpWithNameOnly(updatestart) \ MacroOpWithNameOnly(volumechange) \ MacroOpWithNameOnly(waiting)
diff --git a/src/cobalt/base/type_id.h b/src/cobalt/base/type_id.h index 67ab1be..de6036a 100644 --- a/src/cobalt/base/type_id.h +++ b/src/cobalt/base/type_id.h
@@ -1,18 +1,16 @@ -/* - * Copyright 2015 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2015 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #ifndef COBALT_BASE_TYPE_ID_H_ #define COBALT_BASE_TYPE_ID_H_
diff --git a/src/cobalt/base/unicode/character.cc b/src/cobalt/base/unicode/character.cc index 66a1880..a5fb6ad 100644 --- a/src/cobalt/base/unicode/character.cc +++ b/src/cobalt/base/unicode/character.cc
@@ -1,32 +1,30 @@ -/* - * Copyright (C) 2016 Google Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ +// Copyright (C) 2016 Google Inc. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include <algorithm>
diff --git a/src/cobalt/base/unicode/character.h b/src/cobalt/base/unicode/character.h index ba8ff9a..dae1b1b 100644 --- a/src/cobalt/base/unicode/character.h +++ b/src/cobalt/base/unicode/character.h
@@ -1,32 +1,30 @@ -/* - * Copyright (C) 2016 Google Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ +// Copyright (C) 2016 Google Inc. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef COBALT_BASE_UNICODE_CHARACTER_H_ #define COBALT_BASE_UNICODE_CHARACTER_H_
diff --git a/src/cobalt/base/unicode/character_values.h b/src/cobalt/base/unicode/character_values.h index 0518d87..58b714d 100644 --- a/src/cobalt/base/unicode/character_values.h +++ b/src/cobalt/base/unicode/character_values.h
@@ -1,18 +1,16 @@ -/* - * Copyright 2016 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2016 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #ifndef COBALT_BASE_UNICODE_CHARACTER_VALUES_H_ #define COBALT_BASE_UNICODE_CHARACTER_VALUES_H_
diff --git a/src/cobalt/base/unused.h b/src/cobalt/base/unused.h index 25d998c..85edfa5 100644 --- a/src/cobalt/base/unused.h +++ b/src/cobalt/base/unused.h
@@ -1,18 +1,16 @@ -/* - * Copyright 2015 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2015 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #ifndef COBALT_BASE_UNUSED_H_ #define COBALT_BASE_UNUSED_H_
diff --git a/src/cobalt/base/user_log.cc b/src/cobalt/base/user_log.cc index 4d91768..9ce0f79 100644 --- a/src/cobalt/base/user_log.cc +++ b/src/cobalt/base/user_log.cc
@@ -1,18 +1,16 @@ -/* - * Copyright 2016 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2016 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #include "cobalt/base/user_log.h"
diff --git a/src/cobalt/base/user_log.h b/src/cobalt/base/user_log.h index 5c47910..014f736 100644 --- a/src/cobalt/base/user_log.h +++ b/src/cobalt/base/user_log.h
@@ -1,18 +1,16 @@ -/* - * Copyright 2016 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2016 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #ifndef COBALT_BASE_USER_LOG_H_ #define COBALT_BASE_USER_LOG_H_
diff --git a/src/cobalt/base/wrap_main.h b/src/cobalt/base/wrap_main.h index 193e379..86114e8 100644 --- a/src/cobalt/base/wrap_main.h +++ b/src/cobalt/base/wrap_main.h
@@ -1,18 +1,16 @@ -/* - * Copyright 2016 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2016 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. // This header defines two macros, COBALT_WRAP_SIMPLE_MAIN() and // COBALT_WRAP_BASE_MAIN(). Simple main is for programs that are
diff --git a/src/cobalt/base/wrap_main_starboard.h b/src/cobalt/base/wrap_main_starboard.h index dad3708..17d8d40 100644 --- a/src/cobalt/base/wrap_main_starboard.h +++ b/src/cobalt/base/wrap_main_starboard.h
@@ -1,18 +1,16 @@ -/* - * Copyright 2016 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2016 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #ifndef COBALT_BASE_WRAP_MAIN_STARBOARD_H_ #define COBALT_BASE_WRAP_MAIN_STARBOARD_H_
diff --git a/src/cobalt/bindings/bindings.gypi b/src/cobalt/bindings/bindings.gypi index 3e76733..2db8bb8 100644 --- a/src/cobalt/bindings/bindings.gypi +++ b/src/cobalt/bindings/bindings.gypi
@@ -18,10 +18,9 @@ # target which will be defined in this gyp file. # # Input variables: -# bindings_output_dir: The base path into which all generated files will -# be created. # source_idl_files: All IDL files for which a bindings wrapper should be # created. +# dictionary_idl_files: All IDL files for IDL dictionaries. # dependency_idl_files: IDL files that are dependencies of other IDLs, but no # bindings wrapper will be created. For example, partial interfaces and # the right-hand-side of implements statements. @@ -31,8 +30,11 @@ # section below. # # Output: -# bindings: A gyp target that will build a static library containing all the -# generated bindings. +# generated_bindings: A gyp target that will generate all bindings source +# files. At most one target can declare generated_bindings as a +# dependency. The target that depends on generated_bindings will compile +# the generated sources, since generated_bindings will export the required +# gyp variables to its dependent. # # Basic flow of data: # [All Static files] -> GlobalObjectsPickle @@ -72,6 +74,7 @@ # Templates that are shared by the code generation for multiple engines. 'shared_template_files': [ + 'templates/dictionary.h.template', 'templates/interface-base.cc.template', 'templates/interface-base.h.template', 'templates/callback-interface-base.cc.template', @@ -85,6 +88,12 @@ # directory of each IDL. 'source_idl_files': [], + # A class definition that matches the dictionary definition and is + # suitable to be included and used in Cobalt code will be generated, as well + # as a conversion function between an instance of this class and a JS + # object. + 'dictionary_idl_files': [], + # Partial interfaces and the right-side of "implements" # Code will not get generated for these interfaces; they are used to add # functionality to other interfaces. @@ -143,9 +152,6 @@ # does not have this problem. 'write_file_only_if_changed': 1, - # Generated code will be created here. - 'bindings_source_output_dir': '<(bindings_output_dir)/source', - # Caches and intermediate structures. 'bindings_scripts_output_dir': '<(bindings_output_dir)/scripts', @@ -167,24 +173,27 @@ # All source files that will be generated from the source IDL files. 'generated_sources': - ['<!@pymod_do_main(path_conversion -s' - ' --output_directory <(bindings_source_output_dir)' - ' --output_extension cc --output_prefix <(prefix)' + ['<!@pymod_do_main(cobalt.build.path_conversion -s' + ' --output_directory <(SHARED_INTERMEDIATE_DIR)' + ' --output_extension cc --output_prefix <(prefix)_' + ' --base_directory <(DEPTH)' ' <@(source_idl_files))'], # Generated IDL file that will define all the constructors that should be # on the Window object 'global_constructors_generated_idl_file': - '<(generated_idls_output_dir)/<(window_component)/WindowConstructors.idl', + '<(generated_idls_output_dir)/<(window_component)/window_constructors.idl', # Dummy header file which is generated because the idl compiler assumes # there is a header for each IDL. 'global_constructors_generated_header_file': - '<(generated_idls_output_dir)/<(window_component)/WindowConstructors.h', + '<(generated_idls_output_dir)/<(window_component)/window_constructors.h', }, 'targets': [ { + # Create a target that depends on this target to compile the generated + # source files. There should be only one such target. # Based on blink/Source/bindings/core/v8/generated.gyp:bindings_core_v8_generated_individual 'target_name': 'generated_bindings', 'type': 'none', @@ -194,8 +203,13 @@ 'dependencies': [ 'cached_jinja_templates', 'cached_lex_yacc_tables', + 'generated_dictionaries', 'global_constructors_idls', 'interfaces_info_overall', + '<@(bindings_dependencies)', + ], + 'export_dependent_settings': [ + '<@(bindings_dependencies)', ], 'sources': [ '<@(source_idl_files)', @@ -232,8 +246,10 @@ '<(extended_attributes_file)', ], 'outputs': [ - '<(bindings_source_output_dir)/<(prefix)<(RULE_INPUT_ROOT).cc', - '<(bindings_source_output_dir)/<(prefix)<(RULE_INPUT_ROOT).h', + '<!@pymod_do_main(cobalt.build.path_conversion -s -p <(prefix)_ ' + '-e cc -d <(SHARED_INTERMEDIATE_DIR) -b <(DEPTH) <(RULE_INPUT_DIRNAME)/<(RULE_INPUT_ROOT))', + '<!@pymod_do_main(cobalt.build.path_conversion -s -p <(prefix)_ ' + '-e h -d <(SHARED_INTERMEDIATE_DIR) -b <(DEPTH) <(RULE_INPUT_DIRNAME)/<(RULE_INPUT_ROOT))' ], 'action': [ 'python', @@ -241,7 +257,7 @@ '--cache-dir', '<(bindings_scripts_output_dir)', '--output-dir', - '<(bindings_source_output_dir)', + '<(SHARED_INTERMEDIATE_DIR)', '--interfaces-info', '<(interfaces_info_combined_pickle)', '--extended-attributes', @@ -252,6 +268,94 @@ ], 'message': 'Generating binding from <(RULE_INPUT_PATH)', }], + # The target that depends on this will build the bindings source. + 'direct_dependent_settings': { + 'defines': [ '<@(bindings_defines)' ], + 'include_dirs': [ + '<@(bindings_include_dirs)', + '<(SHARED_INTERMEDIATE_DIR)', + ], + 'sources': [ + '<@(generated_sources)', + ], + 'defines': [ '<@(bindings_defines)'], + } + }, + + { + # Based on the generated_bindings target above. Main difference is that + # this produces two .h files, and takes the dictionary idl files as input. + 'target_name': 'generated_dictionaries', + 'type': 'none', + 'hard_dependency': 1, + 'dependencies': [ + 'cached_jinja_templates', + 'cached_lex_yacc_tables', + 'global_constructors_idls', + 'interfaces_info_overall', + ], + 'sources': [ + '<@(dictionary_idl_files)', + ], + 'all_dependent_settings': { + 'include_dirs': [ + '<(SHARED_INTERMEDIATE_DIR)', + ] + }, + 'rules': [{ + 'rule_name': 'binding', + 'extension': 'idl', + 'msvs_external_rule': 1, + 'inputs': [ + # Script source files, etc. + '<@(bindings_extra_inputs)', + + # This file is global, so if it changes all files are rebuilt. + # However, this file will only change when dependency structure + # changes, so shouldn't change too much. + # See blink/Source/bindings/core/v8/generated.gyp for more info + '<(interfaces_info_combined_pickle)', + + # Similarly, all files are rebuilt if a partial interface or + # right side of 'implements' changes. + # See blink/Source/bindings/core/v8/generated.gyp for more info + '<@(dependency_idl_files)', + + # Also add as a dependency the set of unsupported IDL files. + '<@(unsupported_interface_idl_files)', + + # The generated constructors IDL is also a partial interface, and + # we need to rebuild if it is modified. + '<(global_constructors_generated_idl_file)', + + # The whitelist of what extended attributes we support. If an attribute + # not in this list is encountered, it will cause an error in the + # pipeline. + '<(extended_attributes_file)', + ], + 'outputs': [ + '<!@pymod_do_main(cobalt.build.path_conversion -s ' + '-e h -d <(SHARED_INTERMEDIATE_DIR) -b <(DEPTH) <(RULE_INPUT_DIRNAME)/<(RULE_INPUT_ROOT))', + '<!@pymod_do_main(cobalt.build.path_conversion -s -p <(prefix)_ ' + '-e h -d <(SHARED_INTERMEDIATE_DIR) -b <(DEPTH) <(RULE_INPUT_DIRNAME)/<(RULE_INPUT_ROOT))' + ], + 'action': [ + 'python', + '<(idl_compiler_script)', + '--cache-dir', + '<(bindings_scripts_output_dir)', + '--output-dir', + '<(SHARED_INTERMEDIATE_DIR)', + '--interfaces-info', + '<(interfaces_info_combined_pickle)', + '--extended-attributes', + '<(extended_attributes_file)', + '--write-file-only-if-changed', + '<(write_file_only_if_changed)', + '<(RULE_INPUT_PATH)', + ], + 'message': 'Generating dictionary from <(RULE_INPUT_PATH)', + }], }, { @@ -259,7 +363,7 @@ 'target_name': 'global_objects', 'variables': { 'idl_files': [ - '<@(source_idl_files)', + '<@(source_idl_files)', '<@(dictionary_idl_files)' ], 'output_file': '<(bindings_scripts_output_dir)/GlobalObjects.pickle', }, @@ -300,7 +404,7 @@ ], 'variables': { 'static_idl_files': [ - '<@(source_idl_files)', + '<@(source_idl_files)', '<@(dictionary_idl_files)', '<@(dependency_idl_files)', '<@(unsupported_interface_idl_files)'], 'generated_idl_files': ['<(global_constructors_generated_idl_file)'], @@ -373,20 +477,5 @@ 'message': 'Caching bytecode of Jinja templates', }], }, - { - 'target_name': 'bindings', - 'type': 'static_library', - 'defines': [ '<@(bindings_defines)' ], - 'include_dirs': [ '<@(bindings_include_dirs)' ], - 'sources': [ - '<@(generated_sources)', - ], - 'defines': [ '<@(bindings_defines)'], - 'dependencies': [ - # generated_bindings target is defined in bindings_gen.gypi - 'generated_bindings', - '<@(bindings_dependencies)' - ], - }, ], }
diff --git a/src/cobalt/bindings/bootstrap_path.py b/src/cobalt/bindings/bootstrap_path.py new file mode 100644 index 0000000..9c8decf --- /dev/null +++ b/src/cobalt/bindings/bootstrap_path.py
@@ -0,0 +1,37 @@ +# +# Copyright 2016 Google Inc. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +"""Utility to prepend the top-level source directory to sys.path. + +Since this may be used outside of gclient or git environment (such as part of a +tarball), the path to the root must be hardcoded. +""" + +import os +import sys + + +def _GetSrcRoot(): + """Finds the first directory named 'src' that this module is in.""" + current_path = os.path.normpath(__file__) + while os.path.basename(current_path) != 'src': + next_path = os.path.dirname(current_path) + if next_path == current_path: + raise RuntimeError('Could not find src directory.') + current_path = next_path + return os.path.abspath(current_path) + + +sys.path.insert(0, _GetSrcRoot())
diff --git a/src/cobalt/bindings/code_generator_cobalt.py b/src/cobalt/bindings/code_generator_cobalt.py index 2aa694a..dc43bf0 100644 --- a/src/cobalt/bindings/code_generator_cobalt.py +++ b/src/cobalt/bindings/code_generator_cobalt.py
@@ -22,19 +22,25 @@ import os import sys +import bootstrap_path # pylint: disable=g-bad-import-order,unused-import + # Add blink's binding scripts to the path, so we can import module_path, module_filename = os.path.split(os.path.realpath(__file__)) -blink_script_dir = os.path.normpath(os.path.join( - module_path, os.pardir, os.pardir, 'third_party', 'blink', 'Source')) +blink_script_dir = os.path.normpath( + os.path.join(module_path, os.pardir, os.pardir, 'third_party', 'blink', + 'Source')) sys.path.append(blink_script_dir) from bindings.scripts.code_generator_v8 import CodeGeneratorBase # pylint: disable=g-import-not-at-top + +# the code_generator_v8 module import in the line above updates sys.path, so +# that we can import the jinja2 in third_party. +import jinja2 # pylint: disable=g-bad-import-order + from bindings.scripts.idl_types import IdlType -from bindings.scripts.idl_types import inherits_interface -import contexts -import jinja2 -from name_conversion import convert_to_cobalt_name -from name_conversion import get_interface_name +from cobalt.bindings import contexts +from cobalt.bindings import path_generator +from cobalt.bindings.name_conversion import get_interface_name module_path, module_filename = os.path.split(os.path.realpath(__file__)) @@ -48,6 +54,9 @@ """Initialize the Jinja2 environment.""" assert os.path.isabs(templates_dir) assert os.path.isabs(SHARED_TEMPLATES_DIR) + # Ensure that we are using the version of jinja that's checked in to + # third_party. + assert jinja2.__version__ == '2.7.1' jinja_env = jinja2.Environment( loader=jinja2.FileSystemLoader([templates_dir, SHARED_TEMPLATES_DIR]), extensions=['jinja2.ext.do'], # do statement @@ -67,33 +76,6 @@ return path -def get_implementation_header_path(interface_info): - """Get the path to the implementation header file. - - The interface file must be under cobalt/... - - Args: - interface_info: (dict) Contains the information about an interface - defined in an IDL, as generated by blink's - compute_interfaces_info_individual.py script - Returns: - (str) The path to the corresponding implementation header file, starting - with the 'cobalt' directory. - """ - implementation_header_absdir, filename = os.path.split(interface_info[ - 'full_path']) - - implementation_header_reldir = os.path.relpath(implementation_header_absdir, - cobalt_dir) - assert not os.path.isabs(implementation_header_reldir) - assert os.pardir not in implementation_header_reldir.split(os.sep) - - root, _ = os.path.splitext(filename) - header_filename = convert_to_cobalt_name(root) + '.h' - return normalize_slashes(os.path.join('cobalt', implementation_header_reldir, - header_filename)) - - def is_global_interface(interface): return (('PrimaryGlobal' in interface.extended_attributes) or ('Global' in interface.extended_attributes)) @@ -102,11 +84,11 @@ def get_indexed_special_operation(interface, special): special_operations = list( operation for operation in interface.operations - if (special in operation.specials and operation.arguments and str( - operation.arguments[0].idl_type) == 'unsigned long')) + if (special in operation.specials and operation.arguments and + str(operation.arguments[0].idl_type) == 'unsigned long')) assert len(special_operations) <= 1, ( - 'Multiple indexed %ss defined on interface: %s' % - (special, interface.name)) + 'Multiple indexed %ss defined on interface: %s' % (special, + interface.name)) return special_operations[0] if len(special_operations) else None @@ -131,8 +113,8 @@ def get_named_special_operation(interface, special): special_operations = list( operation for operation in interface.operations - if (special in operation.specials and operation.arguments and str( - operation.arguments[0].idl_type) == 'DOMString')) + if (special in operation.specials and operation.arguments and + str(operation.arguments[0].idl_type) == 'DOMString')) assert len(special_operations) <= 1, ( 'Multiple named %ss defined on interface: %s' % (special, interface.name)) return special_operations[0] if len(special_operations) else None @@ -161,6 +143,8 @@ if idl_type: if idl_type.is_interface_type: yield get_interface_name(idl_type) + if idl_type.is_dictionary: + yield idl_type.name elif idl_type.is_union_type: for interface_name in get_interface_type_names_from_idl_types( idl_type.member_types): @@ -208,6 +192,8 @@ # cache was prepopulated. self.jinja_env = initialize_jinja_env(cache_dir, os.path.abspath(templates_dir)) + self.path_builder = path_generator.PathBuilder( + self.generated_file_prefix, interfaces_info, cobalt_dir, output_dir) @abc.abstractproperty def generated_file_prefix(self): @@ -219,50 +205,11 @@ """An instance that implements the ExpressionGenerator class.""" pass - def wrapper_class_from_interface_name(self, interface_name): - return self.generated_file_prefix + interface_name - - def wrapper_header_from_interface_name(self, interface_name): - attribute_wrapper_class = self.wrapper_class_from_interface_name( - interface_name) - return normalize_slashes(attribute_wrapper_class + '.h') - - def output_paths(self, class_name): - """Construct the filenames for a generated source file. - - Construct the header and cc source file paths based on the - name of the generated class. - - Args: - class_name: A string that is the name of the interface as defined - in the IDL - - Returns: - (str, str): A tuple of two strings representing the full path of - the (.h, .cpp) file that will be generated for this interface - """ - - header_path = os.path.join(self.output_dir, class_name + '.h') - cc_path = os.path.join(self.output_dir, class_name + '.cc') - return header_path, cc_path - - def render_template(self, header_template_filename, cc_template_filename, - template_context): - header_template = self.jinja_env.get_template(header_template_filename) - cc_template = self.jinja_env.get_template(cc_template_filename) - # Make sure extension is .py, not .pyc or .pyo, so doesn't depend on caching - module_path_pyname = os.path.join( - module_path, os.path.splitext(module_filename)[0] + '.py') - # Ensure that posix forward slashes are used - template_context['code_generator'] = normalize_slashes(os.path.relpath( - module_path_pyname, cobalt_dir)) - template_context['header_template_path'] = normalize_slashes( - os.path.relpath(header_template.filename, cobalt_dir)) - template_context['cc_template_path'] = normalize_slashes(os.path.relpath( - cc_template.filename, cobalt_dir)) - header_text = header_template.render(template_context) - cc_text = cc_template.render(template_context) - return header_text, cc_text + def render_template(self, template_filename, template_context): + template = self.jinja_env.get_template(template_filename) + template_context.update(self.common_context(template)) + rendered_text = template.render(template_context) + return rendered_text def generate_code_internal(self, definitions, definition_name): if definition_name in definitions.interfaces: @@ -288,87 +235,160 @@ template_context = self.build_interface_context(interface, interface_info, definitions) - header_text, cc_text = self.render_template(header_template_filename, - cpp_template_filename, - template_context) - header_path, cc_path = self.output_paths(template_context['binding_class']) - return ((header_path, header_text), - (cc_path, cc_text),) + header_text = self.render_template(header_template_filename, + template_context) + cc_text = self.render_template(cpp_template_filename, template_context) + header_path = self.path_builder.BindingsHeaderFullPath(interface_name) + cc_path = self.path_builder.BindingsImplementationPath(interface_name) + return ((header_path, header_text), (cc_path, cc_text),) def generate_dictionary_code(self, definitions, dictionary_name, dictionary): - raise NotImplementedError('Dictionaries not implemented') + header_template_filename = 'dictionary.h.template' + conversion_template_filename = 'dictionary-conversion.h.template' + template_context = self.build_dictionary_context(dictionary, definitions) - def get_interface_components(self, idl_type_name): - """Get the interface's namespace as a list of namespace components.""" - idl_filename = self.interfaces_info[idl_type_name].get('full_path') - # Get the IDL filename relative to the cobalt directory, and split the - # directory to get the list of namespace components. - idl_filename = os.path.relpath(idl_filename, cobalt_dir) - components = os.path.dirname(idl_filename).split(os.sep) - return components + header_text = self.render_template(header_template_filename, + template_context) + conversion_text = self.render_template(conversion_template_filename, + template_context) - def referenced_interface_contexts(self, interface_name): - """Yields information for including and declaring this interface's classes. + header_path = self.path_builder.DictionaryHeaderFullPath(dictionary_name) + conversion_header_path = ( + self.path_builder.DictionaryConversionHeaderFullPath(dictionary_name)) + return ((header_path, header_text), (conversion_header_path, + conversion_text),) + + def referenced_class_contexts(self, + interface_names, + implementation_only=False): + """Returns a list of jinja contexts describing referenced C++ classes. Args: - interface_name: The name of the interface. - Yields: - dict with the following keys: + interface_names: A list of interfaces. + implementation_only: Only include implemetation headers. + Returns: + list() of jinja contexts (python dicts) with information about C++ classes + related to the interfaces in |interface_names|. dict has the following + keys: fully_qualified_name: Fully qualified name of the class. include: Path to the header that defines the class. conditional: Symbol on which this interface is conditional compiled. is_callback_interface: True iff this is a callback interface. """ + referenced_classes = [] + # Iterate over it as a set to uniquify the list. + for interface_name in set(interface_names): + interface_info = self.interfaces_info[interface_name] + is_dictionary = interface_info['is_dictionary'] + namespace = '::'.join( + self.path_builder.NamespaceComponents(interface_name)) + conditional = interface_info['conditional'] + is_callback_interface = interface_name in IdlType.callback_interfaces - conditional = self.interfaces_info[interface_name]['conditional'] - namespace = '::'.join(self.get_interface_components(interface_name)) - full_name = 'cobalt::%s::%s' % (namespace, interface_name) + # Information about the Cobalt implementation class. + if is_dictionary: + referenced_classes.append({ + 'fully_qualified_name': + '%s::%s' % (namespace, interface_name), + 'include': + self.path_builder.BindingsHeaderIncludePath(interface_name), + 'conditional': + conditional, + 'is_callback_interface': + is_callback_interface, + }) + else: + referenced_classes.append({ + 'fully_qualified_name': + '%s::%s' % (namespace, interface_name), + 'include': + self.path_builder.ImplementationHeaderPath(interface_name), + 'conditional': + conditional, + 'is_callback_interface': + is_callback_interface, + }) + if not implementation_only: + referenced_classes.append({ + 'fully_qualified_name': + '%s::%s' % (namespace, + self.path_builder.BindingsClass(interface_name)), + 'include': + self.path_builder.BindingsHeaderIncludePath(interface_name), + 'conditional': + conditional, + 'is_callback_interface': + is_callback_interface, + }) + return referenced_classes - # Information about the Cobalt implementation class. - yield { - 'fully_qualified_name': full_name, - 'include': get_implementation_header_path(self.interfaces_info[ - interface_name]), - 'conditional': conditional, - 'is_callback_interface': interface_name in IdlType.callback_interfaces, + def common_context(self, template): + """Shared stuff.""" + # Make sure extension is .py, not .pyc or .pyo, so doesn't depend on caching + module_path_pyname = os.path.join( + module_path, os.path.splitext(module_filename)[0] + '.py') + + # Ensure that posix forward slashes are used + context = { + 'today': + date.today(), + 'code_generator': + normalize_slashes(os.path.relpath(module_path_pyname, cobalt_dir)), + 'template_path': + normalize_slashes(os.path.relpath(template.filename, cobalt_dir)), } - yield { - 'fully_qualified_name': 'cobalt::%s::%s' % ( - namespace, self.wrapper_class_from_interface_name(interface_name)), - 'include': self.wrapper_header_from_interface_name(interface_name), - 'conditional': conditional, - 'is_callback_interface': interface_name in IdlType.callback_interfaces, + return context + + def build_dictionary_context(self, dictionary, definitions): + context = { + 'class_name': + dictionary.name, + 'header_file': + self.path_builder.DictionaryHeaderIncludePath(dictionary.name), + 'members': [ + contexts.get_dictionary_member_context(dictionary, member) + for member in dictionary.members + ] } + referenced_interface_names = set( + get_interface_type_names_from_typed_objects(dictionary.members)) + referenced_class_contexts = self.referenced_class_contexts( + referenced_interface_names, True) + context['includes'] = sorted((interface['include'] + for interface in referenced_class_contexts)) + context['forward_declarations'] = sorted( + referenced_class_contexts, key=lambda x: x['fully_qualified_name']) + context['components'] = self.path_builder.NamespaceComponents( + dictionary.name) + return context def build_interface_context(self, interface, interface_info, definitions): - wrapper_class_name = self.wrapper_class_from_interface_name(interface.name) - header, _ = self.output_paths(wrapper_class_name) - generated_header_relative_path = os.path.relpath(header, self.output_dir) - assert not os.path.isabs(generated_header_relative_path) - assert os.pardir not in generated_header_relative_path.split(os.sep) - - interface_components = ( - self.get_interface_components(interface.idl_type.name)) context = { # Parameters used for template rendering. - 'today': date.today(), - 'binding_class': wrapper_class_name, - 'fully_qualified_binding_class': ( - '::'.join(interface_components + [wrapper_class_name])), - 'header_file': normalize_slashes(generated_header_relative_path), - 'impl_class': interface.name, - 'fully_qualified_impl_class': ( - '::'.join(interface_components + [interface.name])), - 'interface_name': interface.name, - 'is_event_interface': inherits_interface(interface.name, 'Event'), - 'is_global_interface': is_global_interface(interface), - 'has_interface_object': - ('NoInterfaceObject' not in interface.extended_attributes), - 'conditional': interface.extended_attributes.get('Conditional', None), - 'add_opaque_roots': interface.extended_attributes.get('AddOpaqueRoots', - None), - 'get_opaque_root': interface.extended_attributes.get('GetOpaqueRoot', - None), + 'today': + date.today(), + 'binding_class': + self.path_builder.BindingsClass(interface.name), + 'fully_qualified_binding_class': + self.path_builder.FullBindingsClassName(interface.name), + 'header_file': + self.path_builder.BindingsHeaderIncludePath(interface.name), + 'impl_class': + interface.name, + 'fully_qualified_impl_class': + self.path_builder.FullClassName(interface.name), + 'interface_name': + interface.name, + 'is_global_interface': + is_global_interface(interface), + 'has_interface_object': ( + 'NoInterfaceObject' not in interface.extended_attributes), + 'conditional': + interface.extended_attributes.get('Conditional', None), + 'add_opaque_roots': + interface.extended_attributes.get('AddOpaqueRoots', None), + 'get_opaque_root': + interface.extended_attributes.get('GetOpaqueRoot', None), } if is_global_interface(interface): # Global interface references all interfaces. @@ -376,7 +396,8 @@ interface_name for interface_name in self.interfaces_info['all_interfaces'] if not self.interfaces_info[interface_name]['unsupported'] and - not self.interfaces_info[interface_name]['is_callback_interface']) + not self.interfaces_info[interface_name]['is_callback_interface'] and + not self.interfaces_info[interface_name]['is_dictionary']) referenced_interface_names.update(IdlType.callback_interfaces) else: # Build the set of referenced interfaces from this interface's members. @@ -395,12 +416,16 @@ # to avoid circular dependency problems. header_includes = set() if interface.parent: - header_includes.add(self.wrapper_header_from_interface_name( - interface.parent)) - header_includes.add(get_implementation_header_path(interface_info)) + header_includes.add( + self.path_builder.BindingsHeaderIncludePath(interface.parent)) + referenced_interface_names.add(interface.parent) + header_includes.add( + self.path_builder.ImplementationHeaderPath(interface.name)) - attributes = [contexts.attribute_context(interface, attribute, definitions) - for attribute in interface.attributes] + attributes = [ + contexts.attribute_context(interface, attribute, definitions) + for attribute in interface.attributes + ] constructor = contexts.get_constructor_context(self.expression_generator, interface) methods = contexts.get_method_contexts(self.expression_generator, interface) @@ -415,31 +440,21 @@ constants) # Build a set of all interfaces referenced by this interface. - referenced_interfaces = {} - for interface_name in referenced_interface_names: - # Get information for classes related to this interface. - for referenced_interface_context in self.referenced_interface_contexts( - interface_name): - # Store it in the dictionary using fully_qualified_name as the key so - # we can avoid duplicates - key = referenced_interface_context['fully_qualified_name'] - referenced_interfaces[key] = referenced_interface_context - # Now that we have all the referenced interfaces at most once, just get - # the values(), since the key is duplicated there and we no longer need - # to lookup by name. - referenced_interfaces = referenced_interfaces.values() + referenced_class_contexts = self.referenced_class_contexts( + referenced_interface_names) all_interfaces = [] for interface_name in referenced_interface_names: - if interface_name not in IdlType.callback_interfaces and not ( - self.interfaces_info[interface_name]['unsupported']): + if (interface_name not in IdlType.callback_interfaces and + not self.interfaces_info[interface_name]['unsupported'] and + not self.interfaces_info[interface_name]['is_dictionary']): all_interfaces.append({ 'name': interface_name, 'conditional': self.interfaces_info[interface_name]['conditional'], }) context['implementation_includes'] = sorted( - (interface['include'] for interface in referenced_interfaces)) + (interface['include'] for interface in referenced_class_contexts)) context['header_includes'] = sorted(header_includes) context['attributes'] = [a for a in attributes if not a['is_static']] context['static_attributes'] = [a for a in attributes if a['is_static']] @@ -456,21 +471,19 @@ context['unsupported_constructor_properties'] = set( unsupported_constant_names) if interface.parent: - context['parent_interface'] = ( - '::'.join(self.get_interface_components(interface.parent)) + '::%s' % - self.wrapper_class_from_interface_name(interface.parent)) + context['parent_interface'] = self.path_builder.BindingsClass( + interface.parent) context['is_exception_interface'] = interface.is_exception - context['components'] = self.get_interface_components( - interface.idl_type.name) context['forward_declarations'] = sorted( - referenced_interfaces, - key=lambda x: x['fully_qualified_name']) + referenced_class_contexts, key=lambda x: x['fully_qualified_name']) context['all_interfaces'] = sorted(all_interfaces, key=lambda x: x['name']) context['callback_functions'] = definitions.callback_functions.values() context['enumerations'] = [ contexts.enumeration_context(enumeration) for enumeration in definitions.enumerations.values() ] + context['components'] = self.path_builder.NamespaceComponents( + interface.name) context['stringifier'] = contexts.stringifier_context(interface) context['indexed_property_getter'] = contexts.special_method_context( @@ -495,6 +508,7 @@ return context + ################################################################################ @@ -508,6 +522,14 @@ print 'Usage: %s CACHE_DIR TEMPLATES_DIR DUMMY_FILENAME' % argv[0] return 1 + # Delete all jinja2 .cache files, since they will get regenerated anyways. + for filename in os.listdir(cache_dir): + if os.path.splitext(filename)[1] == '.cache': + # We expect that the only .cache files in this directory are for jinja2 + # and they have a __jinja2_ prefix. + assert filename.startswith('__jinja2_') + os.remove(os.path.join(cache_dir, filename)) + # Cache templates. # Whether the path is absolute or relative affects the cache file name. Use # the absolute path to ensure that the same path is used when we populate the
diff --git a/src/cobalt/bindings/contexts.py b/src/cobalt/bindings/contexts.py index fc2ec98..d739e83 100644 --- a/src/cobalt/bindings/contexts.py +++ b/src/cobalt/bindings/contexts.py
@@ -144,6 +144,8 @@ cobalt_type = 'void' elif is_object_type(idl_type): cobalt_type = 'OpaqueHandle' + elif idl_type.is_dictionary: + cobalt_type = get_interface_name(idl_type) assert cobalt_type, 'Unsupported idl_type %s' % idl_type @@ -204,8 +206,8 @@ if idl_type.is_string_type: if typed_object.extended_attributes.get('TreatNullAs', '') == 'EmptyString': flags.append('kConversionFlagTreatNullAsEmptyString') - elif (typed_object.extended_attributes.get('TreatUndefinedAs', '') == - 'EmptyString'): + elif (typed_object.extended_attributes.get('TreatUndefinedAs', + '') == 'EmptyString'): flags.append('kConversionFlagTreatUndefinedAsEmptyString') if flags: @@ -217,23 +219,33 @@ def argument_context(interface, argument): """Create template values for method/constructor arguments.""" return { - 'idl_type_object': argument.idl_type, - 'name': argument.name, - 'type': typed_object_to_cobalt_type(interface, argument), - 'arg_type': typed_object_to_arg_type(interface, argument), - 'conversion_flags': get_conversion_flags(argument), - 'is_optional': argument.is_optional, - 'is_variadic': argument.is_variadic, - 'default_value': idl_literal_to_cobalt_literal(argument.idl_type, - argument.default_value) if - argument.default_value else None, + 'idl_type_object': + argument.idl_type, + 'name': + argument.name, + 'type': + typed_object_to_cobalt_type(interface, argument), + 'arg_type': + typed_object_to_arg_type(interface, argument), + 'conversion_flags': + get_conversion_flags(argument), + 'is_optional': + argument.is_optional, + 'is_variadic': + argument.is_variadic, + 'default_value': + idl_literal_to_cobalt_literal(argument.idl_type, + argument.default_value) + if argument.default_value else None, } def get_non_optional_arguments(arguments): """Create non optional arguments list.""" - return [argument for argument in arguments - if not argument['is_optional'] and not argument['is_variadic']] + return [ + argument for argument in arguments + if not argument['is_optional'] and not argument['is_variadic'] + ] def get_optional_arguments(arguments): @@ -268,21 +280,26 @@ optional_arguments = get_optional_arguments(arguments) num_default_arguments = get_num_default_arguments(optional_arguments) return { - 'arguments': arguments, - 'non_optional_arguments': get_non_optional_arguments(arguments), - 'optional_arguments': optional_arguments, - 'num_default_arguments': num_default_arguments, - 'variadic_argument': get_variadic_argument(arguments), - 'has_non_default_optional_arguments': len(optional_arguments) > - num_default_arguments, + 'arguments': + arguments, + 'non_optional_arguments': + get_non_optional_arguments(arguments), + 'optional_arguments': + optional_arguments, + 'num_default_arguments': + num_default_arguments, + 'variadic_argument': + get_variadic_argument(arguments), + 'has_non_default_optional_arguments': + len(optional_arguments) > num_default_arguments, } def constructor_context(interface, constructor): """Create template values for generating constructor bindings.""" context = { - 'call_with': interface.extended_attributes.get('ConstructorCallWith', - None), + 'call_with': + interface.extended_attributes.get('ConstructorCallWith', None), 'raises_exception': (interface.extended_attributes.get( 'RaisesException', None) == 'Constructor'), } @@ -294,15 +311,22 @@ def method_context(interface, operation): """Create template values for generating method bindings.""" context = { - 'idl_name': operation.name, - 'name': capitalize_function_name(operation.name), - 'type': typed_object_to_cobalt_type(interface, operation), - 'is_static': operation.is_static, - 'call_with': operation.extended_attributes.get('CallWith', None), + 'idl_name': + operation.name, + 'name': + capitalize_function_name(operation.name), + 'type': + typed_object_to_cobalt_type(interface, operation), + 'is_static': + operation.is_static, + 'call_with': + operation.extended_attributes.get('CallWith', None), 'raises_exception': operation.extended_attributes.has_key('RaisesException'), - 'conditional': operation.extended_attributes.get('Conditional', None), - 'unsupported': 'NotSupported' in operation.extended_attributes, + 'conditional': + operation.extended_attributes.get('Conditional', None), + 'unsupported': + 'NotSupported' in operation.extended_attributes, } context.update(partial_context(interface, operation)) @@ -319,7 +343,9 @@ cobalt_name = capitalize_function_name(interface.stringifier.operation.name) else: cobalt_name = 'AnonymousStringifier' - return {'name': cobalt_name,} + return { + 'name': cobalt_name, + } def special_method_context(interface, operation): @@ -350,7 +376,8 @@ cobalt_name = 'AnonymousNamed%s' % function_suffix[special_type] context = { - 'name': cobalt_name, + 'name': + cobalt_name, 'raises_exception': operation.extended_attributes.has_key('RaisesException'), } @@ -368,18 +395,28 @@ def attribute_context(interface, attribute, definitions): """Create template values for attribute bindings.""" context = { - 'idl_name': attribute.name, - 'getter_function_name': convert_to_cobalt_name(attribute.name), - 'setter_function_name': 'set_' + convert_to_cobalt_name(attribute.name), - 'type': typed_object_to_cobalt_type(interface, attribute), - 'is_static': attribute.is_static, - 'is_read_only': attribute.is_read_only, - 'call_with': attribute.extended_attributes.get('CallWith', None), + 'idl_name': + attribute.name, + 'getter_function_name': + convert_to_cobalt_name(attribute.name), + 'setter_function_name': + 'set_' + convert_to_cobalt_name(attribute.name), + 'type': + typed_object_to_cobalt_type(interface, attribute), + 'is_static': + attribute.is_static, + 'is_read_only': + attribute.is_read_only, + 'call_with': + attribute.extended_attributes.get('CallWith', None), 'raises_exception': attribute.extended_attributes.has_key('RaisesException'), - 'conversion_flags': get_conversion_flags(attribute), - 'conditional': attribute.extended_attributes.get('Conditional', None), - 'unsupported': 'NotSupported' in attribute.extended_attributes, + 'conversion_flags': + get_conversion_flags(attribute), + 'conditional': + attribute.extended_attributes.get('Conditional', None), + 'unsupported': + 'NotSupported' in attribute.extended_attributes, } forwarded_attribute_name = attribute.extended_attributes.get('PutForwards') if forwarded_attribute_name: @@ -389,12 +426,13 @@ 'PutForwards must be on a readonly attribute.') forwarded_interface = definitions.interfaces[get_interface_name( attribute.idl_type)] - matching_attributes = [a for a in forwarded_interface.attributes - if a.name == forwarded_attribute_name] + matching_attributes = [ + a for a in forwarded_interface.attributes + if a.name == forwarded_attribute_name + ] assert len(matching_attributes) == 1 - context['put_forwards'] = attribute_context(forwarded_interface, - matching_attributes[0], - definitions) + context['put_forwards'] = attribute_context( + forwarded_interface, matching_attributes[0], definitions) context['has_setter'] = not attribute.is_read_only or forwarded_attribute_name if is_constructor_attribute(attribute): context['is_constructor_attribute'] = True @@ -409,9 +447,10 @@ def enumeration_context(enumeration): """Create template values for IDL enumeration type bindings.""" return { - 'name': enumeration.name, - 'value_pairs': [(convert_to_cobalt_enumeration_value(value), - value,) for value in enumeration.values], + 'name': + enumeration.name, + 'value_pairs': [(convert_to_cobalt_enumeration_value(value), value,) + for value in enumeration.values], } @@ -451,16 +490,16 @@ # Create overload sets for static and non-static methods seperately. # Each item in the list is a pair of (name, [method_contexts]) where for # each method_context m in the list, m['name'] == name. - static_method_overloads = method_overloads_by_name([m for m in methods - if m['is_static']]) + static_method_overloads = method_overloads_by_name( + [m for m in methods if m['is_static']]) non_static_method_overloads = method_overloads_by_name( [m for m in methods if not m['is_static']]) - static_overload_contexts = get_overload_contexts( - expression_generator, [contexts - for _, contexts in static_method_overloads]) - non_static_overload_contexts = get_overload_contexts( - expression_generator, [contexts - for _, contexts in non_static_method_overloads]) + static_overload_contexts = get_overload_contexts(expression_generator, [ + contexts for _, contexts in static_method_overloads + ]) + non_static_overload_contexts = get_overload_contexts(expression_generator, [ + contexts for _, contexts in non_static_method_overloads + ]) # Set is_static on each of these appropriately. for context in static_overload_contexts: @@ -514,3 +553,30 @@ assert len(overload_contexts) == 1, ( 'Expected exactly one overload context for constructor.') return overload_contexts[0] + + +def get_dictionary_member_context(dictionary, dictionary_member): + """Returns a jinja context for a dictionary member. + + Arguments: + dictionary: An IdlDictionary object + dictionary_member: An IdlDictionaryMember object. + Returns: + dictionary_member_context (dict) + """ + return { + 'idl_type_object': + dictionary_member.idl_type, + 'name': + convert_to_cobalt_name(dictionary_member.name), + 'idl_name': + dictionary_member.name, + 'type': + typed_object_to_cobalt_type(dictionary, dictionary_member), + 'arg_type': + typed_object_to_arg_type(dictionary, dictionary_member), + 'default_value': + idl_literal_to_cobalt_literal(dictionary_member.idl_type, + dictionary_member.default_value) + if dictionary_member.default_value else None, + }
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsAnonymousIndexedGetterInterface.cc b/src/cobalt/bindings/generated/mozjs-45/testing/MozjsAnonymousIndexedGetterInterface.cc deleted file mode 100644 index 9d975aa..0000000 --- a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsAnonymousIndexedGetterInterface.cc +++ /dev/null
@@ -1,488 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! -// Auto-generated from template: bindings/mozjs-45/templates/interface.cc.template - -// clang-format off - -#include "MozjsAnonymousIndexedGetterInterface.h" - -#include "base/debug/trace_event.h" -#include "cobalt/base/polymorphic_downcast.h" -#include "cobalt/script/global_environment.h" -#include "cobalt/script/opaque_handle.h" -#include "cobalt/script/script_object.h" - -#include "base/lazy_instance.h" -#include "cobalt/script/mozjs-45/callback_function_conversion.h" -#include "cobalt/script/exception_state.h" -#include "cobalt/script/mozjs-45/conversion_helpers.h" -#include "cobalt/script/mozjs-45/mozjs_exception_state.h" -#include "cobalt/script/mozjs-45/mozjs_callback_function.h" -#include "cobalt/script/mozjs-45/mozjs_global_environment.h" -#include "cobalt/script/mozjs-45/mozjs_object_handle.h" -#include "cobalt/script/mozjs-45/mozjs_property_enumerator.h" -#include "cobalt/script/mozjs-45/mozjs_user_object_holder.h" -#include "cobalt/script/mozjs-45/proxy_handler.h" -#include "cobalt/script/mozjs-45/type_traits.h" -#include "cobalt/script/mozjs-45/wrapper_factory.h" -#include "cobalt/script/mozjs-45/wrapper_private.h" -#include "cobalt/script/property_enumerator.h" -#include "third_party/mozjs-45/js/src/jsapi.h" -#include "third_party/mozjs-45/js/src/jsfriendapi.h" - -namespace { -using cobalt::bindings::testing::AnonymousIndexedGetterInterface; -using cobalt::bindings::testing::MozjsAnonymousIndexedGetterInterface; -using cobalt::script::CallbackInterfaceTraits; -using cobalt::script::GlobalEnvironment; -using cobalt::script::OpaqueHandle; -using cobalt::script::OpaqueHandleHolder; -using cobalt::script::ScriptObject; -using cobalt::script::Wrappable; - -using cobalt::script::CallbackFunction; -using cobalt::script::CallbackInterfaceTraits; -using cobalt::script::ExceptionState; -using cobalt::script::mozjs::FromJSValue; -using cobalt::script::mozjs::kConversionFlagNullable; -using cobalt::script::mozjs::kConversionFlagRestricted; -using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString; -using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString; -using cobalt::script::mozjs::kNoConversionFlags; -using cobalt::script::mozjs::InterfaceData; -using cobalt::script::mozjs::MozjsCallbackFunction; -using cobalt::script::mozjs::MozjsExceptionState; -using cobalt::script::mozjs::MozjsGlobalEnvironment; -using cobalt::script::mozjs::MozjsUserObjectHolder; -using cobalt::script::mozjs::MozjsPropertyEnumerator; -using cobalt::script::mozjs::ProxyHandler; -using cobalt::script::mozjs::ToJSValue; -using cobalt::script::mozjs::TypeTraits; -using cobalt::script::mozjs::WrapperPrivate; -using cobalt::script::mozjs::WrapperFactory; -using cobalt::script::Wrappable; -} // namespace - -namespace cobalt { -namespace bindings { -namespace testing { - -namespace { - -bool IsSupportedIndexProperty(JSContext* context, JS::HandleObject object, - uint32_t index) { - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - AnonymousIndexedGetterInterface* impl = - wrapper_private->wrappable<AnonymousIndexedGetterInterface>().get(); - return index < impl->length(); -} - -void EnumerateSupportedIndexes(JSContext* context, JS::HandleObject object, - JS::AutoIdVector* properties) { - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - AnonymousIndexedGetterInterface* impl = - wrapper_private->wrappable<AnonymousIndexedGetterInterface>().get(); - const uint32_t kNumIndexedProperties = impl->length(); - for (uint32_t i = 0; i < kNumIndexedProperties; ++i) { - properties->append(INT_TO_JSID(i)); - } -} - -bool GetIndexedProperty( - JSContext* context, JS::HandleObject object, JS::HandleId id, - JS::MutableHandleValue vp) { - JS::RootedValue id_value(context); - if (!JS_IdToValue(context, id, &id_value)) { - NOTREACHED(); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - AnonymousIndexedGetterInterface* impl = - wrapper_private->wrappable<AnonymousIndexedGetterInterface>().get(); - uint32_t index; - FromJSValue(context, id_value, kNoConversionFlags, &exception_state, &index); - if (exception_state.is_exception_set()) { - // The ID should be an integer or a string, so we shouldn't have any - // exceptions converting to string. - NOTREACHED(); - return false; - } - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->AnonymousIndexedGetter(index), - &result_value); - } - if (!exception_state.is_exception_set()) { - vp.set(result_value); - } - return !exception_state.is_exception_set(); -} - -bool SetIndexedProperty( - JSContext* context, JS::HandleObject object, JS::HandleId id, - JS::MutableHandleValue vp, JS::ObjectOpResult& object_op_result) { - JS::RootedValue id_value(context); - if (!JS_IdToValue(context, id, &id_value)) { - NOTREACHED(); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - AnonymousIndexedGetterInterface* impl = - wrapper_private->wrappable<AnonymousIndexedGetterInterface>().get(); - uint32_t index; - FromJSValue(context, id_value, kNoConversionFlags, &exception_state, &index); - if (exception_state.is_exception_set()) { - // The ID should be an integer or a string, so we shouldn't have any - // exceptions converting to string. - NOTREACHED(); - return false; - } - TypeTraits<uint32_t >::ConversionType value; - FromJSValue(context, vp, kNoConversionFlags, - &exception_state, &value); - if (exception_state.is_exception_set()) { - return false; - } - - impl->AnonymousIndexedSetter(index, value); - result_value.set(JS::UndefinedHandleValue); - if (!exception_state.is_exception_set()) { - return object_op_result.succeed(); - } else { - return false; - } -} - -class MozjsAnonymousIndexedGetterInterfaceHandler : public ProxyHandler { - public: - MozjsAnonymousIndexedGetterInterfaceHandler() - : ProxyHandler(indexed_property_hooks, named_property_hooks) {} - - private: - static NamedPropertyHooks named_property_hooks; - static IndexedPropertyHooks indexed_property_hooks; -}; - -ProxyHandler::NamedPropertyHooks -MozjsAnonymousIndexedGetterInterfaceHandler::named_property_hooks = { - NULL, - NULL, - NULL, - NULL, - NULL, -}; -ProxyHandler::IndexedPropertyHooks -MozjsAnonymousIndexedGetterInterfaceHandler::indexed_property_hooks = { - IsSupportedIndexProperty, - EnumerateSupportedIndexes, - GetIndexedProperty, - SetIndexedProperty, - NULL, -}; - -static base::LazyInstance<MozjsAnonymousIndexedGetterInterfaceHandler> - proxy_handler; - -bool HasInstance(JSContext *context, JS::HandleObject type, - JS::MutableHandleValue vp, bool *success) { - JS::RootedObject global_object( - context, JS_GetGlobalForObject(context, type)); - DCHECK(global_object); - - JS::RootedObject prototype( - context, MozjsAnonymousIndexedGetterInterface::GetPrototype(context, global_object)); - - // |IsDelegate| walks the prototype chain of an object returning true if - // .prototype is found. - bool is_delegate; - if (!IsDelegate(context, prototype, vp, &is_delegate)) { - *success = false; - return false; - } - - *success = is_delegate; - return true; -} - -const JSClass instance_class_definition = { - "AnonymousIndexedGetterInterface", - 0 | JSCLASS_HAS_PRIVATE, - NULL, // addProperty - NULL, // delProperty - NULL, // getProperty - NULL, // setProperty - NULL, // enumerate - NULL, // resolve - NULL, // mayResolve - &WrapperPrivate::Finalizer, // finalize - NULL, // call - NULL, // hasInstance - NULL, // construct - &WrapperPrivate::Trace, // trace -}; - -const JSClass prototype_class_definition = { - "AnonymousIndexedGetterInterfacePrototype", -}; - -const JSClass interface_object_class_definition = { - "AnonymousIndexedGetterInterfaceConstructor", - 0, - NULL, // addProperty - NULL, // delProperty - NULL, // getProperty - NULL, // setProperty - NULL, // enumerate - NULL, // resolve - NULL, // mayResolve - NULL, // finalize - NULL, // call - &HasInstance, - NULL, -}; - -bool get_length( - JSContext* context, unsigned argc, JS::Value* vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<AnonymousIndexedGetterInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - AnonymousIndexedGetterInterface* impl = - wrapper_private->wrappable<AnonymousIndexedGetterInterface>().get(); - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->length(), - &result_value); - } - if (!exception_state.is_exception_set()) { - args.rval().set(result_value); - } - return !exception_state.is_exception_set(); -} - - - - -const JSPropertySpec prototype_properties[] = { - { // Readonly attribute - "length", - JSPROP_SHARED | JSPROP_ENUMERATE, - { { &get_length, NULL } }, - JSNATIVE_WRAPPER(NULL), - }, - JS_PS_END -}; - -const JSFunctionSpec prototype_functions[] = { - JS_FS_END -}; - -const JSPropertySpec interface_object_properties[] = { - JS_PS_END -}; - -const JSFunctionSpec interface_object_functions[] = { - JS_FS_END -}; - -const JSPropertySpec own_properties[] = { - JS_PS_END -}; - -void InitializePrototypeAndInterfaceObject( - InterfaceData* interface_data, JSContext* context, - JS::HandleObject global_object) { - DCHECK(!interface_data->prototype); - DCHECK(!interface_data->interface_object); - DCHECK(JS_IsGlobalObject(global_object)); - - JS::RootedObject parent_prototype( - context, JS_GetObjectPrototype(context, global_object)); - DCHECK(parent_prototype); - - interface_data->prototype = JS_NewObjectWithGivenProto( - context, &prototype_class_definition, parent_prototype - ); - - JS::RootedObject rooted_prototype(context, interface_data->prototype); - bool success = JS_DefineProperties( - context, - rooted_prototype, - prototype_properties); - - DCHECK(success); - success = JS_DefineFunctions( - context, rooted_prototype, prototype_functions); - DCHECK(success); - - JS::RootedObject function_prototype( - context, JS_GetFunctionPrototype(context, global_object)); - DCHECK(function_prototype); - // Create the Interface object. - interface_data->interface_object = JS_NewObjectWithGivenProto( - context, &interface_object_class_definition, - function_prototype); - - // Add the InterfaceObject.name property. - JS::RootedObject rooted_interface_object( - context, interface_data->interface_object); - JS::RootedValue name_value(context); - const char name[] = - "AnonymousIndexedGetterInterface"; - name_value.setString(JS_NewStringCopyZ(context, name)); - success = JS_DefineProperty( - context, rooted_interface_object, "name", name_value, JSPROP_READONLY, - NULL, NULL); - DCHECK(success); - - // Define interface object properties (including constants). - success = JS_DefineProperties(context, rooted_interface_object, - interface_object_properties); - DCHECK(success); - // Define interface object functions (static). - success = JS_DefineFunctions(context, rooted_interface_object, - interface_object_functions); - DCHECK(success); - - // Set the Prototype.constructor and Constructor.prototype properties. - DCHECK(interface_data->interface_object); - DCHECK(interface_data->prototype); - success = JS_LinkConstructorAndPrototype( - context, - rooted_interface_object, - rooted_prototype); - DCHECK(success); -} - -InterfaceData* GetInterfaceData(JSContext* context) { - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - // Use the address of the properties definition for this interface as a - // unique key for looking up the InterfaceData for this interface. - intptr_t key = reinterpret_cast<intptr_t>(&own_properties); - InterfaceData* interface_data = global_environment->GetInterfaceData(key); - if (!interface_data) { - interface_data = new InterfaceData(); - DCHECK(interface_data); - global_environment->CacheInterfaceData(key, interface_data); - DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key)); - } - return interface_data; -} - -} // namespace - -// static -JSObject* MozjsAnonymousIndexedGetterInterface::CreateProxy( - JSContext* context, const scoped_refptr<Wrappable>& wrappable) { - DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); - JS::RootedObject global_object( - context, - MozjsGlobalEnvironment::GetFromContext(context)->global_object()); - DCHECK(global_object); - - InterfaceData* interface_data = GetInterfaceData(context); - JS::RootedObject prototype(context, GetPrototype(context, global_object)); - DCHECK(prototype); - JS::RootedObject new_object( - context, - JS_NewObjectWithGivenProto( - context, &instance_class_definition, prototype)); - DCHECK(new_object); - JS::RootedObject proxy(context, - ProxyHandler::NewProxy( - context, proxy_handler.Pointer(), new_object, prototype)); - WrapperPrivate::AddPrivateData(context, proxy, wrappable); - return proxy; -} - -// static -const JSClass* MozjsAnonymousIndexedGetterInterface::PrototypeClass( - JSContext* context) { - DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); - JS::RootedObject global_object( - context, - MozjsGlobalEnvironment::GetFromContext(context)->global_object()); - DCHECK(global_object); - - JS::RootedObject prototype(context, GetPrototype(context, global_object)); - const JSClass* proto_class = JS_GetClass(prototype); - return proto_class; -} - -// static -JSObject* MozjsAnonymousIndexedGetterInterface::GetPrototype( - JSContext* context, JS::HandleObject global_object) { - DCHECK(JS_IsGlobalObject(global_object)); - - InterfaceData* interface_data = GetInterfaceData(context); - if (!interface_data->prototype) { - // Create new prototype that has all the props and methods - InitializePrototypeAndInterfaceObject( - interface_data, context, global_object); - } - DCHECK(interface_data->prototype); - return interface_data->prototype; -} - -// static -JSObject* MozjsAnonymousIndexedGetterInterface::GetInterfaceObject( - JSContext* context, JS::HandleObject global_object) { - DCHECK(JS_IsGlobalObject(global_object)); - - InterfaceData* interface_data = GetInterfaceData(context); - if (!interface_data->interface_object) { - InitializePrototypeAndInterfaceObject( - interface_data, context, global_object); - } - DCHECK(interface_data->interface_object); - return interface_data->interface_object; -} - - -namespace { -} // namespace - - -} // namespace testing -} // namespace bindings -} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsAnonymousIndexedGetterInterface.h b/src/cobalt/bindings/generated/mozjs-45/testing/MozjsAnonymousIndexedGetterInterface.h deleted file mode 100644 index 0b5c17d..0000000 --- a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsAnonymousIndexedGetterInterface.h +++ /dev/null
@@ -1,54 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! -// Auto-generated from template: bindings/mozjs-45/templates/interface.h.template - -// clang-format off - -#ifndef MozjsAnonymousIndexedGetterInterface_h -#define MozjsAnonymousIndexedGetterInterface_h - -#include "base/hash_tables.h" -#include "base/lazy_instance.h" -#include "base/memory/ref_counted.h" -#include "base/threading/thread_checker.h" -#include "cobalt/base/polymorphic_downcast.h" -#include "cobalt/script/wrappable.h" -#include "cobalt/bindings/testing/anonymous_indexed_getter_interface.h" - -#include "third_party/mozjs-45/js/src/jsapi.h" - -namespace cobalt { -namespace bindings { -namespace testing { - -class MozjsAnonymousIndexedGetterInterface { - public: - static JSObject* CreateProxy(JSContext* context, - const scoped_refptr<script::Wrappable>& wrappable); - static const JSClass* PrototypeClass(JSContext* context); - static JSObject* GetPrototype(JSContext* context, - JS::HandleObject global_object); - static JSObject* GetInterfaceObject(JSContext* context, - JS::HandleObject global_object); -}; - -} // namespace bindings -} // namespace testing -} // namespace cobalt - -#endif // MozjsAnonymousIndexedGetterInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsAnonymousNamedGetterInterface.cc b/src/cobalt/bindings/generated/mozjs-45/testing/MozjsAnonymousNamedGetterInterface.cc deleted file mode 100644 index 4049616..0000000 --- a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsAnonymousNamedGetterInterface.cc +++ /dev/null
@@ -1,452 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! -// Auto-generated from template: bindings/mozjs-45/templates/interface.cc.template - -// clang-format off - -#include "MozjsAnonymousNamedGetterInterface.h" - -#include "base/debug/trace_event.h" -#include "cobalt/base/polymorphic_downcast.h" -#include "cobalt/script/global_environment.h" -#include "cobalt/script/opaque_handle.h" -#include "cobalt/script/script_object.h" - -#include "base/lazy_instance.h" -#include "cobalt/script/mozjs-45/callback_function_conversion.h" -#include "cobalt/script/exception_state.h" -#include "cobalt/script/mozjs-45/conversion_helpers.h" -#include "cobalt/script/mozjs-45/mozjs_exception_state.h" -#include "cobalt/script/mozjs-45/mozjs_callback_function.h" -#include "cobalt/script/mozjs-45/mozjs_global_environment.h" -#include "cobalt/script/mozjs-45/mozjs_object_handle.h" -#include "cobalt/script/mozjs-45/mozjs_property_enumerator.h" -#include "cobalt/script/mozjs-45/mozjs_user_object_holder.h" -#include "cobalt/script/mozjs-45/proxy_handler.h" -#include "cobalt/script/mozjs-45/type_traits.h" -#include "cobalt/script/mozjs-45/wrapper_factory.h" -#include "cobalt/script/mozjs-45/wrapper_private.h" -#include "cobalt/script/property_enumerator.h" -#include "third_party/mozjs-45/js/src/jsapi.h" -#include "third_party/mozjs-45/js/src/jsfriendapi.h" - -namespace { -using cobalt::bindings::testing::AnonymousNamedGetterInterface; -using cobalt::bindings::testing::MozjsAnonymousNamedGetterInterface; -using cobalt::script::CallbackInterfaceTraits; -using cobalt::script::GlobalEnvironment; -using cobalt::script::OpaqueHandle; -using cobalt::script::OpaqueHandleHolder; -using cobalt::script::ScriptObject; -using cobalt::script::Wrappable; - -using cobalt::script::CallbackFunction; -using cobalt::script::CallbackInterfaceTraits; -using cobalt::script::ExceptionState; -using cobalt::script::mozjs::FromJSValue; -using cobalt::script::mozjs::kConversionFlagNullable; -using cobalt::script::mozjs::kConversionFlagRestricted; -using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString; -using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString; -using cobalt::script::mozjs::kNoConversionFlags; -using cobalt::script::mozjs::InterfaceData; -using cobalt::script::mozjs::MozjsCallbackFunction; -using cobalt::script::mozjs::MozjsExceptionState; -using cobalt::script::mozjs::MozjsGlobalEnvironment; -using cobalt::script::mozjs::MozjsUserObjectHolder; -using cobalt::script::mozjs::MozjsPropertyEnumerator; -using cobalt::script::mozjs::ProxyHandler; -using cobalt::script::mozjs::ToJSValue; -using cobalt::script::mozjs::TypeTraits; -using cobalt::script::mozjs::WrapperPrivate; -using cobalt::script::mozjs::WrapperFactory; -using cobalt::script::Wrappable; -} // namespace - -namespace cobalt { -namespace bindings { -namespace testing { - -namespace { - -bool IsSupportedNamedProperty(JSContext* context, JS::HandleObject object, - const std::string& property_name) { - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - AnonymousNamedGetterInterface* impl = - wrapper_private->wrappable<AnonymousNamedGetterInterface>().get(); - return impl->CanQueryNamedProperty(property_name); -} - -void EnumerateSupportedNames(JSContext* context, JS::HandleObject object, - JS::AutoIdVector* properties) { - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - AnonymousNamedGetterInterface* impl = - wrapper_private->wrappable<AnonymousNamedGetterInterface>().get(); - MozjsPropertyEnumerator enumerator(context, properties); - impl->EnumerateNamedProperties(&enumerator); -} - -bool GetNamedProperty( - JSContext* context, JS::HandleObject object, JS::HandleId id, - JS::MutableHandleValue vp) { - JS::RootedValue id_value(context); - if (!JS_IdToValue(context, id, &id_value)) { - NOTREACHED(); - return false; - } - - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - AnonymousNamedGetterInterface* impl = - wrapper_private->wrappable<AnonymousNamedGetterInterface>().get(); - std::string property_name; - FromJSValue(context, id_value, kNoConversionFlags, &exception_state, - &property_name); - if (exception_state.is_exception_set()) { - // The ID should be an integer or a string, so we shouldn't have any - // exceptions converting to string. - NOTREACHED(); - return false; - } - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->AnonymousNamedGetter(property_name), - &result_value); - } - if (!exception_state.is_exception_set()) { - vp.set(result_value); - } - return !exception_state.is_exception_set(); - -} - -bool SetNamedProperty( - JSContext* context, JS::HandleObject object, JS::HandleId id, - JS::MutableHandleValue vp, JS::ObjectOpResult& object_op_result) { - JS::RootedValue id_value(context); - if (!JS_IdToValue(context, id, &id_value)) { - NOTREACHED(); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - AnonymousNamedGetterInterface* impl = - wrapper_private->wrappable<AnonymousNamedGetterInterface>().get(); - std::string property_name; - FromJSValue(context, id_value, kNoConversionFlags, &exception_state, - &property_name); - if (exception_state.is_exception_set()) { - // The ID should be an integer or a string, so we shouldn't have any - // exceptions converting to string. - NOTREACHED(); - return false; - } - TypeTraits<std::string >::ConversionType value; - FromJSValue(context, vp, kNoConversionFlags, - &exception_state, &value); - if (exception_state.is_exception_set()) { - return false; - } - - impl->AnonymousNamedSetter(property_name, value); - result_value.set(JS::UndefinedHandleValue); - - if (!exception_state.is_exception_set()) { - return object_op_result.succeed(); - } else { - return false; - } -} - -class MozjsAnonymousNamedGetterInterfaceHandler : public ProxyHandler { - public: - MozjsAnonymousNamedGetterInterfaceHandler() - : ProxyHandler(indexed_property_hooks, named_property_hooks) {} - - private: - static NamedPropertyHooks named_property_hooks; - static IndexedPropertyHooks indexed_property_hooks; -}; - -ProxyHandler::NamedPropertyHooks -MozjsAnonymousNamedGetterInterfaceHandler::named_property_hooks = { - IsSupportedNamedProperty, - EnumerateSupportedNames, - GetNamedProperty, - SetNamedProperty, - NULL, -}; -ProxyHandler::IndexedPropertyHooks -MozjsAnonymousNamedGetterInterfaceHandler::indexed_property_hooks = { - NULL, - NULL, - NULL, - NULL, - NULL, -}; - -static base::LazyInstance<MozjsAnonymousNamedGetterInterfaceHandler> - proxy_handler; - -bool HasInstance(JSContext *context, JS::HandleObject type, - JS::MutableHandleValue vp, bool *success) { - JS::RootedObject global_object( - context, JS_GetGlobalForObject(context, type)); - DCHECK(global_object); - - JS::RootedObject prototype( - context, MozjsAnonymousNamedGetterInterface::GetPrototype(context, global_object)); - - // |IsDelegate| walks the prototype chain of an object returning true if - // .prototype is found. - bool is_delegate; - if (!IsDelegate(context, prototype, vp, &is_delegate)) { - *success = false; - return false; - } - - *success = is_delegate; - return true; -} - -const JSClass instance_class_definition = { - "AnonymousNamedGetterInterface", - 0 | JSCLASS_HAS_PRIVATE, - NULL, // addProperty - NULL, // delProperty - NULL, // getProperty - NULL, // setProperty - NULL, // enumerate - NULL, // resolve - NULL, // mayResolve - &WrapperPrivate::Finalizer, // finalize - NULL, // call - NULL, // hasInstance - NULL, // construct - &WrapperPrivate::Trace, // trace -}; - -const JSClass prototype_class_definition = { - "AnonymousNamedGetterInterfacePrototype", -}; - -const JSClass interface_object_class_definition = { - "AnonymousNamedGetterInterfaceConstructor", - 0, - NULL, // addProperty - NULL, // delProperty - NULL, // getProperty - NULL, // setProperty - NULL, // enumerate - NULL, // resolve - NULL, // mayResolve - NULL, // finalize - NULL, // call - &HasInstance, - NULL, -}; - - - -const JSPropertySpec prototype_properties[] = { - JS_PS_END -}; - -const JSFunctionSpec prototype_functions[] = { - JS_FS_END -}; - -const JSPropertySpec interface_object_properties[] = { - JS_PS_END -}; - -const JSFunctionSpec interface_object_functions[] = { - JS_FS_END -}; - -const JSPropertySpec own_properties[] = { - JS_PS_END -}; - -void InitializePrototypeAndInterfaceObject( - InterfaceData* interface_data, JSContext* context, - JS::HandleObject global_object) { - DCHECK(!interface_data->prototype); - DCHECK(!interface_data->interface_object); - DCHECK(JS_IsGlobalObject(global_object)); - - JS::RootedObject parent_prototype( - context, JS_GetObjectPrototype(context, global_object)); - DCHECK(parent_prototype); - - interface_data->prototype = JS_NewObjectWithGivenProto( - context, &prototype_class_definition, parent_prototype - ); - - JS::RootedObject rooted_prototype(context, interface_data->prototype); - bool success = JS_DefineProperties( - context, - rooted_prototype, - prototype_properties); - - DCHECK(success); - success = JS_DefineFunctions( - context, rooted_prototype, prototype_functions); - DCHECK(success); - - JS::RootedObject function_prototype( - context, JS_GetFunctionPrototype(context, global_object)); - DCHECK(function_prototype); - // Create the Interface object. - interface_data->interface_object = JS_NewObjectWithGivenProto( - context, &interface_object_class_definition, - function_prototype); - - // Add the InterfaceObject.name property. - JS::RootedObject rooted_interface_object( - context, interface_data->interface_object); - JS::RootedValue name_value(context); - const char name[] = - "AnonymousNamedGetterInterface"; - name_value.setString(JS_NewStringCopyZ(context, name)); - success = JS_DefineProperty( - context, rooted_interface_object, "name", name_value, JSPROP_READONLY, - NULL, NULL); - DCHECK(success); - - // Define interface object properties (including constants). - success = JS_DefineProperties(context, rooted_interface_object, - interface_object_properties); - DCHECK(success); - // Define interface object functions (static). - success = JS_DefineFunctions(context, rooted_interface_object, - interface_object_functions); - DCHECK(success); - - // Set the Prototype.constructor and Constructor.prototype properties. - DCHECK(interface_data->interface_object); - DCHECK(interface_data->prototype); - success = JS_LinkConstructorAndPrototype( - context, - rooted_interface_object, - rooted_prototype); - DCHECK(success); -} - -InterfaceData* GetInterfaceData(JSContext* context) { - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - // Use the address of the properties definition for this interface as a - // unique key for looking up the InterfaceData for this interface. - intptr_t key = reinterpret_cast<intptr_t>(&own_properties); - InterfaceData* interface_data = global_environment->GetInterfaceData(key); - if (!interface_data) { - interface_data = new InterfaceData(); - DCHECK(interface_data); - global_environment->CacheInterfaceData(key, interface_data); - DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key)); - } - return interface_data; -} - -} // namespace - -// static -JSObject* MozjsAnonymousNamedGetterInterface::CreateProxy( - JSContext* context, const scoped_refptr<Wrappable>& wrappable) { - DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); - JS::RootedObject global_object( - context, - MozjsGlobalEnvironment::GetFromContext(context)->global_object()); - DCHECK(global_object); - - InterfaceData* interface_data = GetInterfaceData(context); - JS::RootedObject prototype(context, GetPrototype(context, global_object)); - DCHECK(prototype); - JS::RootedObject new_object( - context, - JS_NewObjectWithGivenProto( - context, &instance_class_definition, prototype)); - DCHECK(new_object); - JS::RootedObject proxy(context, - ProxyHandler::NewProxy( - context, proxy_handler.Pointer(), new_object, prototype)); - WrapperPrivate::AddPrivateData(context, proxy, wrappable); - return proxy; -} - -// static -const JSClass* MozjsAnonymousNamedGetterInterface::PrototypeClass( - JSContext* context) { - DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); - JS::RootedObject global_object( - context, - MozjsGlobalEnvironment::GetFromContext(context)->global_object()); - DCHECK(global_object); - - JS::RootedObject prototype(context, GetPrototype(context, global_object)); - const JSClass* proto_class = JS_GetClass(prototype); - return proto_class; -} - -// static -JSObject* MozjsAnonymousNamedGetterInterface::GetPrototype( - JSContext* context, JS::HandleObject global_object) { - DCHECK(JS_IsGlobalObject(global_object)); - - InterfaceData* interface_data = GetInterfaceData(context); - if (!interface_data->prototype) { - // Create new prototype that has all the props and methods - InitializePrototypeAndInterfaceObject( - interface_data, context, global_object); - } - DCHECK(interface_data->prototype); - return interface_data->prototype; -} - -// static -JSObject* MozjsAnonymousNamedGetterInterface::GetInterfaceObject( - JSContext* context, JS::HandleObject global_object) { - DCHECK(JS_IsGlobalObject(global_object)); - - InterfaceData* interface_data = GetInterfaceData(context); - if (!interface_data->interface_object) { - InitializePrototypeAndInterfaceObject( - interface_data, context, global_object); - } - DCHECK(interface_data->interface_object); - return interface_data->interface_object; -} - - -namespace { -} // namespace - - -} // namespace testing -} // namespace bindings -} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsAnonymousNamedGetterInterface.h b/src/cobalt/bindings/generated/mozjs-45/testing/MozjsAnonymousNamedGetterInterface.h deleted file mode 100644 index 468ac97..0000000 --- a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsAnonymousNamedGetterInterface.h +++ /dev/null
@@ -1,54 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! -// Auto-generated from template: bindings/mozjs-45/templates/interface.h.template - -// clang-format off - -#ifndef MozjsAnonymousNamedGetterInterface_h -#define MozjsAnonymousNamedGetterInterface_h - -#include "base/hash_tables.h" -#include "base/lazy_instance.h" -#include "base/memory/ref_counted.h" -#include "base/threading/thread_checker.h" -#include "cobalt/base/polymorphic_downcast.h" -#include "cobalt/script/wrappable.h" -#include "cobalt/bindings/testing/anonymous_named_getter_interface.h" - -#include "third_party/mozjs-45/js/src/jsapi.h" - -namespace cobalt { -namespace bindings { -namespace testing { - -class MozjsAnonymousNamedGetterInterface { - public: - static JSObject* CreateProxy(JSContext* context, - const scoped_refptr<script::Wrappable>& wrappable); - static const JSClass* PrototypeClass(JSContext* context); - static JSObject* GetPrototype(JSContext* context, - JS::HandleObject global_object); - static JSObject* GetInterfaceObject(JSContext* context, - JS::HandleObject global_object); -}; - -} // namespace bindings -} // namespace testing -} // namespace cobalt - -#endif // MozjsAnonymousNamedGetterInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsAnonymousNamedIndexedGetterInterface.cc b/src/cobalt/bindings/generated/mozjs-45/testing/MozjsAnonymousNamedIndexedGetterInterface.cc deleted file mode 100644 index 8b9ca72..0000000 --- a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsAnonymousNamedIndexedGetterInterface.cc +++ /dev/null
@@ -1,586 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! -// Auto-generated from template: bindings/mozjs-45/templates/interface.cc.template - -// clang-format off - -#include "MozjsAnonymousNamedIndexedGetterInterface.h" - -#include "base/debug/trace_event.h" -#include "cobalt/base/polymorphic_downcast.h" -#include "cobalt/script/global_environment.h" -#include "cobalt/script/opaque_handle.h" -#include "cobalt/script/script_object.h" - -#include "base/lazy_instance.h" -#include "cobalt/script/mozjs-45/callback_function_conversion.h" -#include "cobalt/script/exception_state.h" -#include "cobalt/script/mozjs-45/conversion_helpers.h" -#include "cobalt/script/mozjs-45/mozjs_exception_state.h" -#include "cobalt/script/mozjs-45/mozjs_callback_function.h" -#include "cobalt/script/mozjs-45/mozjs_global_environment.h" -#include "cobalt/script/mozjs-45/mozjs_object_handle.h" -#include "cobalt/script/mozjs-45/mozjs_property_enumerator.h" -#include "cobalt/script/mozjs-45/mozjs_user_object_holder.h" -#include "cobalt/script/mozjs-45/proxy_handler.h" -#include "cobalt/script/mozjs-45/type_traits.h" -#include "cobalt/script/mozjs-45/wrapper_factory.h" -#include "cobalt/script/mozjs-45/wrapper_private.h" -#include "cobalt/script/property_enumerator.h" -#include "third_party/mozjs-45/js/src/jsapi.h" -#include "third_party/mozjs-45/js/src/jsfriendapi.h" - -namespace { -using cobalt::bindings::testing::AnonymousNamedIndexedGetterInterface; -using cobalt::bindings::testing::MozjsAnonymousNamedIndexedGetterInterface; -using cobalt::script::CallbackInterfaceTraits; -using cobalt::script::GlobalEnvironment; -using cobalt::script::OpaqueHandle; -using cobalt::script::OpaqueHandleHolder; -using cobalt::script::ScriptObject; -using cobalt::script::Wrappable; - -using cobalt::script::CallbackFunction; -using cobalt::script::CallbackInterfaceTraits; -using cobalt::script::ExceptionState; -using cobalt::script::mozjs::FromJSValue; -using cobalt::script::mozjs::kConversionFlagNullable; -using cobalt::script::mozjs::kConversionFlagRestricted; -using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString; -using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString; -using cobalt::script::mozjs::kNoConversionFlags; -using cobalt::script::mozjs::InterfaceData; -using cobalt::script::mozjs::MozjsCallbackFunction; -using cobalt::script::mozjs::MozjsExceptionState; -using cobalt::script::mozjs::MozjsGlobalEnvironment; -using cobalt::script::mozjs::MozjsUserObjectHolder; -using cobalt::script::mozjs::MozjsPropertyEnumerator; -using cobalt::script::mozjs::ProxyHandler; -using cobalt::script::mozjs::ToJSValue; -using cobalt::script::mozjs::TypeTraits; -using cobalt::script::mozjs::WrapperPrivate; -using cobalt::script::mozjs::WrapperFactory; -using cobalt::script::Wrappable; -} // namespace - -namespace cobalt { -namespace bindings { -namespace testing { - -namespace { - -bool IsSupportedNamedProperty(JSContext* context, JS::HandleObject object, - const std::string& property_name) { - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - AnonymousNamedIndexedGetterInterface* impl = - wrapper_private->wrappable<AnonymousNamedIndexedGetterInterface>().get(); - return impl->CanQueryNamedProperty(property_name); -} - -void EnumerateSupportedNames(JSContext* context, JS::HandleObject object, - JS::AutoIdVector* properties) { - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - AnonymousNamedIndexedGetterInterface* impl = - wrapper_private->wrappable<AnonymousNamedIndexedGetterInterface>().get(); - MozjsPropertyEnumerator enumerator(context, properties); - impl->EnumerateNamedProperties(&enumerator); -} - -bool GetNamedProperty( - JSContext* context, JS::HandleObject object, JS::HandleId id, - JS::MutableHandleValue vp) { - JS::RootedValue id_value(context); - if (!JS_IdToValue(context, id, &id_value)) { - NOTREACHED(); - return false; - } - - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - AnonymousNamedIndexedGetterInterface* impl = - wrapper_private->wrappable<AnonymousNamedIndexedGetterInterface>().get(); - std::string property_name; - FromJSValue(context, id_value, kNoConversionFlags, &exception_state, - &property_name); - if (exception_state.is_exception_set()) { - // The ID should be an integer or a string, so we shouldn't have any - // exceptions converting to string. - NOTREACHED(); - return false; - } - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->AnonymousNamedGetter(property_name), - &result_value); - } - if (!exception_state.is_exception_set()) { - vp.set(result_value); - } - return !exception_state.is_exception_set(); - -} - -bool SetNamedProperty( - JSContext* context, JS::HandleObject object, JS::HandleId id, - JS::MutableHandleValue vp, JS::ObjectOpResult& object_op_result) { - JS::RootedValue id_value(context); - if (!JS_IdToValue(context, id, &id_value)) { - NOTREACHED(); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - AnonymousNamedIndexedGetterInterface* impl = - wrapper_private->wrappable<AnonymousNamedIndexedGetterInterface>().get(); - std::string property_name; - FromJSValue(context, id_value, kNoConversionFlags, &exception_state, - &property_name); - if (exception_state.is_exception_set()) { - // The ID should be an integer or a string, so we shouldn't have any - // exceptions converting to string. - NOTREACHED(); - return false; - } - TypeTraits<std::string >::ConversionType value; - FromJSValue(context, vp, kNoConversionFlags, - &exception_state, &value); - if (exception_state.is_exception_set()) { - return false; - } - - impl->AnonymousNamedSetter(property_name, value); - result_value.set(JS::UndefinedHandleValue); - - if (!exception_state.is_exception_set()) { - return object_op_result.succeed(); - } else { - return false; - } -} - -bool IsSupportedIndexProperty(JSContext* context, JS::HandleObject object, - uint32_t index) { - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - AnonymousNamedIndexedGetterInterface* impl = - wrapper_private->wrappable<AnonymousNamedIndexedGetterInterface>().get(); - return index < impl->length(); -} - -void EnumerateSupportedIndexes(JSContext* context, JS::HandleObject object, - JS::AutoIdVector* properties) { - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - AnonymousNamedIndexedGetterInterface* impl = - wrapper_private->wrappable<AnonymousNamedIndexedGetterInterface>().get(); - const uint32_t kNumIndexedProperties = impl->length(); - for (uint32_t i = 0; i < kNumIndexedProperties; ++i) { - properties->append(INT_TO_JSID(i)); - } -} - -bool GetIndexedProperty( - JSContext* context, JS::HandleObject object, JS::HandleId id, - JS::MutableHandleValue vp) { - JS::RootedValue id_value(context); - if (!JS_IdToValue(context, id, &id_value)) { - NOTREACHED(); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - AnonymousNamedIndexedGetterInterface* impl = - wrapper_private->wrappable<AnonymousNamedIndexedGetterInterface>().get(); - uint32_t index; - FromJSValue(context, id_value, kNoConversionFlags, &exception_state, &index); - if (exception_state.is_exception_set()) { - // The ID should be an integer or a string, so we shouldn't have any - // exceptions converting to string. - NOTREACHED(); - return false; - } - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->AnonymousIndexedGetter(index), - &result_value); - } - if (!exception_state.is_exception_set()) { - vp.set(result_value); - } - return !exception_state.is_exception_set(); -} - -bool SetIndexedProperty( - JSContext* context, JS::HandleObject object, JS::HandleId id, - JS::MutableHandleValue vp, JS::ObjectOpResult& object_op_result) { - JS::RootedValue id_value(context); - if (!JS_IdToValue(context, id, &id_value)) { - NOTREACHED(); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - AnonymousNamedIndexedGetterInterface* impl = - wrapper_private->wrappable<AnonymousNamedIndexedGetterInterface>().get(); - uint32_t index; - FromJSValue(context, id_value, kNoConversionFlags, &exception_state, &index); - if (exception_state.is_exception_set()) { - // The ID should be an integer or a string, so we shouldn't have any - // exceptions converting to string. - NOTREACHED(); - return false; - } - TypeTraits<uint32_t >::ConversionType value; - FromJSValue(context, vp, kNoConversionFlags, - &exception_state, &value); - if (exception_state.is_exception_set()) { - return false; - } - - impl->AnonymousIndexedSetter(index, value); - result_value.set(JS::UndefinedHandleValue); - if (!exception_state.is_exception_set()) { - return object_op_result.succeed(); - } else { - return false; - } -} - -class MozjsAnonymousNamedIndexedGetterInterfaceHandler : public ProxyHandler { - public: - MozjsAnonymousNamedIndexedGetterInterfaceHandler() - : ProxyHandler(indexed_property_hooks, named_property_hooks) {} - - private: - static NamedPropertyHooks named_property_hooks; - static IndexedPropertyHooks indexed_property_hooks; -}; - -ProxyHandler::NamedPropertyHooks -MozjsAnonymousNamedIndexedGetterInterfaceHandler::named_property_hooks = { - IsSupportedNamedProperty, - EnumerateSupportedNames, - GetNamedProperty, - SetNamedProperty, - NULL, -}; -ProxyHandler::IndexedPropertyHooks -MozjsAnonymousNamedIndexedGetterInterfaceHandler::indexed_property_hooks = { - IsSupportedIndexProperty, - EnumerateSupportedIndexes, - GetIndexedProperty, - SetIndexedProperty, - NULL, -}; - -static base::LazyInstance<MozjsAnonymousNamedIndexedGetterInterfaceHandler> - proxy_handler; - -bool HasInstance(JSContext *context, JS::HandleObject type, - JS::MutableHandleValue vp, bool *success) { - JS::RootedObject global_object( - context, JS_GetGlobalForObject(context, type)); - DCHECK(global_object); - - JS::RootedObject prototype( - context, MozjsAnonymousNamedIndexedGetterInterface::GetPrototype(context, global_object)); - - // |IsDelegate| walks the prototype chain of an object returning true if - // .prototype is found. - bool is_delegate; - if (!IsDelegate(context, prototype, vp, &is_delegate)) { - *success = false; - return false; - } - - *success = is_delegate; - return true; -} - -const JSClass instance_class_definition = { - "AnonymousNamedIndexedGetterInterface", - 0 | JSCLASS_HAS_PRIVATE, - NULL, // addProperty - NULL, // delProperty - NULL, // getProperty - NULL, // setProperty - NULL, // enumerate - NULL, // resolve - NULL, // mayResolve - &WrapperPrivate::Finalizer, // finalize - NULL, // call - NULL, // hasInstance - NULL, // construct - &WrapperPrivate::Trace, // trace -}; - -const JSClass prototype_class_definition = { - "AnonymousNamedIndexedGetterInterfacePrototype", -}; - -const JSClass interface_object_class_definition = { - "AnonymousNamedIndexedGetterInterfaceConstructor", - 0, - NULL, // addProperty - NULL, // delProperty - NULL, // getProperty - NULL, // setProperty - NULL, // enumerate - NULL, // resolve - NULL, // mayResolve - NULL, // finalize - NULL, // call - &HasInstance, - NULL, -}; - -bool get_length( - JSContext* context, unsigned argc, JS::Value* vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<AnonymousNamedIndexedGetterInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - AnonymousNamedIndexedGetterInterface* impl = - wrapper_private->wrappable<AnonymousNamedIndexedGetterInterface>().get(); - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->length(), - &result_value); - } - if (!exception_state.is_exception_set()) { - args.rval().set(result_value); - } - return !exception_state.is_exception_set(); -} - - - - -const JSPropertySpec prototype_properties[] = { - { // Readonly attribute - "length", - JSPROP_SHARED | JSPROP_ENUMERATE, - { { &get_length, NULL } }, - JSNATIVE_WRAPPER(NULL), - }, - JS_PS_END -}; - -const JSFunctionSpec prototype_functions[] = { - JS_FS_END -}; - -const JSPropertySpec interface_object_properties[] = { - JS_PS_END -}; - -const JSFunctionSpec interface_object_functions[] = { - JS_FS_END -}; - -const JSPropertySpec own_properties[] = { - JS_PS_END -}; - -void InitializePrototypeAndInterfaceObject( - InterfaceData* interface_data, JSContext* context, - JS::HandleObject global_object) { - DCHECK(!interface_data->prototype); - DCHECK(!interface_data->interface_object); - DCHECK(JS_IsGlobalObject(global_object)); - - JS::RootedObject parent_prototype( - context, JS_GetObjectPrototype(context, global_object)); - DCHECK(parent_prototype); - - interface_data->prototype = JS_NewObjectWithGivenProto( - context, &prototype_class_definition, parent_prototype - ); - - JS::RootedObject rooted_prototype(context, interface_data->prototype); - bool success = JS_DefineProperties( - context, - rooted_prototype, - prototype_properties); - - DCHECK(success); - success = JS_DefineFunctions( - context, rooted_prototype, prototype_functions); - DCHECK(success); - - JS::RootedObject function_prototype( - context, JS_GetFunctionPrototype(context, global_object)); - DCHECK(function_prototype); - // Create the Interface object. - interface_data->interface_object = JS_NewObjectWithGivenProto( - context, &interface_object_class_definition, - function_prototype); - - // Add the InterfaceObject.name property. - JS::RootedObject rooted_interface_object( - context, interface_data->interface_object); - JS::RootedValue name_value(context); - const char name[] = - "AnonymousNamedIndexedGetterInterface"; - name_value.setString(JS_NewStringCopyZ(context, name)); - success = JS_DefineProperty( - context, rooted_interface_object, "name", name_value, JSPROP_READONLY, - NULL, NULL); - DCHECK(success); - - // Define interface object properties (including constants). - success = JS_DefineProperties(context, rooted_interface_object, - interface_object_properties); - DCHECK(success); - // Define interface object functions (static). - success = JS_DefineFunctions(context, rooted_interface_object, - interface_object_functions); - DCHECK(success); - - // Set the Prototype.constructor and Constructor.prototype properties. - DCHECK(interface_data->interface_object); - DCHECK(interface_data->prototype); - success = JS_LinkConstructorAndPrototype( - context, - rooted_interface_object, - rooted_prototype); - DCHECK(success); -} - -InterfaceData* GetInterfaceData(JSContext* context) { - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - // Use the address of the properties definition for this interface as a - // unique key for looking up the InterfaceData for this interface. - intptr_t key = reinterpret_cast<intptr_t>(&own_properties); - InterfaceData* interface_data = global_environment->GetInterfaceData(key); - if (!interface_data) { - interface_data = new InterfaceData(); - DCHECK(interface_data); - global_environment->CacheInterfaceData(key, interface_data); - DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key)); - } - return interface_data; -} - -} // namespace - -// static -JSObject* MozjsAnonymousNamedIndexedGetterInterface::CreateProxy( - JSContext* context, const scoped_refptr<Wrappable>& wrappable) { - DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); - JS::RootedObject global_object( - context, - MozjsGlobalEnvironment::GetFromContext(context)->global_object()); - DCHECK(global_object); - - InterfaceData* interface_data = GetInterfaceData(context); - JS::RootedObject prototype(context, GetPrototype(context, global_object)); - DCHECK(prototype); - JS::RootedObject new_object( - context, - JS_NewObjectWithGivenProto( - context, &instance_class_definition, prototype)); - DCHECK(new_object); - JS::RootedObject proxy(context, - ProxyHandler::NewProxy( - context, proxy_handler.Pointer(), new_object, prototype)); - WrapperPrivate::AddPrivateData(context, proxy, wrappable); - return proxy; -} - -// static -const JSClass* MozjsAnonymousNamedIndexedGetterInterface::PrototypeClass( - JSContext* context) { - DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); - JS::RootedObject global_object( - context, - MozjsGlobalEnvironment::GetFromContext(context)->global_object()); - DCHECK(global_object); - - JS::RootedObject prototype(context, GetPrototype(context, global_object)); - const JSClass* proto_class = JS_GetClass(prototype); - return proto_class; -} - -// static -JSObject* MozjsAnonymousNamedIndexedGetterInterface::GetPrototype( - JSContext* context, JS::HandleObject global_object) { - DCHECK(JS_IsGlobalObject(global_object)); - - InterfaceData* interface_data = GetInterfaceData(context); - if (!interface_data->prototype) { - // Create new prototype that has all the props and methods - InitializePrototypeAndInterfaceObject( - interface_data, context, global_object); - } - DCHECK(interface_data->prototype); - return interface_data->prototype; -} - -// static -JSObject* MozjsAnonymousNamedIndexedGetterInterface::GetInterfaceObject( - JSContext* context, JS::HandleObject global_object) { - DCHECK(JS_IsGlobalObject(global_object)); - - InterfaceData* interface_data = GetInterfaceData(context); - if (!interface_data->interface_object) { - InitializePrototypeAndInterfaceObject( - interface_data, context, global_object); - } - DCHECK(interface_data->interface_object); - return interface_data->interface_object; -} - - -namespace { -} // namespace - - -} // namespace testing -} // namespace bindings -} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsAnonymousNamedIndexedGetterInterface.h b/src/cobalt/bindings/generated/mozjs-45/testing/MozjsAnonymousNamedIndexedGetterInterface.h deleted file mode 100644 index e47b84a..0000000 --- a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsAnonymousNamedIndexedGetterInterface.h +++ /dev/null
@@ -1,54 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! -// Auto-generated from template: bindings/mozjs-45/templates/interface.h.template - -// clang-format off - -#ifndef MozjsAnonymousNamedIndexedGetterInterface_h -#define MozjsAnonymousNamedIndexedGetterInterface_h - -#include "base/hash_tables.h" -#include "base/lazy_instance.h" -#include "base/memory/ref_counted.h" -#include "base/threading/thread_checker.h" -#include "cobalt/base/polymorphic_downcast.h" -#include "cobalt/script/wrappable.h" -#include "cobalt/bindings/testing/anonymous_named_indexed_getter_interface.h" - -#include "third_party/mozjs-45/js/src/jsapi.h" - -namespace cobalt { -namespace bindings { -namespace testing { - -class MozjsAnonymousNamedIndexedGetterInterface { - public: - static JSObject* CreateProxy(JSContext* context, - const scoped_refptr<script::Wrappable>& wrappable); - static const JSClass* PrototypeClass(JSContext* context); - static JSObject* GetPrototype(JSContext* context, - JS::HandleObject global_object); - static JSObject* GetInterfaceObject(JSContext* context, - JS::HandleObject global_object); -}; - -} // namespace bindings -} // namespace testing -} // namespace cobalt - -#endif // MozjsAnonymousNamedIndexedGetterInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsArbitraryInterface.cc b/src/cobalt/bindings/generated/mozjs-45/testing/MozjsArbitraryInterface.cc deleted file mode 100644 index 331d4b0..0000000 --- a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsArbitraryInterface.cc +++ /dev/null
@@ -1,492 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! -// Auto-generated from template: bindings/mozjs-45/templates/interface.cc.template - -// clang-format off - -#include "MozjsArbitraryInterface.h" - -#include "base/debug/trace_event.h" -#include "cobalt/base/polymorphic_downcast.h" -#include "cobalt/script/global_environment.h" -#include "cobalt/script/opaque_handle.h" -#include "cobalt/script/script_object.h" - -#include "base/lazy_instance.h" -#include "cobalt/script/mozjs-45/callback_function_conversion.h" -#include "cobalt/script/exception_state.h" -#include "cobalt/script/mozjs-45/conversion_helpers.h" -#include "cobalt/script/mozjs-45/mozjs_exception_state.h" -#include "cobalt/script/mozjs-45/mozjs_callback_function.h" -#include "cobalt/script/mozjs-45/mozjs_global_environment.h" -#include "cobalt/script/mozjs-45/mozjs_object_handle.h" -#include "cobalt/script/mozjs-45/mozjs_property_enumerator.h" -#include "cobalt/script/mozjs-45/mozjs_user_object_holder.h" -#include "cobalt/script/mozjs-45/proxy_handler.h" -#include "cobalt/script/mozjs-45/type_traits.h" -#include "cobalt/script/mozjs-45/wrapper_factory.h" -#include "cobalt/script/mozjs-45/wrapper_private.h" -#include "cobalt/script/property_enumerator.h" -#include "third_party/mozjs-45/js/src/jsapi.h" -#include "third_party/mozjs-45/js/src/jsfriendapi.h" - -namespace { -using cobalt::bindings::testing::ArbitraryInterface; -using cobalt::bindings::testing::MozjsArbitraryInterface; -using cobalt::script::CallbackInterfaceTraits; -using cobalt::script::GlobalEnvironment; -using cobalt::script::OpaqueHandle; -using cobalt::script::OpaqueHandleHolder; -using cobalt::script::ScriptObject; -using cobalt::script::Wrappable; - -using cobalt::script::CallbackFunction; -using cobalt::script::CallbackInterfaceTraits; -using cobalt::script::ExceptionState; -using cobalt::script::mozjs::FromJSValue; -using cobalt::script::mozjs::kConversionFlagNullable; -using cobalt::script::mozjs::kConversionFlagRestricted; -using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString; -using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString; -using cobalt::script::mozjs::kNoConversionFlags; -using cobalt::script::mozjs::InterfaceData; -using cobalt::script::mozjs::MozjsCallbackFunction; -using cobalt::script::mozjs::MozjsExceptionState; -using cobalt::script::mozjs::MozjsGlobalEnvironment; -using cobalt::script::mozjs::MozjsUserObjectHolder; -using cobalt::script::mozjs::MozjsPropertyEnumerator; -using cobalt::script::mozjs::ProxyHandler; -using cobalt::script::mozjs::ToJSValue; -using cobalt::script::mozjs::TypeTraits; -using cobalt::script::mozjs::WrapperPrivate; -using cobalt::script::mozjs::WrapperFactory; -using cobalt::script::Wrappable; -} // namespace - -namespace cobalt { -namespace bindings { -namespace testing { - -namespace { - -class MozjsArbitraryInterfaceHandler : public ProxyHandler { - public: - MozjsArbitraryInterfaceHandler() - : ProxyHandler(indexed_property_hooks, named_property_hooks) {} - - private: - static NamedPropertyHooks named_property_hooks; - static IndexedPropertyHooks indexed_property_hooks; -}; - -ProxyHandler::NamedPropertyHooks -MozjsArbitraryInterfaceHandler::named_property_hooks = { - NULL, - NULL, - NULL, - NULL, - NULL, -}; -ProxyHandler::IndexedPropertyHooks -MozjsArbitraryInterfaceHandler::indexed_property_hooks = { - NULL, - NULL, - NULL, - NULL, - NULL, -}; - -static base::LazyInstance<MozjsArbitraryInterfaceHandler> - proxy_handler; - -bool Constructor(JSContext* context, unsigned int argc, JS::Value* vp); -bool HasInstance(JSContext *context, JS::HandleObject type, - JS::MutableHandleValue vp, bool *success) { - JS::RootedObject global_object( - context, JS_GetGlobalForObject(context, type)); - DCHECK(global_object); - - JS::RootedObject prototype( - context, MozjsArbitraryInterface::GetPrototype(context, global_object)); - - // |IsDelegate| walks the prototype chain of an object returning true if - // .prototype is found. - bool is_delegate; - if (!IsDelegate(context, prototype, vp, &is_delegate)) { - *success = false; - return false; - } - - *success = is_delegate; - return true; -} - -const JSClass instance_class_definition = { - "ArbitraryInterface", - 0 | JSCLASS_HAS_PRIVATE, - NULL, // addProperty - NULL, // delProperty - NULL, // getProperty - NULL, // setProperty - NULL, // enumerate - NULL, // resolve - NULL, // mayResolve - &WrapperPrivate::Finalizer, // finalize - NULL, // call - NULL, // hasInstance - NULL, // construct - &WrapperPrivate::Trace, // trace -}; - -const JSClass prototype_class_definition = { - "ArbitraryInterfacePrototype", -}; - -const JSClass interface_object_class_definition = { - "ArbitraryInterfaceConstructor", - 0, - NULL, // addProperty - NULL, // delProperty - NULL, // getProperty - NULL, // setProperty - NULL, // enumerate - NULL, // resolve - NULL, // mayResolve - NULL, // finalize - NULL, // call - &HasInstance, - Constructor, -}; - -bool get_arbitraryProperty( - JSContext* context, unsigned argc, JS::Value* vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<ArbitraryInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - ArbitraryInterface* impl = - wrapper_private->wrappable<ArbitraryInterface>().get(); - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->arbitrary_property(), - &result_value); - } - if (!exception_state.is_exception_set()) { - args.rval().set(result_value); - } - return !exception_state.is_exception_set(); -} - -bool set_arbitraryProperty( - JSContext* context, unsigned argc, JS::Value* vp) { - - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<ArbitraryInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - ArbitraryInterface* impl = - wrapper_private->wrappable<ArbitraryInterface>().get(); - TypeTraits<std::string >::ConversionType value; - if (args.length() != 1) { - NOTREACHED(); - return false; - } - FromJSValue(context, args[0], kNoConversionFlags, &exception_state, - &value); - if (exception_state.is_exception_set()) { - return false; - } - - impl->set_arbitrary_property(value); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - -bool fcn_arbitraryFunction( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, &object)) { - NOTREACHED(); - return false; - } - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<ArbitraryInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - ArbitraryInterface* impl = - wrapper_private->wrappable<ArbitraryInterface>().get(); - - impl->ArbitraryFunction(); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - - - -const JSPropertySpec prototype_properties[] = { - { // Read/Write property - "arbitraryProperty", - JSPROP_SHARED | JSPROP_ENUMERATE, - { { &get_arbitraryProperty, NULL } }, - { { &set_arbitraryProperty, NULL } }, - }, - JS_PS_END -}; - -const JSFunctionSpec prototype_functions[] = { - JS_FNSPEC( - "arbitraryFunction", fcn_arbitraryFunction, NULL, - 0, JSPROP_ENUMERATE, NULL), - JS_FS_END -}; - -const JSPropertySpec interface_object_properties[] = { - JS_PS_END -}; - -const JSFunctionSpec interface_object_functions[] = { - JS_FS_END -}; - -const JSPropertySpec own_properties[] = { - JS_PS_END -}; - -void InitializePrototypeAndInterfaceObject( - InterfaceData* interface_data, JSContext* context, - JS::HandleObject global_object) { - DCHECK(!interface_data->prototype); - DCHECK(!interface_data->interface_object); - DCHECK(JS_IsGlobalObject(global_object)); - - JS::RootedObject parent_prototype( - context, JS_GetObjectPrototype(context, global_object)); - DCHECK(parent_prototype); - - interface_data->prototype = JS_NewObjectWithGivenProto( - context, &prototype_class_definition, parent_prototype - ); - - JS::RootedObject rooted_prototype(context, interface_data->prototype); - bool success = JS_DefineProperties( - context, - rooted_prototype, - prototype_properties); - - DCHECK(success); - success = JS_DefineFunctions( - context, rooted_prototype, prototype_functions); - DCHECK(success); - - JS::RootedObject function_prototype( - context, JS_GetFunctionPrototype(context, global_object)); - DCHECK(function_prototype); - // Create the Interface object. - interface_data->interface_object = JS_NewObjectWithGivenProto( - context, &interface_object_class_definition, - function_prototype); - - // Add the InterfaceObject.name property. - JS::RootedObject rooted_interface_object( - context, interface_data->interface_object); - JS::RootedValue name_value(context); - const char name[] = - "ArbitraryInterface"; - name_value.setString(JS_NewStringCopyZ(context, name)); - success = JS_DefineProperty( - context, rooted_interface_object, "name", name_value, JSPROP_READONLY, - NULL, NULL); - DCHECK(success); - - // Add the InterfaceObject.length property. It is set to the length of the - // shortest argument list of all overload constructors. - JS::RootedValue length_value(context); - length_value.setInt32(0); - success = JS_DefineProperty( - context, rooted_interface_object, "length", length_value, - JSPROP_READONLY, NULL, NULL); - DCHECK(success); - - // Define interface object properties (including constants). - success = JS_DefineProperties(context, rooted_interface_object, - interface_object_properties); - DCHECK(success); - // Define interface object functions (static). - success = JS_DefineFunctions(context, rooted_interface_object, - interface_object_functions); - DCHECK(success); - - // Set the Prototype.constructor and Constructor.prototype properties. - DCHECK(interface_data->interface_object); - DCHECK(interface_data->prototype); - success = JS_LinkConstructorAndPrototype( - context, - rooted_interface_object, - rooted_prototype); - DCHECK(success); -} - -InterfaceData* GetInterfaceData(JSContext* context) { - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - // Use the address of the properties definition for this interface as a - // unique key for looking up the InterfaceData for this interface. - intptr_t key = reinterpret_cast<intptr_t>(&own_properties); - InterfaceData* interface_data = global_environment->GetInterfaceData(key); - if (!interface_data) { - interface_data = new InterfaceData(); - DCHECK(interface_data); - global_environment->CacheInterfaceData(key, interface_data); - DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key)); - } - return interface_data; -} - -} // namespace - -// static -JSObject* MozjsArbitraryInterface::CreateProxy( - JSContext* context, const scoped_refptr<Wrappable>& wrappable) { - DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); - JS::RootedObject global_object( - context, - MozjsGlobalEnvironment::GetFromContext(context)->global_object()); - DCHECK(global_object); - - InterfaceData* interface_data = GetInterfaceData(context); - JS::RootedObject prototype(context, GetPrototype(context, global_object)); - DCHECK(prototype); - JS::RootedObject new_object( - context, - JS_NewObjectWithGivenProto( - context, &instance_class_definition, prototype)); - DCHECK(new_object); - JS::RootedObject proxy(context, - ProxyHandler::NewProxy( - context, proxy_handler.Pointer(), new_object, prototype)); - WrapperPrivate::AddPrivateData(context, proxy, wrappable); - return proxy; -} - -// static -const JSClass* MozjsArbitraryInterface::PrototypeClass( - JSContext* context) { - DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); - JS::RootedObject global_object( - context, - MozjsGlobalEnvironment::GetFromContext(context)->global_object()); - DCHECK(global_object); - - JS::RootedObject prototype(context, GetPrototype(context, global_object)); - const JSClass* proto_class = JS_GetClass(prototype); - return proto_class; -} - -// static -JSObject* MozjsArbitraryInterface::GetPrototype( - JSContext* context, JS::HandleObject global_object) { - DCHECK(JS_IsGlobalObject(global_object)); - - InterfaceData* interface_data = GetInterfaceData(context); - if (!interface_data->prototype) { - // Create new prototype that has all the props and methods - InitializePrototypeAndInterfaceObject( - interface_data, context, global_object); - } - DCHECK(interface_data->prototype); - return interface_data->prototype; -} - -// static -JSObject* MozjsArbitraryInterface::GetInterfaceObject( - JSContext* context, JS::HandleObject global_object) { - DCHECK(JS_IsGlobalObject(global_object)); - - InterfaceData* interface_data = GetInterfaceData(context); - if (!interface_data->interface_object) { - InitializePrototypeAndInterfaceObject( - interface_data, context, global_object); - } - DCHECK(interface_data->interface_object); - return interface_data->interface_object; -} - - -namespace { -bool Constructor(JSContext* context, unsigned int argc, JS::Value* vp) { - MozjsExceptionState exception_state(context); - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - - scoped_refptr<ArbitraryInterface> new_object = - new ArbitraryInterface(); - JS::RootedValue result_value(context); - ToJSValue(context, new_object, &result_value); - DCHECK(result_value.isObject()); - args.rval().setObject(result_value.toObject()); - return true; -} -} // namespace - - -} // namespace testing -} // namespace bindings -} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsArbitraryInterface.h b/src/cobalt/bindings/generated/mozjs-45/testing/MozjsArbitraryInterface.h deleted file mode 100644 index 0dc7b0d..0000000 --- a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsArbitraryInterface.h +++ /dev/null
@@ -1,54 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! -// Auto-generated from template: bindings/mozjs-45/templates/interface.h.template - -// clang-format off - -#ifndef MozjsArbitraryInterface_h -#define MozjsArbitraryInterface_h - -#include "base/hash_tables.h" -#include "base/lazy_instance.h" -#include "base/memory/ref_counted.h" -#include "base/threading/thread_checker.h" -#include "cobalt/base/polymorphic_downcast.h" -#include "cobalt/script/wrappable.h" -#include "cobalt/bindings/testing/arbitrary_interface.h" - -#include "third_party/mozjs-45/js/src/jsapi.h" - -namespace cobalt { -namespace bindings { -namespace testing { - -class MozjsArbitraryInterface { - public: - static JSObject* CreateProxy(JSContext* context, - const scoped_refptr<script::Wrappable>& wrappable); - static const JSClass* PrototypeClass(JSContext* context); - static JSObject* GetPrototype(JSContext* context, - JS::HandleObject global_object); - static JSObject* GetInterfaceObject(JSContext* context, - JS::HandleObject global_object); -}; - -} // namespace bindings -} // namespace testing -} // namespace cobalt - -#endif // MozjsArbitraryInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsBaseInterface.cc b/src/cobalt/bindings/generated/mozjs-45/testing/MozjsBaseInterface.cc deleted file mode 100644 index 54b983e..0000000 --- a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsBaseInterface.cc +++ /dev/null
@@ -1,455 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! -// Auto-generated from template: bindings/mozjs-45/templates/interface.cc.template - -// clang-format off - -#include "MozjsBaseInterface.h" - -#include "base/debug/trace_event.h" -#include "cobalt/base/polymorphic_downcast.h" -#include "cobalt/script/global_environment.h" -#include "cobalt/script/opaque_handle.h" -#include "cobalt/script/script_object.h" - -#include "base/lazy_instance.h" -#include "cobalt/script/mozjs-45/callback_function_conversion.h" -#include "cobalt/script/exception_state.h" -#include "cobalt/script/mozjs-45/conversion_helpers.h" -#include "cobalt/script/mozjs-45/mozjs_exception_state.h" -#include "cobalt/script/mozjs-45/mozjs_callback_function.h" -#include "cobalt/script/mozjs-45/mozjs_global_environment.h" -#include "cobalt/script/mozjs-45/mozjs_object_handle.h" -#include "cobalt/script/mozjs-45/mozjs_property_enumerator.h" -#include "cobalt/script/mozjs-45/mozjs_user_object_holder.h" -#include "cobalt/script/mozjs-45/proxy_handler.h" -#include "cobalt/script/mozjs-45/type_traits.h" -#include "cobalt/script/mozjs-45/wrapper_factory.h" -#include "cobalt/script/mozjs-45/wrapper_private.h" -#include "cobalt/script/property_enumerator.h" -#include "third_party/mozjs-45/js/src/jsapi.h" -#include "third_party/mozjs-45/js/src/jsfriendapi.h" - -namespace { -using cobalt::bindings::testing::BaseInterface; -using cobalt::bindings::testing::MozjsBaseInterface; -using cobalt::script::CallbackInterfaceTraits; -using cobalt::script::GlobalEnvironment; -using cobalt::script::OpaqueHandle; -using cobalt::script::OpaqueHandleHolder; -using cobalt::script::ScriptObject; -using cobalt::script::Wrappable; - -using cobalt::script::CallbackFunction; -using cobalt::script::CallbackInterfaceTraits; -using cobalt::script::ExceptionState; -using cobalt::script::mozjs::FromJSValue; -using cobalt::script::mozjs::kConversionFlagNullable; -using cobalt::script::mozjs::kConversionFlagRestricted; -using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString; -using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString; -using cobalt::script::mozjs::kNoConversionFlags; -using cobalt::script::mozjs::InterfaceData; -using cobalt::script::mozjs::MozjsCallbackFunction; -using cobalt::script::mozjs::MozjsExceptionState; -using cobalt::script::mozjs::MozjsGlobalEnvironment; -using cobalt::script::mozjs::MozjsUserObjectHolder; -using cobalt::script::mozjs::MozjsPropertyEnumerator; -using cobalt::script::mozjs::ProxyHandler; -using cobalt::script::mozjs::ToJSValue; -using cobalt::script::mozjs::TypeTraits; -using cobalt::script::mozjs::WrapperPrivate; -using cobalt::script::mozjs::WrapperFactory; -using cobalt::script::Wrappable; -} // namespace - -namespace cobalt { -namespace bindings { -namespace testing { - -namespace { - -class MozjsBaseInterfaceHandler : public ProxyHandler { - public: - MozjsBaseInterfaceHandler() - : ProxyHandler(indexed_property_hooks, named_property_hooks) {} - - private: - static NamedPropertyHooks named_property_hooks; - static IndexedPropertyHooks indexed_property_hooks; -}; - -ProxyHandler::NamedPropertyHooks -MozjsBaseInterfaceHandler::named_property_hooks = { - NULL, - NULL, - NULL, - NULL, - NULL, -}; -ProxyHandler::IndexedPropertyHooks -MozjsBaseInterfaceHandler::indexed_property_hooks = { - NULL, - NULL, - NULL, - NULL, - NULL, -}; - -static base::LazyInstance<MozjsBaseInterfaceHandler> - proxy_handler; - -bool Constructor(JSContext* context, unsigned int argc, JS::Value* vp); -bool HasInstance(JSContext *context, JS::HandleObject type, - JS::MutableHandleValue vp, bool *success) { - JS::RootedObject global_object( - context, JS_GetGlobalForObject(context, type)); - DCHECK(global_object); - - JS::RootedObject prototype( - context, MozjsBaseInterface::GetPrototype(context, global_object)); - - // |IsDelegate| walks the prototype chain of an object returning true if - // .prototype is found. - bool is_delegate; - if (!IsDelegate(context, prototype, vp, &is_delegate)) { - *success = false; - return false; - } - - *success = is_delegate; - return true; -} - -const JSClass instance_class_definition = { - "BaseInterface", - 0 | JSCLASS_HAS_PRIVATE, - NULL, // addProperty - NULL, // delProperty - NULL, // getProperty - NULL, // setProperty - NULL, // enumerate - NULL, // resolve - NULL, // mayResolve - &WrapperPrivate::Finalizer, // finalize - NULL, // call - NULL, // hasInstance - NULL, // construct - &WrapperPrivate::Trace, // trace -}; - -const JSClass prototype_class_definition = { - "BaseInterfacePrototype", -}; - -const JSClass interface_object_class_definition = { - "BaseInterfaceConstructor", - 0, - NULL, // addProperty - NULL, // delProperty - NULL, // getProperty - NULL, // setProperty - NULL, // enumerate - NULL, // resolve - NULL, // mayResolve - NULL, // finalize - NULL, // call - &HasInstance, - Constructor, -}; - -bool get_baseAttribute( - JSContext* context, unsigned argc, JS::Value* vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<BaseInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - BaseInterface* impl = - wrapper_private->wrappable<BaseInterface>().get(); - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->base_attribute(), - &result_value); - } - if (!exception_state.is_exception_set()) { - args.rval().set(result_value); - } - return !exception_state.is_exception_set(); -} - - -bool fcn_baseOperation( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, &object)) { - NOTREACHED(); - return false; - } - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<BaseInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - BaseInterface* impl = - wrapper_private->wrappable<BaseInterface>().get(); - - impl->BaseOperation(); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - - - -const JSPropertySpec prototype_properties[] = { - { // Readonly attribute - "baseAttribute", - JSPROP_SHARED | JSPROP_ENUMERATE, - { { &get_baseAttribute, NULL } }, - JSNATIVE_WRAPPER(NULL), - }, - JS_PS_END -}; - -const JSFunctionSpec prototype_functions[] = { - JS_FNSPEC( - "baseOperation", fcn_baseOperation, NULL, - 0, JSPROP_ENUMERATE, NULL), - JS_FS_END -}; - -const JSPropertySpec interface_object_properties[] = { - JS_PS_END -}; - -const JSFunctionSpec interface_object_functions[] = { - JS_FS_END -}; - -const JSPropertySpec own_properties[] = { - JS_PS_END -}; - -void InitializePrototypeAndInterfaceObject( - InterfaceData* interface_data, JSContext* context, - JS::HandleObject global_object) { - DCHECK(!interface_data->prototype); - DCHECK(!interface_data->interface_object); - DCHECK(JS_IsGlobalObject(global_object)); - - JS::RootedObject parent_prototype( - context, JS_GetObjectPrototype(context, global_object)); - DCHECK(parent_prototype); - - interface_data->prototype = JS_NewObjectWithGivenProto( - context, &prototype_class_definition, parent_prototype - ); - - JS::RootedObject rooted_prototype(context, interface_data->prototype); - bool success = JS_DefineProperties( - context, - rooted_prototype, - prototype_properties); - - DCHECK(success); - success = JS_DefineFunctions( - context, rooted_prototype, prototype_functions); - DCHECK(success); - - JS::RootedObject function_prototype( - context, JS_GetFunctionPrototype(context, global_object)); - DCHECK(function_prototype); - // Create the Interface object. - interface_data->interface_object = JS_NewObjectWithGivenProto( - context, &interface_object_class_definition, - function_prototype); - - // Add the InterfaceObject.name property. - JS::RootedObject rooted_interface_object( - context, interface_data->interface_object); - JS::RootedValue name_value(context); - const char name[] = - "BaseInterface"; - name_value.setString(JS_NewStringCopyZ(context, name)); - success = JS_DefineProperty( - context, rooted_interface_object, "name", name_value, JSPROP_READONLY, - NULL, NULL); - DCHECK(success); - - // Add the InterfaceObject.length property. It is set to the length of the - // shortest argument list of all overload constructors. - JS::RootedValue length_value(context); - length_value.setInt32(0); - success = JS_DefineProperty( - context, rooted_interface_object, "length", length_value, - JSPROP_READONLY, NULL, NULL); - DCHECK(success); - - // Define interface object properties (including constants). - success = JS_DefineProperties(context, rooted_interface_object, - interface_object_properties); - DCHECK(success); - // Define interface object functions (static). - success = JS_DefineFunctions(context, rooted_interface_object, - interface_object_functions); - DCHECK(success); - - // Set the Prototype.constructor and Constructor.prototype properties. - DCHECK(interface_data->interface_object); - DCHECK(interface_data->prototype); - success = JS_LinkConstructorAndPrototype( - context, - rooted_interface_object, - rooted_prototype); - DCHECK(success); -} - -InterfaceData* GetInterfaceData(JSContext* context) { - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - // Use the address of the properties definition for this interface as a - // unique key for looking up the InterfaceData for this interface. - intptr_t key = reinterpret_cast<intptr_t>(&own_properties); - InterfaceData* interface_data = global_environment->GetInterfaceData(key); - if (!interface_data) { - interface_data = new InterfaceData(); - DCHECK(interface_data); - global_environment->CacheInterfaceData(key, interface_data); - DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key)); - } - return interface_data; -} - -} // namespace - -// static -JSObject* MozjsBaseInterface::CreateProxy( - JSContext* context, const scoped_refptr<Wrappable>& wrappable) { - DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); - JS::RootedObject global_object( - context, - MozjsGlobalEnvironment::GetFromContext(context)->global_object()); - DCHECK(global_object); - - InterfaceData* interface_data = GetInterfaceData(context); - JS::RootedObject prototype(context, GetPrototype(context, global_object)); - DCHECK(prototype); - JS::RootedObject new_object( - context, - JS_NewObjectWithGivenProto( - context, &instance_class_definition, prototype)); - DCHECK(new_object); - JS::RootedObject proxy(context, - ProxyHandler::NewProxy( - context, proxy_handler.Pointer(), new_object, prototype)); - WrapperPrivate::AddPrivateData(context, proxy, wrappable); - return proxy; -} - -// static -const JSClass* MozjsBaseInterface::PrototypeClass( - JSContext* context) { - DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); - JS::RootedObject global_object( - context, - MozjsGlobalEnvironment::GetFromContext(context)->global_object()); - DCHECK(global_object); - - JS::RootedObject prototype(context, GetPrototype(context, global_object)); - const JSClass* proto_class = JS_GetClass(prototype); - return proto_class; -} - -// static -JSObject* MozjsBaseInterface::GetPrototype( - JSContext* context, JS::HandleObject global_object) { - DCHECK(JS_IsGlobalObject(global_object)); - - InterfaceData* interface_data = GetInterfaceData(context); - if (!interface_data->prototype) { - // Create new prototype that has all the props and methods - InitializePrototypeAndInterfaceObject( - interface_data, context, global_object); - } - DCHECK(interface_data->prototype); - return interface_data->prototype; -} - -// static -JSObject* MozjsBaseInterface::GetInterfaceObject( - JSContext* context, JS::HandleObject global_object) { - DCHECK(JS_IsGlobalObject(global_object)); - - InterfaceData* interface_data = GetInterfaceData(context); - if (!interface_data->interface_object) { - InitializePrototypeAndInterfaceObject( - interface_data, context, global_object); - } - DCHECK(interface_data->interface_object); - return interface_data->interface_object; -} - - -namespace { -bool Constructor(JSContext* context, unsigned int argc, JS::Value* vp) { - MozjsExceptionState exception_state(context); - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - - scoped_refptr<BaseInterface> new_object = - new BaseInterface(); - JS::RootedValue result_value(context); - ToJSValue(context, new_object, &result_value); - DCHECK(result_value.isObject()); - args.rval().setObject(result_value.toObject()); - return true; -} -} // namespace - - -} // namespace testing -} // namespace bindings -} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsBaseInterface.h b/src/cobalt/bindings/generated/mozjs-45/testing/MozjsBaseInterface.h deleted file mode 100644 index 0845470..0000000 --- a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsBaseInterface.h +++ /dev/null
@@ -1,54 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! -// Auto-generated from template: bindings/mozjs-45/templates/interface.h.template - -// clang-format off - -#ifndef MozjsBaseInterface_h -#define MozjsBaseInterface_h - -#include "base/hash_tables.h" -#include "base/lazy_instance.h" -#include "base/memory/ref_counted.h" -#include "base/threading/thread_checker.h" -#include "cobalt/base/polymorphic_downcast.h" -#include "cobalt/script/wrappable.h" -#include "cobalt/bindings/testing/base_interface.h" - -#include "third_party/mozjs-45/js/src/jsapi.h" - -namespace cobalt { -namespace bindings { -namespace testing { - -class MozjsBaseInterface { - public: - static JSObject* CreateProxy(JSContext* context, - const scoped_refptr<script::Wrappable>& wrappable); - static const JSClass* PrototypeClass(JSContext* context); - static JSObject* GetPrototype(JSContext* context, - JS::HandleObject global_object); - static JSObject* GetInterfaceObject(JSContext* context, - JS::HandleObject global_object); -}; - -} // namespace bindings -} // namespace testing -} // namespace cobalt - -#endif // MozjsBaseInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsBooleanTypeTestInterface.cc b/src/cobalt/bindings/generated/mozjs-45/testing/MozjsBooleanTypeTestInterface.cc deleted file mode 100644 index dba29f8..0000000 --- a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsBooleanTypeTestInterface.cc +++ /dev/null
@@ -1,534 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! -// Auto-generated from template: bindings/mozjs-45/templates/interface.cc.template - -// clang-format off - -#include "MozjsBooleanTypeTestInterface.h" - -#include "base/debug/trace_event.h" -#include "cobalt/base/polymorphic_downcast.h" -#include "cobalt/script/global_environment.h" -#include "cobalt/script/opaque_handle.h" -#include "cobalt/script/script_object.h" - -#include "base/lazy_instance.h" -#include "cobalt/script/mozjs-45/callback_function_conversion.h" -#include "cobalt/script/exception_state.h" -#include "cobalt/script/mozjs-45/conversion_helpers.h" -#include "cobalt/script/mozjs-45/mozjs_exception_state.h" -#include "cobalt/script/mozjs-45/mozjs_callback_function.h" -#include "cobalt/script/mozjs-45/mozjs_global_environment.h" -#include "cobalt/script/mozjs-45/mozjs_object_handle.h" -#include "cobalt/script/mozjs-45/mozjs_property_enumerator.h" -#include "cobalt/script/mozjs-45/mozjs_user_object_holder.h" -#include "cobalt/script/mozjs-45/proxy_handler.h" -#include "cobalt/script/mozjs-45/type_traits.h" -#include "cobalt/script/mozjs-45/wrapper_factory.h" -#include "cobalt/script/mozjs-45/wrapper_private.h" -#include "cobalt/script/property_enumerator.h" -#include "third_party/mozjs-45/js/src/jsapi.h" -#include "third_party/mozjs-45/js/src/jsfriendapi.h" - -namespace { -using cobalt::bindings::testing::BooleanTypeTestInterface; -using cobalt::bindings::testing::MozjsBooleanTypeTestInterface; -using cobalt::script::CallbackInterfaceTraits; -using cobalt::script::GlobalEnvironment; -using cobalt::script::OpaqueHandle; -using cobalt::script::OpaqueHandleHolder; -using cobalt::script::ScriptObject; -using cobalt::script::Wrappable; - -using cobalt::script::CallbackFunction; -using cobalt::script::CallbackInterfaceTraits; -using cobalt::script::ExceptionState; -using cobalt::script::mozjs::FromJSValue; -using cobalt::script::mozjs::kConversionFlagNullable; -using cobalt::script::mozjs::kConversionFlagRestricted; -using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString; -using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString; -using cobalt::script::mozjs::kNoConversionFlags; -using cobalt::script::mozjs::InterfaceData; -using cobalt::script::mozjs::MozjsCallbackFunction; -using cobalt::script::mozjs::MozjsExceptionState; -using cobalt::script::mozjs::MozjsGlobalEnvironment; -using cobalt::script::mozjs::MozjsUserObjectHolder; -using cobalt::script::mozjs::MozjsPropertyEnumerator; -using cobalt::script::mozjs::ProxyHandler; -using cobalt::script::mozjs::ToJSValue; -using cobalt::script::mozjs::TypeTraits; -using cobalt::script::mozjs::WrapperPrivate; -using cobalt::script::mozjs::WrapperFactory; -using cobalt::script::Wrappable; -} // namespace - -namespace cobalt { -namespace bindings { -namespace testing { - -namespace { - -class MozjsBooleanTypeTestInterfaceHandler : public ProxyHandler { - public: - MozjsBooleanTypeTestInterfaceHandler() - : ProxyHandler(indexed_property_hooks, named_property_hooks) {} - - private: - static NamedPropertyHooks named_property_hooks; - static IndexedPropertyHooks indexed_property_hooks; -}; - -ProxyHandler::NamedPropertyHooks -MozjsBooleanTypeTestInterfaceHandler::named_property_hooks = { - NULL, - NULL, - NULL, - NULL, - NULL, -}; -ProxyHandler::IndexedPropertyHooks -MozjsBooleanTypeTestInterfaceHandler::indexed_property_hooks = { - NULL, - NULL, - NULL, - NULL, - NULL, -}; - -static base::LazyInstance<MozjsBooleanTypeTestInterfaceHandler> - proxy_handler; - -bool HasInstance(JSContext *context, JS::HandleObject type, - JS::MutableHandleValue vp, bool *success) { - JS::RootedObject global_object( - context, JS_GetGlobalForObject(context, type)); - DCHECK(global_object); - - JS::RootedObject prototype( - context, MozjsBooleanTypeTestInterface::GetPrototype(context, global_object)); - - // |IsDelegate| walks the prototype chain of an object returning true if - // .prototype is found. - bool is_delegate; - if (!IsDelegate(context, prototype, vp, &is_delegate)) { - *success = false; - return false; - } - - *success = is_delegate; - return true; -} - -const JSClass instance_class_definition = { - "BooleanTypeTestInterface", - 0 | JSCLASS_HAS_PRIVATE, - NULL, // addProperty - NULL, // delProperty - NULL, // getProperty - NULL, // setProperty - NULL, // enumerate - NULL, // resolve - NULL, // mayResolve - &WrapperPrivate::Finalizer, // finalize - NULL, // call - NULL, // hasInstance - NULL, // construct - &WrapperPrivate::Trace, // trace -}; - -const JSClass prototype_class_definition = { - "BooleanTypeTestInterfacePrototype", -}; - -const JSClass interface_object_class_definition = { - "BooleanTypeTestInterfaceConstructor", - 0, - NULL, // addProperty - NULL, // delProperty - NULL, // getProperty - NULL, // setProperty - NULL, // enumerate - NULL, // resolve - NULL, // mayResolve - NULL, // finalize - NULL, // call - &HasInstance, - NULL, -}; - -bool get_booleanProperty( - JSContext* context, unsigned argc, JS::Value* vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<BooleanTypeTestInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - BooleanTypeTestInterface* impl = - wrapper_private->wrappable<BooleanTypeTestInterface>().get(); - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->boolean_property(), - &result_value); - } - if (!exception_state.is_exception_set()) { - args.rval().set(result_value); - } - return !exception_state.is_exception_set(); -} - -bool set_booleanProperty( - JSContext* context, unsigned argc, JS::Value* vp) { - - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<BooleanTypeTestInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - BooleanTypeTestInterface* impl = - wrapper_private->wrappable<BooleanTypeTestInterface>().get(); - TypeTraits<bool >::ConversionType value; - if (args.length() != 1) { - NOTREACHED(); - return false; - } - FromJSValue(context, args[0], kNoConversionFlags, &exception_state, - &value); - if (exception_state.is_exception_set()) { - return false; - } - - impl->set_boolean_property(value); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - -bool fcn_booleanArgumentOperation( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, &object)) { - NOTREACHED(); - return false; - } - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<BooleanTypeTestInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - BooleanTypeTestInterface* impl = - wrapper_private->wrappable<BooleanTypeTestInterface>().get(); - const size_t kMinArguments = 1; - if (args.length() < kMinArguments) { - exception_state.SetSimpleException(script::kInvalidNumberOfArguments); - return false; - } - // Non-optional arguments - TypeTraits<bool >::ConversionType arg1; - - DCHECK_LT(0, args.length()); - JS::RootedValue non_optional_value0( - context, args[0]); - FromJSValue(context, - non_optional_value0, - kNoConversionFlags, - &exception_state, &arg1); - if (exception_state.is_exception_set()) { - return false; - } - - impl->BooleanArgumentOperation(arg1); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - -bool fcn_booleanReturnOperation( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, &object)) { - NOTREACHED(); - return false; - } - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<BooleanTypeTestInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - BooleanTypeTestInterface* impl = - wrapper_private->wrappable<BooleanTypeTestInterface>().get(); - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->BooleanReturnOperation(), - &result_value); - } - if (!exception_state.is_exception_set()) { - args.rval().set(result_value); - } - return !exception_state.is_exception_set(); -} - - - -const JSPropertySpec prototype_properties[] = { - { // Read/Write property - "booleanProperty", - JSPROP_SHARED | JSPROP_ENUMERATE, - { { &get_booleanProperty, NULL } }, - { { &set_booleanProperty, NULL } }, - }, - JS_PS_END -}; - -const JSFunctionSpec prototype_functions[] = { - JS_FNSPEC( - "booleanArgumentOperation", fcn_booleanArgumentOperation, NULL, - 1, JSPROP_ENUMERATE, NULL), - JS_FNSPEC( - "booleanReturnOperation", fcn_booleanReturnOperation, NULL, - 0, JSPROP_ENUMERATE, NULL), - JS_FS_END -}; - -const JSPropertySpec interface_object_properties[] = { - JS_PS_END -}; - -const JSFunctionSpec interface_object_functions[] = { - JS_FS_END -}; - -const JSPropertySpec own_properties[] = { - JS_PS_END -}; - -void InitializePrototypeAndInterfaceObject( - InterfaceData* interface_data, JSContext* context, - JS::HandleObject global_object) { - DCHECK(!interface_data->prototype); - DCHECK(!interface_data->interface_object); - DCHECK(JS_IsGlobalObject(global_object)); - - JS::RootedObject parent_prototype( - context, JS_GetObjectPrototype(context, global_object)); - DCHECK(parent_prototype); - - interface_data->prototype = JS_NewObjectWithGivenProto( - context, &prototype_class_definition, parent_prototype - ); - - JS::RootedObject rooted_prototype(context, interface_data->prototype); - bool success = JS_DefineProperties( - context, - rooted_prototype, - prototype_properties); - - DCHECK(success); - success = JS_DefineFunctions( - context, rooted_prototype, prototype_functions); - DCHECK(success); - - JS::RootedObject function_prototype( - context, JS_GetFunctionPrototype(context, global_object)); - DCHECK(function_prototype); - // Create the Interface object. - interface_data->interface_object = JS_NewObjectWithGivenProto( - context, &interface_object_class_definition, - function_prototype); - - // Add the InterfaceObject.name property. - JS::RootedObject rooted_interface_object( - context, interface_data->interface_object); - JS::RootedValue name_value(context); - const char name[] = - "BooleanTypeTestInterface"; - name_value.setString(JS_NewStringCopyZ(context, name)); - success = JS_DefineProperty( - context, rooted_interface_object, "name", name_value, JSPROP_READONLY, - NULL, NULL); - DCHECK(success); - - // Define interface object properties (including constants). - success = JS_DefineProperties(context, rooted_interface_object, - interface_object_properties); - DCHECK(success); - // Define interface object functions (static). - success = JS_DefineFunctions(context, rooted_interface_object, - interface_object_functions); - DCHECK(success); - - // Set the Prototype.constructor and Constructor.prototype properties. - DCHECK(interface_data->interface_object); - DCHECK(interface_data->prototype); - success = JS_LinkConstructorAndPrototype( - context, - rooted_interface_object, - rooted_prototype); - DCHECK(success); -} - -InterfaceData* GetInterfaceData(JSContext* context) { - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - // Use the address of the properties definition for this interface as a - // unique key for looking up the InterfaceData for this interface. - intptr_t key = reinterpret_cast<intptr_t>(&own_properties); - InterfaceData* interface_data = global_environment->GetInterfaceData(key); - if (!interface_data) { - interface_data = new InterfaceData(); - DCHECK(interface_data); - global_environment->CacheInterfaceData(key, interface_data); - DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key)); - } - return interface_data; -} - -} // namespace - -// static -JSObject* MozjsBooleanTypeTestInterface::CreateProxy( - JSContext* context, const scoped_refptr<Wrappable>& wrappable) { - DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); - JS::RootedObject global_object( - context, - MozjsGlobalEnvironment::GetFromContext(context)->global_object()); - DCHECK(global_object); - - InterfaceData* interface_data = GetInterfaceData(context); - JS::RootedObject prototype(context, GetPrototype(context, global_object)); - DCHECK(prototype); - JS::RootedObject new_object( - context, - JS_NewObjectWithGivenProto( - context, &instance_class_definition, prototype)); - DCHECK(new_object); - JS::RootedObject proxy(context, - ProxyHandler::NewProxy( - context, proxy_handler.Pointer(), new_object, prototype)); - WrapperPrivate::AddPrivateData(context, proxy, wrappable); - return proxy; -} - -// static -const JSClass* MozjsBooleanTypeTestInterface::PrototypeClass( - JSContext* context) { - DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); - JS::RootedObject global_object( - context, - MozjsGlobalEnvironment::GetFromContext(context)->global_object()); - DCHECK(global_object); - - JS::RootedObject prototype(context, GetPrototype(context, global_object)); - const JSClass* proto_class = JS_GetClass(prototype); - return proto_class; -} - -// static -JSObject* MozjsBooleanTypeTestInterface::GetPrototype( - JSContext* context, JS::HandleObject global_object) { - DCHECK(JS_IsGlobalObject(global_object)); - - InterfaceData* interface_data = GetInterfaceData(context); - if (!interface_data->prototype) { - // Create new prototype that has all the props and methods - InitializePrototypeAndInterfaceObject( - interface_data, context, global_object); - } - DCHECK(interface_data->prototype); - return interface_data->prototype; -} - -// static -JSObject* MozjsBooleanTypeTestInterface::GetInterfaceObject( - JSContext* context, JS::HandleObject global_object) { - DCHECK(JS_IsGlobalObject(global_object)); - - InterfaceData* interface_data = GetInterfaceData(context); - if (!interface_data->interface_object) { - InitializePrototypeAndInterfaceObject( - interface_data, context, global_object); - } - DCHECK(interface_data->interface_object); - return interface_data->interface_object; -} - - -namespace { -} // namespace - - -} // namespace testing -} // namespace bindings -} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsBooleanTypeTestInterface.h b/src/cobalt/bindings/generated/mozjs-45/testing/MozjsBooleanTypeTestInterface.h deleted file mode 100644 index fdf5a17..0000000 --- a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsBooleanTypeTestInterface.h +++ /dev/null
@@ -1,54 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! -// Auto-generated from template: bindings/mozjs-45/templates/interface.h.template - -// clang-format off - -#ifndef MozjsBooleanTypeTestInterface_h -#define MozjsBooleanTypeTestInterface_h - -#include "base/hash_tables.h" -#include "base/lazy_instance.h" -#include "base/memory/ref_counted.h" -#include "base/threading/thread_checker.h" -#include "cobalt/base/polymorphic_downcast.h" -#include "cobalt/script/wrappable.h" -#include "cobalt/bindings/testing/boolean_type_test_interface.h" - -#include "third_party/mozjs-45/js/src/jsapi.h" - -namespace cobalt { -namespace bindings { -namespace testing { - -class MozjsBooleanTypeTestInterface { - public: - static JSObject* CreateProxy(JSContext* context, - const scoped_refptr<script::Wrappable>& wrappable); - static const JSClass* PrototypeClass(JSContext* context); - static JSObject* GetPrototype(JSContext* context, - JS::HandleObject global_object); - static JSObject* GetInterfaceObject(JSContext* context, - JS::HandleObject global_object); -}; - -} // namespace bindings -} // namespace testing -} // namespace cobalt - -#endif // MozjsBooleanTypeTestInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsCallbackFunctionInterface.cc b/src/cobalt/bindings/generated/mozjs-45/testing/MozjsCallbackFunctionInterface.cc deleted file mode 100644 index 432036a..0000000 --- a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsCallbackFunctionInterface.cc +++ /dev/null
@@ -1,800 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! -// Auto-generated from template: bindings/mozjs-45/templates/interface.cc.template - -// clang-format off - -#include "MozjsCallbackFunctionInterface.h" - -#include "base/debug/trace_event.h" -#include "cobalt/base/polymorphic_downcast.h" -#include "cobalt/script/global_environment.h" -#include "cobalt/script/opaque_handle.h" -#include "cobalt/script/script_object.h" -#include "MozjsArbitraryInterface.h" -#include "cobalt/bindings/testing/arbitrary_interface.h" - -#include "base/lazy_instance.h" -#include "cobalt/script/mozjs-45/callback_function_conversion.h" -#include "cobalt/script/exception_state.h" -#include "cobalt/script/mozjs-45/conversion_helpers.h" -#include "cobalt/script/mozjs-45/mozjs_exception_state.h" -#include "cobalt/script/mozjs-45/mozjs_callback_function.h" -#include "cobalt/script/mozjs-45/mozjs_global_environment.h" -#include "cobalt/script/mozjs-45/mozjs_object_handle.h" -#include "cobalt/script/mozjs-45/mozjs_property_enumerator.h" -#include "cobalt/script/mozjs-45/mozjs_user_object_holder.h" -#include "cobalt/script/mozjs-45/proxy_handler.h" -#include "cobalt/script/mozjs-45/type_traits.h" -#include "cobalt/script/mozjs-45/wrapper_factory.h" -#include "cobalt/script/mozjs-45/wrapper_private.h" -#include "cobalt/script/property_enumerator.h" -#include "third_party/mozjs-45/js/src/jsapi.h" -#include "third_party/mozjs-45/js/src/jsfriendapi.h" - -namespace { -using cobalt::bindings::testing::CallbackFunctionInterface; -using cobalt::bindings::testing::MozjsCallbackFunctionInterface; -using cobalt::bindings::testing::ArbitraryInterface; -using cobalt::bindings::testing::MozjsArbitraryInterface; -using cobalt::script::CallbackInterfaceTraits; -using cobalt::script::GlobalEnvironment; -using cobalt::script::OpaqueHandle; -using cobalt::script::OpaqueHandleHolder; -using cobalt::script::ScriptObject; -using cobalt::script::Wrappable; - -using cobalt::script::CallbackFunction; -using cobalt::script::CallbackInterfaceTraits; -using cobalt::script::ExceptionState; -using cobalt::script::mozjs::FromJSValue; -using cobalt::script::mozjs::kConversionFlagNullable; -using cobalt::script::mozjs::kConversionFlagRestricted; -using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString; -using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString; -using cobalt::script::mozjs::kNoConversionFlags; -using cobalt::script::mozjs::InterfaceData; -using cobalt::script::mozjs::MozjsCallbackFunction; -using cobalt::script::mozjs::MozjsExceptionState; -using cobalt::script::mozjs::MozjsGlobalEnvironment; -using cobalt::script::mozjs::MozjsUserObjectHolder; -using cobalt::script::mozjs::MozjsPropertyEnumerator; -using cobalt::script::mozjs::ProxyHandler; -using cobalt::script::mozjs::ToJSValue; -using cobalt::script::mozjs::TypeTraits; -using cobalt::script::mozjs::WrapperPrivate; -using cobalt::script::mozjs::WrapperFactory; -using cobalt::script::Wrappable; -} // namespace - -namespace cobalt { -namespace bindings { -namespace testing { - -namespace { - -class MozjsCallbackFunctionInterfaceHandler : public ProxyHandler { - public: - MozjsCallbackFunctionInterfaceHandler() - : ProxyHandler(indexed_property_hooks, named_property_hooks) {} - - private: - static NamedPropertyHooks named_property_hooks; - static IndexedPropertyHooks indexed_property_hooks; -}; - -ProxyHandler::NamedPropertyHooks -MozjsCallbackFunctionInterfaceHandler::named_property_hooks = { - NULL, - NULL, - NULL, - NULL, - NULL, -}; -ProxyHandler::IndexedPropertyHooks -MozjsCallbackFunctionInterfaceHandler::indexed_property_hooks = { - NULL, - NULL, - NULL, - NULL, - NULL, -}; - -static base::LazyInstance<MozjsCallbackFunctionInterfaceHandler> - proxy_handler; - -bool HasInstance(JSContext *context, JS::HandleObject type, - JS::MutableHandleValue vp, bool *success) { - JS::RootedObject global_object( - context, JS_GetGlobalForObject(context, type)); - DCHECK(global_object); - - JS::RootedObject prototype( - context, MozjsCallbackFunctionInterface::GetPrototype(context, global_object)); - - // |IsDelegate| walks the prototype chain of an object returning true if - // .prototype is found. - bool is_delegate; - if (!IsDelegate(context, prototype, vp, &is_delegate)) { - *success = false; - return false; - } - - *success = is_delegate; - return true; -} - -const JSClass instance_class_definition = { - "CallbackFunctionInterface", - 0 | JSCLASS_HAS_PRIVATE, - NULL, // addProperty - NULL, // delProperty - NULL, // getProperty - NULL, // setProperty - NULL, // enumerate - NULL, // resolve - NULL, // mayResolve - &WrapperPrivate::Finalizer, // finalize - NULL, // call - NULL, // hasInstance - NULL, // construct - &WrapperPrivate::Trace, // trace -}; - -const JSClass prototype_class_definition = { - "CallbackFunctionInterfacePrototype", -}; - -const JSClass interface_object_class_definition = { - "CallbackFunctionInterfaceConstructor", - 0, - NULL, // addProperty - NULL, // delProperty - NULL, // getProperty - NULL, // setProperty - NULL, // enumerate - NULL, // resolve - NULL, // mayResolve - NULL, // finalize - NULL, // call - &HasInstance, - NULL, -}; - -bool get_callbackAttribute( - JSContext* context, unsigned argc, JS::Value* vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<CallbackFunctionInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - CallbackFunctionInterface* impl = - wrapper_private->wrappable<CallbackFunctionInterface>().get(); - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->callback_attribute(), - &result_value); - } - if (!exception_state.is_exception_set()) { - args.rval().set(result_value); - } - return !exception_state.is_exception_set(); -} - -bool set_callbackAttribute( - JSContext* context, unsigned argc, JS::Value* vp) { - - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<CallbackFunctionInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - CallbackFunctionInterface* impl = - wrapper_private->wrappable<CallbackFunctionInterface>().get(); - TypeTraits<CallbackFunctionInterface::VoidFunction >::ConversionType value; - if (args.length() != 1) { - NOTREACHED(); - return false; - } - FromJSValue(context, args[0], kNoConversionFlags, &exception_state, - &value); - if (exception_state.is_exception_set()) { - return false; - } - - impl->set_callback_attribute(value); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - -bool get_nullableCallbackAttribute( - JSContext* context, unsigned argc, JS::Value* vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<CallbackFunctionInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - CallbackFunctionInterface* impl = - wrapper_private->wrappable<CallbackFunctionInterface>().get(); - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->nullable_callback_attribute(), - &result_value); - } - if (!exception_state.is_exception_set()) { - args.rval().set(result_value); - } - return !exception_state.is_exception_set(); -} - -bool set_nullableCallbackAttribute( - JSContext* context, unsigned argc, JS::Value* vp) { - - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<CallbackFunctionInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - CallbackFunctionInterface* impl = - wrapper_private->wrappable<CallbackFunctionInterface>().get(); - TypeTraits<CallbackFunctionInterface::VoidFunction >::ConversionType value; - if (args.length() != 1) { - NOTREACHED(); - return false; - } - FromJSValue(context, args[0], (kConversionFlagNullable), &exception_state, - &value); - if (exception_state.is_exception_set()) { - return false; - } - - impl->set_nullable_callback_attribute(value); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - -bool fcn_takesFunctionThatReturnsString( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, &object)) { - NOTREACHED(); - return false; - } - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<CallbackFunctionInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - CallbackFunctionInterface* impl = - wrapper_private->wrappable<CallbackFunctionInterface>().get(); - const size_t kMinArguments = 1; - if (args.length() < kMinArguments) { - exception_state.SetSimpleException(script::kInvalidNumberOfArguments); - return false; - } - // Non-optional arguments - TypeTraits<CallbackFunctionInterface::FunctionThatReturnsString >::ConversionType cb; - - DCHECK_LT(0, args.length()); - JS::RootedValue non_optional_value0( - context, args[0]); - FromJSValue(context, - non_optional_value0, - kNoConversionFlags, - &exception_state, &cb); - if (exception_state.is_exception_set()) { - return false; - } - - impl->TakesFunctionThatReturnsString(cb); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - -bool fcn_takesFunctionWithNullableParameters( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, &object)) { - NOTREACHED(); - return false; - } - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<CallbackFunctionInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - CallbackFunctionInterface* impl = - wrapper_private->wrappable<CallbackFunctionInterface>().get(); - const size_t kMinArguments = 1; - if (args.length() < kMinArguments) { - exception_state.SetSimpleException(script::kInvalidNumberOfArguments); - return false; - } - // Non-optional arguments - TypeTraits<CallbackFunctionInterface::FunctionWithNullableParameters >::ConversionType cb; - - DCHECK_LT(0, args.length()); - JS::RootedValue non_optional_value0( - context, args[0]); - FromJSValue(context, - non_optional_value0, - kNoConversionFlags, - &exception_state, &cb); - if (exception_state.is_exception_set()) { - return false; - } - - impl->TakesFunctionWithNullableParameters(cb); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - -bool fcn_takesFunctionWithOneParameter( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, &object)) { - NOTREACHED(); - return false; - } - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<CallbackFunctionInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - CallbackFunctionInterface* impl = - wrapper_private->wrappable<CallbackFunctionInterface>().get(); - const size_t kMinArguments = 1; - if (args.length() < kMinArguments) { - exception_state.SetSimpleException(script::kInvalidNumberOfArguments); - return false; - } - // Non-optional arguments - TypeTraits<CallbackFunctionInterface::FunctionWithOneParameter >::ConversionType cb; - - DCHECK_LT(0, args.length()); - JS::RootedValue non_optional_value0( - context, args[0]); - FromJSValue(context, - non_optional_value0, - kNoConversionFlags, - &exception_state, &cb); - if (exception_state.is_exception_set()) { - return false; - } - - impl->TakesFunctionWithOneParameter(cb); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - -bool fcn_takesFunctionWithSeveralParameters( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, &object)) { - NOTREACHED(); - return false; - } - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<CallbackFunctionInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - CallbackFunctionInterface* impl = - wrapper_private->wrappable<CallbackFunctionInterface>().get(); - const size_t kMinArguments = 1; - if (args.length() < kMinArguments) { - exception_state.SetSimpleException(script::kInvalidNumberOfArguments); - return false; - } - // Non-optional arguments - TypeTraits<CallbackFunctionInterface::FunctionWithSeveralParameters >::ConversionType cb; - - DCHECK_LT(0, args.length()); - JS::RootedValue non_optional_value0( - context, args[0]); - FromJSValue(context, - non_optional_value0, - kNoConversionFlags, - &exception_state, &cb); - if (exception_state.is_exception_set()) { - return false; - } - - impl->TakesFunctionWithSeveralParameters(cb); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - -bool fcn_takesVoidFunction( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, &object)) { - NOTREACHED(); - return false; - } - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<CallbackFunctionInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - CallbackFunctionInterface* impl = - wrapper_private->wrappable<CallbackFunctionInterface>().get(); - const size_t kMinArguments = 1; - if (args.length() < kMinArguments) { - exception_state.SetSimpleException(script::kInvalidNumberOfArguments); - return false; - } - // Non-optional arguments - TypeTraits<CallbackFunctionInterface::VoidFunction >::ConversionType cb; - - DCHECK_LT(0, args.length()); - JS::RootedValue non_optional_value0( - context, args[0]); - FromJSValue(context, - non_optional_value0, - kNoConversionFlags, - &exception_state, &cb); - if (exception_state.is_exception_set()) { - return false; - } - - impl->TakesVoidFunction(cb); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - - - -const JSPropertySpec prototype_properties[] = { - { // Read/Write property - "callbackAttribute", - JSPROP_SHARED | JSPROP_ENUMERATE, - { { &get_callbackAttribute, NULL } }, - { { &set_callbackAttribute, NULL } }, - }, - { // Read/Write property - "nullableCallbackAttribute", - JSPROP_SHARED | JSPROP_ENUMERATE, - { { &get_nullableCallbackAttribute, NULL } }, - { { &set_nullableCallbackAttribute, NULL } }, - }, - JS_PS_END -}; - -const JSFunctionSpec prototype_functions[] = { - JS_FNSPEC( - "takesFunctionThatReturnsString", fcn_takesFunctionThatReturnsString, NULL, - 1, JSPROP_ENUMERATE, NULL), - JS_FNSPEC( - "takesFunctionWithNullableParameters", fcn_takesFunctionWithNullableParameters, NULL, - 1, JSPROP_ENUMERATE, NULL), - JS_FNSPEC( - "takesFunctionWithOneParameter", fcn_takesFunctionWithOneParameter, NULL, - 1, JSPROP_ENUMERATE, NULL), - JS_FNSPEC( - "takesFunctionWithSeveralParameters", fcn_takesFunctionWithSeveralParameters, NULL, - 1, JSPROP_ENUMERATE, NULL), - JS_FNSPEC( - "takesVoidFunction", fcn_takesVoidFunction, NULL, - 1, JSPROP_ENUMERATE, NULL), - JS_FS_END -}; - -const JSPropertySpec interface_object_properties[] = { - JS_PS_END -}; - -const JSFunctionSpec interface_object_functions[] = { - JS_FS_END -}; - -const JSPropertySpec own_properties[] = { - JS_PS_END -}; - -void InitializePrototypeAndInterfaceObject( - InterfaceData* interface_data, JSContext* context, - JS::HandleObject global_object) { - DCHECK(!interface_data->prototype); - DCHECK(!interface_data->interface_object); - DCHECK(JS_IsGlobalObject(global_object)); - - JS::RootedObject parent_prototype( - context, JS_GetObjectPrototype(context, global_object)); - DCHECK(parent_prototype); - - interface_data->prototype = JS_NewObjectWithGivenProto( - context, &prototype_class_definition, parent_prototype - ); - - JS::RootedObject rooted_prototype(context, interface_data->prototype); - bool success = JS_DefineProperties( - context, - rooted_prototype, - prototype_properties); - - DCHECK(success); - success = JS_DefineFunctions( - context, rooted_prototype, prototype_functions); - DCHECK(success); - - JS::RootedObject function_prototype( - context, JS_GetFunctionPrototype(context, global_object)); - DCHECK(function_prototype); - // Create the Interface object. - interface_data->interface_object = JS_NewObjectWithGivenProto( - context, &interface_object_class_definition, - function_prototype); - - // Add the InterfaceObject.name property. - JS::RootedObject rooted_interface_object( - context, interface_data->interface_object); - JS::RootedValue name_value(context); - const char name[] = - "CallbackFunctionInterface"; - name_value.setString(JS_NewStringCopyZ(context, name)); - success = JS_DefineProperty( - context, rooted_interface_object, "name", name_value, JSPROP_READONLY, - NULL, NULL); - DCHECK(success); - - // Define interface object properties (including constants). - success = JS_DefineProperties(context, rooted_interface_object, - interface_object_properties); - DCHECK(success); - // Define interface object functions (static). - success = JS_DefineFunctions(context, rooted_interface_object, - interface_object_functions); - DCHECK(success); - - // Set the Prototype.constructor and Constructor.prototype properties. - DCHECK(interface_data->interface_object); - DCHECK(interface_data->prototype); - success = JS_LinkConstructorAndPrototype( - context, - rooted_interface_object, - rooted_prototype); - DCHECK(success); -} - -InterfaceData* GetInterfaceData(JSContext* context) { - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - // Use the address of the properties definition for this interface as a - // unique key for looking up the InterfaceData for this interface. - intptr_t key = reinterpret_cast<intptr_t>(&own_properties); - InterfaceData* interface_data = global_environment->GetInterfaceData(key); - if (!interface_data) { - interface_data = new InterfaceData(); - DCHECK(interface_data); - global_environment->CacheInterfaceData(key, interface_data); - DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key)); - } - return interface_data; -} - -} // namespace - -// static -JSObject* MozjsCallbackFunctionInterface::CreateProxy( - JSContext* context, const scoped_refptr<Wrappable>& wrappable) { - DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); - JS::RootedObject global_object( - context, - MozjsGlobalEnvironment::GetFromContext(context)->global_object()); - DCHECK(global_object); - - InterfaceData* interface_data = GetInterfaceData(context); - JS::RootedObject prototype(context, GetPrototype(context, global_object)); - DCHECK(prototype); - JS::RootedObject new_object( - context, - JS_NewObjectWithGivenProto( - context, &instance_class_definition, prototype)); - DCHECK(new_object); - JS::RootedObject proxy(context, - ProxyHandler::NewProxy( - context, proxy_handler.Pointer(), new_object, prototype)); - WrapperPrivate::AddPrivateData(context, proxy, wrappable); - return proxy; -} - -// static -const JSClass* MozjsCallbackFunctionInterface::PrototypeClass( - JSContext* context) { - DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); - JS::RootedObject global_object( - context, - MozjsGlobalEnvironment::GetFromContext(context)->global_object()); - DCHECK(global_object); - - JS::RootedObject prototype(context, GetPrototype(context, global_object)); - const JSClass* proto_class = JS_GetClass(prototype); - return proto_class; -} - -// static -JSObject* MozjsCallbackFunctionInterface::GetPrototype( - JSContext* context, JS::HandleObject global_object) { - DCHECK(JS_IsGlobalObject(global_object)); - - InterfaceData* interface_data = GetInterfaceData(context); - if (!interface_data->prototype) { - // Create new prototype that has all the props and methods - InitializePrototypeAndInterfaceObject( - interface_data, context, global_object); - } - DCHECK(interface_data->prototype); - return interface_data->prototype; -} - -// static -JSObject* MozjsCallbackFunctionInterface::GetInterfaceObject( - JSContext* context, JS::HandleObject global_object) { - DCHECK(JS_IsGlobalObject(global_object)); - - InterfaceData* interface_data = GetInterfaceData(context); - if (!interface_data->interface_object) { - InitializePrototypeAndInterfaceObject( - interface_data, context, global_object); - } - DCHECK(interface_data->interface_object); - return interface_data->interface_object; -} - - -namespace { -} // namespace - - -} // namespace testing -} // namespace bindings -} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsCallbackFunctionInterface.h b/src/cobalt/bindings/generated/mozjs-45/testing/MozjsCallbackFunctionInterface.h deleted file mode 100644 index 601375d..0000000 --- a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsCallbackFunctionInterface.h +++ /dev/null
@@ -1,54 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! -// Auto-generated from template: bindings/mozjs-45/templates/interface.h.template - -// clang-format off - -#ifndef MozjsCallbackFunctionInterface_h -#define MozjsCallbackFunctionInterface_h - -#include "base/hash_tables.h" -#include "base/lazy_instance.h" -#include "base/memory/ref_counted.h" -#include "base/threading/thread_checker.h" -#include "cobalt/base/polymorphic_downcast.h" -#include "cobalt/script/wrappable.h" -#include "cobalt/bindings/testing/callback_function_interface.h" - -#include "third_party/mozjs-45/js/src/jsapi.h" - -namespace cobalt { -namespace bindings { -namespace testing { - -class MozjsCallbackFunctionInterface { - public: - static JSObject* CreateProxy(JSContext* context, - const scoped_refptr<script::Wrappable>& wrappable); - static const JSClass* PrototypeClass(JSContext* context); - static JSObject* GetPrototype(JSContext* context, - JS::HandleObject global_object); - static JSObject* GetInterfaceObject(JSContext* context, - JS::HandleObject global_object); -}; - -} // namespace bindings -} // namespace testing -} // namespace cobalt - -#endif // MozjsCallbackFunctionInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsCallbackInterfaceInterface.cc b/src/cobalt/bindings/generated/mozjs-45/testing/MozjsCallbackInterfaceInterface.cc deleted file mode 100644 index 2cb72c7..0000000 --- a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsCallbackInterfaceInterface.cc +++ /dev/null
@@ -1,532 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! -// Auto-generated from template: bindings/mozjs-45/templates/interface.cc.template - -// clang-format off - -#include "MozjsCallbackInterfaceInterface.h" - -#include "base/debug/trace_event.h" -#include "cobalt/base/polymorphic_downcast.h" -#include "cobalt/script/global_environment.h" -#include "cobalt/script/opaque_handle.h" -#include "cobalt/script/script_object.h" -#include "MozjsSingleOperationInterface.h" -#include "cobalt/bindings/testing/single_operation_interface.h" - -#include "base/lazy_instance.h" -#include "cobalt/script/mozjs-45/callback_function_conversion.h" -#include "cobalt/script/exception_state.h" -#include "cobalt/script/mozjs-45/conversion_helpers.h" -#include "cobalt/script/mozjs-45/mozjs_exception_state.h" -#include "cobalt/script/mozjs-45/mozjs_callback_function.h" -#include "cobalt/script/mozjs-45/mozjs_global_environment.h" -#include "cobalt/script/mozjs-45/mozjs_object_handle.h" -#include "cobalt/script/mozjs-45/mozjs_property_enumerator.h" -#include "cobalt/script/mozjs-45/mozjs_user_object_holder.h" -#include "cobalt/script/mozjs-45/proxy_handler.h" -#include "cobalt/script/mozjs-45/type_traits.h" -#include "cobalt/script/mozjs-45/wrapper_factory.h" -#include "cobalt/script/mozjs-45/wrapper_private.h" -#include "cobalt/script/property_enumerator.h" -#include "third_party/mozjs-45/js/src/jsapi.h" -#include "third_party/mozjs-45/js/src/jsfriendapi.h" - -namespace { -using cobalt::bindings::testing::CallbackInterfaceInterface; -using cobalt::bindings::testing::MozjsCallbackInterfaceInterface; -using cobalt::bindings::testing::MozjsSingleOperationInterface; -using cobalt::bindings::testing::SingleOperationInterface; -using cobalt::script::CallbackInterfaceTraits; -using cobalt::script::GlobalEnvironment; -using cobalt::script::OpaqueHandle; -using cobalt::script::OpaqueHandleHolder; -using cobalt::script::ScriptObject; -using cobalt::script::Wrappable; - -using cobalt::script::CallbackFunction; -using cobalt::script::CallbackInterfaceTraits; -using cobalt::script::ExceptionState; -using cobalt::script::mozjs::FromJSValue; -using cobalt::script::mozjs::kConversionFlagNullable; -using cobalt::script::mozjs::kConversionFlagRestricted; -using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString; -using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString; -using cobalt::script::mozjs::kNoConversionFlags; -using cobalt::script::mozjs::InterfaceData; -using cobalt::script::mozjs::MozjsCallbackFunction; -using cobalt::script::mozjs::MozjsExceptionState; -using cobalt::script::mozjs::MozjsGlobalEnvironment; -using cobalt::script::mozjs::MozjsUserObjectHolder; -using cobalt::script::mozjs::MozjsPropertyEnumerator; -using cobalt::script::mozjs::ProxyHandler; -using cobalt::script::mozjs::ToJSValue; -using cobalt::script::mozjs::TypeTraits; -using cobalt::script::mozjs::WrapperPrivate; -using cobalt::script::mozjs::WrapperFactory; -using cobalt::script::Wrappable; -} // namespace - -namespace cobalt { -namespace bindings { -namespace testing { - -namespace { - -class MozjsCallbackInterfaceInterfaceHandler : public ProxyHandler { - public: - MozjsCallbackInterfaceInterfaceHandler() - : ProxyHandler(indexed_property_hooks, named_property_hooks) {} - - private: - static NamedPropertyHooks named_property_hooks; - static IndexedPropertyHooks indexed_property_hooks; -}; - -ProxyHandler::NamedPropertyHooks -MozjsCallbackInterfaceInterfaceHandler::named_property_hooks = { - NULL, - NULL, - NULL, - NULL, - NULL, -}; -ProxyHandler::IndexedPropertyHooks -MozjsCallbackInterfaceInterfaceHandler::indexed_property_hooks = { - NULL, - NULL, - NULL, - NULL, - NULL, -}; - -static base::LazyInstance<MozjsCallbackInterfaceInterfaceHandler> - proxy_handler; - -bool HasInstance(JSContext *context, JS::HandleObject type, - JS::MutableHandleValue vp, bool *success) { - JS::RootedObject global_object( - context, JS_GetGlobalForObject(context, type)); - DCHECK(global_object); - - JS::RootedObject prototype( - context, MozjsCallbackInterfaceInterface::GetPrototype(context, global_object)); - - // |IsDelegate| walks the prototype chain of an object returning true if - // .prototype is found. - bool is_delegate; - if (!IsDelegate(context, prototype, vp, &is_delegate)) { - *success = false; - return false; - } - - *success = is_delegate; - return true; -} - -const JSClass instance_class_definition = { - "CallbackInterfaceInterface", - 0 | JSCLASS_HAS_PRIVATE, - NULL, // addProperty - NULL, // delProperty - NULL, // getProperty - NULL, // setProperty - NULL, // enumerate - NULL, // resolve - NULL, // mayResolve - &WrapperPrivate::Finalizer, // finalize - NULL, // call - NULL, // hasInstance - NULL, // construct - &WrapperPrivate::Trace, // trace -}; - -const JSClass prototype_class_definition = { - "CallbackInterfaceInterfacePrototype", -}; - -const JSClass interface_object_class_definition = { - "CallbackInterfaceInterfaceConstructor", - 0, - NULL, // addProperty - NULL, // delProperty - NULL, // getProperty - NULL, // setProperty - NULL, // enumerate - NULL, // resolve - NULL, // mayResolve - NULL, // finalize - NULL, // call - &HasInstance, - NULL, -}; - -bool get_callbackAttribute( - JSContext* context, unsigned argc, JS::Value* vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<CallbackInterfaceInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - CallbackInterfaceInterface* impl = - wrapper_private->wrappable<CallbackInterfaceInterface>().get(); - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->callback_attribute(), - &result_value); - } - if (!exception_state.is_exception_set()) { - args.rval().set(result_value); - } - return !exception_state.is_exception_set(); -} - -bool set_callbackAttribute( - JSContext* context, unsigned argc, JS::Value* vp) { - - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<CallbackInterfaceInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - CallbackInterfaceInterface* impl = - wrapper_private->wrappable<CallbackInterfaceInterface>().get(); - TypeTraits<CallbackInterfaceTraits<SingleOperationInterface > >::ConversionType value; - if (args.length() != 1) { - NOTREACHED(); - return false; - } - FromJSValue(context, args[0], (kConversionFlagNullable), &exception_state, - &value); - if (exception_state.is_exception_set()) { - return false; - } - - impl->set_callback_attribute(value); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - -bool fcn_registerCallback( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, &object)) { - NOTREACHED(); - return false; - } - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<CallbackInterfaceInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - CallbackInterfaceInterface* impl = - wrapper_private->wrappable<CallbackInterfaceInterface>().get(); - const size_t kMinArguments = 1; - if (args.length() < kMinArguments) { - exception_state.SetSimpleException(script::kInvalidNumberOfArguments); - return false; - } - // Non-optional arguments - TypeTraits<CallbackInterfaceTraits<SingleOperationInterface > >::ConversionType callback_interface; - - DCHECK_LT(0, args.length()); - JS::RootedValue non_optional_value0( - context, args[0]); - FromJSValue(context, - non_optional_value0, - kNoConversionFlags, - &exception_state, &callback_interface); - if (exception_state.is_exception_set()) { - return false; - } - - impl->RegisterCallback(callback_interface); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - -bool fcn_someOperation( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, &object)) { - NOTREACHED(); - return false; - } - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<CallbackInterfaceInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - CallbackInterfaceInterface* impl = - wrapper_private->wrappable<CallbackInterfaceInterface>().get(); - - impl->SomeOperation(); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - - - -const JSPropertySpec prototype_properties[] = { - { // Read/Write property - "callbackAttribute", - JSPROP_SHARED | JSPROP_ENUMERATE, - { { &get_callbackAttribute, NULL } }, - { { &set_callbackAttribute, NULL } }, - }, - JS_PS_END -}; - -const JSFunctionSpec prototype_functions[] = { - JS_FNSPEC( - "registerCallback", fcn_registerCallback, NULL, - 1, JSPROP_ENUMERATE, NULL), - JS_FNSPEC( - "someOperation", fcn_someOperation, NULL, - 0, JSPROP_ENUMERATE, NULL), - JS_FS_END -}; - -const JSPropertySpec interface_object_properties[] = { - JS_PS_END -}; - -const JSFunctionSpec interface_object_functions[] = { - JS_FS_END -}; - -const JSPropertySpec own_properties[] = { - JS_PS_END -}; - -void InitializePrototypeAndInterfaceObject( - InterfaceData* interface_data, JSContext* context, - JS::HandleObject global_object) { - DCHECK(!interface_data->prototype); - DCHECK(!interface_data->interface_object); - DCHECK(JS_IsGlobalObject(global_object)); - - JS::RootedObject parent_prototype( - context, JS_GetObjectPrototype(context, global_object)); - DCHECK(parent_prototype); - - interface_data->prototype = JS_NewObjectWithGivenProto( - context, &prototype_class_definition, parent_prototype - ); - - JS::RootedObject rooted_prototype(context, interface_data->prototype); - bool success = JS_DefineProperties( - context, - rooted_prototype, - prototype_properties); - - DCHECK(success); - success = JS_DefineFunctions( - context, rooted_prototype, prototype_functions); - DCHECK(success); - - JS::RootedObject function_prototype( - context, JS_GetFunctionPrototype(context, global_object)); - DCHECK(function_prototype); - // Create the Interface object. - interface_data->interface_object = JS_NewObjectWithGivenProto( - context, &interface_object_class_definition, - function_prototype); - - // Add the InterfaceObject.name property. - JS::RootedObject rooted_interface_object( - context, interface_data->interface_object); - JS::RootedValue name_value(context); - const char name[] = - "CallbackInterfaceInterface"; - name_value.setString(JS_NewStringCopyZ(context, name)); - success = JS_DefineProperty( - context, rooted_interface_object, "name", name_value, JSPROP_READONLY, - NULL, NULL); - DCHECK(success); - - // Define interface object properties (including constants). - success = JS_DefineProperties(context, rooted_interface_object, - interface_object_properties); - DCHECK(success); - // Define interface object functions (static). - success = JS_DefineFunctions(context, rooted_interface_object, - interface_object_functions); - DCHECK(success); - - // Set the Prototype.constructor and Constructor.prototype properties. - DCHECK(interface_data->interface_object); - DCHECK(interface_data->prototype); - success = JS_LinkConstructorAndPrototype( - context, - rooted_interface_object, - rooted_prototype); - DCHECK(success); -} - -InterfaceData* GetInterfaceData(JSContext* context) { - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - // Use the address of the properties definition for this interface as a - // unique key for looking up the InterfaceData for this interface. - intptr_t key = reinterpret_cast<intptr_t>(&own_properties); - InterfaceData* interface_data = global_environment->GetInterfaceData(key); - if (!interface_data) { - interface_data = new InterfaceData(); - DCHECK(interface_data); - global_environment->CacheInterfaceData(key, interface_data); - DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key)); - } - return interface_data; -} - -} // namespace - -// static -JSObject* MozjsCallbackInterfaceInterface::CreateProxy( - JSContext* context, const scoped_refptr<Wrappable>& wrappable) { - DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); - JS::RootedObject global_object( - context, - MozjsGlobalEnvironment::GetFromContext(context)->global_object()); - DCHECK(global_object); - - InterfaceData* interface_data = GetInterfaceData(context); - JS::RootedObject prototype(context, GetPrototype(context, global_object)); - DCHECK(prototype); - JS::RootedObject new_object( - context, - JS_NewObjectWithGivenProto( - context, &instance_class_definition, prototype)); - DCHECK(new_object); - JS::RootedObject proxy(context, - ProxyHandler::NewProxy( - context, proxy_handler.Pointer(), new_object, prototype)); - WrapperPrivate::AddPrivateData(context, proxy, wrappable); - return proxy; -} - -// static -const JSClass* MozjsCallbackInterfaceInterface::PrototypeClass( - JSContext* context) { - DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); - JS::RootedObject global_object( - context, - MozjsGlobalEnvironment::GetFromContext(context)->global_object()); - DCHECK(global_object); - - JS::RootedObject prototype(context, GetPrototype(context, global_object)); - const JSClass* proto_class = JS_GetClass(prototype); - return proto_class; -} - -// static -JSObject* MozjsCallbackInterfaceInterface::GetPrototype( - JSContext* context, JS::HandleObject global_object) { - DCHECK(JS_IsGlobalObject(global_object)); - - InterfaceData* interface_data = GetInterfaceData(context); - if (!interface_data->prototype) { - // Create new prototype that has all the props and methods - InitializePrototypeAndInterfaceObject( - interface_data, context, global_object); - } - DCHECK(interface_data->prototype); - return interface_data->prototype; -} - -// static -JSObject* MozjsCallbackInterfaceInterface::GetInterfaceObject( - JSContext* context, JS::HandleObject global_object) { - DCHECK(JS_IsGlobalObject(global_object)); - - InterfaceData* interface_data = GetInterfaceData(context); - if (!interface_data->interface_object) { - InitializePrototypeAndInterfaceObject( - interface_data, context, global_object); - } - DCHECK(interface_data->interface_object); - return interface_data->interface_object; -} - - -namespace { -} // namespace - - -} // namespace testing -} // namespace bindings -} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsCallbackInterfaceInterface.h b/src/cobalt/bindings/generated/mozjs-45/testing/MozjsCallbackInterfaceInterface.h deleted file mode 100644 index 60ea77e..0000000 --- a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsCallbackInterfaceInterface.h +++ /dev/null
@@ -1,54 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! -// Auto-generated from template: bindings/mozjs-45/templates/interface.h.template - -// clang-format off - -#ifndef MozjsCallbackInterfaceInterface_h -#define MozjsCallbackInterfaceInterface_h - -#include "base/hash_tables.h" -#include "base/lazy_instance.h" -#include "base/memory/ref_counted.h" -#include "base/threading/thread_checker.h" -#include "cobalt/base/polymorphic_downcast.h" -#include "cobalt/script/wrappable.h" -#include "cobalt/bindings/testing/callback_interface_interface.h" - -#include "third_party/mozjs-45/js/src/jsapi.h" - -namespace cobalt { -namespace bindings { -namespace testing { - -class MozjsCallbackInterfaceInterface { - public: - static JSObject* CreateProxy(JSContext* context, - const scoped_refptr<script::Wrappable>& wrappable); - static const JSClass* PrototypeClass(JSContext* context); - static JSObject* GetPrototype(JSContext* context, - JS::HandleObject global_object); - static JSObject* GetInterfaceObject(JSContext* context, - JS::HandleObject global_object); -}; - -} // namespace bindings -} // namespace testing -} // namespace cobalt - -#endif // MozjsCallbackInterfaceInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsConditionalInterface.cc b/src/cobalt/bindings/generated/mozjs-45/testing/MozjsConditionalInterface.cc deleted file mode 100644 index 9fa7cb8..0000000 --- a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsConditionalInterface.cc +++ /dev/null
@@ -1,609 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! -// Auto-generated from template: bindings/mozjs-45/templates/interface.cc.template - -// clang-format off - -#if defined(ENABLE_CONDITIONAL_INTERFACE) - -#include "MozjsConditionalInterface.h" - -#include "base/debug/trace_event.h" -#include "cobalt/base/polymorphic_downcast.h" -#include "cobalt/script/global_environment.h" -#include "cobalt/script/opaque_handle.h" -#include "cobalt/script/script_object.h" - -#include "base/lazy_instance.h" -#include "cobalt/script/mozjs-45/callback_function_conversion.h" -#include "cobalt/script/exception_state.h" -#include "cobalt/script/mozjs-45/conversion_helpers.h" -#include "cobalt/script/mozjs-45/mozjs_exception_state.h" -#include "cobalt/script/mozjs-45/mozjs_callback_function.h" -#include "cobalt/script/mozjs-45/mozjs_global_environment.h" -#include "cobalt/script/mozjs-45/mozjs_object_handle.h" -#include "cobalt/script/mozjs-45/mozjs_property_enumerator.h" -#include "cobalt/script/mozjs-45/mozjs_user_object_holder.h" -#include "cobalt/script/mozjs-45/proxy_handler.h" -#include "cobalt/script/mozjs-45/type_traits.h" -#include "cobalt/script/mozjs-45/wrapper_factory.h" -#include "cobalt/script/mozjs-45/wrapper_private.h" -#include "cobalt/script/property_enumerator.h" -#include "third_party/mozjs-45/js/src/jsapi.h" -#include "third_party/mozjs-45/js/src/jsfriendapi.h" - -namespace { -using cobalt::bindings::testing::ConditionalInterface; -using cobalt::bindings::testing::MozjsConditionalInterface; -using cobalt::script::CallbackInterfaceTraits; -using cobalt::script::GlobalEnvironment; -using cobalt::script::OpaqueHandle; -using cobalt::script::OpaqueHandleHolder; -using cobalt::script::ScriptObject; -using cobalt::script::Wrappable; - -using cobalt::script::CallbackFunction; -using cobalt::script::CallbackInterfaceTraits; -using cobalt::script::ExceptionState; -using cobalt::script::mozjs::FromJSValue; -using cobalt::script::mozjs::kConversionFlagNullable; -using cobalt::script::mozjs::kConversionFlagRestricted; -using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString; -using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString; -using cobalt::script::mozjs::kNoConversionFlags; -using cobalt::script::mozjs::InterfaceData; -using cobalt::script::mozjs::MozjsCallbackFunction; -using cobalt::script::mozjs::MozjsExceptionState; -using cobalt::script::mozjs::MozjsGlobalEnvironment; -using cobalt::script::mozjs::MozjsUserObjectHolder; -using cobalt::script::mozjs::MozjsPropertyEnumerator; -using cobalt::script::mozjs::ProxyHandler; -using cobalt::script::mozjs::ToJSValue; -using cobalt::script::mozjs::TypeTraits; -using cobalt::script::mozjs::WrapperPrivate; -using cobalt::script::mozjs::WrapperFactory; -using cobalt::script::Wrappable; -} // namespace - -namespace cobalt { -namespace bindings { -namespace testing { - -namespace { - -class MozjsConditionalInterfaceHandler : public ProxyHandler { - public: - MozjsConditionalInterfaceHandler() - : ProxyHandler(indexed_property_hooks, named_property_hooks) {} - - private: - static NamedPropertyHooks named_property_hooks; - static IndexedPropertyHooks indexed_property_hooks; -}; - -ProxyHandler::NamedPropertyHooks -MozjsConditionalInterfaceHandler::named_property_hooks = { - NULL, - NULL, - NULL, - NULL, - NULL, -}; -ProxyHandler::IndexedPropertyHooks -MozjsConditionalInterfaceHandler::indexed_property_hooks = { - NULL, - NULL, - NULL, - NULL, - NULL, -}; - -static base::LazyInstance<MozjsConditionalInterfaceHandler> - proxy_handler; - -bool HasInstance(JSContext *context, JS::HandleObject type, - JS::MutableHandleValue vp, bool *success) { - JS::RootedObject global_object( - context, JS_GetGlobalForObject(context, type)); - DCHECK(global_object); - - JS::RootedObject prototype( - context, MozjsConditionalInterface::GetPrototype(context, global_object)); - - // |IsDelegate| walks the prototype chain of an object returning true if - // .prototype is found. - bool is_delegate; - if (!IsDelegate(context, prototype, vp, &is_delegate)) { - *success = false; - return false; - } - - *success = is_delegate; - return true; -} - -const JSClass instance_class_definition = { - "ConditionalInterface", - 0 | JSCLASS_HAS_PRIVATE, - NULL, // addProperty - NULL, // delProperty - NULL, // getProperty - NULL, // setProperty - NULL, // enumerate - NULL, // resolve - NULL, // mayResolve - &WrapperPrivate::Finalizer, // finalize - NULL, // call - NULL, // hasInstance - NULL, // construct - &WrapperPrivate::Trace, // trace -}; - -const JSClass prototype_class_definition = { - "ConditionalInterfacePrototype", -}; - -const JSClass interface_object_class_definition = { - "ConditionalInterfaceConstructor", - 0, - NULL, // addProperty - NULL, // delProperty - NULL, // getProperty - NULL, // setProperty - NULL, // enumerate - NULL, // resolve - NULL, // mayResolve - NULL, // finalize - NULL, // call - &HasInstance, - NULL, -}; - -#if defined(ENABLE_CONDITIONAL_PROPERTY) -bool get_enabledAttribute( - JSContext* context, unsigned argc, JS::Value* vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<ConditionalInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - ConditionalInterface* impl = - wrapper_private->wrappable<ConditionalInterface>().get(); - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->enabled_attribute(), - &result_value); - } - if (!exception_state.is_exception_set()) { - args.rval().set(result_value); - } - return !exception_state.is_exception_set(); -} - -bool set_enabledAttribute( - JSContext* context, unsigned argc, JS::Value* vp) { - - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<ConditionalInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - ConditionalInterface* impl = - wrapper_private->wrappable<ConditionalInterface>().get(); - TypeTraits<int32_t >::ConversionType value; - if (args.length() != 1) { - NOTREACHED(); - return false; - } - FromJSValue(context, args[0], kNoConversionFlags, &exception_state, - &value); - if (exception_state.is_exception_set()) { - return false; - } - - impl->set_enabled_attribute(value); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - -#endif // ENABLE_CONDITIONAL_PROPERTY -#if defined(NO_ENABLE_CONDITIONAL_PROPERTY) -bool get_disabledAttribute( - JSContext* context, unsigned argc, JS::Value* vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<ConditionalInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - ConditionalInterface* impl = - wrapper_private->wrappable<ConditionalInterface>().get(); - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->disabled_attribute(), - &result_value); - } - if (!exception_state.is_exception_set()) { - args.rval().set(result_value); - } - return !exception_state.is_exception_set(); -} - -bool set_disabledAttribute( - JSContext* context, unsigned argc, JS::Value* vp) { - - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<ConditionalInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - ConditionalInterface* impl = - wrapper_private->wrappable<ConditionalInterface>().get(); - TypeTraits<int32_t >::ConversionType value; - if (args.length() != 1) { - NOTREACHED(); - return false; - } - FromJSValue(context, args[0], kNoConversionFlags, &exception_state, - &value); - if (exception_state.is_exception_set()) { - return false; - } - - impl->set_disabled_attribute(value); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - -#endif // NO_ENABLE_CONDITIONAL_PROPERTY -#if defined(NO_ENABLE_CONDITIONAL_PROPERTY) -bool fcn_disabledOperation( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, &object)) { - NOTREACHED(); - return false; - } - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<ConditionalInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - ConditionalInterface* impl = - wrapper_private->wrappable<ConditionalInterface>().get(); - - impl->DisabledOperation(); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - -#endif // NO_ENABLE_CONDITIONAL_PROPERTY -#if defined(ENABLE_CONDITIONAL_PROPERTY) -bool fcn_enabledOperation( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, &object)) { - NOTREACHED(); - return false; - } - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<ConditionalInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - ConditionalInterface* impl = - wrapper_private->wrappable<ConditionalInterface>().get(); - - impl->EnabledOperation(); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - -#endif // ENABLE_CONDITIONAL_PROPERTY - - -const JSPropertySpec prototype_properties[] = { -#if defined(ENABLE_CONDITIONAL_PROPERTY) - { // Read/Write property - "enabledAttribute", - JSPROP_SHARED | JSPROP_ENUMERATE, - { { &get_enabledAttribute, NULL } }, - { { &set_enabledAttribute, NULL } }, - }, -#endif // ENABLE_CONDITIONAL_PROPERTY -#if defined(NO_ENABLE_CONDITIONAL_PROPERTY) - { // Read/Write property - "disabledAttribute", - JSPROP_SHARED | JSPROP_ENUMERATE, - { { &get_disabledAttribute, NULL } }, - { { &set_disabledAttribute, NULL } }, - }, -#endif // NO_ENABLE_CONDITIONAL_PROPERTY - JS_PS_END -}; - -const JSFunctionSpec prototype_functions[] = { - -#if defined(NO_ENABLE_CONDITIONAL_PROPERTY) - - JS_FNSPEC( - "disabledOperation", fcn_disabledOperation, NULL, - 0, JSPROP_ENUMERATE, NULL), -#endif // NO_ENABLE_CONDITIONAL_PROPERTY - -#if defined(ENABLE_CONDITIONAL_PROPERTY) - - JS_FNSPEC( - "enabledOperation", fcn_enabledOperation, NULL, - 0, JSPROP_ENUMERATE, NULL), -#endif // ENABLE_CONDITIONAL_PROPERTY - JS_FS_END -}; - -const JSPropertySpec interface_object_properties[] = { - JS_PS_END -}; - -const JSFunctionSpec interface_object_functions[] = { - JS_FS_END -}; - -const JSPropertySpec own_properties[] = { - JS_PS_END -}; - -void InitializePrototypeAndInterfaceObject( - InterfaceData* interface_data, JSContext* context, - JS::HandleObject global_object) { - DCHECK(!interface_data->prototype); - DCHECK(!interface_data->interface_object); - DCHECK(JS_IsGlobalObject(global_object)); - - JS::RootedObject parent_prototype( - context, JS_GetObjectPrototype(context, global_object)); - DCHECK(parent_prototype); - - interface_data->prototype = JS_NewObjectWithGivenProto( - context, &prototype_class_definition, parent_prototype - ); - - JS::RootedObject rooted_prototype(context, interface_data->prototype); - bool success = JS_DefineProperties( - context, - rooted_prototype, - prototype_properties); - - DCHECK(success); - success = JS_DefineFunctions( - context, rooted_prototype, prototype_functions); - DCHECK(success); - - JS::RootedObject function_prototype( - context, JS_GetFunctionPrototype(context, global_object)); - DCHECK(function_prototype); - // Create the Interface object. - interface_data->interface_object = JS_NewObjectWithGivenProto( - context, &interface_object_class_definition, - function_prototype); - - // Add the InterfaceObject.name property. - JS::RootedObject rooted_interface_object( - context, interface_data->interface_object); - JS::RootedValue name_value(context); - const char name[] = - "ConditionalInterface"; - name_value.setString(JS_NewStringCopyZ(context, name)); - success = JS_DefineProperty( - context, rooted_interface_object, "name", name_value, JSPROP_READONLY, - NULL, NULL); - DCHECK(success); - - // Define interface object properties (including constants). - success = JS_DefineProperties(context, rooted_interface_object, - interface_object_properties); - DCHECK(success); - // Define interface object functions (static). - success = JS_DefineFunctions(context, rooted_interface_object, - interface_object_functions); - DCHECK(success); - - // Set the Prototype.constructor and Constructor.prototype properties. - DCHECK(interface_data->interface_object); - DCHECK(interface_data->prototype); - success = JS_LinkConstructorAndPrototype( - context, - rooted_interface_object, - rooted_prototype); - DCHECK(success); -} - -InterfaceData* GetInterfaceData(JSContext* context) { - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - // Use the address of the properties definition for this interface as a - // unique key for looking up the InterfaceData for this interface. - intptr_t key = reinterpret_cast<intptr_t>(&own_properties); - InterfaceData* interface_data = global_environment->GetInterfaceData(key); - if (!interface_data) { - interface_data = new InterfaceData(); - DCHECK(interface_data); - global_environment->CacheInterfaceData(key, interface_data); - DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key)); - } - return interface_data; -} - -} // namespace - -// static -JSObject* MozjsConditionalInterface::CreateProxy( - JSContext* context, const scoped_refptr<Wrappable>& wrappable) { - DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); - JS::RootedObject global_object( - context, - MozjsGlobalEnvironment::GetFromContext(context)->global_object()); - DCHECK(global_object); - - InterfaceData* interface_data = GetInterfaceData(context); - JS::RootedObject prototype(context, GetPrototype(context, global_object)); - DCHECK(prototype); - JS::RootedObject new_object( - context, - JS_NewObjectWithGivenProto( - context, &instance_class_definition, prototype)); - DCHECK(new_object); - JS::RootedObject proxy(context, - ProxyHandler::NewProxy( - context, proxy_handler.Pointer(), new_object, prototype)); - WrapperPrivate::AddPrivateData(context, proxy, wrappable); - return proxy; -} - -// static -const JSClass* MozjsConditionalInterface::PrototypeClass( - JSContext* context) { - DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); - JS::RootedObject global_object( - context, - MozjsGlobalEnvironment::GetFromContext(context)->global_object()); - DCHECK(global_object); - - JS::RootedObject prototype(context, GetPrototype(context, global_object)); - const JSClass* proto_class = JS_GetClass(prototype); - return proto_class; -} - -// static -JSObject* MozjsConditionalInterface::GetPrototype( - JSContext* context, JS::HandleObject global_object) { - DCHECK(JS_IsGlobalObject(global_object)); - - InterfaceData* interface_data = GetInterfaceData(context); - if (!interface_data->prototype) { - // Create new prototype that has all the props and methods - InitializePrototypeAndInterfaceObject( - interface_data, context, global_object); - } - DCHECK(interface_data->prototype); - return interface_data->prototype; -} - -// static -JSObject* MozjsConditionalInterface::GetInterfaceObject( - JSContext* context, JS::HandleObject global_object) { - DCHECK(JS_IsGlobalObject(global_object)); - - InterfaceData* interface_data = GetInterfaceData(context); - if (!interface_data->interface_object) { - InitializePrototypeAndInterfaceObject( - interface_data, context, global_object); - } - DCHECK(interface_data->interface_object); - return interface_data->interface_object; -} - - -namespace { -} // namespace - - -} // namespace testing -} // namespace bindings -} // namespace cobalt -#endif // defined(ENABLE_CONDITIONAL_INTERFACE)
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsConditionalInterface.h b/src/cobalt/bindings/generated/mozjs-45/testing/MozjsConditionalInterface.h deleted file mode 100644 index a5472b2..0000000 --- a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsConditionalInterface.h +++ /dev/null
@@ -1,58 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! -// Auto-generated from template: bindings/mozjs-45/templates/interface.h.template - -// clang-format off - -#ifndef MozjsConditionalInterface_h -#define MozjsConditionalInterface_h - -#if defined(ENABLE_CONDITIONAL_INTERFACE) - -#include "base/hash_tables.h" -#include "base/lazy_instance.h" -#include "base/memory/ref_counted.h" -#include "base/threading/thread_checker.h" -#include "cobalt/base/polymorphic_downcast.h" -#include "cobalt/script/wrappable.h" -#include "cobalt/bindings/testing/conditional_interface.h" - -#include "third_party/mozjs-45/js/src/jsapi.h" - -namespace cobalt { -namespace bindings { -namespace testing { - -class MozjsConditionalInterface { - public: - static JSObject* CreateProxy(JSContext* context, - const scoped_refptr<script::Wrappable>& wrappable); - static const JSClass* PrototypeClass(JSContext* context); - static JSObject* GetPrototype(JSContext* context, - JS::HandleObject global_object); - static JSObject* GetInterfaceObject(JSContext* context, - JS::HandleObject global_object); -}; - -} // namespace bindings -} // namespace testing -} // namespace cobalt - -#endif // defined(ENABLE_CONDITIONAL_INTERFACE) - -#endif // MozjsConditionalInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsConstantsInterface.cc b/src/cobalt/bindings/generated/mozjs-45/testing/MozjsConstantsInterface.cc deleted file mode 100644 index 3836b6c..0000000 --- a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsConstantsInterface.cc +++ /dev/null
@@ -1,411 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! -// Auto-generated from template: bindings/mozjs-45/templates/interface.cc.template - -// clang-format off - -#include "MozjsConstantsInterface.h" - -#include "base/debug/trace_event.h" -#include "cobalt/base/polymorphic_downcast.h" -#include "cobalt/script/global_environment.h" -#include "cobalt/script/opaque_handle.h" -#include "cobalt/script/script_object.h" - -#include "base/lazy_instance.h" -#include "cobalt/script/mozjs-45/callback_function_conversion.h" -#include "cobalt/script/exception_state.h" -#include "cobalt/script/mozjs-45/conversion_helpers.h" -#include "cobalt/script/mozjs-45/mozjs_exception_state.h" -#include "cobalt/script/mozjs-45/mozjs_callback_function.h" -#include "cobalt/script/mozjs-45/mozjs_global_environment.h" -#include "cobalt/script/mozjs-45/mozjs_object_handle.h" -#include "cobalt/script/mozjs-45/mozjs_property_enumerator.h" -#include "cobalt/script/mozjs-45/mozjs_user_object_holder.h" -#include "cobalt/script/mozjs-45/proxy_handler.h" -#include "cobalt/script/mozjs-45/type_traits.h" -#include "cobalt/script/mozjs-45/wrapper_factory.h" -#include "cobalt/script/mozjs-45/wrapper_private.h" -#include "cobalt/script/property_enumerator.h" -#include "third_party/mozjs-45/js/src/jsapi.h" -#include "third_party/mozjs-45/js/src/jsfriendapi.h" - -namespace { -using cobalt::bindings::testing::ConstantsInterface; -using cobalt::bindings::testing::MozjsConstantsInterface; -using cobalt::script::CallbackInterfaceTraits; -using cobalt::script::GlobalEnvironment; -using cobalt::script::OpaqueHandle; -using cobalt::script::OpaqueHandleHolder; -using cobalt::script::ScriptObject; -using cobalt::script::Wrappable; - -using cobalt::script::CallbackFunction; -using cobalt::script::CallbackInterfaceTraits; -using cobalt::script::ExceptionState; -using cobalt::script::mozjs::FromJSValue; -using cobalt::script::mozjs::kConversionFlagNullable; -using cobalt::script::mozjs::kConversionFlagRestricted; -using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString; -using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString; -using cobalt::script::mozjs::kNoConversionFlags; -using cobalt::script::mozjs::InterfaceData; -using cobalt::script::mozjs::MozjsCallbackFunction; -using cobalt::script::mozjs::MozjsExceptionState; -using cobalt::script::mozjs::MozjsGlobalEnvironment; -using cobalt::script::mozjs::MozjsUserObjectHolder; -using cobalt::script::mozjs::MozjsPropertyEnumerator; -using cobalt::script::mozjs::ProxyHandler; -using cobalt::script::mozjs::ToJSValue; -using cobalt::script::mozjs::TypeTraits; -using cobalt::script::mozjs::WrapperPrivate; -using cobalt::script::mozjs::WrapperFactory; -using cobalt::script::Wrappable; -} // namespace - -namespace cobalt { -namespace bindings { -namespace testing { - -namespace { - -class MozjsConstantsInterfaceHandler : public ProxyHandler { - public: - MozjsConstantsInterfaceHandler() - : ProxyHandler(indexed_property_hooks, named_property_hooks) {} - - private: - static NamedPropertyHooks named_property_hooks; - static IndexedPropertyHooks indexed_property_hooks; -}; - -ProxyHandler::NamedPropertyHooks -MozjsConstantsInterfaceHandler::named_property_hooks = { - NULL, - NULL, - NULL, - NULL, - NULL, -}; -ProxyHandler::IndexedPropertyHooks -MozjsConstantsInterfaceHandler::indexed_property_hooks = { - NULL, - NULL, - NULL, - NULL, - NULL, -}; - -static base::LazyInstance<MozjsConstantsInterfaceHandler> - proxy_handler; - -bool get_INTEGER_CONSTANT( - JSContext* context, unsigned argc, JS::Value* vp) { - COMPILE_ASSERT(ConstantsInterface::kIntegerConstant == 5, - ValueForConstantsInterface_kIntegerConstantDoesNotMatchIDL); - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - ToJSValue(context, 5, &result_value); - if (!exception_state.is_exception_set()) { - args.rval().set(result_value); - } - return !exception_state.is_exception_set(); -} - -bool get_DOUBLE_CONSTANT( - JSContext* context, unsigned argc, JS::Value* vp) { - DCHECK_EQ(2.718, ConstantsInterface::kDoubleConstant) << - "The value for ConstantsInterface::kDoubleConstant does not match " - "the value in the interface definition."; - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - ToJSValue(context, 2.718, &result_value); - if (!exception_state.is_exception_set()) { - args.rval().set(result_value); - } - return !exception_state.is_exception_set(); -} - -bool HasInstance(JSContext *context, JS::HandleObject type, - JS::MutableHandleValue vp, bool *success) { - JS::RootedObject global_object( - context, JS_GetGlobalForObject(context, type)); - DCHECK(global_object); - - JS::RootedObject prototype( - context, MozjsConstantsInterface::GetPrototype(context, global_object)); - - // |IsDelegate| walks the prototype chain of an object returning true if - // .prototype is found. - bool is_delegate; - if (!IsDelegate(context, prototype, vp, &is_delegate)) { - *success = false; - return false; - } - - *success = is_delegate; - return true; -} - -const JSClass instance_class_definition = { - "ConstantsInterface", - 0 | JSCLASS_HAS_PRIVATE, - NULL, // addProperty - NULL, // delProperty - NULL, // getProperty - NULL, // setProperty - NULL, // enumerate - NULL, // resolve - NULL, // mayResolve - &WrapperPrivate::Finalizer, // finalize - NULL, // call - NULL, // hasInstance - NULL, // construct - &WrapperPrivate::Trace, // trace -}; - -const JSClass prototype_class_definition = { - "ConstantsInterfacePrototype", -}; - -const JSClass interface_object_class_definition = { - "ConstantsInterfaceConstructor", - 0, - NULL, // addProperty - NULL, // delProperty - NULL, // getProperty - NULL, // setProperty - NULL, // enumerate - NULL, // resolve - NULL, // mayResolve - NULL, // finalize - NULL, // call - &HasInstance, - NULL, -}; - - - -const JSPropertySpec prototype_properties[] = { - { - "INTEGER_CONSTANT", - JSPROP_PERMANENT | JSPROP_SHARED | JSPROP_ENUMERATE, - { { &get_INTEGER_CONSTANT, NULL } }, - JSNATIVE_WRAPPER(NULL) - }, - { - "DOUBLE_CONSTANT", - JSPROP_PERMANENT | JSPROP_SHARED | JSPROP_ENUMERATE, - { { &get_DOUBLE_CONSTANT, NULL } }, - JSNATIVE_WRAPPER(NULL) - }, - JS_PS_END -}; - -const JSFunctionSpec prototype_functions[] = { - JS_FS_END -}; - -const JSPropertySpec interface_object_properties[] = { - { - "INTEGER_CONSTANT", - JSPROP_SHARED | JSPROP_ENUMERATE, - { { &get_INTEGER_CONSTANT, NULL } }, - JSNATIVE_WRAPPER(NULL), - }, - - { - "DOUBLE_CONSTANT", - JSPROP_SHARED | JSPROP_ENUMERATE, - { { &get_DOUBLE_CONSTANT, NULL } }, - JSNATIVE_WRAPPER(NULL), - }, - - JS_PS_END -}; - -const JSFunctionSpec interface_object_functions[] = { - JS_FS_END -}; - -const JSPropertySpec own_properties[] = { - JS_PS_END -}; - -void InitializePrototypeAndInterfaceObject( - InterfaceData* interface_data, JSContext* context, - JS::HandleObject global_object) { - DCHECK(!interface_data->prototype); - DCHECK(!interface_data->interface_object); - DCHECK(JS_IsGlobalObject(global_object)); - - JS::RootedObject parent_prototype( - context, JS_GetObjectPrototype(context, global_object)); - DCHECK(parent_prototype); - - interface_data->prototype = JS_NewObjectWithGivenProto( - context, &prototype_class_definition, parent_prototype - ); - - JS::RootedObject rooted_prototype(context, interface_data->prototype); - bool success = JS_DefineProperties( - context, - rooted_prototype, - prototype_properties); - - DCHECK(success); - success = JS_DefineFunctions( - context, rooted_prototype, prototype_functions); - DCHECK(success); - - JS::RootedObject function_prototype( - context, JS_GetFunctionPrototype(context, global_object)); - DCHECK(function_prototype); - // Create the Interface object. - interface_data->interface_object = JS_NewObjectWithGivenProto( - context, &interface_object_class_definition, - function_prototype); - - // Add the InterfaceObject.name property. - JS::RootedObject rooted_interface_object( - context, interface_data->interface_object); - JS::RootedValue name_value(context); - const char name[] = - "ConstantsInterface"; - name_value.setString(JS_NewStringCopyZ(context, name)); - success = JS_DefineProperty( - context, rooted_interface_object, "name", name_value, JSPROP_READONLY, - NULL, NULL); - DCHECK(success); - - // Define interface object properties (including constants). - success = JS_DefineProperties(context, rooted_interface_object, - interface_object_properties); - DCHECK(success); - // Define interface object functions (static). - success = JS_DefineFunctions(context, rooted_interface_object, - interface_object_functions); - DCHECK(success); - - // Set the Prototype.constructor and Constructor.prototype properties. - DCHECK(interface_data->interface_object); - DCHECK(interface_data->prototype); - success = JS_LinkConstructorAndPrototype( - context, - rooted_interface_object, - rooted_prototype); - DCHECK(success); -} - -InterfaceData* GetInterfaceData(JSContext* context) { - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - // Use the address of the properties definition for this interface as a - // unique key for looking up the InterfaceData for this interface. - intptr_t key = reinterpret_cast<intptr_t>(&own_properties); - InterfaceData* interface_data = global_environment->GetInterfaceData(key); - if (!interface_data) { - interface_data = new InterfaceData(); - DCHECK(interface_data); - global_environment->CacheInterfaceData(key, interface_data); - DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key)); - } - return interface_data; -} - -} // namespace - -// static -JSObject* MozjsConstantsInterface::CreateProxy( - JSContext* context, const scoped_refptr<Wrappable>& wrappable) { - DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); - JS::RootedObject global_object( - context, - MozjsGlobalEnvironment::GetFromContext(context)->global_object()); - DCHECK(global_object); - - InterfaceData* interface_data = GetInterfaceData(context); - JS::RootedObject prototype(context, GetPrototype(context, global_object)); - DCHECK(prototype); - JS::RootedObject new_object( - context, - JS_NewObjectWithGivenProto( - context, &instance_class_definition, prototype)); - DCHECK(new_object); - JS::RootedObject proxy(context, - ProxyHandler::NewProxy( - context, proxy_handler.Pointer(), new_object, prototype)); - WrapperPrivate::AddPrivateData(context, proxy, wrappable); - return proxy; -} - -// static -const JSClass* MozjsConstantsInterface::PrototypeClass( - JSContext* context) { - DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); - JS::RootedObject global_object( - context, - MozjsGlobalEnvironment::GetFromContext(context)->global_object()); - DCHECK(global_object); - - JS::RootedObject prototype(context, GetPrototype(context, global_object)); - const JSClass* proto_class = JS_GetClass(prototype); - return proto_class; -} - -// static -JSObject* MozjsConstantsInterface::GetPrototype( - JSContext* context, JS::HandleObject global_object) { - DCHECK(JS_IsGlobalObject(global_object)); - - InterfaceData* interface_data = GetInterfaceData(context); - if (!interface_data->prototype) { - // Create new prototype that has all the props and methods - InitializePrototypeAndInterfaceObject( - interface_data, context, global_object); - } - DCHECK(interface_data->prototype); - return interface_data->prototype; -} - -// static -JSObject* MozjsConstantsInterface::GetInterfaceObject( - JSContext* context, JS::HandleObject global_object) { - DCHECK(JS_IsGlobalObject(global_object)); - - InterfaceData* interface_data = GetInterfaceData(context); - if (!interface_data->interface_object) { - InitializePrototypeAndInterfaceObject( - interface_data, context, global_object); - } - DCHECK(interface_data->interface_object); - return interface_data->interface_object; -} - - -namespace { -} // namespace - - -} // namespace testing -} // namespace bindings -} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsConstantsInterface.h b/src/cobalt/bindings/generated/mozjs-45/testing/MozjsConstantsInterface.h deleted file mode 100644 index 19b353b..0000000 --- a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsConstantsInterface.h +++ /dev/null
@@ -1,54 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! -// Auto-generated from template: bindings/mozjs-45/templates/interface.h.template - -// clang-format off - -#ifndef MozjsConstantsInterface_h -#define MozjsConstantsInterface_h - -#include "base/hash_tables.h" -#include "base/lazy_instance.h" -#include "base/memory/ref_counted.h" -#include "base/threading/thread_checker.h" -#include "cobalt/base/polymorphic_downcast.h" -#include "cobalt/script/wrappable.h" -#include "cobalt/bindings/testing/constants_interface.h" - -#include "third_party/mozjs-45/js/src/jsapi.h" - -namespace cobalt { -namespace bindings { -namespace testing { - -class MozjsConstantsInterface { - public: - static JSObject* CreateProxy(JSContext* context, - const scoped_refptr<script::Wrappable>& wrappable); - static const JSClass* PrototypeClass(JSContext* context); - static JSObject* GetPrototype(JSContext* context, - JS::HandleObject global_object); - static JSObject* GetInterfaceObject(JSContext* context, - JS::HandleObject global_object); -}; - -} // namespace bindings -} // namespace testing -} // namespace cobalt - -#endif // MozjsConstantsInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsConstructorInterface.cc b/src/cobalt/bindings/generated/mozjs-45/testing/MozjsConstructorInterface.cc deleted file mode 100644 index 4ace1ae..0000000 --- a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsConstructorInterface.cc +++ /dev/null
@@ -1,439 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! -// Auto-generated from template: bindings/mozjs-45/templates/interface.cc.template - -// clang-format off - -#include "MozjsConstructorInterface.h" - -#include "base/debug/trace_event.h" -#include "cobalt/base/polymorphic_downcast.h" -#include "cobalt/script/global_environment.h" -#include "cobalt/script/opaque_handle.h" -#include "cobalt/script/script_object.h" - -#include "base/lazy_instance.h" -#include "cobalt/script/mozjs-45/callback_function_conversion.h" -#include "cobalt/script/exception_state.h" -#include "cobalt/script/mozjs-45/conversion_helpers.h" -#include "cobalt/script/mozjs-45/mozjs_exception_state.h" -#include "cobalt/script/mozjs-45/mozjs_callback_function.h" -#include "cobalt/script/mozjs-45/mozjs_global_environment.h" -#include "cobalt/script/mozjs-45/mozjs_object_handle.h" -#include "cobalt/script/mozjs-45/mozjs_property_enumerator.h" -#include "cobalt/script/mozjs-45/mozjs_user_object_holder.h" -#include "cobalt/script/mozjs-45/proxy_handler.h" -#include "cobalt/script/mozjs-45/type_traits.h" -#include "cobalt/script/mozjs-45/wrapper_factory.h" -#include "cobalt/script/mozjs-45/wrapper_private.h" -#include "cobalt/script/property_enumerator.h" -#include "third_party/mozjs-45/js/src/jsapi.h" -#include "third_party/mozjs-45/js/src/jsfriendapi.h" - -namespace { -using cobalt::bindings::testing::ConstructorInterface; -using cobalt::bindings::testing::MozjsConstructorInterface; -using cobalt::script::CallbackInterfaceTraits; -using cobalt::script::GlobalEnvironment; -using cobalt::script::OpaqueHandle; -using cobalt::script::OpaqueHandleHolder; -using cobalt::script::ScriptObject; -using cobalt::script::Wrappable; - -using cobalt::script::CallbackFunction; -using cobalt::script::CallbackInterfaceTraits; -using cobalt::script::ExceptionState; -using cobalt::script::mozjs::FromJSValue; -using cobalt::script::mozjs::kConversionFlagNullable; -using cobalt::script::mozjs::kConversionFlagRestricted; -using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString; -using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString; -using cobalt::script::mozjs::kNoConversionFlags; -using cobalt::script::mozjs::InterfaceData; -using cobalt::script::mozjs::MozjsCallbackFunction; -using cobalt::script::mozjs::MozjsExceptionState; -using cobalt::script::mozjs::MozjsGlobalEnvironment; -using cobalt::script::mozjs::MozjsUserObjectHolder; -using cobalt::script::mozjs::MozjsPropertyEnumerator; -using cobalt::script::mozjs::ProxyHandler; -using cobalt::script::mozjs::ToJSValue; -using cobalt::script::mozjs::TypeTraits; -using cobalt::script::mozjs::WrapperPrivate; -using cobalt::script::mozjs::WrapperFactory; -using cobalt::script::Wrappable; -} // namespace - -namespace cobalt { -namespace bindings { -namespace testing { - -namespace { - -class MozjsConstructorInterfaceHandler : public ProxyHandler { - public: - MozjsConstructorInterfaceHandler() - : ProxyHandler(indexed_property_hooks, named_property_hooks) {} - - private: - static NamedPropertyHooks named_property_hooks; - static IndexedPropertyHooks indexed_property_hooks; -}; - -ProxyHandler::NamedPropertyHooks -MozjsConstructorInterfaceHandler::named_property_hooks = { - NULL, - NULL, - NULL, - NULL, - NULL, -}; -ProxyHandler::IndexedPropertyHooks -MozjsConstructorInterfaceHandler::indexed_property_hooks = { - NULL, - NULL, - NULL, - NULL, - NULL, -}; - -static base::LazyInstance<MozjsConstructorInterfaceHandler> - proxy_handler; - -bool Constructor(JSContext* context, unsigned int argc, JS::Value* vp); -bool HasInstance(JSContext *context, JS::HandleObject type, - JS::MutableHandleValue vp, bool *success) { - JS::RootedObject global_object( - context, JS_GetGlobalForObject(context, type)); - DCHECK(global_object); - - JS::RootedObject prototype( - context, MozjsConstructorInterface::GetPrototype(context, global_object)); - - // |IsDelegate| walks the prototype chain of an object returning true if - // .prototype is found. - bool is_delegate; - if (!IsDelegate(context, prototype, vp, &is_delegate)) { - *success = false; - return false; - } - - *success = is_delegate; - return true; -} - -const JSClass instance_class_definition = { - "ConstructorInterface", - 0 | JSCLASS_HAS_PRIVATE, - NULL, // addProperty - NULL, // delProperty - NULL, // getProperty - NULL, // setProperty - NULL, // enumerate - NULL, // resolve - NULL, // mayResolve - &WrapperPrivate::Finalizer, // finalize - NULL, // call - NULL, // hasInstance - NULL, // construct - &WrapperPrivate::Trace, // trace -}; - -const JSClass prototype_class_definition = { - "ConstructorInterfacePrototype", -}; - -const JSClass interface_object_class_definition = { - "ConstructorInterfaceConstructor", - 0, - NULL, // addProperty - NULL, // delProperty - NULL, // getProperty - NULL, // setProperty - NULL, // enumerate - NULL, // resolve - NULL, // mayResolve - NULL, // finalize - NULL, // call - &HasInstance, - Constructor, -}; - - - -const JSPropertySpec prototype_properties[] = { - JS_PS_END -}; - -const JSFunctionSpec prototype_functions[] = { - JS_FS_END -}; - -const JSPropertySpec interface_object_properties[] = { - JS_PS_END -}; - -const JSFunctionSpec interface_object_functions[] = { - JS_FS_END -}; - -const JSPropertySpec own_properties[] = { - JS_PS_END -}; - -void InitializePrototypeAndInterfaceObject( - InterfaceData* interface_data, JSContext* context, - JS::HandleObject global_object) { - DCHECK(!interface_data->prototype); - DCHECK(!interface_data->interface_object); - DCHECK(JS_IsGlobalObject(global_object)); - - JS::RootedObject parent_prototype( - context, JS_GetObjectPrototype(context, global_object)); - DCHECK(parent_prototype); - - interface_data->prototype = JS_NewObjectWithGivenProto( - context, &prototype_class_definition, parent_prototype - ); - - JS::RootedObject rooted_prototype(context, interface_data->prototype); - bool success = JS_DefineProperties( - context, - rooted_prototype, - prototype_properties); - - DCHECK(success); - success = JS_DefineFunctions( - context, rooted_prototype, prototype_functions); - DCHECK(success); - - JS::RootedObject function_prototype( - context, JS_GetFunctionPrototype(context, global_object)); - DCHECK(function_prototype); - // Create the Interface object. - interface_data->interface_object = JS_NewObjectWithGivenProto( - context, &interface_object_class_definition, - function_prototype); - - // Add the InterfaceObject.name property. - JS::RootedObject rooted_interface_object( - context, interface_data->interface_object); - JS::RootedValue name_value(context); - const char name[] = - "ConstructorInterface"; - name_value.setString(JS_NewStringCopyZ(context, name)); - success = JS_DefineProperty( - context, rooted_interface_object, "name", name_value, JSPROP_READONLY, - NULL, NULL); - DCHECK(success); - - // Add the InterfaceObject.length property. It is set to the length of the - // shortest argument list of all overload constructors. - JS::RootedValue length_value(context); - length_value.setInt32(0); - success = JS_DefineProperty( - context, rooted_interface_object, "length", length_value, - JSPROP_READONLY, NULL, NULL); - DCHECK(success); - - // Define interface object properties (including constants). - success = JS_DefineProperties(context, rooted_interface_object, - interface_object_properties); - DCHECK(success); - // Define interface object functions (static). - success = JS_DefineFunctions(context, rooted_interface_object, - interface_object_functions); - DCHECK(success); - - // Set the Prototype.constructor and Constructor.prototype properties. - DCHECK(interface_data->interface_object); - DCHECK(interface_data->prototype); - success = JS_LinkConstructorAndPrototype( - context, - rooted_interface_object, - rooted_prototype); - DCHECK(success); -} - -InterfaceData* GetInterfaceData(JSContext* context) { - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - // Use the address of the properties definition for this interface as a - // unique key for looking up the InterfaceData for this interface. - intptr_t key = reinterpret_cast<intptr_t>(&own_properties); - InterfaceData* interface_data = global_environment->GetInterfaceData(key); - if (!interface_data) { - interface_data = new InterfaceData(); - DCHECK(interface_data); - global_environment->CacheInterfaceData(key, interface_data); - DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key)); - } - return interface_data; -} - -} // namespace - -// static -JSObject* MozjsConstructorInterface::CreateProxy( - JSContext* context, const scoped_refptr<Wrappable>& wrappable) { - DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); - JS::RootedObject global_object( - context, - MozjsGlobalEnvironment::GetFromContext(context)->global_object()); - DCHECK(global_object); - - InterfaceData* interface_data = GetInterfaceData(context); - JS::RootedObject prototype(context, GetPrototype(context, global_object)); - DCHECK(prototype); - JS::RootedObject new_object( - context, - JS_NewObjectWithGivenProto( - context, &instance_class_definition, prototype)); - DCHECK(new_object); - JS::RootedObject proxy(context, - ProxyHandler::NewProxy( - context, proxy_handler.Pointer(), new_object, prototype)); - WrapperPrivate::AddPrivateData(context, proxy, wrappable); - return proxy; -} - -// static -const JSClass* MozjsConstructorInterface::PrototypeClass( - JSContext* context) { - DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); - JS::RootedObject global_object( - context, - MozjsGlobalEnvironment::GetFromContext(context)->global_object()); - DCHECK(global_object); - - JS::RootedObject prototype(context, GetPrototype(context, global_object)); - const JSClass* proto_class = JS_GetClass(prototype); - return proto_class; -} - -// static -JSObject* MozjsConstructorInterface::GetPrototype( - JSContext* context, JS::HandleObject global_object) { - DCHECK(JS_IsGlobalObject(global_object)); - - InterfaceData* interface_data = GetInterfaceData(context); - if (!interface_data->prototype) { - // Create new prototype that has all the props and methods - InitializePrototypeAndInterfaceObject( - interface_data, context, global_object); - } - DCHECK(interface_data->prototype); - return interface_data->prototype; -} - -// static -JSObject* MozjsConstructorInterface::GetInterfaceObject( - JSContext* context, JS::HandleObject global_object) { - DCHECK(JS_IsGlobalObject(global_object)); - - InterfaceData* interface_data = GetInterfaceData(context); - if (!interface_data->interface_object) { - InitializePrototypeAndInterfaceObject( - interface_data, context, global_object); - } - DCHECK(interface_data->interface_object); - return interface_data->interface_object; -} - - -namespace { -bool Constructor1( - JSContext* context, unsigned int argc, JS::Value* vp) { - MozjsExceptionState exception_state(context); - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - - scoped_refptr<ConstructorInterface> new_object = - new ConstructorInterface(); - JS::RootedValue result_value(context); - ToJSValue(context, new_object, &result_value); - DCHECK(result_value.isObject()); - args.rval().setObject(result_value.toObject()); - return true; -} - -bool Constructor2( - JSContext* context, unsigned int argc, JS::Value* vp) { - MozjsExceptionState exception_state(context); - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - const size_t kMinArguments = 1; - if (args.length() < kMinArguments) { - exception_state.SetSimpleException(script::kInvalidNumberOfArguments); - return false; - } - // Non-optional arguments - TypeTraits<bool >::ConversionType arg; - - DCHECK_LT(0, args.length()); - JS::RootedValue non_optional_value0( - context, args[0]); - FromJSValue(context, - non_optional_value0, - kNoConversionFlags, - &exception_state, &arg); - if (exception_state.is_exception_set()) { - return false; - } - - scoped_refptr<ConstructorInterface> new_object = - new ConstructorInterface(arg); - JS::RootedValue result_value(context); - ToJSValue(context, new_object, &result_value); - DCHECK(result_value.isObject()); - args.rval().setObject(result_value.toObject()); - return true; -} - -bool Constructor(JSContext* context, unsigned int argc, JS::Value* vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - switch(argc) { - case(0): { - // Overload resolution algorithm details found here: - // http://heycam.github.io/webidl/#dfn-overload-resolution-algorithm - if (true) { - return Constructor1( - context, argc, vp); - } - break; - } - case(1): { - // Overload resolution algorithm details found here: - // http://heycam.github.io/webidl/#dfn-overload-resolution-algorithm - if (true) { - return Constructor2( - context, argc, vp); - } - break; - } - } - // Invalid number of args - // http://heycam.github.io/webidl/#dfn-overload-resolution-algorithm - // 4. If S is empty, then throw a TypeError. - MozjsExceptionState exception_state(context); - exception_state.SetSimpleException(script::kInvalidNumberOfArguments); - return false; -} -} // namespace - - -} // namespace testing -} // namespace bindings -} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsConstructorInterface.h b/src/cobalt/bindings/generated/mozjs-45/testing/MozjsConstructorInterface.h deleted file mode 100644 index c0c1958..0000000 --- a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsConstructorInterface.h +++ /dev/null
@@ -1,54 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! -// Auto-generated from template: bindings/mozjs-45/templates/interface.h.template - -// clang-format off - -#ifndef MozjsConstructorInterface_h -#define MozjsConstructorInterface_h - -#include "base/hash_tables.h" -#include "base/lazy_instance.h" -#include "base/memory/ref_counted.h" -#include "base/threading/thread_checker.h" -#include "cobalt/base/polymorphic_downcast.h" -#include "cobalt/script/wrappable.h" -#include "cobalt/bindings/testing/constructor_interface.h" - -#include "third_party/mozjs-45/js/src/jsapi.h" - -namespace cobalt { -namespace bindings { -namespace testing { - -class MozjsConstructorInterface { - public: - static JSObject* CreateProxy(JSContext* context, - const scoped_refptr<script::Wrappable>& wrappable); - static const JSClass* PrototypeClass(JSContext* context); - static JSObject* GetPrototype(JSContext* context, - JS::HandleObject global_object); - static JSObject* GetInterfaceObject(JSContext* context, - JS::HandleObject global_object); -}; - -} // namespace bindings -} // namespace testing -} // namespace cobalt - -#endif // MozjsConstructorInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsConstructorWithArgumentsInterface.cc b/src/cobalt/bindings/generated/mozjs-45/testing/MozjsConstructorWithArgumentsInterface.cc deleted file mode 100644 index 16d2ffd..0000000 --- a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsConstructorWithArgumentsInterface.cc +++ /dev/null
@@ -1,539 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! -// Auto-generated from template: bindings/mozjs-45/templates/interface.cc.template - -// clang-format off - -#include "MozjsConstructorWithArgumentsInterface.h" - -#include "base/debug/trace_event.h" -#include "cobalt/base/polymorphic_downcast.h" -#include "cobalt/script/global_environment.h" -#include "cobalt/script/opaque_handle.h" -#include "cobalt/script/script_object.h" - -#include "base/lazy_instance.h" -#include "cobalt/script/mozjs-45/callback_function_conversion.h" -#include "cobalt/script/exception_state.h" -#include "cobalt/script/mozjs-45/conversion_helpers.h" -#include "cobalt/script/mozjs-45/mozjs_exception_state.h" -#include "cobalt/script/mozjs-45/mozjs_callback_function.h" -#include "cobalt/script/mozjs-45/mozjs_global_environment.h" -#include "cobalt/script/mozjs-45/mozjs_object_handle.h" -#include "cobalt/script/mozjs-45/mozjs_property_enumerator.h" -#include "cobalt/script/mozjs-45/mozjs_user_object_holder.h" -#include "cobalt/script/mozjs-45/proxy_handler.h" -#include "cobalt/script/mozjs-45/type_traits.h" -#include "cobalt/script/mozjs-45/wrapper_factory.h" -#include "cobalt/script/mozjs-45/wrapper_private.h" -#include "cobalt/script/property_enumerator.h" -#include "third_party/mozjs-45/js/src/jsapi.h" -#include "third_party/mozjs-45/js/src/jsfriendapi.h" - -namespace { -using cobalt::bindings::testing::ConstructorWithArgumentsInterface; -using cobalt::bindings::testing::MozjsConstructorWithArgumentsInterface; -using cobalt::script::CallbackInterfaceTraits; -using cobalt::script::GlobalEnvironment; -using cobalt::script::OpaqueHandle; -using cobalt::script::OpaqueHandleHolder; -using cobalt::script::ScriptObject; -using cobalt::script::Wrappable; - -using cobalt::script::CallbackFunction; -using cobalt::script::CallbackInterfaceTraits; -using cobalt::script::ExceptionState; -using cobalt::script::mozjs::FromJSValue; -using cobalt::script::mozjs::kConversionFlagNullable; -using cobalt::script::mozjs::kConversionFlagRestricted; -using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString; -using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString; -using cobalt::script::mozjs::kNoConversionFlags; -using cobalt::script::mozjs::InterfaceData; -using cobalt::script::mozjs::MozjsCallbackFunction; -using cobalt::script::mozjs::MozjsExceptionState; -using cobalt::script::mozjs::MozjsGlobalEnvironment; -using cobalt::script::mozjs::MozjsUserObjectHolder; -using cobalt::script::mozjs::MozjsPropertyEnumerator; -using cobalt::script::mozjs::ProxyHandler; -using cobalt::script::mozjs::ToJSValue; -using cobalt::script::mozjs::TypeTraits; -using cobalt::script::mozjs::WrapperPrivate; -using cobalt::script::mozjs::WrapperFactory; -using cobalt::script::Wrappable; -} // namespace - -namespace cobalt { -namespace bindings { -namespace testing { - -namespace { - -class MozjsConstructorWithArgumentsInterfaceHandler : public ProxyHandler { - public: - MozjsConstructorWithArgumentsInterfaceHandler() - : ProxyHandler(indexed_property_hooks, named_property_hooks) {} - - private: - static NamedPropertyHooks named_property_hooks; - static IndexedPropertyHooks indexed_property_hooks; -}; - -ProxyHandler::NamedPropertyHooks -MozjsConstructorWithArgumentsInterfaceHandler::named_property_hooks = { - NULL, - NULL, - NULL, - NULL, - NULL, -}; -ProxyHandler::IndexedPropertyHooks -MozjsConstructorWithArgumentsInterfaceHandler::indexed_property_hooks = { - NULL, - NULL, - NULL, - NULL, - NULL, -}; - -static base::LazyInstance<MozjsConstructorWithArgumentsInterfaceHandler> - proxy_handler; - -bool Constructor(JSContext* context, unsigned int argc, JS::Value* vp); -bool HasInstance(JSContext *context, JS::HandleObject type, - JS::MutableHandleValue vp, bool *success) { - JS::RootedObject global_object( - context, JS_GetGlobalForObject(context, type)); - DCHECK(global_object); - - JS::RootedObject prototype( - context, MozjsConstructorWithArgumentsInterface::GetPrototype(context, global_object)); - - // |IsDelegate| walks the prototype chain of an object returning true if - // .prototype is found. - bool is_delegate; - if (!IsDelegate(context, prototype, vp, &is_delegate)) { - *success = false; - return false; - } - - *success = is_delegate; - return true; -} - -const JSClass instance_class_definition = { - "ConstructorWithArgumentsInterface", - 0 | JSCLASS_HAS_PRIVATE, - NULL, // addProperty - NULL, // delProperty - NULL, // getProperty - NULL, // setProperty - NULL, // enumerate - NULL, // resolve - NULL, // mayResolve - &WrapperPrivate::Finalizer, // finalize - NULL, // call - NULL, // hasInstance - NULL, // construct - &WrapperPrivate::Trace, // trace -}; - -const JSClass prototype_class_definition = { - "ConstructorWithArgumentsInterfacePrototype", -}; - -const JSClass interface_object_class_definition = { - "ConstructorWithArgumentsInterfaceConstructor", - 0, - NULL, // addProperty - NULL, // delProperty - NULL, // getProperty - NULL, // setProperty - NULL, // enumerate - NULL, // resolve - NULL, // mayResolve - NULL, // finalize - NULL, // call - &HasInstance, - Constructor, -}; - -bool get_longArg( - JSContext* context, unsigned argc, JS::Value* vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<ConstructorWithArgumentsInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - ConstructorWithArgumentsInterface* impl = - wrapper_private->wrappable<ConstructorWithArgumentsInterface>().get(); - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->long_arg(), - &result_value); - } - if (!exception_state.is_exception_set()) { - args.rval().set(result_value); - } - return !exception_state.is_exception_set(); -} - - -bool get_booleanArg( - JSContext* context, unsigned argc, JS::Value* vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<ConstructorWithArgumentsInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - ConstructorWithArgumentsInterface* impl = - wrapper_private->wrappable<ConstructorWithArgumentsInterface>().get(); - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->boolean_arg(), - &result_value); - } - if (!exception_state.is_exception_set()) { - args.rval().set(result_value); - } - return !exception_state.is_exception_set(); -} - - -bool get_stringArg( - JSContext* context, unsigned argc, JS::Value* vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<ConstructorWithArgumentsInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - ConstructorWithArgumentsInterface* impl = - wrapper_private->wrappable<ConstructorWithArgumentsInterface>().get(); - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->string_arg(), - &result_value); - } - if (!exception_state.is_exception_set()) { - args.rval().set(result_value); - } - return !exception_state.is_exception_set(); -} - - - - -const JSPropertySpec prototype_properties[] = { - { // Readonly attribute - "longArg", - JSPROP_SHARED | JSPROP_ENUMERATE, - { { &get_longArg, NULL } }, - JSNATIVE_WRAPPER(NULL), - }, - { // Readonly attribute - "booleanArg", - JSPROP_SHARED | JSPROP_ENUMERATE, - { { &get_booleanArg, NULL } }, - JSNATIVE_WRAPPER(NULL), - }, - { // Readonly attribute - "stringArg", - JSPROP_SHARED | JSPROP_ENUMERATE, - { { &get_stringArg, NULL } }, - JSNATIVE_WRAPPER(NULL), - }, - JS_PS_END -}; - -const JSFunctionSpec prototype_functions[] = { - JS_FS_END -}; - -const JSPropertySpec interface_object_properties[] = { - JS_PS_END -}; - -const JSFunctionSpec interface_object_functions[] = { - JS_FS_END -}; - -const JSPropertySpec own_properties[] = { - JS_PS_END -}; - -void InitializePrototypeAndInterfaceObject( - InterfaceData* interface_data, JSContext* context, - JS::HandleObject global_object) { - DCHECK(!interface_data->prototype); - DCHECK(!interface_data->interface_object); - DCHECK(JS_IsGlobalObject(global_object)); - - JS::RootedObject parent_prototype( - context, JS_GetObjectPrototype(context, global_object)); - DCHECK(parent_prototype); - - interface_data->prototype = JS_NewObjectWithGivenProto( - context, &prototype_class_definition, parent_prototype - ); - - JS::RootedObject rooted_prototype(context, interface_data->prototype); - bool success = JS_DefineProperties( - context, - rooted_prototype, - prototype_properties); - - DCHECK(success); - success = JS_DefineFunctions( - context, rooted_prototype, prototype_functions); - DCHECK(success); - - JS::RootedObject function_prototype( - context, JS_GetFunctionPrototype(context, global_object)); - DCHECK(function_prototype); - // Create the Interface object. - interface_data->interface_object = JS_NewObjectWithGivenProto( - context, &interface_object_class_definition, - function_prototype); - - // Add the InterfaceObject.name property. - JS::RootedObject rooted_interface_object( - context, interface_data->interface_object); - JS::RootedValue name_value(context); - const char name[] = - "ConstructorWithArgumentsInterface"; - name_value.setString(JS_NewStringCopyZ(context, name)); - success = JS_DefineProperty( - context, rooted_interface_object, "name", name_value, JSPROP_READONLY, - NULL, NULL); - DCHECK(success); - - // Add the InterfaceObject.length property. It is set to the length of the - // shortest argument list of all overload constructors. - JS::RootedValue length_value(context); - length_value.setInt32(2); - success = JS_DefineProperty( - context, rooted_interface_object, "length", length_value, - JSPROP_READONLY, NULL, NULL); - DCHECK(success); - - // Define interface object properties (including constants). - success = JS_DefineProperties(context, rooted_interface_object, - interface_object_properties); - DCHECK(success); - // Define interface object functions (static). - success = JS_DefineFunctions(context, rooted_interface_object, - interface_object_functions); - DCHECK(success); - - // Set the Prototype.constructor and Constructor.prototype properties. - DCHECK(interface_data->interface_object); - DCHECK(interface_data->prototype); - success = JS_LinkConstructorAndPrototype( - context, - rooted_interface_object, - rooted_prototype); - DCHECK(success); -} - -InterfaceData* GetInterfaceData(JSContext* context) { - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - // Use the address of the properties definition for this interface as a - // unique key for looking up the InterfaceData for this interface. - intptr_t key = reinterpret_cast<intptr_t>(&own_properties); - InterfaceData* interface_data = global_environment->GetInterfaceData(key); - if (!interface_data) { - interface_data = new InterfaceData(); - DCHECK(interface_data); - global_environment->CacheInterfaceData(key, interface_data); - DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key)); - } - return interface_data; -} - -} // namespace - -// static -JSObject* MozjsConstructorWithArgumentsInterface::CreateProxy( - JSContext* context, const scoped_refptr<Wrappable>& wrappable) { - DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); - JS::RootedObject global_object( - context, - MozjsGlobalEnvironment::GetFromContext(context)->global_object()); - DCHECK(global_object); - - InterfaceData* interface_data = GetInterfaceData(context); - JS::RootedObject prototype(context, GetPrototype(context, global_object)); - DCHECK(prototype); - JS::RootedObject new_object( - context, - JS_NewObjectWithGivenProto( - context, &instance_class_definition, prototype)); - DCHECK(new_object); - JS::RootedObject proxy(context, - ProxyHandler::NewProxy( - context, proxy_handler.Pointer(), new_object, prototype)); - WrapperPrivate::AddPrivateData(context, proxy, wrappable); - return proxy; -} - -// static -const JSClass* MozjsConstructorWithArgumentsInterface::PrototypeClass( - JSContext* context) { - DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); - JS::RootedObject global_object( - context, - MozjsGlobalEnvironment::GetFromContext(context)->global_object()); - DCHECK(global_object); - - JS::RootedObject prototype(context, GetPrototype(context, global_object)); - const JSClass* proto_class = JS_GetClass(prototype); - return proto_class; -} - -// static -JSObject* MozjsConstructorWithArgumentsInterface::GetPrototype( - JSContext* context, JS::HandleObject global_object) { - DCHECK(JS_IsGlobalObject(global_object)); - - InterfaceData* interface_data = GetInterfaceData(context); - if (!interface_data->prototype) { - // Create new prototype that has all the props and methods - InitializePrototypeAndInterfaceObject( - interface_data, context, global_object); - } - DCHECK(interface_data->prototype); - return interface_data->prototype; -} - -// static -JSObject* MozjsConstructorWithArgumentsInterface::GetInterfaceObject( - JSContext* context, JS::HandleObject global_object) { - DCHECK(JS_IsGlobalObject(global_object)); - - InterfaceData* interface_data = GetInterfaceData(context); - if (!interface_data->interface_object) { - InitializePrototypeAndInterfaceObject( - interface_data, context, global_object); - } - DCHECK(interface_data->interface_object); - return interface_data->interface_object; -} - - -namespace { -bool Constructor(JSContext* context, unsigned int argc, JS::Value* vp) { - MozjsExceptionState exception_state(context); - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - const size_t kMinArguments = 2; - if (args.length() < kMinArguments) { - exception_state.SetSimpleException(script::kInvalidNumberOfArguments); - return false; - } - // Non-optional arguments - TypeTraits<int32_t >::ConversionType arg1; - TypeTraits<bool >::ConversionType arg2; - // Optional arguments with default values - TypeTraits<std::string >::ConversionType default_arg = - "default"; - - DCHECK_LT(0, args.length()); - JS::RootedValue non_optional_value0( - context, args[0]); - FromJSValue(context, - non_optional_value0, - kNoConversionFlags, - &exception_state, &arg1); - if (exception_state.is_exception_set()) { - return false; - } - - DCHECK_LT(1, args.length()); - JS::RootedValue non_optional_value1( - context, args[1]); - FromJSValue(context, - non_optional_value1, - kNoConversionFlags, - &exception_state, &arg2); - if (exception_state.is_exception_set()) { - return false; - } - size_t num_set_arguments = 3; - if (args.length() > 2) { - JS::RootedValue optional_value0( - context, args[2]); - FromJSValue(context, - optional_value0, - kNoConversionFlags, - &exception_state, - &default_arg); - if (exception_state.is_exception_set()) { - return false; - } - } - - scoped_refptr<ConstructorWithArgumentsInterface> new_object = - new ConstructorWithArgumentsInterface(arg1, arg2, default_arg); - JS::RootedValue result_value(context); - ToJSValue(context, new_object, &result_value); - DCHECK(result_value.isObject()); - args.rval().setObject(result_value.toObject()); - return true; -} -} // namespace - - -} // namespace testing -} // namespace bindings -} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsConstructorWithArgumentsInterface.h b/src/cobalt/bindings/generated/mozjs-45/testing/MozjsConstructorWithArgumentsInterface.h deleted file mode 100644 index 7d7f3bb..0000000 --- a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsConstructorWithArgumentsInterface.h +++ /dev/null
@@ -1,54 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! -// Auto-generated from template: bindings/mozjs-45/templates/interface.h.template - -// clang-format off - -#ifndef MozjsConstructorWithArgumentsInterface_h -#define MozjsConstructorWithArgumentsInterface_h - -#include "base/hash_tables.h" -#include "base/lazy_instance.h" -#include "base/memory/ref_counted.h" -#include "base/threading/thread_checker.h" -#include "cobalt/base/polymorphic_downcast.h" -#include "cobalt/script/wrappable.h" -#include "cobalt/bindings/testing/constructor_with_arguments_interface.h" - -#include "third_party/mozjs-45/js/src/jsapi.h" - -namespace cobalt { -namespace bindings { -namespace testing { - -class MozjsConstructorWithArgumentsInterface { - public: - static JSObject* CreateProxy(JSContext* context, - const scoped_refptr<script::Wrappable>& wrappable); - static const JSClass* PrototypeClass(JSContext* context); - static JSObject* GetPrototype(JSContext* context, - JS::HandleObject global_object); - static JSObject* GetInterfaceObject(JSContext* context, - JS::HandleObject global_object); -}; - -} // namespace bindings -} // namespace testing -} // namespace cobalt - -#endif // MozjsConstructorWithArgumentsInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsDOMStringTestInterface.cc b/src/cobalt/bindings/generated/mozjs-45/testing/MozjsDOMStringTestInterface.cc deleted file mode 100644 index 724a7b3..0000000 --- a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsDOMStringTestInterface.cc +++ /dev/null
@@ -1,736 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! -// Auto-generated from template: bindings/mozjs-45/templates/interface.cc.template - -// clang-format off - -#include "MozjsDOMStringTestInterface.h" - -#include "base/debug/trace_event.h" -#include "cobalt/base/polymorphic_downcast.h" -#include "cobalt/script/global_environment.h" -#include "cobalt/script/opaque_handle.h" -#include "cobalt/script/script_object.h" - -#include "base/lazy_instance.h" -#include "cobalt/script/mozjs-45/callback_function_conversion.h" -#include "cobalt/script/exception_state.h" -#include "cobalt/script/mozjs-45/conversion_helpers.h" -#include "cobalt/script/mozjs-45/mozjs_exception_state.h" -#include "cobalt/script/mozjs-45/mozjs_callback_function.h" -#include "cobalt/script/mozjs-45/mozjs_global_environment.h" -#include "cobalt/script/mozjs-45/mozjs_object_handle.h" -#include "cobalt/script/mozjs-45/mozjs_property_enumerator.h" -#include "cobalt/script/mozjs-45/mozjs_user_object_holder.h" -#include "cobalt/script/mozjs-45/proxy_handler.h" -#include "cobalt/script/mozjs-45/type_traits.h" -#include "cobalt/script/mozjs-45/wrapper_factory.h" -#include "cobalt/script/mozjs-45/wrapper_private.h" -#include "cobalt/script/property_enumerator.h" -#include "third_party/mozjs-45/js/src/jsapi.h" -#include "third_party/mozjs-45/js/src/jsfriendapi.h" - -namespace { -using cobalt::bindings::testing::DOMStringTestInterface; -using cobalt::bindings::testing::MozjsDOMStringTestInterface; -using cobalt::script::CallbackInterfaceTraits; -using cobalt::script::GlobalEnvironment; -using cobalt::script::OpaqueHandle; -using cobalt::script::OpaqueHandleHolder; -using cobalt::script::ScriptObject; -using cobalt::script::Wrappable; - -using cobalt::script::CallbackFunction; -using cobalt::script::CallbackInterfaceTraits; -using cobalt::script::ExceptionState; -using cobalt::script::mozjs::FromJSValue; -using cobalt::script::mozjs::kConversionFlagNullable; -using cobalt::script::mozjs::kConversionFlagRestricted; -using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString; -using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString; -using cobalt::script::mozjs::kNoConversionFlags; -using cobalt::script::mozjs::InterfaceData; -using cobalt::script::mozjs::MozjsCallbackFunction; -using cobalt::script::mozjs::MozjsExceptionState; -using cobalt::script::mozjs::MozjsGlobalEnvironment; -using cobalt::script::mozjs::MozjsUserObjectHolder; -using cobalt::script::mozjs::MozjsPropertyEnumerator; -using cobalt::script::mozjs::ProxyHandler; -using cobalt::script::mozjs::ToJSValue; -using cobalt::script::mozjs::TypeTraits; -using cobalt::script::mozjs::WrapperPrivate; -using cobalt::script::mozjs::WrapperFactory; -using cobalt::script::Wrappable; -} // namespace - -namespace cobalt { -namespace bindings { -namespace testing { - -namespace { - -class MozjsDOMStringTestInterfaceHandler : public ProxyHandler { - public: - MozjsDOMStringTestInterfaceHandler() - : ProxyHandler(indexed_property_hooks, named_property_hooks) {} - - private: - static NamedPropertyHooks named_property_hooks; - static IndexedPropertyHooks indexed_property_hooks; -}; - -ProxyHandler::NamedPropertyHooks -MozjsDOMStringTestInterfaceHandler::named_property_hooks = { - NULL, - NULL, - NULL, - NULL, - NULL, -}; -ProxyHandler::IndexedPropertyHooks -MozjsDOMStringTestInterfaceHandler::indexed_property_hooks = { - NULL, - NULL, - NULL, - NULL, - NULL, -}; - -static base::LazyInstance<MozjsDOMStringTestInterfaceHandler> - proxy_handler; - -bool HasInstance(JSContext *context, JS::HandleObject type, - JS::MutableHandleValue vp, bool *success) { - JS::RootedObject global_object( - context, JS_GetGlobalForObject(context, type)); - DCHECK(global_object); - - JS::RootedObject prototype( - context, MozjsDOMStringTestInterface::GetPrototype(context, global_object)); - - // |IsDelegate| walks the prototype chain of an object returning true if - // .prototype is found. - bool is_delegate; - if (!IsDelegate(context, prototype, vp, &is_delegate)) { - *success = false; - return false; - } - - *success = is_delegate; - return true; -} - -const JSClass instance_class_definition = { - "DOMStringTestInterface", - 0 | JSCLASS_HAS_PRIVATE, - NULL, // addProperty - NULL, // delProperty - NULL, // getProperty - NULL, // setProperty - NULL, // enumerate - NULL, // resolve - NULL, // mayResolve - &WrapperPrivate::Finalizer, // finalize - NULL, // call - NULL, // hasInstance - NULL, // construct - &WrapperPrivate::Trace, // trace -}; - -const JSClass prototype_class_definition = { - "DOMStringTestInterfacePrototype", -}; - -const JSClass interface_object_class_definition = { - "DOMStringTestInterfaceConstructor", - 0, - NULL, // addProperty - NULL, // delProperty - NULL, // getProperty - NULL, // setProperty - NULL, // enumerate - NULL, // resolve - NULL, // mayResolve - NULL, // finalize - NULL, // call - &HasInstance, - NULL, -}; - -bool get_property( - JSContext* context, unsigned argc, JS::Value* vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<DOMStringTestInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - DOMStringTestInterface* impl = - wrapper_private->wrappable<DOMStringTestInterface>().get(); - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->property(), - &result_value); - } - if (!exception_state.is_exception_set()) { - args.rval().set(result_value); - } - return !exception_state.is_exception_set(); -} - -bool set_property( - JSContext* context, unsigned argc, JS::Value* vp) { - - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<DOMStringTestInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - DOMStringTestInterface* impl = - wrapper_private->wrappable<DOMStringTestInterface>().get(); - TypeTraits<std::string >::ConversionType value; - if (args.length() != 1) { - NOTREACHED(); - return false; - } - FromJSValue(context, args[0], kNoConversionFlags, &exception_state, - &value); - if (exception_state.is_exception_set()) { - return false; - } - - impl->set_property(value); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - -bool get_readOnlyProperty( - JSContext* context, unsigned argc, JS::Value* vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<DOMStringTestInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - DOMStringTestInterface* impl = - wrapper_private->wrappable<DOMStringTestInterface>().get(); - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->read_only_property(), - &result_value); - } - if (!exception_state.is_exception_set()) { - args.rval().set(result_value); - } - return !exception_state.is_exception_set(); -} - - -bool get_readOnlyTokenProperty( - JSContext* context, unsigned argc, JS::Value* vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<DOMStringTestInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - DOMStringTestInterface* impl = - wrapper_private->wrappable<DOMStringTestInterface>().get(); - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->read_only_token_property(), - &result_value); - } - if (!exception_state.is_exception_set()) { - args.rval().set(result_value); - } - return !exception_state.is_exception_set(); -} - - -bool get_nullIsEmptyProperty( - JSContext* context, unsigned argc, JS::Value* vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<DOMStringTestInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - DOMStringTestInterface* impl = - wrapper_private->wrappable<DOMStringTestInterface>().get(); - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->null_is_empty_property(), - &result_value); - } - if (!exception_state.is_exception_set()) { - args.rval().set(result_value); - } - return !exception_state.is_exception_set(); -} - -bool set_nullIsEmptyProperty( - JSContext* context, unsigned argc, JS::Value* vp) { - - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<DOMStringTestInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - DOMStringTestInterface* impl = - wrapper_private->wrappable<DOMStringTestInterface>().get(); - TypeTraits<std::string >::ConversionType value; - if (args.length() != 1) { - NOTREACHED(); - return false; - } - FromJSValue(context, args[0], (kConversionFlagTreatNullAsEmptyString), &exception_state, - &value); - if (exception_state.is_exception_set()) { - return false; - } - - impl->set_null_is_empty_property(value); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - -bool get_undefinedIsEmptyProperty( - JSContext* context, unsigned argc, JS::Value* vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<DOMStringTestInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - DOMStringTestInterface* impl = - wrapper_private->wrappable<DOMStringTestInterface>().get(); - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->undefined_is_empty_property(), - &result_value); - } - if (!exception_state.is_exception_set()) { - args.rval().set(result_value); - } - return !exception_state.is_exception_set(); -} - -bool set_undefinedIsEmptyProperty( - JSContext* context, unsigned argc, JS::Value* vp) { - - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<DOMStringTestInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - DOMStringTestInterface* impl = - wrapper_private->wrappable<DOMStringTestInterface>().get(); - TypeTraits<std::string >::ConversionType value; - if (args.length() != 1) { - NOTREACHED(); - return false; - } - FromJSValue(context, args[0], (kConversionFlagTreatUndefinedAsEmptyString), &exception_state, - &value); - if (exception_state.is_exception_set()) { - return false; - } - - impl->set_undefined_is_empty_property(value); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - -bool get_nullableUndefinedIsEmptyProperty( - JSContext* context, unsigned argc, JS::Value* vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<DOMStringTestInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - DOMStringTestInterface* impl = - wrapper_private->wrappable<DOMStringTestInterface>().get(); - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->nullable_undefined_is_empty_property(), - &result_value); - } - if (!exception_state.is_exception_set()) { - args.rval().set(result_value); - } - return !exception_state.is_exception_set(); -} - -bool set_nullableUndefinedIsEmptyProperty( - JSContext* context, unsigned argc, JS::Value* vp) { - - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<DOMStringTestInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - DOMStringTestInterface* impl = - wrapper_private->wrappable<DOMStringTestInterface>().get(); - TypeTraits<base::optional<std::string > >::ConversionType value; - if (args.length() != 1) { - NOTREACHED(); - return false; - } - FromJSValue(context, args[0], (kConversionFlagNullable | kConversionFlagTreatUndefinedAsEmptyString), &exception_state, - &value); - if (exception_state.is_exception_set()) { - return false; - } - - impl->set_nullable_undefined_is_empty_property(value); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - - - -const JSPropertySpec prototype_properties[] = { - { // Read/Write property - "property", - JSPROP_SHARED | JSPROP_ENUMERATE, - { { &get_property, NULL } }, - { { &set_property, NULL } }, - }, - { // Readonly attribute - "readOnlyProperty", - JSPROP_SHARED | JSPROP_ENUMERATE, - { { &get_readOnlyProperty, NULL } }, - JSNATIVE_WRAPPER(NULL), - }, - { // Readonly attribute - "readOnlyTokenProperty", - JSPROP_SHARED | JSPROP_ENUMERATE, - { { &get_readOnlyTokenProperty, NULL } }, - JSNATIVE_WRAPPER(NULL), - }, - { // Read/Write property - "nullIsEmptyProperty", - JSPROP_SHARED | JSPROP_ENUMERATE, - { { &get_nullIsEmptyProperty, NULL } }, - { { &set_nullIsEmptyProperty, NULL } }, - }, - { // Read/Write property - "undefinedIsEmptyProperty", - JSPROP_SHARED | JSPROP_ENUMERATE, - { { &get_undefinedIsEmptyProperty, NULL } }, - { { &set_undefinedIsEmptyProperty, NULL } }, - }, - { // Read/Write property - "nullableUndefinedIsEmptyProperty", - JSPROP_SHARED | JSPROP_ENUMERATE, - { { &get_nullableUndefinedIsEmptyProperty, NULL } }, - { { &set_nullableUndefinedIsEmptyProperty, NULL } }, - }, - JS_PS_END -}; - -const JSFunctionSpec prototype_functions[] = { - JS_FS_END -}; - -const JSPropertySpec interface_object_properties[] = { - JS_PS_END -}; - -const JSFunctionSpec interface_object_functions[] = { - JS_FS_END -}; - -const JSPropertySpec own_properties[] = { - JS_PS_END -}; - -void InitializePrototypeAndInterfaceObject( - InterfaceData* interface_data, JSContext* context, - JS::HandleObject global_object) { - DCHECK(!interface_data->prototype); - DCHECK(!interface_data->interface_object); - DCHECK(JS_IsGlobalObject(global_object)); - - JS::RootedObject parent_prototype( - context, JS_GetObjectPrototype(context, global_object)); - DCHECK(parent_prototype); - - interface_data->prototype = JS_NewObjectWithGivenProto( - context, &prototype_class_definition, parent_prototype - ); - - JS::RootedObject rooted_prototype(context, interface_data->prototype); - bool success = JS_DefineProperties( - context, - rooted_prototype, - prototype_properties); - - DCHECK(success); - success = JS_DefineFunctions( - context, rooted_prototype, prototype_functions); - DCHECK(success); - - JS::RootedObject function_prototype( - context, JS_GetFunctionPrototype(context, global_object)); - DCHECK(function_prototype); - // Create the Interface object. - interface_data->interface_object = JS_NewObjectWithGivenProto( - context, &interface_object_class_definition, - function_prototype); - - // Add the InterfaceObject.name property. - JS::RootedObject rooted_interface_object( - context, interface_data->interface_object); - JS::RootedValue name_value(context); - const char name[] = - "DOMStringTestInterface"; - name_value.setString(JS_NewStringCopyZ(context, name)); - success = JS_DefineProperty( - context, rooted_interface_object, "name", name_value, JSPROP_READONLY, - NULL, NULL); - DCHECK(success); - - // Define interface object properties (including constants). - success = JS_DefineProperties(context, rooted_interface_object, - interface_object_properties); - DCHECK(success); - // Define interface object functions (static). - success = JS_DefineFunctions(context, rooted_interface_object, - interface_object_functions); - DCHECK(success); - - // Set the Prototype.constructor and Constructor.prototype properties. - DCHECK(interface_data->interface_object); - DCHECK(interface_data->prototype); - success = JS_LinkConstructorAndPrototype( - context, - rooted_interface_object, - rooted_prototype); - DCHECK(success); -} - -InterfaceData* GetInterfaceData(JSContext* context) { - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - // Use the address of the properties definition for this interface as a - // unique key for looking up the InterfaceData for this interface. - intptr_t key = reinterpret_cast<intptr_t>(&own_properties); - InterfaceData* interface_data = global_environment->GetInterfaceData(key); - if (!interface_data) { - interface_data = new InterfaceData(); - DCHECK(interface_data); - global_environment->CacheInterfaceData(key, interface_data); - DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key)); - } - return interface_data; -} - -} // namespace - -// static -JSObject* MozjsDOMStringTestInterface::CreateProxy( - JSContext* context, const scoped_refptr<Wrappable>& wrappable) { - DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); - JS::RootedObject global_object( - context, - MozjsGlobalEnvironment::GetFromContext(context)->global_object()); - DCHECK(global_object); - - InterfaceData* interface_data = GetInterfaceData(context); - JS::RootedObject prototype(context, GetPrototype(context, global_object)); - DCHECK(prototype); - JS::RootedObject new_object( - context, - JS_NewObjectWithGivenProto( - context, &instance_class_definition, prototype)); - DCHECK(new_object); - JS::RootedObject proxy(context, - ProxyHandler::NewProxy( - context, proxy_handler.Pointer(), new_object, prototype)); - WrapperPrivate::AddPrivateData(context, proxy, wrappable); - return proxy; -} - -// static -const JSClass* MozjsDOMStringTestInterface::PrototypeClass( - JSContext* context) { - DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); - JS::RootedObject global_object( - context, - MozjsGlobalEnvironment::GetFromContext(context)->global_object()); - DCHECK(global_object); - - JS::RootedObject prototype(context, GetPrototype(context, global_object)); - const JSClass* proto_class = JS_GetClass(prototype); - return proto_class; -} - -// static -JSObject* MozjsDOMStringTestInterface::GetPrototype( - JSContext* context, JS::HandleObject global_object) { - DCHECK(JS_IsGlobalObject(global_object)); - - InterfaceData* interface_data = GetInterfaceData(context); - if (!interface_data->prototype) { - // Create new prototype that has all the props and methods - InitializePrototypeAndInterfaceObject( - interface_data, context, global_object); - } - DCHECK(interface_data->prototype); - return interface_data->prototype; -} - -// static -JSObject* MozjsDOMStringTestInterface::GetInterfaceObject( - JSContext* context, JS::HandleObject global_object) { - DCHECK(JS_IsGlobalObject(global_object)); - - InterfaceData* interface_data = GetInterfaceData(context); - if (!interface_data->interface_object) { - InitializePrototypeAndInterfaceObject( - interface_data, context, global_object); - } - DCHECK(interface_data->interface_object); - return interface_data->interface_object; -} - - -namespace { -} // namespace - - -} // namespace testing -} // namespace bindings -} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsDOMStringTestInterface.h b/src/cobalt/bindings/generated/mozjs-45/testing/MozjsDOMStringTestInterface.h deleted file mode 100644 index 4a7e2c5..0000000 --- a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsDOMStringTestInterface.h +++ /dev/null
@@ -1,54 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! -// Auto-generated from template: bindings/mozjs-45/templates/interface.h.template - -// clang-format off - -#ifndef MozjsDOMStringTestInterface_h -#define MozjsDOMStringTestInterface_h - -#include "base/hash_tables.h" -#include "base/lazy_instance.h" -#include "base/memory/ref_counted.h" -#include "base/threading/thread_checker.h" -#include "cobalt/base/polymorphic_downcast.h" -#include "cobalt/script/wrappable.h" -#include "cobalt/bindings/testing/dom_string_test_interface.h" - -#include "third_party/mozjs-45/js/src/jsapi.h" - -namespace cobalt { -namespace bindings { -namespace testing { - -class MozjsDOMStringTestInterface { - public: - static JSObject* CreateProxy(JSContext* context, - const scoped_refptr<script::Wrappable>& wrappable); - static const JSClass* PrototypeClass(JSContext* context); - static JSObject* GetPrototype(JSContext* context, - JS::HandleObject global_object); - static JSObject* GetInterfaceObject(JSContext* context, - JS::HandleObject global_object); -}; - -} // namespace bindings -} // namespace testing -} // namespace cobalt - -#endif // MozjsDOMStringTestInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsDerivedGetterSetterInterface.cc b/src/cobalt/bindings/generated/mozjs-45/testing/MozjsDerivedGetterSetterInterface.cc deleted file mode 100644 index ca70494..0000000 --- a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsDerivedGetterSetterInterface.cc +++ /dev/null
@@ -1,836 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! -// Auto-generated from template: bindings/mozjs-45/templates/interface.cc.template - -// clang-format off - -#include "MozjsDerivedGetterSetterInterface.h" - -#include "base/debug/trace_event.h" -#include "cobalt/base/polymorphic_downcast.h" -#include "cobalt/script/global_environment.h" -#include "cobalt/script/opaque_handle.h" -#include "cobalt/script/script_object.h" - -#include "base/lazy_instance.h" -#include "cobalt/script/mozjs-45/callback_function_conversion.h" -#include "cobalt/script/exception_state.h" -#include "cobalt/script/mozjs-45/conversion_helpers.h" -#include "cobalt/script/mozjs-45/mozjs_exception_state.h" -#include "cobalt/script/mozjs-45/mozjs_callback_function.h" -#include "cobalt/script/mozjs-45/mozjs_global_environment.h" -#include "cobalt/script/mozjs-45/mozjs_object_handle.h" -#include "cobalt/script/mozjs-45/mozjs_property_enumerator.h" -#include "cobalt/script/mozjs-45/mozjs_user_object_holder.h" -#include "cobalt/script/mozjs-45/proxy_handler.h" -#include "cobalt/script/mozjs-45/type_traits.h" -#include "cobalt/script/mozjs-45/wrapper_factory.h" -#include "cobalt/script/mozjs-45/wrapper_private.h" -#include "cobalt/script/property_enumerator.h" -#include "third_party/mozjs-45/js/src/jsapi.h" -#include "third_party/mozjs-45/js/src/jsfriendapi.h" - -namespace { -using cobalt::bindings::testing::DerivedGetterSetterInterface; -using cobalt::bindings::testing::MozjsDerivedGetterSetterInterface; -using cobalt::script::CallbackInterfaceTraits; -using cobalt::script::GlobalEnvironment; -using cobalt::script::OpaqueHandle; -using cobalt::script::OpaqueHandleHolder; -using cobalt::script::ScriptObject; -using cobalt::script::Wrappable; - -using cobalt::script::CallbackFunction; -using cobalt::script::CallbackInterfaceTraits; -using cobalt::script::ExceptionState; -using cobalt::script::mozjs::FromJSValue; -using cobalt::script::mozjs::kConversionFlagNullable; -using cobalt::script::mozjs::kConversionFlagRestricted; -using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString; -using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString; -using cobalt::script::mozjs::kNoConversionFlags; -using cobalt::script::mozjs::InterfaceData; -using cobalt::script::mozjs::MozjsCallbackFunction; -using cobalt::script::mozjs::MozjsExceptionState; -using cobalt::script::mozjs::MozjsGlobalEnvironment; -using cobalt::script::mozjs::MozjsUserObjectHolder; -using cobalt::script::mozjs::MozjsPropertyEnumerator; -using cobalt::script::mozjs::ProxyHandler; -using cobalt::script::mozjs::ToJSValue; -using cobalt::script::mozjs::TypeTraits; -using cobalt::script::mozjs::WrapperPrivate; -using cobalt::script::mozjs::WrapperFactory; -using cobalt::script::Wrappable; -} // namespace - -namespace cobalt { -namespace bindings { -namespace testing { - -namespace { - -bool IsSupportedNamedProperty(JSContext* context, JS::HandleObject object, - const std::string& property_name) { - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - DerivedGetterSetterInterface* impl = - wrapper_private->wrappable<DerivedGetterSetterInterface>().get(); - return impl->CanQueryNamedProperty(property_name); -} - -void EnumerateSupportedNames(JSContext* context, JS::HandleObject object, - JS::AutoIdVector* properties) { - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - DerivedGetterSetterInterface* impl = - wrapper_private->wrappable<DerivedGetterSetterInterface>().get(); - MozjsPropertyEnumerator enumerator(context, properties); - impl->EnumerateNamedProperties(&enumerator); -} - -bool GetNamedProperty( - JSContext* context, JS::HandleObject object, JS::HandleId id, - JS::MutableHandleValue vp) { - JS::RootedValue id_value(context); - if (!JS_IdToValue(context, id, &id_value)) { - NOTREACHED(); - return false; - } - - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - DerivedGetterSetterInterface* impl = - wrapper_private->wrappable<DerivedGetterSetterInterface>().get(); - std::string property_name; - FromJSValue(context, id_value, kNoConversionFlags, &exception_state, - &property_name); - if (exception_state.is_exception_set()) { - // The ID should be an integer or a string, so we shouldn't have any - // exceptions converting to string. - NOTREACHED(); - return false; - } - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->AnonymousNamedGetter(property_name), - &result_value); - } - if (!exception_state.is_exception_set()) { - vp.set(result_value); - } - return !exception_state.is_exception_set(); - -} - -bool SetNamedProperty( - JSContext* context, JS::HandleObject object, JS::HandleId id, - JS::MutableHandleValue vp, JS::ObjectOpResult& object_op_result) { - JS::RootedValue id_value(context); - if (!JS_IdToValue(context, id, &id_value)) { - NOTREACHED(); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - DerivedGetterSetterInterface* impl = - wrapper_private->wrappable<DerivedGetterSetterInterface>().get(); - std::string property_name; - FromJSValue(context, id_value, kNoConversionFlags, &exception_state, - &property_name); - if (exception_state.is_exception_set()) { - // The ID should be an integer or a string, so we shouldn't have any - // exceptions converting to string. - NOTREACHED(); - return false; - } - TypeTraits<std::string >::ConversionType value; - FromJSValue(context, vp, kNoConversionFlags, - &exception_state, &value); - if (exception_state.is_exception_set()) { - return false; - } - - impl->AnonymousNamedSetter(property_name, value); - result_value.set(JS::UndefinedHandleValue); - - if (!exception_state.is_exception_set()) { - return object_op_result.succeed(); - } else { - return false; - } -} - -bool IsSupportedIndexProperty(JSContext* context, JS::HandleObject object, - uint32_t index) { - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - DerivedGetterSetterInterface* impl = - wrapper_private->wrappable<DerivedGetterSetterInterface>().get(); - return index < impl->length(); -} - -void EnumerateSupportedIndexes(JSContext* context, JS::HandleObject object, - JS::AutoIdVector* properties) { - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - DerivedGetterSetterInterface* impl = - wrapper_private->wrappable<DerivedGetterSetterInterface>().get(); - const uint32_t kNumIndexedProperties = impl->length(); - for (uint32_t i = 0; i < kNumIndexedProperties; ++i) { - properties->append(INT_TO_JSID(i)); - } -} - -bool GetIndexedProperty( - JSContext* context, JS::HandleObject object, JS::HandleId id, - JS::MutableHandleValue vp) { - JS::RootedValue id_value(context); - if (!JS_IdToValue(context, id, &id_value)) { - NOTREACHED(); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - DerivedGetterSetterInterface* impl = - wrapper_private->wrappable<DerivedGetterSetterInterface>().get(); - uint32_t index; - FromJSValue(context, id_value, kNoConversionFlags, &exception_state, &index); - if (exception_state.is_exception_set()) { - // The ID should be an integer or a string, so we shouldn't have any - // exceptions converting to string. - NOTREACHED(); - return false; - } - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->DerivedIndexedGetter(index), - &result_value); - } - if (!exception_state.is_exception_set()) { - vp.set(result_value); - } - return !exception_state.is_exception_set(); -} - -bool SetIndexedProperty( - JSContext* context, JS::HandleObject object, JS::HandleId id, - JS::MutableHandleValue vp, JS::ObjectOpResult& object_op_result) { - JS::RootedValue id_value(context); - if (!JS_IdToValue(context, id, &id_value)) { - NOTREACHED(); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - DerivedGetterSetterInterface* impl = - wrapper_private->wrappable<DerivedGetterSetterInterface>().get(); - uint32_t index; - FromJSValue(context, id_value, kNoConversionFlags, &exception_state, &index); - if (exception_state.is_exception_set()) { - // The ID should be an integer or a string, so we shouldn't have any - // exceptions converting to string. - NOTREACHED(); - return false; - } - TypeTraits<uint32_t >::ConversionType value; - FromJSValue(context, vp, kNoConversionFlags, - &exception_state, &value); - if (exception_state.is_exception_set()) { - return false; - } - - impl->DerivedIndexedSetter(index, value); - result_value.set(JS::UndefinedHandleValue); - if (!exception_state.is_exception_set()) { - return object_op_result.succeed(); - } else { - return false; - } -} - -class MozjsDerivedGetterSetterInterfaceHandler : public ProxyHandler { - public: - MozjsDerivedGetterSetterInterfaceHandler() - : ProxyHandler(indexed_property_hooks, named_property_hooks) {} - - private: - static NamedPropertyHooks named_property_hooks; - static IndexedPropertyHooks indexed_property_hooks; -}; - -ProxyHandler::NamedPropertyHooks -MozjsDerivedGetterSetterInterfaceHandler::named_property_hooks = { - IsSupportedNamedProperty, - EnumerateSupportedNames, - GetNamedProperty, - SetNamedProperty, - NULL, -}; -ProxyHandler::IndexedPropertyHooks -MozjsDerivedGetterSetterInterfaceHandler::indexed_property_hooks = { - IsSupportedIndexProperty, - EnumerateSupportedIndexes, - GetIndexedProperty, - SetIndexedProperty, - NULL, -}; - -static base::LazyInstance<MozjsDerivedGetterSetterInterfaceHandler> - proxy_handler; - -bool HasInstance(JSContext *context, JS::HandleObject type, - JS::MutableHandleValue vp, bool *success) { - JS::RootedObject global_object( - context, JS_GetGlobalForObject(context, type)); - DCHECK(global_object); - - JS::RootedObject prototype( - context, MozjsDerivedGetterSetterInterface::GetPrototype(context, global_object)); - - // |IsDelegate| walks the prototype chain of an object returning true if - // .prototype is found. - bool is_delegate; - if (!IsDelegate(context, prototype, vp, &is_delegate)) { - *success = false; - return false; - } - - *success = is_delegate; - return true; -} - -const JSClass instance_class_definition = { - "DerivedGetterSetterInterface", - 0 | JSCLASS_HAS_PRIVATE, - NULL, // addProperty - NULL, // delProperty - NULL, // getProperty - NULL, // setProperty - NULL, // enumerate - NULL, // resolve - NULL, // mayResolve - &WrapperPrivate::Finalizer, // finalize - NULL, // call - NULL, // hasInstance - NULL, // construct - &WrapperPrivate::Trace, // trace -}; - -const JSClass prototype_class_definition = { - "DerivedGetterSetterInterfacePrototype", -}; - -const JSClass interface_object_class_definition = { - "DerivedGetterSetterInterfaceConstructor", - 0, - NULL, // addProperty - NULL, // delProperty - NULL, // getProperty - NULL, // setProperty - NULL, // enumerate - NULL, // resolve - NULL, // mayResolve - NULL, // finalize - NULL, // call - &HasInstance, - NULL, -}; - -bool get_length( - JSContext* context, unsigned argc, JS::Value* vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<DerivedGetterSetterInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - DerivedGetterSetterInterface* impl = - wrapper_private->wrappable<DerivedGetterSetterInterface>().get(); - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->length(), - &result_value); - } - if (!exception_state.is_exception_set()) { - args.rval().set(result_value); - } - return !exception_state.is_exception_set(); -} - - -bool get_propertyOnDerivedClass( - JSContext* context, unsigned argc, JS::Value* vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<DerivedGetterSetterInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - DerivedGetterSetterInterface* impl = - wrapper_private->wrappable<DerivedGetterSetterInterface>().get(); - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->property_on_derived_class(), - &result_value); - } - if (!exception_state.is_exception_set()) { - args.rval().set(result_value); - } - return !exception_state.is_exception_set(); -} - -bool set_propertyOnDerivedClass( - JSContext* context, unsigned argc, JS::Value* vp) { - - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<DerivedGetterSetterInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - DerivedGetterSetterInterface* impl = - wrapper_private->wrappable<DerivedGetterSetterInterface>().get(); - TypeTraits<bool >::ConversionType value; - if (args.length() != 1) { - NOTREACHED(); - return false; - } - FromJSValue(context, args[0], kNoConversionFlags, &exception_state, - &value); - if (exception_state.is_exception_set()) { - return false; - } - - impl->set_property_on_derived_class(value); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - -bool fcn_derivedIndexedGetter( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, &object)) { - NOTREACHED(); - return false; - } - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<DerivedGetterSetterInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - DerivedGetterSetterInterface* impl = - wrapper_private->wrappable<DerivedGetterSetterInterface>().get(); - const size_t kMinArguments = 1; - if (args.length() < kMinArguments) { - exception_state.SetSimpleException(script::kInvalidNumberOfArguments); - return false; - } - // Non-optional arguments - TypeTraits<uint32_t >::ConversionType index; - - DCHECK_LT(0, args.length()); - JS::RootedValue non_optional_value0( - context, args[0]); - FromJSValue(context, - non_optional_value0, - kNoConversionFlags, - &exception_state, &index); - if (exception_state.is_exception_set()) { - return false; - } - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->DerivedIndexedGetter(index), - &result_value); - } - if (!exception_state.is_exception_set()) { - args.rval().set(result_value); - } - return !exception_state.is_exception_set(); -} - -bool fcn_derivedIndexedSetter( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, &object)) { - NOTREACHED(); - return false; - } - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<DerivedGetterSetterInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - DerivedGetterSetterInterface* impl = - wrapper_private->wrappable<DerivedGetterSetterInterface>().get(); - const size_t kMinArguments = 2; - if (args.length() < kMinArguments) { - exception_state.SetSimpleException(script::kInvalidNumberOfArguments); - return false; - } - // Non-optional arguments - TypeTraits<uint32_t >::ConversionType index; - TypeTraits<uint32_t >::ConversionType value; - - DCHECK_LT(0, args.length()); - JS::RootedValue non_optional_value0( - context, args[0]); - FromJSValue(context, - non_optional_value0, - kNoConversionFlags, - &exception_state, &index); - if (exception_state.is_exception_set()) { - return false; - } - - DCHECK_LT(1, args.length()); - JS::RootedValue non_optional_value1( - context, args[1]); - FromJSValue(context, - non_optional_value1, - kNoConversionFlags, - &exception_state, &value); - if (exception_state.is_exception_set()) { - return false; - } - - impl->DerivedIndexedSetter(index, value); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - -bool fcn_operationOnDerivedClass( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, &object)) { - NOTREACHED(); - return false; - } - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<DerivedGetterSetterInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - DerivedGetterSetterInterface* impl = - wrapper_private->wrappable<DerivedGetterSetterInterface>().get(); - - impl->OperationOnDerivedClass(); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - - - -const JSPropertySpec prototype_properties[] = { - { // Readonly attribute - "length", - JSPROP_SHARED | JSPROP_ENUMERATE, - { { &get_length, NULL } }, - JSNATIVE_WRAPPER(NULL), - }, - { // Read/Write property - "propertyOnDerivedClass", - JSPROP_SHARED | JSPROP_ENUMERATE, - { { &get_propertyOnDerivedClass, NULL } }, - { { &set_propertyOnDerivedClass, NULL } }, - }, - JS_PS_END -}; - -const JSFunctionSpec prototype_functions[] = { - JS_FNSPEC( - "derivedIndexedGetter", fcn_derivedIndexedGetter, NULL, - 1, JSPROP_ENUMERATE, NULL), - JS_FNSPEC( - "derivedIndexedSetter", fcn_derivedIndexedSetter, NULL, - 2, JSPROP_ENUMERATE, NULL), - JS_FNSPEC( - "operationOnDerivedClass", fcn_operationOnDerivedClass, NULL, - 0, JSPROP_ENUMERATE, NULL), - JS_FS_END -}; - -const JSPropertySpec interface_object_properties[] = { - JS_PS_END -}; - -const JSFunctionSpec interface_object_functions[] = { - JS_FS_END -}; - -const JSPropertySpec own_properties[] = { - JS_PS_END -}; - -void InitializePrototypeAndInterfaceObject( - InterfaceData* interface_data, JSContext* context, - JS::HandleObject global_object) { - DCHECK(!interface_data->prototype); - DCHECK(!interface_data->interface_object); - DCHECK(JS_IsGlobalObject(global_object)); - - JS::RootedObject parent_prototype( - context, bindings::testing::MozjsNamedIndexedGetterInterface::GetPrototype(context, global_object)); - DCHECK(parent_prototype); - - interface_data->prototype = JS_NewObjectWithGivenProto( - context, &prototype_class_definition, parent_prototype - ); - - JS::RootedObject rooted_prototype(context, interface_data->prototype); - bool success = JS_DefineProperties( - context, - rooted_prototype, - prototype_properties); - - DCHECK(success); - success = JS_DefineFunctions( - context, rooted_prototype, prototype_functions); - DCHECK(success); - - JS::RootedObject function_prototype( - context, JS_GetFunctionPrototype(context, global_object)); - DCHECK(function_prototype); - // Create the Interface object. - interface_data->interface_object = JS_NewObjectWithGivenProto( - context, &interface_object_class_definition, - function_prototype); - - // Add the InterfaceObject.name property. - JS::RootedObject rooted_interface_object( - context, interface_data->interface_object); - JS::RootedValue name_value(context); - const char name[] = - "DerivedGetterSetterInterface"; - name_value.setString(JS_NewStringCopyZ(context, name)); - success = JS_DefineProperty( - context, rooted_interface_object, "name", name_value, JSPROP_READONLY, - NULL, NULL); - DCHECK(success); - - // Define interface object properties (including constants). - success = JS_DefineProperties(context, rooted_interface_object, - interface_object_properties); - DCHECK(success); - // Define interface object functions (static). - success = JS_DefineFunctions(context, rooted_interface_object, - interface_object_functions); - DCHECK(success); - - // Set the Prototype.constructor and Constructor.prototype properties. - DCHECK(interface_data->interface_object); - DCHECK(interface_data->prototype); - success = JS_LinkConstructorAndPrototype( - context, - rooted_interface_object, - rooted_prototype); - DCHECK(success); -} - -InterfaceData* GetInterfaceData(JSContext* context) { - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - // Use the address of the properties definition for this interface as a - // unique key for looking up the InterfaceData for this interface. - intptr_t key = reinterpret_cast<intptr_t>(&own_properties); - InterfaceData* interface_data = global_environment->GetInterfaceData(key); - if (!interface_data) { - interface_data = new InterfaceData(); - DCHECK(interface_data); - global_environment->CacheInterfaceData(key, interface_data); - DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key)); - } - return interface_data; -} - -} // namespace - -// static -JSObject* MozjsDerivedGetterSetterInterface::CreateProxy( - JSContext* context, const scoped_refptr<Wrappable>& wrappable) { - DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); - JS::RootedObject global_object( - context, - MozjsGlobalEnvironment::GetFromContext(context)->global_object()); - DCHECK(global_object); - - InterfaceData* interface_data = GetInterfaceData(context); - JS::RootedObject prototype(context, GetPrototype(context, global_object)); - DCHECK(prototype); - JS::RootedObject new_object( - context, - JS_NewObjectWithGivenProto( - context, &instance_class_definition, prototype)); - DCHECK(new_object); - JS::RootedObject proxy(context, - ProxyHandler::NewProxy( - context, proxy_handler.Pointer(), new_object, prototype)); - WrapperPrivate::AddPrivateData(context, proxy, wrappable); - return proxy; -} - -// static -const JSClass* MozjsDerivedGetterSetterInterface::PrototypeClass( - JSContext* context) { - DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); - JS::RootedObject global_object( - context, - MozjsGlobalEnvironment::GetFromContext(context)->global_object()); - DCHECK(global_object); - - JS::RootedObject prototype(context, GetPrototype(context, global_object)); - const JSClass* proto_class = JS_GetClass(prototype); - return proto_class; -} - -// static -JSObject* MozjsDerivedGetterSetterInterface::GetPrototype( - JSContext* context, JS::HandleObject global_object) { - DCHECK(JS_IsGlobalObject(global_object)); - - InterfaceData* interface_data = GetInterfaceData(context); - if (!interface_data->prototype) { - // Create new prototype that has all the props and methods - InitializePrototypeAndInterfaceObject( - interface_data, context, global_object); - } - DCHECK(interface_data->prototype); - return interface_data->prototype; -} - -// static -JSObject* MozjsDerivedGetterSetterInterface::GetInterfaceObject( - JSContext* context, JS::HandleObject global_object) { - DCHECK(JS_IsGlobalObject(global_object)); - - InterfaceData* interface_data = GetInterfaceData(context); - if (!interface_data->interface_object) { - InitializePrototypeAndInterfaceObject( - interface_data, context, global_object); - } - DCHECK(interface_data->interface_object); - return interface_data->interface_object; -} - - -namespace { -} // namespace - - -} // namespace testing -} // namespace bindings -} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsDerivedGetterSetterInterface.h b/src/cobalt/bindings/generated/mozjs-45/testing/MozjsDerivedGetterSetterInterface.h deleted file mode 100644 index ff7c1ed..0000000 --- a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsDerivedGetterSetterInterface.h +++ /dev/null
@@ -1,55 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! -// Auto-generated from template: bindings/mozjs-45/templates/interface.h.template - -// clang-format off - -#ifndef MozjsDerivedGetterSetterInterface_h -#define MozjsDerivedGetterSetterInterface_h - -#include "base/hash_tables.h" -#include "base/lazy_instance.h" -#include "base/memory/ref_counted.h" -#include "base/threading/thread_checker.h" -#include "cobalt/base/polymorphic_downcast.h" -#include "cobalt/script/wrappable.h" -#include "MozjsNamedIndexedGetterInterface.h" -#include "cobalt/bindings/testing/derived_getter_setter_interface.h" - -#include "third_party/mozjs-45/js/src/jsapi.h" - -namespace cobalt { -namespace bindings { -namespace testing { - -class MozjsDerivedGetterSetterInterface { - public: - static JSObject* CreateProxy(JSContext* context, - const scoped_refptr<script::Wrappable>& wrappable); - static const JSClass* PrototypeClass(JSContext* context); - static JSObject* GetPrototype(JSContext* context, - JS::HandleObject global_object); - static JSObject* GetInterfaceObject(JSContext* context, - JS::HandleObject global_object); -}; - -} // namespace bindings -} // namespace testing -} // namespace cobalt - -#endif // MozjsDerivedGetterSetterInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsDerivedInterface.cc b/src/cobalt/bindings/generated/mozjs-45/testing/MozjsDerivedInterface.cc deleted file mode 100644 index 6095e07..0000000 --- a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsDerivedInterface.cc +++ /dev/null
@@ -1,455 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! -// Auto-generated from template: bindings/mozjs-45/templates/interface.cc.template - -// clang-format off - -#include "MozjsDerivedInterface.h" - -#include "base/debug/trace_event.h" -#include "cobalt/base/polymorphic_downcast.h" -#include "cobalt/script/global_environment.h" -#include "cobalt/script/opaque_handle.h" -#include "cobalt/script/script_object.h" - -#include "base/lazy_instance.h" -#include "cobalt/script/mozjs-45/callback_function_conversion.h" -#include "cobalt/script/exception_state.h" -#include "cobalt/script/mozjs-45/conversion_helpers.h" -#include "cobalt/script/mozjs-45/mozjs_exception_state.h" -#include "cobalt/script/mozjs-45/mozjs_callback_function.h" -#include "cobalt/script/mozjs-45/mozjs_global_environment.h" -#include "cobalt/script/mozjs-45/mozjs_object_handle.h" -#include "cobalt/script/mozjs-45/mozjs_property_enumerator.h" -#include "cobalt/script/mozjs-45/mozjs_user_object_holder.h" -#include "cobalt/script/mozjs-45/proxy_handler.h" -#include "cobalt/script/mozjs-45/type_traits.h" -#include "cobalt/script/mozjs-45/wrapper_factory.h" -#include "cobalt/script/mozjs-45/wrapper_private.h" -#include "cobalt/script/property_enumerator.h" -#include "third_party/mozjs-45/js/src/jsapi.h" -#include "third_party/mozjs-45/js/src/jsfriendapi.h" - -namespace { -using cobalt::bindings::testing::DerivedInterface; -using cobalt::bindings::testing::MozjsDerivedInterface; -using cobalt::script::CallbackInterfaceTraits; -using cobalt::script::GlobalEnvironment; -using cobalt::script::OpaqueHandle; -using cobalt::script::OpaqueHandleHolder; -using cobalt::script::ScriptObject; -using cobalt::script::Wrappable; - -using cobalt::script::CallbackFunction; -using cobalt::script::CallbackInterfaceTraits; -using cobalt::script::ExceptionState; -using cobalt::script::mozjs::FromJSValue; -using cobalt::script::mozjs::kConversionFlagNullable; -using cobalt::script::mozjs::kConversionFlagRestricted; -using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString; -using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString; -using cobalt::script::mozjs::kNoConversionFlags; -using cobalt::script::mozjs::InterfaceData; -using cobalt::script::mozjs::MozjsCallbackFunction; -using cobalt::script::mozjs::MozjsExceptionState; -using cobalt::script::mozjs::MozjsGlobalEnvironment; -using cobalt::script::mozjs::MozjsUserObjectHolder; -using cobalt::script::mozjs::MozjsPropertyEnumerator; -using cobalt::script::mozjs::ProxyHandler; -using cobalt::script::mozjs::ToJSValue; -using cobalt::script::mozjs::TypeTraits; -using cobalt::script::mozjs::WrapperPrivate; -using cobalt::script::mozjs::WrapperFactory; -using cobalt::script::Wrappable; -} // namespace - -namespace cobalt { -namespace bindings { -namespace testing { - -namespace { - -class MozjsDerivedInterfaceHandler : public ProxyHandler { - public: - MozjsDerivedInterfaceHandler() - : ProxyHandler(indexed_property_hooks, named_property_hooks) {} - - private: - static NamedPropertyHooks named_property_hooks; - static IndexedPropertyHooks indexed_property_hooks; -}; - -ProxyHandler::NamedPropertyHooks -MozjsDerivedInterfaceHandler::named_property_hooks = { - NULL, - NULL, - NULL, - NULL, - NULL, -}; -ProxyHandler::IndexedPropertyHooks -MozjsDerivedInterfaceHandler::indexed_property_hooks = { - NULL, - NULL, - NULL, - NULL, - NULL, -}; - -static base::LazyInstance<MozjsDerivedInterfaceHandler> - proxy_handler; - -bool Constructor(JSContext* context, unsigned int argc, JS::Value* vp); -bool HasInstance(JSContext *context, JS::HandleObject type, - JS::MutableHandleValue vp, bool *success) { - JS::RootedObject global_object( - context, JS_GetGlobalForObject(context, type)); - DCHECK(global_object); - - JS::RootedObject prototype( - context, MozjsDerivedInterface::GetPrototype(context, global_object)); - - // |IsDelegate| walks the prototype chain of an object returning true if - // .prototype is found. - bool is_delegate; - if (!IsDelegate(context, prototype, vp, &is_delegate)) { - *success = false; - return false; - } - - *success = is_delegate; - return true; -} - -const JSClass instance_class_definition = { - "DerivedInterface", - 0 | JSCLASS_HAS_PRIVATE, - NULL, // addProperty - NULL, // delProperty - NULL, // getProperty - NULL, // setProperty - NULL, // enumerate - NULL, // resolve - NULL, // mayResolve - &WrapperPrivate::Finalizer, // finalize - NULL, // call - NULL, // hasInstance - NULL, // construct - &WrapperPrivate::Trace, // trace -}; - -const JSClass prototype_class_definition = { - "DerivedInterfacePrototype", -}; - -const JSClass interface_object_class_definition = { - "DerivedInterfaceConstructor", - 0, - NULL, // addProperty - NULL, // delProperty - NULL, // getProperty - NULL, // setProperty - NULL, // enumerate - NULL, // resolve - NULL, // mayResolve - NULL, // finalize - NULL, // call - &HasInstance, - Constructor, -}; - -bool get_derivedAttribute( - JSContext* context, unsigned argc, JS::Value* vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<DerivedInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - DerivedInterface* impl = - wrapper_private->wrappable<DerivedInterface>().get(); - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->derived_attribute(), - &result_value); - } - if (!exception_state.is_exception_set()) { - args.rval().set(result_value); - } - return !exception_state.is_exception_set(); -} - - -bool fcn_derivedOperation( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, &object)) { - NOTREACHED(); - return false; - } - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<DerivedInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - DerivedInterface* impl = - wrapper_private->wrappable<DerivedInterface>().get(); - - impl->DerivedOperation(); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - - - -const JSPropertySpec prototype_properties[] = { - { // Readonly attribute - "derivedAttribute", - JSPROP_SHARED | JSPROP_ENUMERATE, - { { &get_derivedAttribute, NULL } }, - JSNATIVE_WRAPPER(NULL), - }, - JS_PS_END -}; - -const JSFunctionSpec prototype_functions[] = { - JS_FNSPEC( - "derivedOperation", fcn_derivedOperation, NULL, - 0, JSPROP_ENUMERATE, NULL), - JS_FS_END -}; - -const JSPropertySpec interface_object_properties[] = { - JS_PS_END -}; - -const JSFunctionSpec interface_object_functions[] = { - JS_FS_END -}; - -const JSPropertySpec own_properties[] = { - JS_PS_END -}; - -void InitializePrototypeAndInterfaceObject( - InterfaceData* interface_data, JSContext* context, - JS::HandleObject global_object) { - DCHECK(!interface_data->prototype); - DCHECK(!interface_data->interface_object); - DCHECK(JS_IsGlobalObject(global_object)); - - JS::RootedObject parent_prototype( - context, bindings::testing::MozjsBaseInterface::GetPrototype(context, global_object)); - DCHECK(parent_prototype); - - interface_data->prototype = JS_NewObjectWithGivenProto( - context, &prototype_class_definition, parent_prototype - ); - - JS::RootedObject rooted_prototype(context, interface_data->prototype); - bool success = JS_DefineProperties( - context, - rooted_prototype, - prototype_properties); - - DCHECK(success); - success = JS_DefineFunctions( - context, rooted_prototype, prototype_functions); - DCHECK(success); - - JS::RootedObject function_prototype( - context, JS_GetFunctionPrototype(context, global_object)); - DCHECK(function_prototype); - // Create the Interface object. - interface_data->interface_object = JS_NewObjectWithGivenProto( - context, &interface_object_class_definition, - function_prototype); - - // Add the InterfaceObject.name property. - JS::RootedObject rooted_interface_object( - context, interface_data->interface_object); - JS::RootedValue name_value(context); - const char name[] = - "DerivedInterface"; - name_value.setString(JS_NewStringCopyZ(context, name)); - success = JS_DefineProperty( - context, rooted_interface_object, "name", name_value, JSPROP_READONLY, - NULL, NULL); - DCHECK(success); - - // Add the InterfaceObject.length property. It is set to the length of the - // shortest argument list of all overload constructors. - JS::RootedValue length_value(context); - length_value.setInt32(0); - success = JS_DefineProperty( - context, rooted_interface_object, "length", length_value, - JSPROP_READONLY, NULL, NULL); - DCHECK(success); - - // Define interface object properties (including constants). - success = JS_DefineProperties(context, rooted_interface_object, - interface_object_properties); - DCHECK(success); - // Define interface object functions (static). - success = JS_DefineFunctions(context, rooted_interface_object, - interface_object_functions); - DCHECK(success); - - // Set the Prototype.constructor and Constructor.prototype properties. - DCHECK(interface_data->interface_object); - DCHECK(interface_data->prototype); - success = JS_LinkConstructorAndPrototype( - context, - rooted_interface_object, - rooted_prototype); - DCHECK(success); -} - -InterfaceData* GetInterfaceData(JSContext* context) { - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - // Use the address of the properties definition for this interface as a - // unique key for looking up the InterfaceData for this interface. - intptr_t key = reinterpret_cast<intptr_t>(&own_properties); - InterfaceData* interface_data = global_environment->GetInterfaceData(key); - if (!interface_data) { - interface_data = new InterfaceData(); - DCHECK(interface_data); - global_environment->CacheInterfaceData(key, interface_data); - DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key)); - } - return interface_data; -} - -} // namespace - -// static -JSObject* MozjsDerivedInterface::CreateProxy( - JSContext* context, const scoped_refptr<Wrappable>& wrappable) { - DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); - JS::RootedObject global_object( - context, - MozjsGlobalEnvironment::GetFromContext(context)->global_object()); - DCHECK(global_object); - - InterfaceData* interface_data = GetInterfaceData(context); - JS::RootedObject prototype(context, GetPrototype(context, global_object)); - DCHECK(prototype); - JS::RootedObject new_object( - context, - JS_NewObjectWithGivenProto( - context, &instance_class_definition, prototype)); - DCHECK(new_object); - JS::RootedObject proxy(context, - ProxyHandler::NewProxy( - context, proxy_handler.Pointer(), new_object, prototype)); - WrapperPrivate::AddPrivateData(context, proxy, wrappable); - return proxy; -} - -// static -const JSClass* MozjsDerivedInterface::PrototypeClass( - JSContext* context) { - DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); - JS::RootedObject global_object( - context, - MozjsGlobalEnvironment::GetFromContext(context)->global_object()); - DCHECK(global_object); - - JS::RootedObject prototype(context, GetPrototype(context, global_object)); - const JSClass* proto_class = JS_GetClass(prototype); - return proto_class; -} - -// static -JSObject* MozjsDerivedInterface::GetPrototype( - JSContext* context, JS::HandleObject global_object) { - DCHECK(JS_IsGlobalObject(global_object)); - - InterfaceData* interface_data = GetInterfaceData(context); - if (!interface_data->prototype) { - // Create new prototype that has all the props and methods - InitializePrototypeAndInterfaceObject( - interface_data, context, global_object); - } - DCHECK(interface_data->prototype); - return interface_data->prototype; -} - -// static -JSObject* MozjsDerivedInterface::GetInterfaceObject( - JSContext* context, JS::HandleObject global_object) { - DCHECK(JS_IsGlobalObject(global_object)); - - InterfaceData* interface_data = GetInterfaceData(context); - if (!interface_data->interface_object) { - InitializePrototypeAndInterfaceObject( - interface_data, context, global_object); - } - DCHECK(interface_data->interface_object); - return interface_data->interface_object; -} - - -namespace { -bool Constructor(JSContext* context, unsigned int argc, JS::Value* vp) { - MozjsExceptionState exception_state(context); - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - - scoped_refptr<DerivedInterface> new_object = - new DerivedInterface(); - JS::RootedValue result_value(context); - ToJSValue(context, new_object, &result_value); - DCHECK(result_value.isObject()); - args.rval().setObject(result_value.toObject()); - return true; -} -} // namespace - - -} // namespace testing -} // namespace bindings -} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsDerivedInterface.h b/src/cobalt/bindings/generated/mozjs-45/testing/MozjsDerivedInterface.h deleted file mode 100644 index 86ad04d..0000000 --- a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsDerivedInterface.h +++ /dev/null
@@ -1,55 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! -// Auto-generated from template: bindings/mozjs-45/templates/interface.h.template - -// clang-format off - -#ifndef MozjsDerivedInterface_h -#define MozjsDerivedInterface_h - -#include "base/hash_tables.h" -#include "base/lazy_instance.h" -#include "base/memory/ref_counted.h" -#include "base/threading/thread_checker.h" -#include "cobalt/base/polymorphic_downcast.h" -#include "cobalt/script/wrappable.h" -#include "MozjsBaseInterface.h" -#include "cobalt/bindings/testing/derived_interface.h" - -#include "third_party/mozjs-45/js/src/jsapi.h" - -namespace cobalt { -namespace bindings { -namespace testing { - -class MozjsDerivedInterface { - public: - static JSObject* CreateProxy(JSContext* context, - const scoped_refptr<script::Wrappable>& wrappable); - static const JSClass* PrototypeClass(JSContext* context); - static JSObject* GetPrototype(JSContext* context, - JS::HandleObject global_object); - static JSObject* GetInterfaceObject(JSContext* context, - JS::HandleObject global_object); -}; - -} // namespace bindings -} // namespace testing -} // namespace cobalt - -#endif // MozjsDerivedInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsDisabledInterface.cc b/src/cobalt/bindings/generated/mozjs-45/testing/MozjsDisabledInterface.cc deleted file mode 100644 index 6a7b849..0000000 --- a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsDisabledInterface.cc +++ /dev/null
@@ -1,473 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! -// Auto-generated from template: bindings/mozjs-45/templates/interface.cc.template - -// clang-format off - -#if defined(NO_ENABLE_CONDITIONAL_INTERFACE) - -#include "MozjsDisabledInterface.h" - -#include "base/debug/trace_event.h" -#include "cobalt/base/polymorphic_downcast.h" -#include "cobalt/script/global_environment.h" -#include "cobalt/script/opaque_handle.h" -#include "cobalt/script/script_object.h" - -#include "base/lazy_instance.h" -#include "cobalt/script/mozjs-45/callback_function_conversion.h" -#include "cobalt/script/exception_state.h" -#include "cobalt/script/mozjs-45/conversion_helpers.h" -#include "cobalt/script/mozjs-45/mozjs_exception_state.h" -#include "cobalt/script/mozjs-45/mozjs_callback_function.h" -#include "cobalt/script/mozjs-45/mozjs_global_environment.h" -#include "cobalt/script/mozjs-45/mozjs_object_handle.h" -#include "cobalt/script/mozjs-45/mozjs_property_enumerator.h" -#include "cobalt/script/mozjs-45/mozjs_user_object_holder.h" -#include "cobalt/script/mozjs-45/proxy_handler.h" -#include "cobalt/script/mozjs-45/type_traits.h" -#include "cobalt/script/mozjs-45/wrapper_factory.h" -#include "cobalt/script/mozjs-45/wrapper_private.h" -#include "cobalt/script/property_enumerator.h" -#include "third_party/mozjs-45/js/src/jsapi.h" -#include "third_party/mozjs-45/js/src/jsfriendapi.h" - -namespace { -using cobalt::bindings::testing::DisabledInterface; -using cobalt::bindings::testing::MozjsDisabledInterface; -using cobalt::script::CallbackInterfaceTraits; -using cobalt::script::GlobalEnvironment; -using cobalt::script::OpaqueHandle; -using cobalt::script::OpaqueHandleHolder; -using cobalt::script::ScriptObject; -using cobalt::script::Wrappable; - -using cobalt::script::CallbackFunction; -using cobalt::script::CallbackInterfaceTraits; -using cobalt::script::ExceptionState; -using cobalt::script::mozjs::FromJSValue; -using cobalt::script::mozjs::kConversionFlagNullable; -using cobalt::script::mozjs::kConversionFlagRestricted; -using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString; -using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString; -using cobalt::script::mozjs::kNoConversionFlags; -using cobalt::script::mozjs::InterfaceData; -using cobalt::script::mozjs::MozjsCallbackFunction; -using cobalt::script::mozjs::MozjsExceptionState; -using cobalt::script::mozjs::MozjsGlobalEnvironment; -using cobalt::script::mozjs::MozjsUserObjectHolder; -using cobalt::script::mozjs::MozjsPropertyEnumerator; -using cobalt::script::mozjs::ProxyHandler; -using cobalt::script::mozjs::ToJSValue; -using cobalt::script::mozjs::TypeTraits; -using cobalt::script::mozjs::WrapperPrivate; -using cobalt::script::mozjs::WrapperFactory; -using cobalt::script::Wrappable; -} // namespace - -namespace cobalt { -namespace bindings { -namespace testing { - -namespace { - -class MozjsDisabledInterfaceHandler : public ProxyHandler { - public: - MozjsDisabledInterfaceHandler() - : ProxyHandler(indexed_property_hooks, named_property_hooks) {} - - private: - static NamedPropertyHooks named_property_hooks; - static IndexedPropertyHooks indexed_property_hooks; -}; - -ProxyHandler::NamedPropertyHooks -MozjsDisabledInterfaceHandler::named_property_hooks = { - NULL, - NULL, - NULL, - NULL, - NULL, -}; -ProxyHandler::IndexedPropertyHooks -MozjsDisabledInterfaceHandler::indexed_property_hooks = { - NULL, - NULL, - NULL, - NULL, - NULL, -}; - -static base::LazyInstance<MozjsDisabledInterfaceHandler> - proxy_handler; - -bool HasInstance(JSContext *context, JS::HandleObject type, - JS::MutableHandleValue vp, bool *success) { - JS::RootedObject global_object( - context, JS_GetGlobalForObject(context, type)); - DCHECK(global_object); - - JS::RootedObject prototype( - context, MozjsDisabledInterface::GetPrototype(context, global_object)); - - // |IsDelegate| walks the prototype chain of an object returning true if - // .prototype is found. - bool is_delegate; - if (!IsDelegate(context, prototype, vp, &is_delegate)) { - *success = false; - return false; - } - - *success = is_delegate; - return true; -} - -const JSClass instance_class_definition = { - "DisabledInterface", - 0 | JSCLASS_HAS_PRIVATE, - NULL, // addProperty - NULL, // delProperty - NULL, // getProperty - NULL, // setProperty - NULL, // enumerate - NULL, // resolve - NULL, // mayResolve - &WrapperPrivate::Finalizer, // finalize - NULL, // call - NULL, // hasInstance - NULL, // construct - &WrapperPrivate::Trace, // trace -}; - -const JSClass prototype_class_definition = { - "DisabledInterfacePrototype", -}; - -const JSClass interface_object_class_definition = { - "DisabledInterfaceConstructor", - 0, - NULL, // addProperty - NULL, // delProperty - NULL, // getProperty - NULL, // setProperty - NULL, // enumerate - NULL, // resolve - NULL, // mayResolve - NULL, // finalize - NULL, // call - &HasInstance, - NULL, -}; - -bool get_disabledProperty( - JSContext* context, unsigned argc, JS::Value* vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<DisabledInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - DisabledInterface* impl = - wrapper_private->wrappable<DisabledInterface>().get(); - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->disabled_property(), - &result_value); - } - if (!exception_state.is_exception_set()) { - args.rval().set(result_value); - } - return !exception_state.is_exception_set(); -} - -bool set_disabledProperty( - JSContext* context, unsigned argc, JS::Value* vp) { - - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<DisabledInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - DisabledInterface* impl = - wrapper_private->wrappable<DisabledInterface>().get(); - TypeTraits<int32_t >::ConversionType value; - if (args.length() != 1) { - NOTREACHED(); - return false; - } - FromJSValue(context, args[0], kNoConversionFlags, &exception_state, - &value); - if (exception_state.is_exception_set()) { - return false; - } - - impl->set_disabled_property(value); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - -bool fcn_disabledFunction( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, &object)) { - NOTREACHED(); - return false; - } - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<DisabledInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - DisabledInterface* impl = - wrapper_private->wrappable<DisabledInterface>().get(); - - impl->DisabledFunction(); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - - - -const JSPropertySpec prototype_properties[] = { - { // Read/Write property - "disabledProperty", - JSPROP_SHARED | JSPROP_ENUMERATE, - { { &get_disabledProperty, NULL } }, - { { &set_disabledProperty, NULL } }, - }, - JS_PS_END -}; - -const JSFunctionSpec prototype_functions[] = { - JS_FNSPEC( - "disabledFunction", fcn_disabledFunction, NULL, - 0, JSPROP_ENUMERATE, NULL), - JS_FS_END -}; - -const JSPropertySpec interface_object_properties[] = { - JS_PS_END -}; - -const JSFunctionSpec interface_object_functions[] = { - JS_FS_END -}; - -const JSPropertySpec own_properties[] = { - JS_PS_END -}; - -void InitializePrototypeAndInterfaceObject( - InterfaceData* interface_data, JSContext* context, - JS::HandleObject global_object) { - DCHECK(!interface_data->prototype); - DCHECK(!interface_data->interface_object); - DCHECK(JS_IsGlobalObject(global_object)); - - JS::RootedObject parent_prototype( - context, JS_GetObjectPrototype(context, global_object)); - DCHECK(parent_prototype); - - interface_data->prototype = JS_NewObjectWithGivenProto( - context, &prototype_class_definition, parent_prototype - ); - - JS::RootedObject rooted_prototype(context, interface_data->prototype); - bool success = JS_DefineProperties( - context, - rooted_prototype, - prototype_properties); - - DCHECK(success); - success = JS_DefineFunctions( - context, rooted_prototype, prototype_functions); - DCHECK(success); - - JS::RootedObject function_prototype( - context, JS_GetFunctionPrototype(context, global_object)); - DCHECK(function_prototype); - // Create the Interface object. - interface_data->interface_object = JS_NewObjectWithGivenProto( - context, &interface_object_class_definition, - function_prototype); - - // Add the InterfaceObject.name property. - JS::RootedObject rooted_interface_object( - context, interface_data->interface_object); - JS::RootedValue name_value(context); - const char name[] = - "DisabledInterface"; - name_value.setString(JS_NewStringCopyZ(context, name)); - success = JS_DefineProperty( - context, rooted_interface_object, "name", name_value, JSPROP_READONLY, - NULL, NULL); - DCHECK(success); - - // Define interface object properties (including constants). - success = JS_DefineProperties(context, rooted_interface_object, - interface_object_properties); - DCHECK(success); - // Define interface object functions (static). - success = JS_DefineFunctions(context, rooted_interface_object, - interface_object_functions); - DCHECK(success); - - // Set the Prototype.constructor and Constructor.prototype properties. - DCHECK(interface_data->interface_object); - DCHECK(interface_data->prototype); - success = JS_LinkConstructorAndPrototype( - context, - rooted_interface_object, - rooted_prototype); - DCHECK(success); -} - -InterfaceData* GetInterfaceData(JSContext* context) { - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - // Use the address of the properties definition for this interface as a - // unique key for looking up the InterfaceData for this interface. - intptr_t key = reinterpret_cast<intptr_t>(&own_properties); - InterfaceData* interface_data = global_environment->GetInterfaceData(key); - if (!interface_data) { - interface_data = new InterfaceData(); - DCHECK(interface_data); - global_environment->CacheInterfaceData(key, interface_data); - DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key)); - } - return interface_data; -} - -} // namespace - -// static -JSObject* MozjsDisabledInterface::CreateProxy( - JSContext* context, const scoped_refptr<Wrappable>& wrappable) { - DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); - JS::RootedObject global_object( - context, - MozjsGlobalEnvironment::GetFromContext(context)->global_object()); - DCHECK(global_object); - - InterfaceData* interface_data = GetInterfaceData(context); - JS::RootedObject prototype(context, GetPrototype(context, global_object)); - DCHECK(prototype); - JS::RootedObject new_object( - context, - JS_NewObjectWithGivenProto( - context, &instance_class_definition, prototype)); - DCHECK(new_object); - JS::RootedObject proxy(context, - ProxyHandler::NewProxy( - context, proxy_handler.Pointer(), new_object, prototype)); - WrapperPrivate::AddPrivateData(context, proxy, wrappable); - return proxy; -} - -// static -const JSClass* MozjsDisabledInterface::PrototypeClass( - JSContext* context) { - DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); - JS::RootedObject global_object( - context, - MozjsGlobalEnvironment::GetFromContext(context)->global_object()); - DCHECK(global_object); - - JS::RootedObject prototype(context, GetPrototype(context, global_object)); - const JSClass* proto_class = JS_GetClass(prototype); - return proto_class; -} - -// static -JSObject* MozjsDisabledInterface::GetPrototype( - JSContext* context, JS::HandleObject global_object) { - DCHECK(JS_IsGlobalObject(global_object)); - - InterfaceData* interface_data = GetInterfaceData(context); - if (!interface_data->prototype) { - // Create new prototype that has all the props and methods - InitializePrototypeAndInterfaceObject( - interface_data, context, global_object); - } - DCHECK(interface_data->prototype); - return interface_data->prototype; -} - -// static -JSObject* MozjsDisabledInterface::GetInterfaceObject( - JSContext* context, JS::HandleObject global_object) { - DCHECK(JS_IsGlobalObject(global_object)); - - InterfaceData* interface_data = GetInterfaceData(context); - if (!interface_data->interface_object) { - InitializePrototypeAndInterfaceObject( - interface_data, context, global_object); - } - DCHECK(interface_data->interface_object); - return interface_data->interface_object; -} - - -namespace { -} // namespace - - -} // namespace testing -} // namespace bindings -} // namespace cobalt -#endif // defined(NO_ENABLE_CONDITIONAL_INTERFACE)
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsDisabledInterface.h b/src/cobalt/bindings/generated/mozjs-45/testing/MozjsDisabledInterface.h deleted file mode 100644 index 01d48c8..0000000 --- a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsDisabledInterface.h +++ /dev/null
@@ -1,58 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! -// Auto-generated from template: bindings/mozjs-45/templates/interface.h.template - -// clang-format off - -#ifndef MozjsDisabledInterface_h -#define MozjsDisabledInterface_h - -#if defined(NO_ENABLE_CONDITIONAL_INTERFACE) - -#include "base/hash_tables.h" -#include "base/lazy_instance.h" -#include "base/memory/ref_counted.h" -#include "base/threading/thread_checker.h" -#include "cobalt/base/polymorphic_downcast.h" -#include "cobalt/script/wrappable.h" -#include "cobalt/bindings/testing/disabled_interface.h" - -#include "third_party/mozjs-45/js/src/jsapi.h" - -namespace cobalt { -namespace bindings { -namespace testing { - -class MozjsDisabledInterface { - public: - static JSObject* CreateProxy(JSContext* context, - const scoped_refptr<script::Wrappable>& wrappable); - static const JSClass* PrototypeClass(JSContext* context); - static JSObject* GetPrototype(JSContext* context, - JS::HandleObject global_object); - static JSObject* GetInterfaceObject(JSContext* context, - JS::HandleObject global_object); -}; - -} // namespace bindings -} // namespace testing -} // namespace cobalt - -#endif // defined(NO_ENABLE_CONDITIONAL_INTERFACE) - -#endif // MozjsDisabledInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsEnumerationInterface.cc b/src/cobalt/bindings/generated/mozjs-45/testing/MozjsEnumerationInterface.cc deleted file mode 100644 index 90e02ed..0000000 --- a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsEnumerationInterface.cc +++ /dev/null
@@ -1,515 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! -// Auto-generated from template: bindings/mozjs-45/templates/interface.cc.template - -// clang-format off - -#include "MozjsEnumerationInterface.h" - -#include "base/debug/trace_event.h" -#include "cobalt/base/polymorphic_downcast.h" -#include "cobalt/script/global_environment.h" -#include "cobalt/script/opaque_handle.h" -#include "cobalt/script/script_object.h" - -#include "base/lazy_instance.h" -#include "cobalt/script/mozjs-45/callback_function_conversion.h" -#include "cobalt/script/exception_state.h" -#include "cobalt/script/mozjs-45/conversion_helpers.h" -#include "cobalt/script/mozjs-45/mozjs_exception_state.h" -#include "cobalt/script/mozjs-45/mozjs_callback_function.h" -#include "cobalt/script/mozjs-45/mozjs_global_environment.h" -#include "cobalt/script/mozjs-45/mozjs_object_handle.h" -#include "cobalt/script/mozjs-45/mozjs_property_enumerator.h" -#include "cobalt/script/mozjs-45/mozjs_user_object_holder.h" -#include "cobalt/script/mozjs-45/proxy_handler.h" -#include "cobalt/script/mozjs-45/type_traits.h" -#include "cobalt/script/mozjs-45/wrapper_factory.h" -#include "cobalt/script/mozjs-45/wrapper_private.h" -#include "cobalt/script/property_enumerator.h" -#include "third_party/mozjs-45/js/src/jsapi.h" -#include "third_party/mozjs-45/js/src/jsfriendapi.h" - -namespace { -using cobalt::bindings::testing::EnumerationInterface; -using cobalt::bindings::testing::MozjsEnumerationInterface; -using cobalt::script::CallbackInterfaceTraits; -using cobalt::script::GlobalEnvironment; -using cobalt::script::OpaqueHandle; -using cobalt::script::OpaqueHandleHolder; -using cobalt::script::ScriptObject; -using cobalt::script::Wrappable; - -using cobalt::script::CallbackFunction; -using cobalt::script::CallbackInterfaceTraits; -using cobalt::script::ExceptionState; -using cobalt::script::mozjs::FromJSValue; -using cobalt::script::mozjs::kConversionFlagNullable; -using cobalt::script::mozjs::kConversionFlagRestricted; -using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString; -using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString; -using cobalt::script::mozjs::kNoConversionFlags; -using cobalt::script::mozjs::InterfaceData; -using cobalt::script::mozjs::MozjsCallbackFunction; -using cobalt::script::mozjs::MozjsExceptionState; -using cobalt::script::mozjs::MozjsGlobalEnvironment; -using cobalt::script::mozjs::MozjsUserObjectHolder; -using cobalt::script::mozjs::MozjsPropertyEnumerator; -using cobalt::script::mozjs::ProxyHandler; -using cobalt::script::mozjs::ToJSValue; -using cobalt::script::mozjs::TypeTraits; -using cobalt::script::mozjs::WrapperPrivate; -using cobalt::script::mozjs::WrapperFactory; -using cobalt::script::Wrappable; -// Declare and define these in the same namespace that the other overloads -// were brought into with the using declaration. -void ToJSValue( - JSContext* context, - EnumerationInterface::TestEnum in_enum, - JS::MutableHandleValue out_value); -void FromJSValue(JSContext* context, JS::HandleValue value, - int conversion_flags, ExceptionState* exception_state, - EnumerationInterface::TestEnum* out_enum); -} // namespace - -namespace cobalt { -namespace bindings { -namespace testing { - -namespace { - -class MozjsEnumerationInterfaceHandler : public ProxyHandler { - public: - MozjsEnumerationInterfaceHandler() - : ProxyHandler(indexed_property_hooks, named_property_hooks) {} - - private: - static NamedPropertyHooks named_property_hooks; - static IndexedPropertyHooks indexed_property_hooks; -}; - -ProxyHandler::NamedPropertyHooks -MozjsEnumerationInterfaceHandler::named_property_hooks = { - NULL, - NULL, - NULL, - NULL, - NULL, -}; -ProxyHandler::IndexedPropertyHooks -MozjsEnumerationInterfaceHandler::indexed_property_hooks = { - NULL, - NULL, - NULL, - NULL, - NULL, -}; - -static base::LazyInstance<MozjsEnumerationInterfaceHandler> - proxy_handler; - -bool Constructor(JSContext* context, unsigned int argc, JS::Value* vp); -bool HasInstance(JSContext *context, JS::HandleObject type, - JS::MutableHandleValue vp, bool *success) { - JS::RootedObject global_object( - context, JS_GetGlobalForObject(context, type)); - DCHECK(global_object); - - JS::RootedObject prototype( - context, MozjsEnumerationInterface::GetPrototype(context, global_object)); - - // |IsDelegate| walks the prototype chain of an object returning true if - // .prototype is found. - bool is_delegate; - if (!IsDelegate(context, prototype, vp, &is_delegate)) { - *success = false; - return false; - } - - *success = is_delegate; - return true; -} - -const JSClass instance_class_definition = { - "EnumerationInterface", - 0 | JSCLASS_HAS_PRIVATE, - NULL, // addProperty - NULL, // delProperty - NULL, // getProperty - NULL, // setProperty - NULL, // enumerate - NULL, // resolve - NULL, // mayResolve - &WrapperPrivate::Finalizer, // finalize - NULL, // call - NULL, // hasInstance - NULL, // construct - &WrapperPrivate::Trace, // trace -}; - -const JSClass prototype_class_definition = { - "EnumerationInterfacePrototype", -}; - -const JSClass interface_object_class_definition = { - "EnumerationInterfaceConstructor", - 0, - NULL, // addProperty - NULL, // delProperty - NULL, // getProperty - NULL, // setProperty - NULL, // enumerate - NULL, // resolve - NULL, // mayResolve - NULL, // finalize - NULL, // call - &HasInstance, - Constructor, -}; - -bool get_enumProperty( - JSContext* context, unsigned argc, JS::Value* vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<EnumerationInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - EnumerationInterface* impl = - wrapper_private->wrappable<EnumerationInterface>().get(); - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->enum_property(), - &result_value); - } - if (!exception_state.is_exception_set()) { - args.rval().set(result_value); - } - return !exception_state.is_exception_set(); -} - -bool set_enumProperty( - JSContext* context, unsigned argc, JS::Value* vp) { - - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<EnumerationInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - EnumerationInterface* impl = - wrapper_private->wrappable<EnumerationInterface>().get(); - TypeTraits<EnumerationInterface::TestEnum >::ConversionType value; - if (args.length() != 1) { - NOTREACHED(); - return false; - } - FromJSValue(context, args[0], kNoConversionFlags, &exception_state, - &value); - if (exception_state.is_exception_set()) { - return false; - } - - impl->set_enum_property(value); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - - - -const JSPropertySpec prototype_properties[] = { - { // Read/Write property - "enumProperty", - JSPROP_SHARED | JSPROP_ENUMERATE, - { { &get_enumProperty, NULL } }, - { { &set_enumProperty, NULL } }, - }, - JS_PS_END -}; - -const JSFunctionSpec prototype_functions[] = { - JS_FS_END -}; - -const JSPropertySpec interface_object_properties[] = { - JS_PS_END -}; - -const JSFunctionSpec interface_object_functions[] = { - JS_FS_END -}; - -const JSPropertySpec own_properties[] = { - JS_PS_END -}; - -void InitializePrototypeAndInterfaceObject( - InterfaceData* interface_data, JSContext* context, - JS::HandleObject global_object) { - DCHECK(!interface_data->prototype); - DCHECK(!interface_data->interface_object); - DCHECK(JS_IsGlobalObject(global_object)); - - JS::RootedObject parent_prototype( - context, JS_GetObjectPrototype(context, global_object)); - DCHECK(parent_prototype); - - interface_data->prototype = JS_NewObjectWithGivenProto( - context, &prototype_class_definition, parent_prototype - ); - - JS::RootedObject rooted_prototype(context, interface_data->prototype); - bool success = JS_DefineProperties( - context, - rooted_prototype, - prototype_properties); - - DCHECK(success); - success = JS_DefineFunctions( - context, rooted_prototype, prototype_functions); - DCHECK(success); - - JS::RootedObject function_prototype( - context, JS_GetFunctionPrototype(context, global_object)); - DCHECK(function_prototype); - // Create the Interface object. - interface_data->interface_object = JS_NewObjectWithGivenProto( - context, &interface_object_class_definition, - function_prototype); - - // Add the InterfaceObject.name property. - JS::RootedObject rooted_interface_object( - context, interface_data->interface_object); - JS::RootedValue name_value(context); - const char name[] = - "EnumerationInterface"; - name_value.setString(JS_NewStringCopyZ(context, name)); - success = JS_DefineProperty( - context, rooted_interface_object, "name", name_value, JSPROP_READONLY, - NULL, NULL); - DCHECK(success); - - // Add the InterfaceObject.length property. It is set to the length of the - // shortest argument list of all overload constructors. - JS::RootedValue length_value(context); - length_value.setInt32(0); - success = JS_DefineProperty( - context, rooted_interface_object, "length", length_value, - JSPROP_READONLY, NULL, NULL); - DCHECK(success); - - // Define interface object properties (including constants). - success = JS_DefineProperties(context, rooted_interface_object, - interface_object_properties); - DCHECK(success); - // Define interface object functions (static). - success = JS_DefineFunctions(context, rooted_interface_object, - interface_object_functions); - DCHECK(success); - - // Set the Prototype.constructor and Constructor.prototype properties. - DCHECK(interface_data->interface_object); - DCHECK(interface_data->prototype); - success = JS_LinkConstructorAndPrototype( - context, - rooted_interface_object, - rooted_prototype); - DCHECK(success); -} - -InterfaceData* GetInterfaceData(JSContext* context) { - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - // Use the address of the properties definition for this interface as a - // unique key for looking up the InterfaceData for this interface. - intptr_t key = reinterpret_cast<intptr_t>(&own_properties); - InterfaceData* interface_data = global_environment->GetInterfaceData(key); - if (!interface_data) { - interface_data = new InterfaceData(); - DCHECK(interface_data); - global_environment->CacheInterfaceData(key, interface_data); - DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key)); - } - return interface_data; -} - -} // namespace - -// static -JSObject* MozjsEnumerationInterface::CreateProxy( - JSContext* context, const scoped_refptr<Wrappable>& wrappable) { - DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); - JS::RootedObject global_object( - context, - MozjsGlobalEnvironment::GetFromContext(context)->global_object()); - DCHECK(global_object); - - InterfaceData* interface_data = GetInterfaceData(context); - JS::RootedObject prototype(context, GetPrototype(context, global_object)); - DCHECK(prototype); - JS::RootedObject new_object( - context, - JS_NewObjectWithGivenProto( - context, &instance_class_definition, prototype)); - DCHECK(new_object); - JS::RootedObject proxy(context, - ProxyHandler::NewProxy( - context, proxy_handler.Pointer(), new_object, prototype)); - WrapperPrivate::AddPrivateData(context, proxy, wrappable); - return proxy; -} - -// static -const JSClass* MozjsEnumerationInterface::PrototypeClass( - JSContext* context) { - DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); - JS::RootedObject global_object( - context, - MozjsGlobalEnvironment::GetFromContext(context)->global_object()); - DCHECK(global_object); - - JS::RootedObject prototype(context, GetPrototype(context, global_object)); - const JSClass* proto_class = JS_GetClass(prototype); - return proto_class; -} - -// static -JSObject* MozjsEnumerationInterface::GetPrototype( - JSContext* context, JS::HandleObject global_object) { - DCHECK(JS_IsGlobalObject(global_object)); - - InterfaceData* interface_data = GetInterfaceData(context); - if (!interface_data->prototype) { - // Create new prototype that has all the props and methods - InitializePrototypeAndInterfaceObject( - interface_data, context, global_object); - } - DCHECK(interface_data->prototype); - return interface_data->prototype; -} - -// static -JSObject* MozjsEnumerationInterface::GetInterfaceObject( - JSContext* context, JS::HandleObject global_object) { - DCHECK(JS_IsGlobalObject(global_object)); - - InterfaceData* interface_data = GetInterfaceData(context); - if (!interface_data->interface_object) { - InitializePrototypeAndInterfaceObject( - interface_data, context, global_object); - } - DCHECK(interface_data->interface_object); - return interface_data->interface_object; -} - - -namespace { -bool Constructor(JSContext* context, unsigned int argc, JS::Value* vp) { - MozjsExceptionState exception_state(context); - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - - scoped_refptr<EnumerationInterface> new_object = - new EnumerationInterface(); - JS::RootedValue result_value(context); - ToJSValue(context, new_object, &result_value); - DCHECK(result_value.isObject()); - args.rval().setObject(result_value.toObject()); - return true; -} -} // namespace - - -} // namespace testing -} // namespace bindings -} // namespace cobalt - -namespace { - -inline void ToJSValue( - JSContext* context, - EnumerationInterface::TestEnum in_enum, - JS::MutableHandleValue out_value) { - - switch (in_enum) { - case EnumerationInterface::kAlpha: - ToJSValue(context, std::string("alpha"), out_value); - return; - case EnumerationInterface::kBeta: - ToJSValue(context, std::string("beta"), out_value); - return; - case EnumerationInterface::kGamma: - ToJSValue(context, std::string("gamma"), out_value); - return; - default: - NOTREACHED(); - out_value.set(JS::UndefinedValue()); - } -} - -inline void FromJSValue(JSContext* context, JS::HandleValue value, - int conversion_flags, ExceptionState* exception_state, - EnumerationInterface::TestEnum* out_enum) { - DCHECK_EQ(0, conversion_flags) << "Unexpected conversion flags."; - // JSValue -> IDL enum algorithm described here: - // http://heycam.github.io/webidl/#es-enumeration - // 1. Let S be the result of calling ToString(V). - JS::RootedString rooted_string(context, JS::ToString(context, value)); - - bool match = false; -// 3. Return the enumeration value of type E that is equal to S. -if (JS_StringEqualsAscii( - context, rooted_string, "alpha", &match) - && match) { - *out_enum = EnumerationInterface::kAlpha; - } else if (JS_StringEqualsAscii( - context, rooted_string, "beta", &match) - && match) { - *out_enum = EnumerationInterface::kBeta; - } else if (JS_StringEqualsAscii( - context, rooted_string, "gamma", &match) - && match) { - *out_enum = EnumerationInterface::kGamma; - } else { - // 2. If S is not one of E's enumeration values, then throw a TypeError. - exception_state->SetSimpleException(cobalt::script::kConvertToEnumFailed); - return; - } -} -} // namespace
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsEnumerationInterface.h b/src/cobalt/bindings/generated/mozjs-45/testing/MozjsEnumerationInterface.h deleted file mode 100644 index 94fe232..0000000 --- a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsEnumerationInterface.h +++ /dev/null
@@ -1,54 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! -// Auto-generated from template: bindings/mozjs-45/templates/interface.h.template - -// clang-format off - -#ifndef MozjsEnumerationInterface_h -#define MozjsEnumerationInterface_h - -#include "base/hash_tables.h" -#include "base/lazy_instance.h" -#include "base/memory/ref_counted.h" -#include "base/threading/thread_checker.h" -#include "cobalt/base/polymorphic_downcast.h" -#include "cobalt/script/wrappable.h" -#include "cobalt/bindings/testing/enumeration_interface.h" - -#include "third_party/mozjs-45/js/src/jsapi.h" - -namespace cobalt { -namespace bindings { -namespace testing { - -class MozjsEnumerationInterface { - public: - static JSObject* CreateProxy(JSContext* context, - const scoped_refptr<script::Wrappable>& wrappable); - static const JSClass* PrototypeClass(JSContext* context); - static JSObject* GetPrototype(JSContext* context, - JS::HandleObject global_object); - static JSObject* GetInterfaceObject(JSContext* context, - JS::HandleObject global_object); -}; - -} // namespace bindings -} // namespace testing -} // namespace cobalt - -#endif // MozjsEnumerationInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsExceptionObjectInterface.cc b/src/cobalt/bindings/generated/mozjs-45/testing/MozjsExceptionObjectInterface.cc deleted file mode 100644 index 10c4703..0000000 --- a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsExceptionObjectInterface.cc +++ /dev/null
@@ -1,436 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! -// Auto-generated from template: bindings/mozjs-45/templates/interface.cc.template - -// clang-format off - -#include "MozjsExceptionObjectInterface.h" - -#include "base/debug/trace_event.h" -#include "cobalt/base/polymorphic_downcast.h" -#include "cobalt/script/global_environment.h" -#include "cobalt/script/opaque_handle.h" -#include "cobalt/script/script_object.h" - -#include "base/lazy_instance.h" -#include "cobalt/script/mozjs-45/callback_function_conversion.h" -#include "cobalt/script/exception_state.h" -#include "cobalt/script/mozjs-45/conversion_helpers.h" -#include "cobalt/script/mozjs-45/mozjs_exception_state.h" -#include "cobalt/script/mozjs-45/mozjs_callback_function.h" -#include "cobalt/script/mozjs-45/mozjs_global_environment.h" -#include "cobalt/script/mozjs-45/mozjs_object_handle.h" -#include "cobalt/script/mozjs-45/mozjs_property_enumerator.h" -#include "cobalt/script/mozjs-45/mozjs_user_object_holder.h" -#include "cobalt/script/mozjs-45/proxy_handler.h" -#include "cobalt/script/mozjs-45/type_traits.h" -#include "cobalt/script/mozjs-45/wrapper_factory.h" -#include "cobalt/script/mozjs-45/wrapper_private.h" -#include "cobalt/script/property_enumerator.h" -#include "third_party/mozjs-45/js/src/jsapi.h" -#include "third_party/mozjs-45/js/src/jsexn.h" -#include "third_party/mozjs-45/js/src/jsfriendapi.h" - -namespace { -using cobalt::bindings::testing::ExceptionObjectInterface; -using cobalt::bindings::testing::MozjsExceptionObjectInterface; -using cobalt::script::CallbackInterfaceTraits; -using cobalt::script::GlobalEnvironment; -using cobalt::script::OpaqueHandle; -using cobalt::script::OpaqueHandleHolder; -using cobalt::script::ScriptObject; -using cobalt::script::Wrappable; - -using cobalt::script::CallbackFunction; -using cobalt::script::CallbackInterfaceTraits; -using cobalt::script::ExceptionState; -using cobalt::script::mozjs::FromJSValue; -using cobalt::script::mozjs::kConversionFlagNullable; -using cobalt::script::mozjs::kConversionFlagRestricted; -using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString; -using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString; -using cobalt::script::mozjs::kNoConversionFlags; -using cobalt::script::mozjs::InterfaceData; -using cobalt::script::mozjs::MozjsCallbackFunction; -using cobalt::script::mozjs::MozjsExceptionState; -using cobalt::script::mozjs::MozjsGlobalEnvironment; -using cobalt::script::mozjs::MozjsUserObjectHolder; -using cobalt::script::mozjs::MozjsPropertyEnumerator; -using cobalt::script::mozjs::ProxyHandler; -using cobalt::script::mozjs::ToJSValue; -using cobalt::script::mozjs::TypeTraits; -using cobalt::script::mozjs::WrapperPrivate; -using cobalt::script::mozjs::WrapperFactory; -using cobalt::script::Wrappable; -} // namespace - -namespace cobalt { -namespace bindings { -namespace testing { - -namespace { - -class MozjsExceptionObjectInterfaceHandler : public ProxyHandler { - public: - MozjsExceptionObjectInterfaceHandler() - : ProxyHandler(indexed_property_hooks, named_property_hooks) {} - - private: - static NamedPropertyHooks named_property_hooks; - static IndexedPropertyHooks indexed_property_hooks; -}; - -ProxyHandler::NamedPropertyHooks -MozjsExceptionObjectInterfaceHandler::named_property_hooks = { - NULL, - NULL, - NULL, - NULL, - NULL, -}; -ProxyHandler::IndexedPropertyHooks -MozjsExceptionObjectInterfaceHandler::indexed_property_hooks = { - NULL, - NULL, - NULL, - NULL, - NULL, -}; - -static base::LazyInstance<MozjsExceptionObjectInterfaceHandler> - proxy_handler; - -bool HasInstance(JSContext *context, JS::HandleObject type, - JS::MutableHandleValue vp, bool *success) { - JS::RootedObject global_object( - context, JS_GetGlobalForObject(context, type)); - DCHECK(global_object); - - JS::RootedObject prototype( - context, MozjsExceptionObjectInterface::GetPrototype(context, global_object)); - - // |IsDelegate| walks the prototype chain of an object returning true if - // .prototype is found. - bool is_delegate; - if (!IsDelegate(context, prototype, vp, &is_delegate)) { - *success = false; - return false; - } - - *success = is_delegate; - return true; -} - -const JSClass instance_class_definition = { - "ExceptionObjectInterface", - 0 | JSCLASS_HAS_PRIVATE, - NULL, // addProperty - NULL, // delProperty - NULL, // getProperty - NULL, // setProperty - NULL, // enumerate - NULL, // resolve - NULL, // mayResolve - &WrapperPrivate::Finalizer, // finalize - NULL, // call - NULL, // hasInstance - NULL, // construct - &WrapperPrivate::Trace, // trace -}; - -const JSClass prototype_class_definition = { - "ExceptionObjectInterfacePrototype", -}; - -const JSClass interface_object_class_definition = { - "ExceptionObjectInterfaceConstructor", - 0, - NULL, // addProperty - NULL, // delProperty - NULL, // getProperty - NULL, // setProperty - NULL, // enumerate - NULL, // resolve - NULL, // mayResolve - NULL, // finalize - NULL, // call - &HasInstance, - NULL, -}; - -bool get_error( - JSContext* context, unsigned argc, JS::Value* vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<ExceptionObjectInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - ExceptionObjectInterface* impl = - wrapper_private->wrappable<ExceptionObjectInterface>().get(); - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->error(), - &result_value); - } - if (!exception_state.is_exception_set()) { - args.rval().set(result_value); - } - return !exception_state.is_exception_set(); -} - - -bool get_message( - JSContext* context, unsigned argc, JS::Value* vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<ExceptionObjectInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - ExceptionObjectInterface* impl = - wrapper_private->wrappable<ExceptionObjectInterface>().get(); - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->message(), - &result_value); - } - if (!exception_state.is_exception_set()) { - args.rval().set(result_value); - } - return !exception_state.is_exception_set(); -} - - - - -const JSPropertySpec prototype_properties[] = { - { // Readonly attribute - "error", - JSPROP_SHARED | JSPROP_ENUMERATE, - { { &get_error, NULL } }, - JSNATIVE_WRAPPER(NULL), - }, - { // Readonly attribute - "message", - JSPROP_SHARED | JSPROP_ENUMERATE, - { { &get_message, NULL } }, - JSNATIVE_WRAPPER(NULL), - }, - JS_PS_END -}; - -const JSFunctionSpec prototype_functions[] = { - JS_FS_END -}; - -const JSPropertySpec interface_object_properties[] = { - JS_PS_END -}; - -const JSFunctionSpec interface_object_functions[] = { - JS_FS_END -}; - -const JSPropertySpec own_properties[] = { - JS_PS_END -}; - -void InitializePrototypeAndInterfaceObject( - InterfaceData* interface_data, JSContext* context, - JS::HandleObject global_object) { - DCHECK(!interface_data->prototype); - DCHECK(!interface_data->interface_object); - DCHECK(JS_IsGlobalObject(global_object)); - - // Get Error prototype. - JS::RootedObject parent_prototype(context); - bool success_check = JS_GetClassPrototype( - context, js::GetExceptionProtoKey(JSEXN_ERR), &parent_prototype); - DCHECK(success_check); - DCHECK(parent_prototype); - - interface_data->prototype = JS_NewObjectWithGivenProto( - context, &prototype_class_definition, parent_prototype - ); - - JS::RootedObject rooted_prototype(context, interface_data->prototype); - bool success = JS_DefineProperties( - context, - rooted_prototype, - prototype_properties); - - DCHECK(success); - success = JS_DefineFunctions( - context, rooted_prototype, prototype_functions); - DCHECK(success); - - JS::RootedObject function_prototype( - context, JS_GetFunctionPrototype(context, global_object)); - DCHECK(function_prototype); - // Create the Interface object. - interface_data->interface_object = JS_NewObjectWithGivenProto( - context, &interface_object_class_definition, - function_prototype); - - // Add the InterfaceObject.name property. - JS::RootedObject rooted_interface_object( - context, interface_data->interface_object); - JS::RootedValue name_value(context); - const char name[] = - "ExceptionObjectInterface"; - name_value.setString(JS_NewStringCopyZ(context, name)); - success = JS_DefineProperty( - context, rooted_interface_object, "name", name_value, JSPROP_READONLY, - NULL, NULL); - DCHECK(success); - - // Define interface object properties (including constants). - success = JS_DefineProperties(context, rooted_interface_object, - interface_object_properties); - DCHECK(success); - // Define interface object functions (static). - success = JS_DefineFunctions(context, rooted_interface_object, - interface_object_functions); - DCHECK(success); - - // Set the Prototype.constructor and Constructor.prototype properties. - DCHECK(interface_data->interface_object); - DCHECK(interface_data->prototype); - success = JS_LinkConstructorAndPrototype( - context, - rooted_interface_object, - rooted_prototype); - DCHECK(success); -} - -InterfaceData* GetInterfaceData(JSContext* context) { - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - // Use the address of the properties definition for this interface as a - // unique key for looking up the InterfaceData for this interface. - intptr_t key = reinterpret_cast<intptr_t>(&own_properties); - InterfaceData* interface_data = global_environment->GetInterfaceData(key); - if (!interface_data) { - interface_data = new InterfaceData(); - DCHECK(interface_data); - global_environment->CacheInterfaceData(key, interface_data); - DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key)); - } - return interface_data; -} - -} // namespace - -// static -JSObject* MozjsExceptionObjectInterface::CreateProxy( - JSContext* context, const scoped_refptr<Wrappable>& wrappable) { - DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); - JS::RootedObject global_object( - context, - MozjsGlobalEnvironment::GetFromContext(context)->global_object()); - DCHECK(global_object); - - InterfaceData* interface_data = GetInterfaceData(context); - JS::RootedObject prototype(context, GetPrototype(context, global_object)); - DCHECK(prototype); - JS::RootedObject new_object( - context, - JS_NewObjectWithGivenProto( - context, &instance_class_definition, prototype)); - DCHECK(new_object); - JS::RootedObject proxy(context, - ProxyHandler::NewProxy( - context, proxy_handler.Pointer(), new_object, prototype)); - WrapperPrivate::AddPrivateData(context, proxy, wrappable); - return proxy; -} - -// static -const JSClass* MozjsExceptionObjectInterface::PrototypeClass( - JSContext* context) { - DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); - JS::RootedObject global_object( - context, - MozjsGlobalEnvironment::GetFromContext(context)->global_object()); - DCHECK(global_object); - - JS::RootedObject prototype(context, GetPrototype(context, global_object)); - const JSClass* proto_class = JS_GetClass(prototype); - return proto_class; -} - -// static -JSObject* MozjsExceptionObjectInterface::GetPrototype( - JSContext* context, JS::HandleObject global_object) { - DCHECK(JS_IsGlobalObject(global_object)); - - InterfaceData* interface_data = GetInterfaceData(context); - if (!interface_data->prototype) { - // Create new prototype that has all the props and methods - InitializePrototypeAndInterfaceObject( - interface_data, context, global_object); - } - DCHECK(interface_data->prototype); - return interface_data->prototype; -} - -// static -JSObject* MozjsExceptionObjectInterface::GetInterfaceObject( - JSContext* context, JS::HandleObject global_object) { - DCHECK(JS_IsGlobalObject(global_object)); - - InterfaceData* interface_data = GetInterfaceData(context); - if (!interface_data->interface_object) { - InitializePrototypeAndInterfaceObject( - interface_data, context, global_object); - } - DCHECK(interface_data->interface_object); - return interface_data->interface_object; -} - - -namespace { -} // namespace - - -} // namespace testing -} // namespace bindings -} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsExceptionObjectInterface.h b/src/cobalt/bindings/generated/mozjs-45/testing/MozjsExceptionObjectInterface.h deleted file mode 100644 index 3cb1e3d..0000000 --- a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsExceptionObjectInterface.h +++ /dev/null
@@ -1,54 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! -// Auto-generated from template: bindings/mozjs-45/templates/interface.h.template - -// clang-format off - -#ifndef MozjsExceptionObjectInterface_h -#define MozjsExceptionObjectInterface_h - -#include "base/hash_tables.h" -#include "base/lazy_instance.h" -#include "base/memory/ref_counted.h" -#include "base/threading/thread_checker.h" -#include "cobalt/base/polymorphic_downcast.h" -#include "cobalt/script/wrappable.h" -#include "cobalt/bindings/testing/exception_object_interface.h" - -#include "third_party/mozjs-45/js/src/jsapi.h" - -namespace cobalt { -namespace bindings { -namespace testing { - -class MozjsExceptionObjectInterface { - public: - static JSObject* CreateProxy(JSContext* context, - const scoped_refptr<script::Wrappable>& wrappable); - static const JSClass* PrototypeClass(JSContext* context); - static JSObject* GetPrototype(JSContext* context, - JS::HandleObject global_object); - static JSObject* GetInterfaceObject(JSContext* context, - JS::HandleObject global_object); -}; - -} // namespace bindings -} // namespace testing -} // namespace cobalt - -#endif // MozjsExceptionObjectInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsExceptionsInterface.cc b/src/cobalt/bindings/generated/mozjs-45/testing/MozjsExceptionsInterface.cc deleted file mode 100644 index dffae7b..0000000 --- a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsExceptionsInterface.cc +++ /dev/null
@@ -1,496 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! -// Auto-generated from template: bindings/mozjs-45/templates/interface.cc.template - -// clang-format off - -#include "MozjsExceptionsInterface.h" - -#include "base/debug/trace_event.h" -#include "cobalt/base/polymorphic_downcast.h" -#include "cobalt/script/global_environment.h" -#include "cobalt/script/opaque_handle.h" -#include "cobalt/script/script_object.h" - -#include "base/lazy_instance.h" -#include "cobalt/script/mozjs-45/callback_function_conversion.h" -#include "cobalt/script/exception_state.h" -#include "cobalt/script/mozjs-45/conversion_helpers.h" -#include "cobalt/script/mozjs-45/mozjs_exception_state.h" -#include "cobalt/script/mozjs-45/mozjs_callback_function.h" -#include "cobalt/script/mozjs-45/mozjs_global_environment.h" -#include "cobalt/script/mozjs-45/mozjs_object_handle.h" -#include "cobalt/script/mozjs-45/mozjs_property_enumerator.h" -#include "cobalt/script/mozjs-45/mozjs_user_object_holder.h" -#include "cobalt/script/mozjs-45/proxy_handler.h" -#include "cobalt/script/mozjs-45/type_traits.h" -#include "cobalt/script/mozjs-45/wrapper_factory.h" -#include "cobalt/script/mozjs-45/wrapper_private.h" -#include "cobalt/script/property_enumerator.h" -#include "third_party/mozjs-45/js/src/jsapi.h" -#include "third_party/mozjs-45/js/src/jsfriendapi.h" - -namespace { -using cobalt::bindings::testing::ExceptionsInterface; -using cobalt::bindings::testing::MozjsExceptionsInterface; -using cobalt::script::CallbackInterfaceTraits; -using cobalt::script::GlobalEnvironment; -using cobalt::script::OpaqueHandle; -using cobalt::script::OpaqueHandleHolder; -using cobalt::script::ScriptObject; -using cobalt::script::Wrappable; - -using cobalt::script::CallbackFunction; -using cobalt::script::CallbackInterfaceTraits; -using cobalt::script::ExceptionState; -using cobalt::script::mozjs::FromJSValue; -using cobalt::script::mozjs::kConversionFlagNullable; -using cobalt::script::mozjs::kConversionFlagRestricted; -using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString; -using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString; -using cobalt::script::mozjs::kNoConversionFlags; -using cobalt::script::mozjs::InterfaceData; -using cobalt::script::mozjs::MozjsCallbackFunction; -using cobalt::script::mozjs::MozjsExceptionState; -using cobalt::script::mozjs::MozjsGlobalEnvironment; -using cobalt::script::mozjs::MozjsUserObjectHolder; -using cobalt::script::mozjs::MozjsPropertyEnumerator; -using cobalt::script::mozjs::ProxyHandler; -using cobalt::script::mozjs::ToJSValue; -using cobalt::script::mozjs::TypeTraits; -using cobalt::script::mozjs::WrapperPrivate; -using cobalt::script::mozjs::WrapperFactory; -using cobalt::script::Wrappable; -} // namespace - -namespace cobalt { -namespace bindings { -namespace testing { - -namespace { - -class MozjsExceptionsInterfaceHandler : public ProxyHandler { - public: - MozjsExceptionsInterfaceHandler() - : ProxyHandler(indexed_property_hooks, named_property_hooks) {} - - private: - static NamedPropertyHooks named_property_hooks; - static IndexedPropertyHooks indexed_property_hooks; -}; - -ProxyHandler::NamedPropertyHooks -MozjsExceptionsInterfaceHandler::named_property_hooks = { - NULL, - NULL, - NULL, - NULL, - NULL, -}; -ProxyHandler::IndexedPropertyHooks -MozjsExceptionsInterfaceHandler::indexed_property_hooks = { - NULL, - NULL, - NULL, - NULL, - NULL, -}; - -static base::LazyInstance<MozjsExceptionsInterfaceHandler> - proxy_handler; - -bool Constructor(JSContext* context, unsigned int argc, JS::Value* vp); -bool HasInstance(JSContext *context, JS::HandleObject type, - JS::MutableHandleValue vp, bool *success) { - JS::RootedObject global_object( - context, JS_GetGlobalForObject(context, type)); - DCHECK(global_object); - - JS::RootedObject prototype( - context, MozjsExceptionsInterface::GetPrototype(context, global_object)); - - // |IsDelegate| walks the prototype chain of an object returning true if - // .prototype is found. - bool is_delegate; - if (!IsDelegate(context, prototype, vp, &is_delegate)) { - *success = false; - return false; - } - - *success = is_delegate; - return true; -} - -const JSClass instance_class_definition = { - "ExceptionsInterface", - 0 | JSCLASS_HAS_PRIVATE, - NULL, // addProperty - NULL, // delProperty - NULL, // getProperty - NULL, // setProperty - NULL, // enumerate - NULL, // resolve - NULL, // mayResolve - &WrapperPrivate::Finalizer, // finalize - NULL, // call - NULL, // hasInstance - NULL, // construct - &WrapperPrivate::Trace, // trace -}; - -const JSClass prototype_class_definition = { - "ExceptionsInterfacePrototype", -}; - -const JSClass interface_object_class_definition = { - "ExceptionsInterfaceConstructor", - 0, - NULL, // addProperty - NULL, // delProperty - NULL, // getProperty - NULL, // setProperty - NULL, // enumerate - NULL, // resolve - NULL, // mayResolve - NULL, // finalize - NULL, // call - &HasInstance, - Constructor, -}; - -bool get_attributeThrowsException( - JSContext* context, unsigned argc, JS::Value* vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<ExceptionsInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - ExceptionsInterface* impl = - wrapper_private->wrappable<ExceptionsInterface>().get(); - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->attribute_throws_exception(&exception_state), - &result_value); - } - if (!exception_state.is_exception_set()) { - args.rval().set(result_value); - } - return !exception_state.is_exception_set(); -} - -bool set_attributeThrowsException( - JSContext* context, unsigned argc, JS::Value* vp) { - - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<ExceptionsInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - ExceptionsInterface* impl = - wrapper_private->wrappable<ExceptionsInterface>().get(); - TypeTraits<bool >::ConversionType value; - if (args.length() != 1) { - NOTREACHED(); - return false; - } - FromJSValue(context, args[0], kNoConversionFlags, &exception_state, - &value); - if (exception_state.is_exception_set()) { - return false; - } - - impl->set_attribute_throws_exception(value, &exception_state); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - -bool fcn_functionThrowsException( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, &object)) { - NOTREACHED(); - return false; - } - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<ExceptionsInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - ExceptionsInterface* impl = - wrapper_private->wrappable<ExceptionsInterface>().get(); - - impl->FunctionThrowsException(&exception_state); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - - - -const JSPropertySpec prototype_properties[] = { - { // Read/Write property - "attributeThrowsException", - JSPROP_SHARED | JSPROP_ENUMERATE, - { { &get_attributeThrowsException, NULL } }, - { { &set_attributeThrowsException, NULL } }, - }, - JS_PS_END -}; - -const JSFunctionSpec prototype_functions[] = { - JS_FNSPEC( - "functionThrowsException", fcn_functionThrowsException, NULL, - 0, JSPROP_ENUMERATE, NULL), - JS_FS_END -}; - -const JSPropertySpec interface_object_properties[] = { - JS_PS_END -}; - -const JSFunctionSpec interface_object_functions[] = { - JS_FS_END -}; - -const JSPropertySpec own_properties[] = { - JS_PS_END -}; - -void InitializePrototypeAndInterfaceObject( - InterfaceData* interface_data, JSContext* context, - JS::HandleObject global_object) { - DCHECK(!interface_data->prototype); - DCHECK(!interface_data->interface_object); - DCHECK(JS_IsGlobalObject(global_object)); - - JS::RootedObject parent_prototype( - context, JS_GetObjectPrototype(context, global_object)); - DCHECK(parent_prototype); - - interface_data->prototype = JS_NewObjectWithGivenProto( - context, &prototype_class_definition, parent_prototype - ); - - JS::RootedObject rooted_prototype(context, interface_data->prototype); - bool success = JS_DefineProperties( - context, - rooted_prototype, - prototype_properties); - - DCHECK(success); - success = JS_DefineFunctions( - context, rooted_prototype, prototype_functions); - DCHECK(success); - - JS::RootedObject function_prototype( - context, JS_GetFunctionPrototype(context, global_object)); - DCHECK(function_prototype); - // Create the Interface object. - interface_data->interface_object = JS_NewObjectWithGivenProto( - context, &interface_object_class_definition, - function_prototype); - - // Add the InterfaceObject.name property. - JS::RootedObject rooted_interface_object( - context, interface_data->interface_object); - JS::RootedValue name_value(context); - const char name[] = - "ExceptionsInterface"; - name_value.setString(JS_NewStringCopyZ(context, name)); - success = JS_DefineProperty( - context, rooted_interface_object, "name", name_value, JSPROP_READONLY, - NULL, NULL); - DCHECK(success); - - // Add the InterfaceObject.length property. It is set to the length of the - // shortest argument list of all overload constructors. - JS::RootedValue length_value(context); - length_value.setInt32(0); - success = JS_DefineProperty( - context, rooted_interface_object, "length", length_value, - JSPROP_READONLY, NULL, NULL); - DCHECK(success); - - // Define interface object properties (including constants). - success = JS_DefineProperties(context, rooted_interface_object, - interface_object_properties); - DCHECK(success); - // Define interface object functions (static). - success = JS_DefineFunctions(context, rooted_interface_object, - interface_object_functions); - DCHECK(success); - - // Set the Prototype.constructor and Constructor.prototype properties. - DCHECK(interface_data->interface_object); - DCHECK(interface_data->prototype); - success = JS_LinkConstructorAndPrototype( - context, - rooted_interface_object, - rooted_prototype); - DCHECK(success); -} - -InterfaceData* GetInterfaceData(JSContext* context) { - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - // Use the address of the properties definition for this interface as a - // unique key for looking up the InterfaceData for this interface. - intptr_t key = reinterpret_cast<intptr_t>(&own_properties); - InterfaceData* interface_data = global_environment->GetInterfaceData(key); - if (!interface_data) { - interface_data = new InterfaceData(); - DCHECK(interface_data); - global_environment->CacheInterfaceData(key, interface_data); - DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key)); - } - return interface_data; -} - -} // namespace - -// static -JSObject* MozjsExceptionsInterface::CreateProxy( - JSContext* context, const scoped_refptr<Wrappable>& wrappable) { - DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); - JS::RootedObject global_object( - context, - MozjsGlobalEnvironment::GetFromContext(context)->global_object()); - DCHECK(global_object); - - InterfaceData* interface_data = GetInterfaceData(context); - JS::RootedObject prototype(context, GetPrototype(context, global_object)); - DCHECK(prototype); - JS::RootedObject new_object( - context, - JS_NewObjectWithGivenProto( - context, &instance_class_definition, prototype)); - DCHECK(new_object); - JS::RootedObject proxy(context, - ProxyHandler::NewProxy( - context, proxy_handler.Pointer(), new_object, prototype)); - WrapperPrivate::AddPrivateData(context, proxy, wrappable); - return proxy; -} - -// static -const JSClass* MozjsExceptionsInterface::PrototypeClass( - JSContext* context) { - DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); - JS::RootedObject global_object( - context, - MozjsGlobalEnvironment::GetFromContext(context)->global_object()); - DCHECK(global_object); - - JS::RootedObject prototype(context, GetPrototype(context, global_object)); - const JSClass* proto_class = JS_GetClass(prototype); - return proto_class; -} - -// static -JSObject* MozjsExceptionsInterface::GetPrototype( - JSContext* context, JS::HandleObject global_object) { - DCHECK(JS_IsGlobalObject(global_object)); - - InterfaceData* interface_data = GetInterfaceData(context); - if (!interface_data->prototype) { - // Create new prototype that has all the props and methods - InitializePrototypeAndInterfaceObject( - interface_data, context, global_object); - } - DCHECK(interface_data->prototype); - return interface_data->prototype; -} - -// static -JSObject* MozjsExceptionsInterface::GetInterfaceObject( - JSContext* context, JS::HandleObject global_object) { - DCHECK(JS_IsGlobalObject(global_object)); - - InterfaceData* interface_data = GetInterfaceData(context); - if (!interface_data->interface_object) { - InitializePrototypeAndInterfaceObject( - interface_data, context, global_object); - } - DCHECK(interface_data->interface_object); - return interface_data->interface_object; -} - - -namespace { -bool Constructor(JSContext* context, unsigned int argc, JS::Value* vp) { - MozjsExceptionState exception_state(context); - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - - scoped_refptr<ExceptionsInterface> new_object = - new ExceptionsInterface(&exception_state); - // In case that an exception is thrown from constructor. - if (exception_state.is_exception_set()) { - return false; - } - JS::RootedValue result_value(context); - ToJSValue(context, new_object, &result_value); - DCHECK(result_value.isObject()); - args.rval().setObject(result_value.toObject()); - return true; -} -} // namespace - - -} // namespace testing -} // namespace bindings -} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsExceptionsInterface.h b/src/cobalt/bindings/generated/mozjs-45/testing/MozjsExceptionsInterface.h deleted file mode 100644 index 0e467fd..0000000 --- a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsExceptionsInterface.h +++ /dev/null
@@ -1,54 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! -// Auto-generated from template: bindings/mozjs-45/templates/interface.h.template - -// clang-format off - -#ifndef MozjsExceptionsInterface_h -#define MozjsExceptionsInterface_h - -#include "base/hash_tables.h" -#include "base/lazy_instance.h" -#include "base/memory/ref_counted.h" -#include "base/threading/thread_checker.h" -#include "cobalt/base/polymorphic_downcast.h" -#include "cobalt/script/wrappable.h" -#include "cobalt/bindings/testing/exceptions_interface.h" - -#include "third_party/mozjs-45/js/src/jsapi.h" - -namespace cobalt { -namespace bindings { -namespace testing { - -class MozjsExceptionsInterface { - public: - static JSObject* CreateProxy(JSContext* context, - const scoped_refptr<script::Wrappable>& wrappable); - static const JSClass* PrototypeClass(JSContext* context); - static JSObject* GetPrototype(JSContext* context, - JS::HandleObject global_object); - static JSObject* GetInterfaceObject(JSContext* context, - JS::HandleObject global_object); -}; - -} // namespace bindings -} // namespace testing -} // namespace cobalt - -#endif // MozjsExceptionsInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsExtendedIDLAttributesInterface.cc b/src/cobalt/bindings/generated/mozjs-45/testing/MozjsExtendedIDLAttributesInterface.cc deleted file mode 100644 index f47b0d6..0000000 --- a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsExtendedIDLAttributesInterface.cc +++ /dev/null
@@ -1,396 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! -// Auto-generated from template: bindings/mozjs-45/templates/interface.cc.template - -// clang-format off - -#include "MozjsExtendedIDLAttributesInterface.h" - -#include "base/debug/trace_event.h" -#include "cobalt/base/polymorphic_downcast.h" -#include "cobalt/script/global_environment.h" -#include "cobalt/script/opaque_handle.h" -#include "cobalt/script/script_object.h" - -#include "base/lazy_instance.h" -#include "cobalt/script/mozjs-45/callback_function_conversion.h" -#include "cobalt/script/exception_state.h" -#include "cobalt/script/mozjs-45/conversion_helpers.h" -#include "cobalt/script/mozjs-45/mozjs_exception_state.h" -#include "cobalt/script/mozjs-45/mozjs_callback_function.h" -#include "cobalt/script/mozjs-45/mozjs_global_environment.h" -#include "cobalt/script/mozjs-45/mozjs_object_handle.h" -#include "cobalt/script/mozjs-45/mozjs_property_enumerator.h" -#include "cobalt/script/mozjs-45/mozjs_user_object_holder.h" -#include "cobalt/script/mozjs-45/proxy_handler.h" -#include "cobalt/script/mozjs-45/type_traits.h" -#include "cobalt/script/mozjs-45/wrapper_factory.h" -#include "cobalt/script/mozjs-45/wrapper_private.h" -#include "cobalt/script/property_enumerator.h" -#include "third_party/mozjs-45/js/src/jsapi.h" -#include "third_party/mozjs-45/js/src/jsfriendapi.h" - -namespace { -using cobalt::bindings::testing::ExtendedIDLAttributesInterface; -using cobalt::bindings::testing::MozjsExtendedIDLAttributesInterface; -using cobalt::script::CallbackInterfaceTraits; -using cobalt::script::GlobalEnvironment; -using cobalt::script::OpaqueHandle; -using cobalt::script::OpaqueHandleHolder; -using cobalt::script::ScriptObject; -using cobalt::script::Wrappable; - -using cobalt::script::CallbackFunction; -using cobalt::script::CallbackInterfaceTraits; -using cobalt::script::ExceptionState; -using cobalt::script::mozjs::FromJSValue; -using cobalt::script::mozjs::kConversionFlagNullable; -using cobalt::script::mozjs::kConversionFlagRestricted; -using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString; -using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString; -using cobalt::script::mozjs::kNoConversionFlags; -using cobalt::script::mozjs::InterfaceData; -using cobalt::script::mozjs::MozjsCallbackFunction; -using cobalt::script::mozjs::MozjsExceptionState; -using cobalt::script::mozjs::MozjsGlobalEnvironment; -using cobalt::script::mozjs::MozjsUserObjectHolder; -using cobalt::script::mozjs::MozjsPropertyEnumerator; -using cobalt::script::mozjs::ProxyHandler; -using cobalt::script::mozjs::ToJSValue; -using cobalt::script::mozjs::TypeTraits; -using cobalt::script::mozjs::WrapperPrivate; -using cobalt::script::mozjs::WrapperFactory; -using cobalt::script::Wrappable; -} // namespace - -namespace cobalt { -namespace bindings { -namespace testing { - -namespace { - -class MozjsExtendedIDLAttributesInterfaceHandler : public ProxyHandler { - public: - MozjsExtendedIDLAttributesInterfaceHandler() - : ProxyHandler(indexed_property_hooks, named_property_hooks) {} - - private: - static NamedPropertyHooks named_property_hooks; - static IndexedPropertyHooks indexed_property_hooks; -}; - -ProxyHandler::NamedPropertyHooks -MozjsExtendedIDLAttributesInterfaceHandler::named_property_hooks = { - NULL, - NULL, - NULL, - NULL, - NULL, -}; -ProxyHandler::IndexedPropertyHooks -MozjsExtendedIDLAttributesInterfaceHandler::indexed_property_hooks = { - NULL, - NULL, - NULL, - NULL, - NULL, -}; - -static base::LazyInstance<MozjsExtendedIDLAttributesInterfaceHandler> - proxy_handler; - -bool HasInstance(JSContext *context, JS::HandleObject type, - JS::MutableHandleValue vp, bool *success) { - JS::RootedObject global_object( - context, JS_GetGlobalForObject(context, type)); - DCHECK(global_object); - - JS::RootedObject prototype( - context, MozjsExtendedIDLAttributesInterface::GetPrototype(context, global_object)); - - // |IsDelegate| walks the prototype chain of an object returning true if - // .prototype is found. - bool is_delegate; - if (!IsDelegate(context, prototype, vp, &is_delegate)) { - *success = false; - return false; - } - - *success = is_delegate; - return true; -} - -const JSClass instance_class_definition = { - "ExtendedIDLAttributesInterface", - 0 | JSCLASS_HAS_PRIVATE, - NULL, // addProperty - NULL, // delProperty - NULL, // getProperty - NULL, // setProperty - NULL, // enumerate - NULL, // resolve - NULL, // mayResolve - &WrapperPrivate::Finalizer, // finalize - NULL, // call - NULL, // hasInstance - NULL, // construct - &WrapperPrivate::Trace, // trace -}; - -const JSClass prototype_class_definition = { - "ExtendedIDLAttributesInterfacePrototype", -}; - -const JSClass interface_object_class_definition = { - "ExtendedIDLAttributesInterfaceConstructor", - 0, - NULL, // addProperty - NULL, // delProperty - NULL, // getProperty - NULL, // setProperty - NULL, // enumerate - NULL, // resolve - NULL, // mayResolve - NULL, // finalize - NULL, // call - &HasInstance, - NULL, -}; - -bool fcn_callWithSettings( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, &object)) { - NOTREACHED(); - return false; - } - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<ExtendedIDLAttributesInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - ExtendedIDLAttributesInterface* impl = - wrapper_private->wrappable<ExtendedIDLAttributesInterface>().get(); - MozjsGlobalEnvironment* callwith_global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - - impl->CallWithSettings(callwith_global_environment->GetEnvironmentSettings()); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - - - -const JSPropertySpec prototype_properties[] = { - JS_PS_END -}; - -const JSFunctionSpec prototype_functions[] = { - JS_FNSPEC( - "callWithSettings", fcn_callWithSettings, NULL, - 0, JSPROP_ENUMERATE, NULL), - JS_FS_END -}; - -const JSPropertySpec interface_object_properties[] = { - JS_PS_END -}; - -const JSFunctionSpec interface_object_functions[] = { - JS_FS_END -}; - -const JSPropertySpec own_properties[] = { - JS_PS_END -}; - -void InitializePrototypeAndInterfaceObject( - InterfaceData* interface_data, JSContext* context, - JS::HandleObject global_object) { - DCHECK(!interface_data->prototype); - DCHECK(!interface_data->interface_object); - DCHECK(JS_IsGlobalObject(global_object)); - - JS::RootedObject parent_prototype( - context, JS_GetObjectPrototype(context, global_object)); - DCHECK(parent_prototype); - - interface_data->prototype = JS_NewObjectWithGivenProto( - context, &prototype_class_definition, parent_prototype - ); - - JS::RootedObject rooted_prototype(context, interface_data->prototype); - bool success = JS_DefineProperties( - context, - rooted_prototype, - prototype_properties); - - DCHECK(success); - success = JS_DefineFunctions( - context, rooted_prototype, prototype_functions); - DCHECK(success); - - JS::RootedObject function_prototype( - context, JS_GetFunctionPrototype(context, global_object)); - DCHECK(function_prototype); - // Create the Interface object. - interface_data->interface_object = JS_NewObjectWithGivenProto( - context, &interface_object_class_definition, - function_prototype); - - // Add the InterfaceObject.name property. - JS::RootedObject rooted_interface_object( - context, interface_data->interface_object); - JS::RootedValue name_value(context); - const char name[] = - "ExtendedIDLAttributesInterface"; - name_value.setString(JS_NewStringCopyZ(context, name)); - success = JS_DefineProperty( - context, rooted_interface_object, "name", name_value, JSPROP_READONLY, - NULL, NULL); - DCHECK(success); - - // Define interface object properties (including constants). - success = JS_DefineProperties(context, rooted_interface_object, - interface_object_properties); - DCHECK(success); - // Define interface object functions (static). - success = JS_DefineFunctions(context, rooted_interface_object, - interface_object_functions); - DCHECK(success); - - // Set the Prototype.constructor and Constructor.prototype properties. - DCHECK(interface_data->interface_object); - DCHECK(interface_data->prototype); - success = JS_LinkConstructorAndPrototype( - context, - rooted_interface_object, - rooted_prototype); - DCHECK(success); -} - -InterfaceData* GetInterfaceData(JSContext* context) { - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - // Use the address of the properties definition for this interface as a - // unique key for looking up the InterfaceData for this interface. - intptr_t key = reinterpret_cast<intptr_t>(&own_properties); - InterfaceData* interface_data = global_environment->GetInterfaceData(key); - if (!interface_data) { - interface_data = new InterfaceData(); - DCHECK(interface_data); - global_environment->CacheInterfaceData(key, interface_data); - DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key)); - } - return interface_data; -} - -} // namespace - -// static -JSObject* MozjsExtendedIDLAttributesInterface::CreateProxy( - JSContext* context, const scoped_refptr<Wrappable>& wrappable) { - DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); - JS::RootedObject global_object( - context, - MozjsGlobalEnvironment::GetFromContext(context)->global_object()); - DCHECK(global_object); - - InterfaceData* interface_data = GetInterfaceData(context); - JS::RootedObject prototype(context, GetPrototype(context, global_object)); - DCHECK(prototype); - JS::RootedObject new_object( - context, - JS_NewObjectWithGivenProto( - context, &instance_class_definition, prototype)); - DCHECK(new_object); - JS::RootedObject proxy(context, - ProxyHandler::NewProxy( - context, proxy_handler.Pointer(), new_object, prototype)); - WrapperPrivate::AddPrivateData(context, proxy, wrappable); - return proxy; -} - -// static -const JSClass* MozjsExtendedIDLAttributesInterface::PrototypeClass( - JSContext* context) { - DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); - JS::RootedObject global_object( - context, - MozjsGlobalEnvironment::GetFromContext(context)->global_object()); - DCHECK(global_object); - - JS::RootedObject prototype(context, GetPrototype(context, global_object)); - const JSClass* proto_class = JS_GetClass(prototype); - return proto_class; -} - -// static -JSObject* MozjsExtendedIDLAttributesInterface::GetPrototype( - JSContext* context, JS::HandleObject global_object) { - DCHECK(JS_IsGlobalObject(global_object)); - - InterfaceData* interface_data = GetInterfaceData(context); - if (!interface_data->prototype) { - // Create new prototype that has all the props and methods - InitializePrototypeAndInterfaceObject( - interface_data, context, global_object); - } - DCHECK(interface_data->prototype); - return interface_data->prototype; -} - -// static -JSObject* MozjsExtendedIDLAttributesInterface::GetInterfaceObject( - JSContext* context, JS::HandleObject global_object) { - DCHECK(JS_IsGlobalObject(global_object)); - - InterfaceData* interface_data = GetInterfaceData(context); - if (!interface_data->interface_object) { - InitializePrototypeAndInterfaceObject( - interface_data, context, global_object); - } - DCHECK(interface_data->interface_object); - return interface_data->interface_object; -} - - -namespace { -} // namespace - - -} // namespace testing -} // namespace bindings -} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsExtendedIDLAttributesInterface.h b/src/cobalt/bindings/generated/mozjs-45/testing/MozjsExtendedIDLAttributesInterface.h deleted file mode 100644 index 0136a91..0000000 --- a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsExtendedIDLAttributesInterface.h +++ /dev/null
@@ -1,54 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! -// Auto-generated from template: bindings/mozjs-45/templates/interface.h.template - -// clang-format off - -#ifndef MozjsExtendedIDLAttributesInterface_h -#define MozjsExtendedIDLAttributesInterface_h - -#include "base/hash_tables.h" -#include "base/lazy_instance.h" -#include "base/memory/ref_counted.h" -#include "base/threading/thread_checker.h" -#include "cobalt/base/polymorphic_downcast.h" -#include "cobalt/script/wrappable.h" -#include "cobalt/bindings/testing/extended_idl_attributes_interface.h" - -#include "third_party/mozjs-45/js/src/jsapi.h" - -namespace cobalt { -namespace bindings { -namespace testing { - -class MozjsExtendedIDLAttributesInterface { - public: - static JSObject* CreateProxy(JSContext* context, - const scoped_refptr<script::Wrappable>& wrappable); - static const JSClass* PrototypeClass(JSContext* context); - static JSObject* GetPrototype(JSContext* context, - JS::HandleObject global_object); - static JSObject* GetInterfaceObject(JSContext* context, - JS::HandleObject global_object); -}; - -} // namespace bindings -} // namespace testing -} // namespace cobalt - -#endif // MozjsExtendedIDLAttributesInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsGarbageCollectionTestInterface.cc b/src/cobalt/bindings/generated/mozjs-45/testing/MozjsGarbageCollectionTestInterface.cc deleted file mode 100644 index e63da77..0000000 --- a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsGarbageCollectionTestInterface.cc +++ /dev/null
@@ -1,543 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! -// Auto-generated from template: bindings/mozjs-45/templates/interface.cc.template - -// clang-format off - -#include "MozjsGarbageCollectionTestInterface.h" - -#include "base/debug/trace_event.h" -#include "cobalt/base/polymorphic_downcast.h" -#include "cobalt/script/global_environment.h" -#include "cobalt/script/opaque_handle.h" -#include "cobalt/script/script_object.h" -#include "MozjsGarbageCollectionTestInterface.h" -#include "cobalt/bindings/testing/garbage_collection_test_interface.h" - -#include "base/lazy_instance.h" -#include "cobalt/script/mozjs-45/callback_function_conversion.h" -#include "cobalt/script/exception_state.h" -#include "cobalt/script/mozjs-45/conversion_helpers.h" -#include "cobalt/script/mozjs-45/mozjs_exception_state.h" -#include "cobalt/script/mozjs-45/mozjs_callback_function.h" -#include "cobalt/script/mozjs-45/mozjs_global_environment.h" -#include "cobalt/script/mozjs-45/mozjs_object_handle.h" -#include "cobalt/script/mozjs-45/mozjs_property_enumerator.h" -#include "cobalt/script/mozjs-45/mozjs_user_object_holder.h" -#include "cobalt/script/mozjs-45/proxy_handler.h" -#include "cobalt/script/mozjs-45/type_traits.h" -#include "cobalt/script/mozjs-45/wrapper_factory.h" -#include "cobalt/script/mozjs-45/wrapper_private.h" -#include "cobalt/script/property_enumerator.h" -#include "third_party/mozjs-45/js/src/jsapi.h" -#include "third_party/mozjs-45/js/src/jsfriendapi.h" - -namespace { -using cobalt::bindings::testing::GarbageCollectionTestInterface; -using cobalt::bindings::testing::MozjsGarbageCollectionTestInterface; -using cobalt::bindings::testing::GarbageCollectionTestInterface; -using cobalt::bindings::testing::MozjsGarbageCollectionTestInterface; -using cobalt::script::CallbackInterfaceTraits; -using cobalt::script::GlobalEnvironment; -using cobalt::script::OpaqueHandle; -using cobalt::script::OpaqueHandleHolder; -using cobalt::script::ScriptObject; -using cobalt::script::Wrappable; - -using cobalt::script::CallbackFunction; -using cobalt::script::CallbackInterfaceTraits; -using cobalt::script::ExceptionState; -using cobalt::script::mozjs::FromJSValue; -using cobalt::script::mozjs::kConversionFlagNullable; -using cobalt::script::mozjs::kConversionFlagRestricted; -using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString; -using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString; -using cobalt::script::mozjs::kNoConversionFlags; -using cobalt::script::mozjs::InterfaceData; -using cobalt::script::mozjs::MozjsCallbackFunction; -using cobalt::script::mozjs::MozjsExceptionState; -using cobalt::script::mozjs::MozjsGlobalEnvironment; -using cobalt::script::mozjs::MozjsUserObjectHolder; -using cobalt::script::mozjs::MozjsPropertyEnumerator; -using cobalt::script::mozjs::ProxyHandler; -using cobalt::script::mozjs::ToJSValue; -using cobalt::script::mozjs::TypeTraits; -using cobalt::script::mozjs::WrapperPrivate; -using cobalt::script::mozjs::WrapperFactory; -using cobalt::script::Wrappable; -} // namespace - -namespace cobalt { -namespace bindings { -namespace testing { - -namespace { - -Wrappable* GetOpaqueRootFromWrappable( - const scoped_refptr<Wrappable>& wrappable) { - GarbageCollectionTestInterface* impl = - base::polymorphic_downcast<GarbageCollectionTestInterface*>(wrappable.get()); - return impl->GetHead(); -} - -class MozjsGarbageCollectionTestInterfaceHandler : public ProxyHandler { - public: - MozjsGarbageCollectionTestInterfaceHandler() - : ProxyHandler(indexed_property_hooks, named_property_hooks) {} - - private: - static NamedPropertyHooks named_property_hooks; - static IndexedPropertyHooks indexed_property_hooks; -}; - -ProxyHandler::NamedPropertyHooks -MozjsGarbageCollectionTestInterfaceHandler::named_property_hooks = { - NULL, - NULL, - NULL, - NULL, - NULL, -}; -ProxyHandler::IndexedPropertyHooks -MozjsGarbageCollectionTestInterfaceHandler::indexed_property_hooks = { - NULL, - NULL, - NULL, - NULL, - NULL, -}; - -static base::LazyInstance<MozjsGarbageCollectionTestInterfaceHandler> - proxy_handler; - -bool Constructor(JSContext* context, unsigned int argc, JS::Value* vp); -bool HasInstance(JSContext *context, JS::HandleObject type, - JS::MutableHandleValue vp, bool *success) { - JS::RootedObject global_object( - context, JS_GetGlobalForObject(context, type)); - DCHECK(global_object); - - JS::RootedObject prototype( - context, MozjsGarbageCollectionTestInterface::GetPrototype(context, global_object)); - - // |IsDelegate| walks the prototype chain of an object returning true if - // .prototype is found. - bool is_delegate; - if (!IsDelegate(context, prototype, vp, &is_delegate)) { - *success = false; - return false; - } - - *success = is_delegate; - return true; -} - -const JSClass instance_class_definition = { - "GarbageCollectionTestInterface", - 0 | JSCLASS_HAS_PRIVATE, - NULL, // addProperty - NULL, // delProperty - NULL, // getProperty - NULL, // setProperty - NULL, // enumerate - NULL, // resolve - NULL, // mayResolve - &WrapperPrivate::Finalizer, // finalize - NULL, // call - NULL, // hasInstance - NULL, // construct - &WrapperPrivate::Trace, // trace -}; - -const JSClass prototype_class_definition = { - "GarbageCollectionTestInterfacePrototype", -}; - -const JSClass interface_object_class_definition = { - "GarbageCollectionTestInterfaceConstructor", - 0, - NULL, // addProperty - NULL, // delProperty - NULL, // getProperty - NULL, // setProperty - NULL, // enumerate - NULL, // resolve - NULL, // mayResolve - NULL, // finalize - NULL, // call - &HasInstance, - Constructor, -}; - -bool get_previous( - JSContext* context, unsigned argc, JS::Value* vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<GarbageCollectionTestInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - GarbageCollectionTestInterface* impl = - wrapper_private->wrappable<GarbageCollectionTestInterface>().get(); - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->previous(), - &result_value); - } - if (!exception_state.is_exception_set()) { - args.rval().set(result_value); - } - return !exception_state.is_exception_set(); -} - -bool set_previous( - JSContext* context, unsigned argc, JS::Value* vp) { - - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<GarbageCollectionTestInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - GarbageCollectionTestInterface* impl = - wrapper_private->wrappable<GarbageCollectionTestInterface>().get(); - TypeTraits<scoped_refptr<GarbageCollectionTestInterface> >::ConversionType value; - if (args.length() != 1) { - NOTREACHED(); - return false; - } - FromJSValue(context, args[0], (kConversionFlagNullable), &exception_state, - &value); - if (exception_state.is_exception_set()) { - return false; - } - - impl->set_previous(value); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - -bool get_next( - JSContext* context, unsigned argc, JS::Value* vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<GarbageCollectionTestInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - GarbageCollectionTestInterface* impl = - wrapper_private->wrappable<GarbageCollectionTestInterface>().get(); - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->next(), - &result_value); - } - if (!exception_state.is_exception_set()) { - args.rval().set(result_value); - } - return !exception_state.is_exception_set(); -} - -bool set_next( - JSContext* context, unsigned argc, JS::Value* vp) { - - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<GarbageCollectionTestInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - GarbageCollectionTestInterface* impl = - wrapper_private->wrappable<GarbageCollectionTestInterface>().get(); - TypeTraits<scoped_refptr<GarbageCollectionTestInterface> >::ConversionType value; - if (args.length() != 1) { - NOTREACHED(); - return false; - } - FromJSValue(context, args[0], (kConversionFlagNullable), &exception_state, - &value); - if (exception_state.is_exception_set()) { - return false; - } - - impl->set_next(value); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - - - -const JSPropertySpec prototype_properties[] = { - { // Read/Write property - "previous", - JSPROP_SHARED | JSPROP_ENUMERATE, - { { &get_previous, NULL } }, - { { &set_previous, NULL } }, - }, - { // Read/Write property - "next", - JSPROP_SHARED | JSPROP_ENUMERATE, - { { &get_next, NULL } }, - { { &set_next, NULL } }, - }, - JS_PS_END -}; - -const JSFunctionSpec prototype_functions[] = { - JS_FS_END -}; - -const JSPropertySpec interface_object_properties[] = { - JS_PS_END -}; - -const JSFunctionSpec interface_object_functions[] = { - JS_FS_END -}; - -const JSPropertySpec own_properties[] = { - JS_PS_END -}; - -void InitializePrototypeAndInterfaceObject( - InterfaceData* interface_data, JSContext* context, - JS::HandleObject global_object) { - DCHECK(!interface_data->prototype); - DCHECK(!interface_data->interface_object); - DCHECK(JS_IsGlobalObject(global_object)); - - JS::RootedObject parent_prototype( - context, JS_GetObjectPrototype(context, global_object)); - DCHECK(parent_prototype); - - interface_data->prototype = JS_NewObjectWithGivenProto( - context, &prototype_class_definition, parent_prototype - ); - - JS::RootedObject rooted_prototype(context, interface_data->prototype); - bool success = JS_DefineProperties( - context, - rooted_prototype, - prototype_properties); - - DCHECK(success); - success = JS_DefineFunctions( - context, rooted_prototype, prototype_functions); - DCHECK(success); - - JS::RootedObject function_prototype( - context, JS_GetFunctionPrototype(context, global_object)); - DCHECK(function_prototype); - // Create the Interface object. - interface_data->interface_object = JS_NewObjectWithGivenProto( - context, &interface_object_class_definition, - function_prototype); - - // Add the InterfaceObject.name property. - JS::RootedObject rooted_interface_object( - context, interface_data->interface_object); - JS::RootedValue name_value(context); - const char name[] = - "GarbageCollectionTestInterface"; - name_value.setString(JS_NewStringCopyZ(context, name)); - success = JS_DefineProperty( - context, rooted_interface_object, "name", name_value, JSPROP_READONLY, - NULL, NULL); - DCHECK(success); - - // Add the InterfaceObject.length property. It is set to the length of the - // shortest argument list of all overload constructors. - JS::RootedValue length_value(context); - length_value.setInt32(0); - success = JS_DefineProperty( - context, rooted_interface_object, "length", length_value, - JSPROP_READONLY, NULL, NULL); - DCHECK(success); - - // Define interface object properties (including constants). - success = JS_DefineProperties(context, rooted_interface_object, - interface_object_properties); - DCHECK(success); - // Define interface object functions (static). - success = JS_DefineFunctions(context, rooted_interface_object, - interface_object_functions); - DCHECK(success); - - // Set the Prototype.constructor and Constructor.prototype properties. - DCHECK(interface_data->interface_object); - DCHECK(interface_data->prototype); - success = JS_LinkConstructorAndPrototype( - context, - rooted_interface_object, - rooted_prototype); - DCHECK(success); -} - -InterfaceData* GetInterfaceData(JSContext* context) { - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - // Use the address of the properties definition for this interface as a - // unique key for looking up the InterfaceData for this interface. - intptr_t key = reinterpret_cast<intptr_t>(&own_properties); - InterfaceData* interface_data = global_environment->GetInterfaceData(key); - if (!interface_data) { - interface_data = new InterfaceData(); - DCHECK(interface_data); - global_environment->CacheInterfaceData(key, interface_data); - DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key)); - } - return interface_data; -} - -} // namespace - -// static -JSObject* MozjsGarbageCollectionTestInterface::CreateProxy( - JSContext* context, const scoped_refptr<Wrappable>& wrappable) { - DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); - JS::RootedObject global_object( - context, - MozjsGlobalEnvironment::GetFromContext(context)->global_object()); - DCHECK(global_object); - - InterfaceData* interface_data = GetInterfaceData(context); - JS::RootedObject prototype(context, GetPrototype(context, global_object)); - DCHECK(prototype); - JS::RootedObject new_object( - context, - JS_NewObjectWithGivenProto( - context, &instance_class_definition, prototype)); - DCHECK(new_object); - JS::RootedObject proxy(context, - ProxyHandler::NewProxy( - context, proxy_handler.Pointer(), new_object, prototype)); - WrapperPrivate::GetOpaqueRootFunction get_root; - WrapperPrivate::GetReachableWrappablesFunction get_reachable_wrappables; - get_root = base::Bind(&GetOpaqueRootFromWrappable); - WrapperPrivate::AddPrivateData( - context, proxy, wrappable, get_root, get_reachable_wrappables); - return proxy; -} - -// static -const JSClass* MozjsGarbageCollectionTestInterface::PrototypeClass( - JSContext* context) { - DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); - JS::RootedObject global_object( - context, - MozjsGlobalEnvironment::GetFromContext(context)->global_object()); - DCHECK(global_object); - - JS::RootedObject prototype(context, GetPrototype(context, global_object)); - const JSClass* proto_class = JS_GetClass(prototype); - return proto_class; -} - -// static -JSObject* MozjsGarbageCollectionTestInterface::GetPrototype( - JSContext* context, JS::HandleObject global_object) { - DCHECK(JS_IsGlobalObject(global_object)); - - InterfaceData* interface_data = GetInterfaceData(context); - if (!interface_data->prototype) { - // Create new prototype that has all the props and methods - InitializePrototypeAndInterfaceObject( - interface_data, context, global_object); - } - DCHECK(interface_data->prototype); - return interface_data->prototype; -} - -// static -JSObject* MozjsGarbageCollectionTestInterface::GetInterfaceObject( - JSContext* context, JS::HandleObject global_object) { - DCHECK(JS_IsGlobalObject(global_object)); - - InterfaceData* interface_data = GetInterfaceData(context); - if (!interface_data->interface_object) { - InitializePrototypeAndInterfaceObject( - interface_data, context, global_object); - } - DCHECK(interface_data->interface_object); - return interface_data->interface_object; -} - - -namespace { -bool Constructor(JSContext* context, unsigned int argc, JS::Value* vp) { - MozjsExceptionState exception_state(context); - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - - scoped_refptr<GarbageCollectionTestInterface> new_object = - new GarbageCollectionTestInterface(); - JS::RootedValue result_value(context); - ToJSValue(context, new_object, &result_value); - DCHECK(result_value.isObject()); - args.rval().setObject(result_value.toObject()); - return true; -} -} // namespace - - -} // namespace testing -} // namespace bindings -} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsGarbageCollectionTestInterface.h b/src/cobalt/bindings/generated/mozjs-45/testing/MozjsGarbageCollectionTestInterface.h deleted file mode 100644 index ac3294e..0000000 --- a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsGarbageCollectionTestInterface.h +++ /dev/null
@@ -1,54 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! -// Auto-generated from template: bindings/mozjs-45/templates/interface.h.template - -// clang-format off - -#ifndef MozjsGarbageCollectionTestInterface_h -#define MozjsGarbageCollectionTestInterface_h - -#include "base/hash_tables.h" -#include "base/lazy_instance.h" -#include "base/memory/ref_counted.h" -#include "base/threading/thread_checker.h" -#include "cobalt/base/polymorphic_downcast.h" -#include "cobalt/script/wrappable.h" -#include "cobalt/bindings/testing/garbage_collection_test_interface.h" - -#include "third_party/mozjs-45/js/src/jsapi.h" - -namespace cobalt { -namespace bindings { -namespace testing { - -class MozjsGarbageCollectionTestInterface { - public: - static JSObject* CreateProxy(JSContext* context, - const scoped_refptr<script::Wrappable>& wrappable); - static const JSClass* PrototypeClass(JSContext* context); - static JSObject* GetPrototype(JSContext* context, - JS::HandleObject global_object); - static JSObject* GetInterfaceObject(JSContext* context, - JS::HandleObject global_object); -}; - -} // namespace bindings -} // namespace testing -} // namespace cobalt - -#endif // MozjsGarbageCollectionTestInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsGetOpaqueRootInterface.cc b/src/cobalt/bindings/generated/mozjs-45/testing/MozjsGetOpaqueRootInterface.cc deleted file mode 100644 index 01a7f3d..0000000 --- a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsGetOpaqueRootInterface.cc +++ /dev/null
@@ -1,399 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! -// Auto-generated from template: bindings/mozjs-45/templates/interface.cc.template - -// clang-format off - -#include "MozjsGetOpaqueRootInterface.h" - -#include "base/debug/trace_event.h" -#include "cobalt/base/polymorphic_downcast.h" -#include "cobalt/script/global_environment.h" -#include "cobalt/script/opaque_handle.h" -#include "cobalt/script/script_object.h" - -#include "base/lazy_instance.h" -#include "cobalt/script/mozjs-45/callback_function_conversion.h" -#include "cobalt/script/exception_state.h" -#include "cobalt/script/mozjs-45/conversion_helpers.h" -#include "cobalt/script/mozjs-45/mozjs_exception_state.h" -#include "cobalt/script/mozjs-45/mozjs_callback_function.h" -#include "cobalt/script/mozjs-45/mozjs_global_environment.h" -#include "cobalt/script/mozjs-45/mozjs_object_handle.h" -#include "cobalt/script/mozjs-45/mozjs_property_enumerator.h" -#include "cobalt/script/mozjs-45/mozjs_user_object_holder.h" -#include "cobalt/script/mozjs-45/proxy_handler.h" -#include "cobalt/script/mozjs-45/type_traits.h" -#include "cobalt/script/mozjs-45/wrapper_factory.h" -#include "cobalt/script/mozjs-45/wrapper_private.h" -#include "cobalt/script/property_enumerator.h" -#include "third_party/mozjs-45/js/src/jsapi.h" -#include "third_party/mozjs-45/js/src/jsfriendapi.h" - -namespace { -using cobalt::bindings::testing::GetOpaqueRootInterface; -using cobalt::bindings::testing::MozjsGetOpaqueRootInterface; -using cobalt::script::CallbackInterfaceTraits; -using cobalt::script::GlobalEnvironment; -using cobalt::script::OpaqueHandle; -using cobalt::script::OpaqueHandleHolder; -using cobalt::script::ScriptObject; -using cobalt::script::Wrappable; - -using cobalt::script::CallbackFunction; -using cobalt::script::CallbackInterfaceTraits; -using cobalt::script::ExceptionState; -using cobalt::script::mozjs::FromJSValue; -using cobalt::script::mozjs::kConversionFlagNullable; -using cobalt::script::mozjs::kConversionFlagRestricted; -using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString; -using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString; -using cobalt::script::mozjs::kNoConversionFlags; -using cobalt::script::mozjs::InterfaceData; -using cobalt::script::mozjs::MozjsCallbackFunction; -using cobalt::script::mozjs::MozjsExceptionState; -using cobalt::script::mozjs::MozjsGlobalEnvironment; -using cobalt::script::mozjs::MozjsUserObjectHolder; -using cobalt::script::mozjs::MozjsPropertyEnumerator; -using cobalt::script::mozjs::ProxyHandler; -using cobalt::script::mozjs::ToJSValue; -using cobalt::script::mozjs::TypeTraits; -using cobalt::script::mozjs::WrapperPrivate; -using cobalt::script::mozjs::WrapperFactory; -using cobalt::script::Wrappable; -} // namespace - -namespace cobalt { -namespace bindings { -namespace testing { - -namespace { - -Wrappable* GetOpaqueRootFromWrappable( - const scoped_refptr<Wrappable>& wrappable) { - GetOpaqueRootInterface* impl = - base::polymorphic_downcast<GetOpaqueRootInterface*>(wrappable.get()); - return impl->get_opaque_root_function_name(); -} - -void GetReachableWrappables(const scoped_refptr<Wrappable>& wrappable, - WrapperPrivate::WrappableVector* reachable) { - DCHECK(reachable); - GetOpaqueRootInterface* impl = - base::polymorphic_downcast<GetOpaqueRootInterface*>(wrappable.get()); - Wrappable* reachable_0 = impl->add_opaque_root_function_name(); - if (reachable_0) { - reachable->push_back(reachable_0); - } -} - -class MozjsGetOpaqueRootInterfaceHandler : public ProxyHandler { - public: - MozjsGetOpaqueRootInterfaceHandler() - : ProxyHandler(indexed_property_hooks, named_property_hooks) {} - - private: - static NamedPropertyHooks named_property_hooks; - static IndexedPropertyHooks indexed_property_hooks; -}; - -ProxyHandler::NamedPropertyHooks -MozjsGetOpaqueRootInterfaceHandler::named_property_hooks = { - NULL, - NULL, - NULL, - NULL, - NULL, -}; -ProxyHandler::IndexedPropertyHooks -MozjsGetOpaqueRootInterfaceHandler::indexed_property_hooks = { - NULL, - NULL, - NULL, - NULL, - NULL, -}; - -static base::LazyInstance<MozjsGetOpaqueRootInterfaceHandler> - proxy_handler; - -bool Constructor(JSContext* context, unsigned int argc, JS::Value* vp); -bool HasInstance(JSContext *context, JS::HandleObject type, - JS::MutableHandleValue vp, bool *success) { - JS::RootedObject global_object( - context, JS_GetGlobalForObject(context, type)); - DCHECK(global_object); - - JS::RootedObject prototype( - context, MozjsGetOpaqueRootInterface::GetPrototype(context, global_object)); - - // |IsDelegate| walks the prototype chain of an object returning true if - // .prototype is found. - bool is_delegate; - if (!IsDelegate(context, prototype, vp, &is_delegate)) { - *success = false; - return false; - } - - *success = is_delegate; - return true; -} - -const JSClass instance_class_definition = { - "GetOpaqueRootInterface", - 0 | JSCLASS_HAS_PRIVATE, - NULL, // addProperty - NULL, // delProperty - NULL, // getProperty - NULL, // setProperty - NULL, // enumerate - NULL, // resolve - NULL, // mayResolve - &WrapperPrivate::Finalizer, // finalize - NULL, // call - NULL, // hasInstance - NULL, // construct - &WrapperPrivate::Trace, // trace -}; - -const JSClass prototype_class_definition = { - "GetOpaqueRootInterfacePrototype", -}; - -const JSClass interface_object_class_definition = { - "GetOpaqueRootInterfaceConstructor", - 0, - NULL, // addProperty - NULL, // delProperty - NULL, // getProperty - NULL, // setProperty - NULL, // enumerate - NULL, // resolve - NULL, // mayResolve - NULL, // finalize - NULL, // call - &HasInstance, - Constructor, -}; - - - -const JSPropertySpec prototype_properties[] = { - JS_PS_END -}; - -const JSFunctionSpec prototype_functions[] = { - JS_FS_END -}; - -const JSPropertySpec interface_object_properties[] = { - JS_PS_END -}; - -const JSFunctionSpec interface_object_functions[] = { - JS_FS_END -}; - -const JSPropertySpec own_properties[] = { - JS_PS_END -}; - -void InitializePrototypeAndInterfaceObject( - InterfaceData* interface_data, JSContext* context, - JS::HandleObject global_object) { - DCHECK(!interface_data->prototype); - DCHECK(!interface_data->interface_object); - DCHECK(JS_IsGlobalObject(global_object)); - - JS::RootedObject parent_prototype( - context, JS_GetObjectPrototype(context, global_object)); - DCHECK(parent_prototype); - - interface_data->prototype = JS_NewObjectWithGivenProto( - context, &prototype_class_definition, parent_prototype - ); - - JS::RootedObject rooted_prototype(context, interface_data->prototype); - bool success = JS_DefineProperties( - context, - rooted_prototype, - prototype_properties); - - DCHECK(success); - success = JS_DefineFunctions( - context, rooted_prototype, prototype_functions); - DCHECK(success); - - JS::RootedObject function_prototype( - context, JS_GetFunctionPrototype(context, global_object)); - DCHECK(function_prototype); - // Create the Interface object. - interface_data->interface_object = JS_NewObjectWithGivenProto( - context, &interface_object_class_definition, - function_prototype); - - // Add the InterfaceObject.name property. - JS::RootedObject rooted_interface_object( - context, interface_data->interface_object); - JS::RootedValue name_value(context); - const char name[] = - "GetOpaqueRootInterface"; - name_value.setString(JS_NewStringCopyZ(context, name)); - success = JS_DefineProperty( - context, rooted_interface_object, "name", name_value, JSPROP_READONLY, - NULL, NULL); - DCHECK(success); - - // Add the InterfaceObject.length property. It is set to the length of the - // shortest argument list of all overload constructors. - JS::RootedValue length_value(context); - length_value.setInt32(0); - success = JS_DefineProperty( - context, rooted_interface_object, "length", length_value, - JSPROP_READONLY, NULL, NULL); - DCHECK(success); - - // Define interface object properties (including constants). - success = JS_DefineProperties(context, rooted_interface_object, - interface_object_properties); - DCHECK(success); - // Define interface object functions (static). - success = JS_DefineFunctions(context, rooted_interface_object, - interface_object_functions); - DCHECK(success); - - // Set the Prototype.constructor and Constructor.prototype properties. - DCHECK(interface_data->interface_object); - DCHECK(interface_data->prototype); - success = JS_LinkConstructorAndPrototype( - context, - rooted_interface_object, - rooted_prototype); - DCHECK(success); -} - -InterfaceData* GetInterfaceData(JSContext* context) { - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - // Use the address of the properties definition for this interface as a - // unique key for looking up the InterfaceData for this interface. - intptr_t key = reinterpret_cast<intptr_t>(&own_properties); - InterfaceData* interface_data = global_environment->GetInterfaceData(key); - if (!interface_data) { - interface_data = new InterfaceData(); - DCHECK(interface_data); - global_environment->CacheInterfaceData(key, interface_data); - DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key)); - } - return interface_data; -} - -} // namespace - -// static -JSObject* MozjsGetOpaqueRootInterface::CreateProxy( - JSContext* context, const scoped_refptr<Wrappable>& wrappable) { - DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); - JS::RootedObject global_object( - context, - MozjsGlobalEnvironment::GetFromContext(context)->global_object()); - DCHECK(global_object); - - InterfaceData* interface_data = GetInterfaceData(context); - JS::RootedObject prototype(context, GetPrototype(context, global_object)); - DCHECK(prototype); - JS::RootedObject new_object( - context, - JS_NewObjectWithGivenProto( - context, &instance_class_definition, prototype)); - DCHECK(new_object); - JS::RootedObject proxy(context, - ProxyHandler::NewProxy( - context, proxy_handler.Pointer(), new_object, prototype)); - WrapperPrivate::GetOpaqueRootFunction get_root; - WrapperPrivate::GetReachableWrappablesFunction get_reachable_wrappables; - get_root = base::Bind(&GetOpaqueRootFromWrappable); - get_reachable_wrappables = base::Bind(&GetReachableWrappables); - WrapperPrivate::AddPrivateData( - context, proxy, wrappable, get_root, get_reachable_wrappables); - return proxy; -} - -// static -const JSClass* MozjsGetOpaqueRootInterface::PrototypeClass( - JSContext* context) { - DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); - JS::RootedObject global_object( - context, - MozjsGlobalEnvironment::GetFromContext(context)->global_object()); - DCHECK(global_object); - - JS::RootedObject prototype(context, GetPrototype(context, global_object)); - const JSClass* proto_class = JS_GetClass(prototype); - return proto_class; -} - -// static -JSObject* MozjsGetOpaqueRootInterface::GetPrototype( - JSContext* context, JS::HandleObject global_object) { - DCHECK(JS_IsGlobalObject(global_object)); - - InterfaceData* interface_data = GetInterfaceData(context); - if (!interface_data->prototype) { - // Create new prototype that has all the props and methods - InitializePrototypeAndInterfaceObject( - interface_data, context, global_object); - } - DCHECK(interface_data->prototype); - return interface_data->prototype; -} - -// static -JSObject* MozjsGetOpaqueRootInterface::GetInterfaceObject( - JSContext* context, JS::HandleObject global_object) { - DCHECK(JS_IsGlobalObject(global_object)); - - InterfaceData* interface_data = GetInterfaceData(context); - if (!interface_data->interface_object) { - InitializePrototypeAndInterfaceObject( - interface_data, context, global_object); - } - DCHECK(interface_data->interface_object); - return interface_data->interface_object; -} - - -namespace { -bool Constructor(JSContext* context, unsigned int argc, JS::Value* vp) { - MozjsExceptionState exception_state(context); - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - - scoped_refptr<GetOpaqueRootInterface> new_object = - new GetOpaqueRootInterface(); - JS::RootedValue result_value(context); - ToJSValue(context, new_object, &result_value); - DCHECK(result_value.isObject()); - args.rval().setObject(result_value.toObject()); - return true; -} -} // namespace - - -} // namespace testing -} // namespace bindings -} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsGetOpaqueRootInterface.h b/src/cobalt/bindings/generated/mozjs-45/testing/MozjsGetOpaqueRootInterface.h deleted file mode 100644 index d55546d..0000000 --- a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsGetOpaqueRootInterface.h +++ /dev/null
@@ -1,54 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! -// Auto-generated from template: bindings/mozjs-45/templates/interface.h.template - -// clang-format off - -#ifndef MozjsGetOpaqueRootInterface_h -#define MozjsGetOpaqueRootInterface_h - -#include "base/hash_tables.h" -#include "base/lazy_instance.h" -#include "base/memory/ref_counted.h" -#include "base/threading/thread_checker.h" -#include "cobalt/base/polymorphic_downcast.h" -#include "cobalt/script/wrappable.h" -#include "cobalt/bindings/testing/get_opaque_root_interface.h" - -#include "third_party/mozjs-45/js/src/jsapi.h" - -namespace cobalt { -namespace bindings { -namespace testing { - -class MozjsGetOpaqueRootInterface { - public: - static JSObject* CreateProxy(JSContext* context, - const scoped_refptr<script::Wrappable>& wrappable); - static const JSClass* PrototypeClass(JSContext* context); - static JSObject* GetPrototype(JSContext* context, - JS::HandleObject global_object); - static JSObject* GetInterfaceObject(JSContext* context, - JS::HandleObject global_object); -}; - -} // namespace bindings -} // namespace testing -} // namespace cobalt - -#endif // MozjsGetOpaqueRootInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsGlobalInterfaceParent.cc b/src/cobalt/bindings/generated/mozjs-45/testing/MozjsGlobalInterfaceParent.cc deleted file mode 100644 index ee77916..0000000 --- a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsGlobalInterfaceParent.cc +++ /dev/null
@@ -1,394 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! -// Auto-generated from template: bindings/mozjs-45/templates/interface.cc.template - -// clang-format off - -#include "MozjsGlobalInterfaceParent.h" - -#include "base/debug/trace_event.h" -#include "cobalt/base/polymorphic_downcast.h" -#include "cobalt/script/global_environment.h" -#include "cobalt/script/opaque_handle.h" -#include "cobalt/script/script_object.h" - -#include "base/lazy_instance.h" -#include "cobalt/script/mozjs-45/callback_function_conversion.h" -#include "cobalt/script/exception_state.h" -#include "cobalt/script/mozjs-45/conversion_helpers.h" -#include "cobalt/script/mozjs-45/mozjs_exception_state.h" -#include "cobalt/script/mozjs-45/mozjs_callback_function.h" -#include "cobalt/script/mozjs-45/mozjs_global_environment.h" -#include "cobalt/script/mozjs-45/mozjs_object_handle.h" -#include "cobalt/script/mozjs-45/mozjs_property_enumerator.h" -#include "cobalt/script/mozjs-45/mozjs_user_object_holder.h" -#include "cobalt/script/mozjs-45/proxy_handler.h" -#include "cobalt/script/mozjs-45/type_traits.h" -#include "cobalt/script/mozjs-45/wrapper_factory.h" -#include "cobalt/script/mozjs-45/wrapper_private.h" -#include "cobalt/script/property_enumerator.h" -#include "third_party/mozjs-45/js/src/jsapi.h" -#include "third_party/mozjs-45/js/src/jsfriendapi.h" - -namespace { -using cobalt::bindings::testing::GlobalInterfaceParent; -using cobalt::bindings::testing::MozjsGlobalInterfaceParent; -using cobalt::script::CallbackInterfaceTraits; -using cobalt::script::GlobalEnvironment; -using cobalt::script::OpaqueHandle; -using cobalt::script::OpaqueHandleHolder; -using cobalt::script::ScriptObject; -using cobalt::script::Wrappable; - -using cobalt::script::CallbackFunction; -using cobalt::script::CallbackInterfaceTraits; -using cobalt::script::ExceptionState; -using cobalt::script::mozjs::FromJSValue; -using cobalt::script::mozjs::kConversionFlagNullable; -using cobalt::script::mozjs::kConversionFlagRestricted; -using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString; -using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString; -using cobalt::script::mozjs::kNoConversionFlags; -using cobalt::script::mozjs::InterfaceData; -using cobalt::script::mozjs::MozjsCallbackFunction; -using cobalt::script::mozjs::MozjsExceptionState; -using cobalt::script::mozjs::MozjsGlobalEnvironment; -using cobalt::script::mozjs::MozjsUserObjectHolder; -using cobalt::script::mozjs::MozjsPropertyEnumerator; -using cobalt::script::mozjs::ProxyHandler; -using cobalt::script::mozjs::ToJSValue; -using cobalt::script::mozjs::TypeTraits; -using cobalt::script::mozjs::WrapperPrivate; -using cobalt::script::mozjs::WrapperFactory; -using cobalt::script::Wrappable; -} // namespace - -namespace cobalt { -namespace bindings { -namespace testing { - -namespace { - -class MozjsGlobalInterfaceParentHandler : public ProxyHandler { - public: - MozjsGlobalInterfaceParentHandler() - : ProxyHandler(indexed_property_hooks, named_property_hooks) {} - - private: - static NamedPropertyHooks named_property_hooks; - static IndexedPropertyHooks indexed_property_hooks; -}; - -ProxyHandler::NamedPropertyHooks -MozjsGlobalInterfaceParentHandler::named_property_hooks = { - NULL, - NULL, - NULL, - NULL, - NULL, -}; -ProxyHandler::IndexedPropertyHooks -MozjsGlobalInterfaceParentHandler::indexed_property_hooks = { - NULL, - NULL, - NULL, - NULL, - NULL, -}; - -static base::LazyInstance<MozjsGlobalInterfaceParentHandler> - proxy_handler; - -bool HasInstance(JSContext *context, JS::HandleObject type, - JS::MutableHandleValue vp, bool *success) { - JS::RootedObject global_object( - context, JS_GetGlobalForObject(context, type)); - DCHECK(global_object); - - JS::RootedObject prototype( - context, MozjsGlobalInterfaceParent::GetPrototype(context, global_object)); - - // |IsDelegate| walks the prototype chain of an object returning true if - // .prototype is found. - bool is_delegate; - if (!IsDelegate(context, prototype, vp, &is_delegate)) { - *success = false; - return false; - } - - *success = is_delegate; - return true; -} - -const JSClass instance_class_definition = { - "GlobalInterfaceParent", - 0 | JSCLASS_HAS_PRIVATE, - NULL, // addProperty - NULL, // delProperty - NULL, // getProperty - NULL, // setProperty - NULL, // enumerate - NULL, // resolve - NULL, // mayResolve - &WrapperPrivate::Finalizer, // finalize - NULL, // call - NULL, // hasInstance - NULL, // construct - &WrapperPrivate::Trace, // trace -}; - -const JSClass prototype_class_definition = { - "GlobalInterfaceParentPrototype", -}; - -const JSClass interface_object_class_definition = { - "GlobalInterfaceParentConstructor", - 0, - NULL, // addProperty - NULL, // delProperty - NULL, // getProperty - NULL, // setProperty - NULL, // enumerate - NULL, // resolve - NULL, // mayResolve - NULL, // finalize - NULL, // call - &HasInstance, - NULL, -}; - -bool fcn_parentOperation( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, &object)) { - NOTREACHED(); - return false; - } - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<GlobalInterfaceParent>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - GlobalInterfaceParent* impl = - wrapper_private->wrappable<GlobalInterfaceParent>().get(); - - impl->ParentOperation(); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - - - -const JSPropertySpec prototype_properties[] = { - JS_PS_END -}; - -const JSFunctionSpec prototype_functions[] = { - JS_FNSPEC( - "parentOperation", fcn_parentOperation, NULL, - 0, JSPROP_ENUMERATE, NULL), - JS_FS_END -}; - -const JSPropertySpec interface_object_properties[] = { - JS_PS_END -}; - -const JSFunctionSpec interface_object_functions[] = { - JS_FS_END -}; - -const JSPropertySpec own_properties[] = { - JS_PS_END -}; - -void InitializePrototypeAndInterfaceObject( - InterfaceData* interface_data, JSContext* context, - JS::HandleObject global_object) { - DCHECK(!interface_data->prototype); - DCHECK(!interface_data->interface_object); - DCHECK(JS_IsGlobalObject(global_object)); - - JS::RootedObject parent_prototype( - context, JS_GetObjectPrototype(context, global_object)); - DCHECK(parent_prototype); - - interface_data->prototype = JS_NewObjectWithGivenProto( - context, &prototype_class_definition, parent_prototype - ); - - JS::RootedObject rooted_prototype(context, interface_data->prototype); - bool success = JS_DefineProperties( - context, - rooted_prototype, - prototype_properties); - - DCHECK(success); - success = JS_DefineFunctions( - context, rooted_prototype, prototype_functions); - DCHECK(success); - - JS::RootedObject function_prototype( - context, JS_GetFunctionPrototype(context, global_object)); - DCHECK(function_prototype); - // Create the Interface object. - interface_data->interface_object = JS_NewObjectWithGivenProto( - context, &interface_object_class_definition, - function_prototype); - - // Add the InterfaceObject.name property. - JS::RootedObject rooted_interface_object( - context, interface_data->interface_object); - JS::RootedValue name_value(context); - const char name[] = - "GlobalInterfaceParent"; - name_value.setString(JS_NewStringCopyZ(context, name)); - success = JS_DefineProperty( - context, rooted_interface_object, "name", name_value, JSPROP_READONLY, - NULL, NULL); - DCHECK(success); - - // Define interface object properties (including constants). - success = JS_DefineProperties(context, rooted_interface_object, - interface_object_properties); - DCHECK(success); - // Define interface object functions (static). - success = JS_DefineFunctions(context, rooted_interface_object, - interface_object_functions); - DCHECK(success); - - // Set the Prototype.constructor and Constructor.prototype properties. - DCHECK(interface_data->interface_object); - DCHECK(interface_data->prototype); - success = JS_LinkConstructorAndPrototype( - context, - rooted_interface_object, - rooted_prototype); - DCHECK(success); -} - -InterfaceData* GetInterfaceData(JSContext* context) { - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - // Use the address of the properties definition for this interface as a - // unique key for looking up the InterfaceData for this interface. - intptr_t key = reinterpret_cast<intptr_t>(&own_properties); - InterfaceData* interface_data = global_environment->GetInterfaceData(key); - if (!interface_data) { - interface_data = new InterfaceData(); - DCHECK(interface_data); - global_environment->CacheInterfaceData(key, interface_data); - DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key)); - } - return interface_data; -} - -} // namespace - -// static -JSObject* MozjsGlobalInterfaceParent::CreateProxy( - JSContext* context, const scoped_refptr<Wrappable>& wrappable) { - DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); - JS::RootedObject global_object( - context, - MozjsGlobalEnvironment::GetFromContext(context)->global_object()); - DCHECK(global_object); - - InterfaceData* interface_data = GetInterfaceData(context); - JS::RootedObject prototype(context, GetPrototype(context, global_object)); - DCHECK(prototype); - JS::RootedObject new_object( - context, - JS_NewObjectWithGivenProto( - context, &instance_class_definition, prototype)); - DCHECK(new_object); - JS::RootedObject proxy(context, - ProxyHandler::NewProxy( - context, proxy_handler.Pointer(), new_object, prototype)); - WrapperPrivate::AddPrivateData(context, proxy, wrappable); - return proxy; -} - -// static -const JSClass* MozjsGlobalInterfaceParent::PrototypeClass( - JSContext* context) { - DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); - JS::RootedObject global_object( - context, - MozjsGlobalEnvironment::GetFromContext(context)->global_object()); - DCHECK(global_object); - - JS::RootedObject prototype(context, GetPrototype(context, global_object)); - const JSClass* proto_class = JS_GetClass(prototype); - return proto_class; -} - -// static -JSObject* MozjsGlobalInterfaceParent::GetPrototype( - JSContext* context, JS::HandleObject global_object) { - DCHECK(JS_IsGlobalObject(global_object)); - - InterfaceData* interface_data = GetInterfaceData(context); - if (!interface_data->prototype) { - // Create new prototype that has all the props and methods - InitializePrototypeAndInterfaceObject( - interface_data, context, global_object); - } - DCHECK(interface_data->prototype); - return interface_data->prototype; -} - -// static -JSObject* MozjsGlobalInterfaceParent::GetInterfaceObject( - JSContext* context, JS::HandleObject global_object) { - DCHECK(JS_IsGlobalObject(global_object)); - - InterfaceData* interface_data = GetInterfaceData(context); - if (!interface_data->interface_object) { - InitializePrototypeAndInterfaceObject( - interface_data, context, global_object); - } - DCHECK(interface_data->interface_object); - return interface_data->interface_object; -} - - -namespace { -} // namespace - - -} // namespace testing -} // namespace bindings -} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsGlobalInterfaceParent.h b/src/cobalt/bindings/generated/mozjs-45/testing/MozjsGlobalInterfaceParent.h deleted file mode 100644 index f21529b..0000000 --- a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsGlobalInterfaceParent.h +++ /dev/null
@@ -1,54 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! -// Auto-generated from template: bindings/mozjs-45/templates/interface.h.template - -// clang-format off - -#ifndef MozjsGlobalInterfaceParent_h -#define MozjsGlobalInterfaceParent_h - -#include "base/hash_tables.h" -#include "base/lazy_instance.h" -#include "base/memory/ref_counted.h" -#include "base/threading/thread_checker.h" -#include "cobalt/base/polymorphic_downcast.h" -#include "cobalt/script/wrappable.h" -#include "cobalt/bindings/testing/global_interface_parent.h" - -#include "third_party/mozjs-45/js/src/jsapi.h" - -namespace cobalt { -namespace bindings { -namespace testing { - -class MozjsGlobalInterfaceParent { - public: - static JSObject* CreateProxy(JSContext* context, - const scoped_refptr<script::Wrappable>& wrappable); - static const JSClass* PrototypeClass(JSContext* context); - static JSObject* GetPrototype(JSContext* context, - JS::HandleObject global_object); - static JSObject* GetInterfaceObject(JSContext* context, - JS::HandleObject global_object); -}; - -} // namespace bindings -} // namespace testing -} // namespace cobalt - -#endif // MozjsGlobalInterfaceParent_h
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsIndexedGetterInterface.cc b/src/cobalt/bindings/generated/mozjs-45/testing/MozjsIndexedGetterInterface.cc deleted file mode 100644 index 859a662..0000000 --- a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsIndexedGetterInterface.cc +++ /dev/null
@@ -1,695 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! -// Auto-generated from template: bindings/mozjs-45/templates/interface.cc.template - -// clang-format off - -#include "MozjsIndexedGetterInterface.h" - -#include "base/debug/trace_event.h" -#include "cobalt/base/polymorphic_downcast.h" -#include "cobalt/script/global_environment.h" -#include "cobalt/script/opaque_handle.h" -#include "cobalt/script/script_object.h" - -#include "base/lazy_instance.h" -#include "cobalt/script/mozjs-45/callback_function_conversion.h" -#include "cobalt/script/exception_state.h" -#include "cobalt/script/mozjs-45/conversion_helpers.h" -#include "cobalt/script/mozjs-45/mozjs_exception_state.h" -#include "cobalt/script/mozjs-45/mozjs_callback_function.h" -#include "cobalt/script/mozjs-45/mozjs_global_environment.h" -#include "cobalt/script/mozjs-45/mozjs_object_handle.h" -#include "cobalt/script/mozjs-45/mozjs_property_enumerator.h" -#include "cobalt/script/mozjs-45/mozjs_user_object_holder.h" -#include "cobalt/script/mozjs-45/proxy_handler.h" -#include "cobalt/script/mozjs-45/type_traits.h" -#include "cobalt/script/mozjs-45/wrapper_factory.h" -#include "cobalt/script/mozjs-45/wrapper_private.h" -#include "cobalt/script/property_enumerator.h" -#include "third_party/mozjs-45/js/src/jsapi.h" -#include "third_party/mozjs-45/js/src/jsfriendapi.h" - -namespace { -using cobalt::bindings::testing::IndexedGetterInterface; -using cobalt::bindings::testing::MozjsIndexedGetterInterface; -using cobalt::script::CallbackInterfaceTraits; -using cobalt::script::GlobalEnvironment; -using cobalt::script::OpaqueHandle; -using cobalt::script::OpaqueHandleHolder; -using cobalt::script::ScriptObject; -using cobalt::script::Wrappable; - -using cobalt::script::CallbackFunction; -using cobalt::script::CallbackInterfaceTraits; -using cobalt::script::ExceptionState; -using cobalt::script::mozjs::FromJSValue; -using cobalt::script::mozjs::kConversionFlagNullable; -using cobalt::script::mozjs::kConversionFlagRestricted; -using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString; -using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString; -using cobalt::script::mozjs::kNoConversionFlags; -using cobalt::script::mozjs::InterfaceData; -using cobalt::script::mozjs::MozjsCallbackFunction; -using cobalt::script::mozjs::MozjsExceptionState; -using cobalt::script::mozjs::MozjsGlobalEnvironment; -using cobalt::script::mozjs::MozjsUserObjectHolder; -using cobalt::script::mozjs::MozjsPropertyEnumerator; -using cobalt::script::mozjs::ProxyHandler; -using cobalt::script::mozjs::ToJSValue; -using cobalt::script::mozjs::TypeTraits; -using cobalt::script::mozjs::WrapperPrivate; -using cobalt::script::mozjs::WrapperFactory; -using cobalt::script::Wrappable; -} // namespace - -namespace cobalt { -namespace bindings { -namespace testing { - -namespace { - -bool IsSupportedIndexProperty(JSContext* context, JS::HandleObject object, - uint32_t index) { - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - IndexedGetterInterface* impl = - wrapper_private->wrappable<IndexedGetterInterface>().get(); - return index < impl->length(); -} - -void EnumerateSupportedIndexes(JSContext* context, JS::HandleObject object, - JS::AutoIdVector* properties) { - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - IndexedGetterInterface* impl = - wrapper_private->wrappable<IndexedGetterInterface>().get(); - const uint32_t kNumIndexedProperties = impl->length(); - for (uint32_t i = 0; i < kNumIndexedProperties; ++i) { - properties->append(INT_TO_JSID(i)); - } -} - -bool GetIndexedProperty( - JSContext* context, JS::HandleObject object, JS::HandleId id, - JS::MutableHandleValue vp) { - JS::RootedValue id_value(context); - if (!JS_IdToValue(context, id, &id_value)) { - NOTREACHED(); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - IndexedGetterInterface* impl = - wrapper_private->wrappable<IndexedGetterInterface>().get(); - uint32_t index; - FromJSValue(context, id_value, kNoConversionFlags, &exception_state, &index); - if (exception_state.is_exception_set()) { - // The ID should be an integer or a string, so we shouldn't have any - // exceptions converting to string. - NOTREACHED(); - return false; - } - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->IndexedGetter(index), - &result_value); - } - if (!exception_state.is_exception_set()) { - vp.set(result_value); - } - return !exception_state.is_exception_set(); -} - -bool SetIndexedProperty( - JSContext* context, JS::HandleObject object, JS::HandleId id, - JS::MutableHandleValue vp, JS::ObjectOpResult& object_op_result) { - JS::RootedValue id_value(context); - if (!JS_IdToValue(context, id, &id_value)) { - NOTREACHED(); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - IndexedGetterInterface* impl = - wrapper_private->wrappable<IndexedGetterInterface>().get(); - uint32_t index; - FromJSValue(context, id_value, kNoConversionFlags, &exception_state, &index); - if (exception_state.is_exception_set()) { - // The ID should be an integer or a string, so we shouldn't have any - // exceptions converting to string. - NOTREACHED(); - return false; - } - TypeTraits<uint32_t >::ConversionType value; - FromJSValue(context, vp, kNoConversionFlags, - &exception_state, &value); - if (exception_state.is_exception_set()) { - return false; - } - - impl->IndexedSetter(index, value); - result_value.set(JS::UndefinedHandleValue); - if (!exception_state.is_exception_set()) { - return object_op_result.succeed(); - } else { - return false; - } -} - -bool DeleteIndexedProperty( - JSContext* context, JS::HandleObject object, uint32_t index) { - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - IndexedGetterInterface* impl = - wrapper_private->wrappable<IndexedGetterInterface>().get(); - - impl->IndexedDeleter(index); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - -class MozjsIndexedGetterInterfaceHandler : public ProxyHandler { - public: - MozjsIndexedGetterInterfaceHandler() - : ProxyHandler(indexed_property_hooks, named_property_hooks) {} - - private: - static NamedPropertyHooks named_property_hooks; - static IndexedPropertyHooks indexed_property_hooks; -}; - -ProxyHandler::NamedPropertyHooks -MozjsIndexedGetterInterfaceHandler::named_property_hooks = { - NULL, - NULL, - NULL, - NULL, - NULL, -}; -ProxyHandler::IndexedPropertyHooks -MozjsIndexedGetterInterfaceHandler::indexed_property_hooks = { - IsSupportedIndexProperty, - EnumerateSupportedIndexes, - GetIndexedProperty, - SetIndexedProperty, - DeleteIndexedProperty, -}; - -static base::LazyInstance<MozjsIndexedGetterInterfaceHandler> - proxy_handler; - -bool HasInstance(JSContext *context, JS::HandleObject type, - JS::MutableHandleValue vp, bool *success) { - JS::RootedObject global_object( - context, JS_GetGlobalForObject(context, type)); - DCHECK(global_object); - - JS::RootedObject prototype( - context, MozjsIndexedGetterInterface::GetPrototype(context, global_object)); - - // |IsDelegate| walks the prototype chain of an object returning true if - // .prototype is found. - bool is_delegate; - if (!IsDelegate(context, prototype, vp, &is_delegate)) { - *success = false; - return false; - } - - *success = is_delegate; - return true; -} - -const JSClass instance_class_definition = { - "IndexedGetterInterface", - 0 | JSCLASS_HAS_PRIVATE, - NULL, // addProperty - NULL, // delProperty - NULL, // getProperty - NULL, // setProperty - NULL, // enumerate - NULL, // resolve - NULL, // mayResolve - &WrapperPrivate::Finalizer, // finalize - NULL, // call - NULL, // hasInstance - NULL, // construct - &WrapperPrivate::Trace, // trace -}; - -const JSClass prototype_class_definition = { - "IndexedGetterInterfacePrototype", -}; - -const JSClass interface_object_class_definition = { - "IndexedGetterInterfaceConstructor", - 0, - NULL, // addProperty - NULL, // delProperty - NULL, // getProperty - NULL, // setProperty - NULL, // enumerate - NULL, // resolve - NULL, // mayResolve - NULL, // finalize - NULL, // call - &HasInstance, - NULL, -}; - -bool get_length( - JSContext* context, unsigned argc, JS::Value* vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<IndexedGetterInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - IndexedGetterInterface* impl = - wrapper_private->wrappable<IndexedGetterInterface>().get(); - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->length(), - &result_value); - } - if (!exception_state.is_exception_set()) { - args.rval().set(result_value); - } - return !exception_state.is_exception_set(); -} - - -bool fcn_indexedDeleter( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, &object)) { - NOTREACHED(); - return false; - } - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<IndexedGetterInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - IndexedGetterInterface* impl = - wrapper_private->wrappable<IndexedGetterInterface>().get(); - const size_t kMinArguments = 1; - if (args.length() < kMinArguments) { - exception_state.SetSimpleException(script::kInvalidNumberOfArguments); - return false; - } - // Non-optional arguments - TypeTraits<uint32_t >::ConversionType index; - - DCHECK_LT(0, args.length()); - JS::RootedValue non_optional_value0( - context, args[0]); - FromJSValue(context, - non_optional_value0, - kNoConversionFlags, - &exception_state, &index); - if (exception_state.is_exception_set()) { - return false; - } - - impl->IndexedDeleter(index); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - -bool fcn_indexedGetter( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, &object)) { - NOTREACHED(); - return false; - } - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<IndexedGetterInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - IndexedGetterInterface* impl = - wrapper_private->wrappable<IndexedGetterInterface>().get(); - const size_t kMinArguments = 1; - if (args.length() < kMinArguments) { - exception_state.SetSimpleException(script::kInvalidNumberOfArguments); - return false; - } - // Non-optional arguments - TypeTraits<uint32_t >::ConversionType index; - - DCHECK_LT(0, args.length()); - JS::RootedValue non_optional_value0( - context, args[0]); - FromJSValue(context, - non_optional_value0, - kNoConversionFlags, - &exception_state, &index); - if (exception_state.is_exception_set()) { - return false; - } - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->IndexedGetter(index), - &result_value); - } - if (!exception_state.is_exception_set()) { - args.rval().set(result_value); - } - return !exception_state.is_exception_set(); -} - -bool fcn_indexedSetter( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, &object)) { - NOTREACHED(); - return false; - } - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<IndexedGetterInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - IndexedGetterInterface* impl = - wrapper_private->wrappable<IndexedGetterInterface>().get(); - const size_t kMinArguments = 2; - if (args.length() < kMinArguments) { - exception_state.SetSimpleException(script::kInvalidNumberOfArguments); - return false; - } - // Non-optional arguments - TypeTraits<uint32_t >::ConversionType index; - TypeTraits<uint32_t >::ConversionType value; - - DCHECK_LT(0, args.length()); - JS::RootedValue non_optional_value0( - context, args[0]); - FromJSValue(context, - non_optional_value0, - kNoConversionFlags, - &exception_state, &index); - if (exception_state.is_exception_set()) { - return false; - } - - DCHECK_LT(1, args.length()); - JS::RootedValue non_optional_value1( - context, args[1]); - FromJSValue(context, - non_optional_value1, - kNoConversionFlags, - &exception_state, &value); - if (exception_state.is_exception_set()) { - return false; - } - - impl->IndexedSetter(index, value); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - - - -const JSPropertySpec prototype_properties[] = { - { // Readonly attribute - "length", - JSPROP_SHARED | JSPROP_ENUMERATE, - { { &get_length, NULL } }, - JSNATIVE_WRAPPER(NULL), - }, - JS_PS_END -}; - -const JSFunctionSpec prototype_functions[] = { - JS_FNSPEC( - "indexedDeleter", fcn_indexedDeleter, NULL, - 1, JSPROP_ENUMERATE, NULL), - JS_FNSPEC( - "indexedGetter", fcn_indexedGetter, NULL, - 1, JSPROP_ENUMERATE, NULL), - JS_FNSPEC( - "indexedSetter", fcn_indexedSetter, NULL, - 2, JSPROP_ENUMERATE, NULL), - JS_FS_END -}; - -const JSPropertySpec interface_object_properties[] = { - JS_PS_END -}; - -const JSFunctionSpec interface_object_functions[] = { - JS_FS_END -}; - -const JSPropertySpec own_properties[] = { - JS_PS_END -}; - -void InitializePrototypeAndInterfaceObject( - InterfaceData* interface_data, JSContext* context, - JS::HandleObject global_object) { - DCHECK(!interface_data->prototype); - DCHECK(!interface_data->interface_object); - DCHECK(JS_IsGlobalObject(global_object)); - - JS::RootedObject parent_prototype( - context, JS_GetObjectPrototype(context, global_object)); - DCHECK(parent_prototype); - - interface_data->prototype = JS_NewObjectWithGivenProto( - context, &prototype_class_definition, parent_prototype - ); - - JS::RootedObject rooted_prototype(context, interface_data->prototype); - bool success = JS_DefineProperties( - context, - rooted_prototype, - prototype_properties); - - DCHECK(success); - success = JS_DefineFunctions( - context, rooted_prototype, prototype_functions); - DCHECK(success); - - JS::RootedObject function_prototype( - context, JS_GetFunctionPrototype(context, global_object)); - DCHECK(function_prototype); - // Create the Interface object. - interface_data->interface_object = JS_NewObjectWithGivenProto( - context, &interface_object_class_definition, - function_prototype); - - // Add the InterfaceObject.name property. - JS::RootedObject rooted_interface_object( - context, interface_data->interface_object); - JS::RootedValue name_value(context); - const char name[] = - "IndexedGetterInterface"; - name_value.setString(JS_NewStringCopyZ(context, name)); - success = JS_DefineProperty( - context, rooted_interface_object, "name", name_value, JSPROP_READONLY, - NULL, NULL); - DCHECK(success); - - // Define interface object properties (including constants). - success = JS_DefineProperties(context, rooted_interface_object, - interface_object_properties); - DCHECK(success); - // Define interface object functions (static). - success = JS_DefineFunctions(context, rooted_interface_object, - interface_object_functions); - DCHECK(success); - - // Set the Prototype.constructor and Constructor.prototype properties. - DCHECK(interface_data->interface_object); - DCHECK(interface_data->prototype); - success = JS_LinkConstructorAndPrototype( - context, - rooted_interface_object, - rooted_prototype); - DCHECK(success); -} - -InterfaceData* GetInterfaceData(JSContext* context) { - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - // Use the address of the properties definition for this interface as a - // unique key for looking up the InterfaceData for this interface. - intptr_t key = reinterpret_cast<intptr_t>(&own_properties); - InterfaceData* interface_data = global_environment->GetInterfaceData(key); - if (!interface_data) { - interface_data = new InterfaceData(); - DCHECK(interface_data); - global_environment->CacheInterfaceData(key, interface_data); - DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key)); - } - return interface_data; -} - -} // namespace - -// static -JSObject* MozjsIndexedGetterInterface::CreateProxy( - JSContext* context, const scoped_refptr<Wrappable>& wrappable) { - DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); - JS::RootedObject global_object( - context, - MozjsGlobalEnvironment::GetFromContext(context)->global_object()); - DCHECK(global_object); - - InterfaceData* interface_data = GetInterfaceData(context); - JS::RootedObject prototype(context, GetPrototype(context, global_object)); - DCHECK(prototype); - JS::RootedObject new_object( - context, - JS_NewObjectWithGivenProto( - context, &instance_class_definition, prototype)); - DCHECK(new_object); - JS::RootedObject proxy(context, - ProxyHandler::NewProxy( - context, proxy_handler.Pointer(), new_object, prototype)); - WrapperPrivate::AddPrivateData(context, proxy, wrappable); - return proxy; -} - -// static -const JSClass* MozjsIndexedGetterInterface::PrototypeClass( - JSContext* context) { - DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); - JS::RootedObject global_object( - context, - MozjsGlobalEnvironment::GetFromContext(context)->global_object()); - DCHECK(global_object); - - JS::RootedObject prototype(context, GetPrototype(context, global_object)); - const JSClass* proto_class = JS_GetClass(prototype); - return proto_class; -} - -// static -JSObject* MozjsIndexedGetterInterface::GetPrototype( - JSContext* context, JS::HandleObject global_object) { - DCHECK(JS_IsGlobalObject(global_object)); - - InterfaceData* interface_data = GetInterfaceData(context); - if (!interface_data->prototype) { - // Create new prototype that has all the props and methods - InitializePrototypeAndInterfaceObject( - interface_data, context, global_object); - } - DCHECK(interface_data->prototype); - return interface_data->prototype; -} - -// static -JSObject* MozjsIndexedGetterInterface::GetInterfaceObject( - JSContext* context, JS::HandleObject global_object) { - DCHECK(JS_IsGlobalObject(global_object)); - - InterfaceData* interface_data = GetInterfaceData(context); - if (!interface_data->interface_object) { - InitializePrototypeAndInterfaceObject( - interface_data, context, global_object); - } - DCHECK(interface_data->interface_object); - return interface_data->interface_object; -} - - -namespace { -} // namespace - - -} // namespace testing -} // namespace bindings -} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsIndexedGetterInterface.h b/src/cobalt/bindings/generated/mozjs-45/testing/MozjsIndexedGetterInterface.h deleted file mode 100644 index a7a8e2b..0000000 --- a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsIndexedGetterInterface.h +++ /dev/null
@@ -1,54 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! -// Auto-generated from template: bindings/mozjs-45/templates/interface.h.template - -// clang-format off - -#ifndef MozjsIndexedGetterInterface_h -#define MozjsIndexedGetterInterface_h - -#include "base/hash_tables.h" -#include "base/lazy_instance.h" -#include "base/memory/ref_counted.h" -#include "base/threading/thread_checker.h" -#include "cobalt/base/polymorphic_downcast.h" -#include "cobalt/script/wrappable.h" -#include "cobalt/bindings/testing/indexed_getter_interface.h" - -#include "third_party/mozjs-45/js/src/jsapi.h" - -namespace cobalt { -namespace bindings { -namespace testing { - -class MozjsIndexedGetterInterface { - public: - static JSObject* CreateProxy(JSContext* context, - const scoped_refptr<script::Wrappable>& wrappable); - static const JSClass* PrototypeClass(JSContext* context); - static JSObject* GetPrototype(JSContext* context, - JS::HandleObject global_object); - static JSObject* GetInterfaceObject(JSContext* context, - JS::HandleObject global_object); -}; - -} // namespace bindings -} // namespace testing -} // namespace cobalt - -#endif // MozjsIndexedGetterInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsInterfaceWithUnsupportedProperties.cc b/src/cobalt/bindings/generated/mozjs-45/testing/MozjsInterfaceWithUnsupportedProperties.cc deleted file mode 100644 index f16faf8..0000000 --- a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsInterfaceWithUnsupportedProperties.cc +++ /dev/null
@@ -1,393 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! -// Auto-generated from template: bindings/mozjs-45/templates/interface.cc.template - -// clang-format off - -#include "MozjsInterfaceWithUnsupportedProperties.h" - -#include "base/debug/trace_event.h" -#include "cobalt/base/polymorphic_downcast.h" -#include "cobalt/script/global_environment.h" -#include "cobalt/script/opaque_handle.h" -#include "cobalt/script/script_object.h" - -#include "base/lazy_instance.h" -#include "cobalt/script/mozjs-45/callback_function_conversion.h" -#include "cobalt/script/exception_state.h" -#include "cobalt/script/mozjs-45/conversion_helpers.h" -#include "cobalt/script/mozjs-45/mozjs_exception_state.h" -#include "cobalt/script/mozjs-45/mozjs_callback_function.h" -#include "cobalt/script/mozjs-45/mozjs_global_environment.h" -#include "cobalt/script/mozjs-45/mozjs_object_handle.h" -#include "cobalt/script/mozjs-45/mozjs_property_enumerator.h" -#include "cobalt/script/mozjs-45/mozjs_user_object_holder.h" -#include "cobalt/script/mozjs-45/proxy_handler.h" -#include "cobalt/script/mozjs-45/type_traits.h" -#include "cobalt/script/mozjs-45/wrapper_factory.h" -#include "cobalt/script/mozjs-45/wrapper_private.h" -#include "cobalt/script/property_enumerator.h" -#include "third_party/mozjs-45/js/src/jsapi.h" -#include "third_party/mozjs-45/js/src/jsfriendapi.h" - -namespace { -using cobalt::bindings::testing::InterfaceWithUnsupportedProperties; -using cobalt::bindings::testing::MozjsInterfaceWithUnsupportedProperties; -using cobalt::script::CallbackInterfaceTraits; -using cobalt::script::GlobalEnvironment; -using cobalt::script::OpaqueHandle; -using cobalt::script::OpaqueHandleHolder; -using cobalt::script::ScriptObject; -using cobalt::script::Wrappable; - -using cobalt::script::CallbackFunction; -using cobalt::script::CallbackInterfaceTraits; -using cobalt::script::ExceptionState; -using cobalt::script::mozjs::FromJSValue; -using cobalt::script::mozjs::kConversionFlagNullable; -using cobalt::script::mozjs::kConversionFlagRestricted; -using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString; -using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString; -using cobalt::script::mozjs::kNoConversionFlags; -using cobalt::script::mozjs::InterfaceData; -using cobalt::script::mozjs::MozjsCallbackFunction; -using cobalt::script::mozjs::MozjsExceptionState; -using cobalt::script::mozjs::MozjsGlobalEnvironment; -using cobalt::script::mozjs::MozjsUserObjectHolder; -using cobalt::script::mozjs::MozjsPropertyEnumerator; -using cobalt::script::mozjs::ProxyHandler; -using cobalt::script::mozjs::ToJSValue; -using cobalt::script::mozjs::TypeTraits; -using cobalt::script::mozjs::WrapperPrivate; -using cobalt::script::mozjs::WrapperFactory; -using cobalt::script::Wrappable; -} // namespace - -namespace cobalt { -namespace bindings { -namespace testing { - -namespace { - -class MozjsInterfaceWithUnsupportedPropertiesHandler : public ProxyHandler { - public: - MozjsInterfaceWithUnsupportedPropertiesHandler() - : ProxyHandler(indexed_property_hooks, named_property_hooks) {} - - private: - static NamedPropertyHooks named_property_hooks; - static IndexedPropertyHooks indexed_property_hooks; -}; - -ProxyHandler::NamedPropertyHooks -MozjsInterfaceWithUnsupportedPropertiesHandler::named_property_hooks = { - NULL, - NULL, - NULL, - NULL, - NULL, -}; -ProxyHandler::IndexedPropertyHooks -MozjsInterfaceWithUnsupportedPropertiesHandler::indexed_property_hooks = { - NULL, - NULL, - NULL, - NULL, - NULL, -}; - -static base::LazyInstance<MozjsInterfaceWithUnsupportedPropertiesHandler> - proxy_handler; - -bool HasInstance(JSContext *context, JS::HandleObject type, - JS::MutableHandleValue vp, bool *success) { - JS::RootedObject global_object( - context, JS_GetGlobalForObject(context, type)); - DCHECK(global_object); - - JS::RootedObject prototype( - context, MozjsInterfaceWithUnsupportedProperties::GetPrototype(context, global_object)); - - // |IsDelegate| walks the prototype chain of an object returning true if - // .prototype is found. - bool is_delegate; - if (!IsDelegate(context, prototype, vp, &is_delegate)) { - *success = false; - return false; - } - - *success = is_delegate; - return true; -} - -const JSClass instance_class_definition = { - "InterfaceWithUnsupportedProperties", - 0 | JSCLASS_HAS_PRIVATE, - NULL, // addProperty - NULL, // delProperty - NULL, // getProperty - NULL, // setProperty - NULL, // enumerate - NULL, // resolve - NULL, // mayResolve - &WrapperPrivate::Finalizer, // finalize - NULL, // call - NULL, // hasInstance - NULL, // construct - &WrapperPrivate::Trace, // trace -}; - -const JSClass prototype_class_definition = { - "InterfaceWithUnsupportedPropertiesPrototype", -}; - -const JSClass interface_object_class_definition = { - "InterfaceWithUnsupportedPropertiesConstructor", - 0, - NULL, // addProperty - NULL, // delProperty - NULL, // getProperty - NULL, // setProperty - NULL, // enumerate - NULL, // resolve - NULL, // mayResolve - NULL, // finalize - NULL, // call - &HasInstance, - NULL, -}; - -bool get_supportedAttribute( - JSContext* context, unsigned argc, JS::Value* vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<InterfaceWithUnsupportedProperties>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - InterfaceWithUnsupportedProperties* impl = - wrapper_private->wrappable<InterfaceWithUnsupportedProperties>().get(); - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->supported_attribute(), - &result_value); - } - if (!exception_state.is_exception_set()) { - args.rval().set(result_value); - } - return !exception_state.is_exception_set(); -} - - - - -const JSPropertySpec prototype_properties[] = { - { // Readonly attribute - "supportedAttribute", - JSPROP_SHARED | JSPROP_ENUMERATE, - { { &get_supportedAttribute, NULL } }, - JSNATIVE_WRAPPER(NULL), - }, - JS_PS_END -}; - -const JSFunctionSpec prototype_functions[] = { - JS_FS_END -}; - -const JSPropertySpec interface_object_properties[] = { - JS_PS_END -}; - -const JSFunctionSpec interface_object_functions[] = { - JS_FS_END -}; - -const JSPropertySpec own_properties[] = { - JS_PS_END -}; - -void InitializePrototypeAndInterfaceObject( - InterfaceData* interface_data, JSContext* context, - JS::HandleObject global_object) { - DCHECK(!interface_data->prototype); - DCHECK(!interface_data->interface_object); - DCHECK(JS_IsGlobalObject(global_object)); - - JS::RootedObject parent_prototype( - context, JS_GetObjectPrototype(context, global_object)); - DCHECK(parent_prototype); - - interface_data->prototype = JS_NewObjectWithGivenProto( - context, &prototype_class_definition, parent_prototype - ); - - JS::RootedObject rooted_prototype(context, interface_data->prototype); - bool success = JS_DefineProperties( - context, - rooted_prototype, - prototype_properties); - - DCHECK(success); - success = JS_DefineFunctions( - context, rooted_prototype, prototype_functions); - DCHECK(success); - - JS::RootedObject function_prototype( - context, JS_GetFunctionPrototype(context, global_object)); - DCHECK(function_prototype); - // Create the Interface object. - interface_data->interface_object = JS_NewObjectWithGivenProto( - context, &interface_object_class_definition, - function_prototype); - - // Add the InterfaceObject.name property. - JS::RootedObject rooted_interface_object( - context, interface_data->interface_object); - JS::RootedValue name_value(context); - const char name[] = - "InterfaceWithUnsupportedProperties"; - name_value.setString(JS_NewStringCopyZ(context, name)); - success = JS_DefineProperty( - context, rooted_interface_object, "name", name_value, JSPROP_READONLY, - NULL, NULL); - DCHECK(success); - - // Define interface object properties (including constants). - success = JS_DefineProperties(context, rooted_interface_object, - interface_object_properties); - DCHECK(success); - // Define interface object functions (static). - success = JS_DefineFunctions(context, rooted_interface_object, - interface_object_functions); - DCHECK(success); - - // Set the Prototype.constructor and Constructor.prototype properties. - DCHECK(interface_data->interface_object); - DCHECK(interface_data->prototype); - success = JS_LinkConstructorAndPrototype( - context, - rooted_interface_object, - rooted_prototype); - DCHECK(success); -} - -InterfaceData* GetInterfaceData(JSContext* context) { - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - // Use the address of the properties definition for this interface as a - // unique key for looking up the InterfaceData for this interface. - intptr_t key = reinterpret_cast<intptr_t>(&own_properties); - InterfaceData* interface_data = global_environment->GetInterfaceData(key); - if (!interface_data) { - interface_data = new InterfaceData(); - DCHECK(interface_data); - global_environment->CacheInterfaceData(key, interface_data); - DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key)); - } - return interface_data; -} - -} // namespace - -// static -JSObject* MozjsInterfaceWithUnsupportedProperties::CreateProxy( - JSContext* context, const scoped_refptr<Wrappable>& wrappable) { - DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); - JS::RootedObject global_object( - context, - MozjsGlobalEnvironment::GetFromContext(context)->global_object()); - DCHECK(global_object); - - InterfaceData* interface_data = GetInterfaceData(context); - JS::RootedObject prototype(context, GetPrototype(context, global_object)); - DCHECK(prototype); - JS::RootedObject new_object( - context, - JS_NewObjectWithGivenProto( - context, &instance_class_definition, prototype)); - DCHECK(new_object); - JS::RootedObject proxy(context, - ProxyHandler::NewProxy( - context, proxy_handler.Pointer(), new_object, prototype)); - WrapperPrivate::AddPrivateData(context, proxy, wrappable); - return proxy; -} - -// static -const JSClass* MozjsInterfaceWithUnsupportedProperties::PrototypeClass( - JSContext* context) { - DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); - JS::RootedObject global_object( - context, - MozjsGlobalEnvironment::GetFromContext(context)->global_object()); - DCHECK(global_object); - - JS::RootedObject prototype(context, GetPrototype(context, global_object)); - const JSClass* proto_class = JS_GetClass(prototype); - return proto_class; -} - -// static -JSObject* MozjsInterfaceWithUnsupportedProperties::GetPrototype( - JSContext* context, JS::HandleObject global_object) { - DCHECK(JS_IsGlobalObject(global_object)); - - InterfaceData* interface_data = GetInterfaceData(context); - if (!interface_data->prototype) { - // Create new prototype that has all the props and methods - InitializePrototypeAndInterfaceObject( - interface_data, context, global_object); - } - DCHECK(interface_data->prototype); - return interface_data->prototype; -} - -// static -JSObject* MozjsInterfaceWithUnsupportedProperties::GetInterfaceObject( - JSContext* context, JS::HandleObject global_object) { - DCHECK(JS_IsGlobalObject(global_object)); - - InterfaceData* interface_data = GetInterfaceData(context); - if (!interface_data->interface_object) { - InitializePrototypeAndInterfaceObject( - interface_data, context, global_object); - } - DCHECK(interface_data->interface_object); - return interface_data->interface_object; -} - - -namespace { -} // namespace - - -} // namespace testing -} // namespace bindings -} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsInterfaceWithUnsupportedProperties.h b/src/cobalt/bindings/generated/mozjs-45/testing/MozjsInterfaceWithUnsupportedProperties.h deleted file mode 100644 index bb3c59b..0000000 --- a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsInterfaceWithUnsupportedProperties.h +++ /dev/null
@@ -1,54 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! -// Auto-generated from template: bindings/mozjs-45/templates/interface.h.template - -// clang-format off - -#ifndef MozjsInterfaceWithUnsupportedProperties_h -#define MozjsInterfaceWithUnsupportedProperties_h - -#include "base/hash_tables.h" -#include "base/lazy_instance.h" -#include "base/memory/ref_counted.h" -#include "base/threading/thread_checker.h" -#include "cobalt/base/polymorphic_downcast.h" -#include "cobalt/script/wrappable.h" -#include "cobalt/bindings/testing/interface_with_unsupported_properties.h" - -#include "third_party/mozjs-45/js/src/jsapi.h" - -namespace cobalt { -namespace bindings { -namespace testing { - -class MozjsInterfaceWithUnsupportedProperties { - public: - static JSObject* CreateProxy(JSContext* context, - const scoped_refptr<script::Wrappable>& wrappable); - static const JSClass* PrototypeClass(JSContext* context); - static JSObject* GetPrototype(JSContext* context, - JS::HandleObject global_object); - static JSObject* GetInterfaceObject(JSContext* context, - JS::HandleObject global_object); -}; - -} // namespace bindings -} // namespace testing -} // namespace cobalt - -#endif // MozjsInterfaceWithUnsupportedProperties_h
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsNamedConstructorInterface.cc b/src/cobalt/bindings/generated/mozjs-45/testing/MozjsNamedConstructorInterface.cc deleted file mode 100644 index d965074..0000000 --- a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsNamedConstructorInterface.cc +++ /dev/null
@@ -1,376 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! -// Auto-generated from template: bindings/mozjs-45/templates/interface.cc.template - -// clang-format off - -#include "MozjsNamedConstructorInterface.h" - -#include "base/debug/trace_event.h" -#include "cobalt/base/polymorphic_downcast.h" -#include "cobalt/script/global_environment.h" -#include "cobalt/script/opaque_handle.h" -#include "cobalt/script/script_object.h" - -#include "base/lazy_instance.h" -#include "cobalt/script/mozjs-45/callback_function_conversion.h" -#include "cobalt/script/exception_state.h" -#include "cobalt/script/mozjs-45/conversion_helpers.h" -#include "cobalt/script/mozjs-45/mozjs_exception_state.h" -#include "cobalt/script/mozjs-45/mozjs_callback_function.h" -#include "cobalt/script/mozjs-45/mozjs_global_environment.h" -#include "cobalt/script/mozjs-45/mozjs_object_handle.h" -#include "cobalt/script/mozjs-45/mozjs_property_enumerator.h" -#include "cobalt/script/mozjs-45/mozjs_user_object_holder.h" -#include "cobalt/script/mozjs-45/proxy_handler.h" -#include "cobalt/script/mozjs-45/type_traits.h" -#include "cobalt/script/mozjs-45/wrapper_factory.h" -#include "cobalt/script/mozjs-45/wrapper_private.h" -#include "cobalt/script/property_enumerator.h" -#include "third_party/mozjs-45/js/src/jsapi.h" -#include "third_party/mozjs-45/js/src/jsfriendapi.h" - -namespace { -using cobalt::bindings::testing::NamedConstructorInterface; -using cobalt::bindings::testing::MozjsNamedConstructorInterface; -using cobalt::script::CallbackInterfaceTraits; -using cobalt::script::GlobalEnvironment; -using cobalt::script::OpaqueHandle; -using cobalt::script::OpaqueHandleHolder; -using cobalt::script::ScriptObject; -using cobalt::script::Wrappable; - -using cobalt::script::CallbackFunction; -using cobalt::script::CallbackInterfaceTraits; -using cobalt::script::ExceptionState; -using cobalt::script::mozjs::FromJSValue; -using cobalt::script::mozjs::kConversionFlagNullable; -using cobalt::script::mozjs::kConversionFlagRestricted; -using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString; -using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString; -using cobalt::script::mozjs::kNoConversionFlags; -using cobalt::script::mozjs::InterfaceData; -using cobalt::script::mozjs::MozjsCallbackFunction; -using cobalt::script::mozjs::MozjsExceptionState; -using cobalt::script::mozjs::MozjsGlobalEnvironment; -using cobalt::script::mozjs::MozjsUserObjectHolder; -using cobalt::script::mozjs::MozjsPropertyEnumerator; -using cobalt::script::mozjs::ProxyHandler; -using cobalt::script::mozjs::ToJSValue; -using cobalt::script::mozjs::TypeTraits; -using cobalt::script::mozjs::WrapperPrivate; -using cobalt::script::mozjs::WrapperFactory; -using cobalt::script::Wrappable; -} // namespace - -namespace cobalt { -namespace bindings { -namespace testing { - -namespace { - -class MozjsNamedConstructorInterfaceHandler : public ProxyHandler { - public: - MozjsNamedConstructorInterfaceHandler() - : ProxyHandler(indexed_property_hooks, named_property_hooks) {} - - private: - static NamedPropertyHooks named_property_hooks; - static IndexedPropertyHooks indexed_property_hooks; -}; - -ProxyHandler::NamedPropertyHooks -MozjsNamedConstructorInterfaceHandler::named_property_hooks = { - NULL, - NULL, - NULL, - NULL, - NULL, -}; -ProxyHandler::IndexedPropertyHooks -MozjsNamedConstructorInterfaceHandler::indexed_property_hooks = { - NULL, - NULL, - NULL, - NULL, - NULL, -}; - -static base::LazyInstance<MozjsNamedConstructorInterfaceHandler> - proxy_handler; - -bool Constructor(JSContext* context, unsigned int argc, JS::Value* vp); -bool HasInstance(JSContext *context, JS::HandleObject type, - JS::MutableHandleValue vp, bool *success) { - JS::RootedObject global_object( - context, JS_GetGlobalForObject(context, type)); - DCHECK(global_object); - - JS::RootedObject prototype( - context, MozjsNamedConstructorInterface::GetPrototype(context, global_object)); - - // |IsDelegate| walks the prototype chain of an object returning true if - // .prototype is found. - bool is_delegate; - if (!IsDelegate(context, prototype, vp, &is_delegate)) { - *success = false; - return false; - } - - *success = is_delegate; - return true; -} - -const JSClass instance_class_definition = { - "NamedConstructorInterface", - 0 | JSCLASS_HAS_PRIVATE, - NULL, // addProperty - NULL, // delProperty - NULL, // getProperty - NULL, // setProperty - NULL, // enumerate - NULL, // resolve - NULL, // mayResolve - &WrapperPrivate::Finalizer, // finalize - NULL, // call - NULL, // hasInstance - NULL, // construct - &WrapperPrivate::Trace, // trace -}; - -const JSClass prototype_class_definition = { - "NamedConstructorInterfacePrototype", -}; - -const JSClass interface_object_class_definition = { - "NamedConstructorInterfaceConstructor", - 0, - NULL, // addProperty - NULL, // delProperty - NULL, // getProperty - NULL, // setProperty - NULL, // enumerate - NULL, // resolve - NULL, // mayResolve - NULL, // finalize - NULL, // call - &HasInstance, - Constructor, -}; - - - -const JSPropertySpec prototype_properties[] = { - JS_PS_END -}; - -const JSFunctionSpec prototype_functions[] = { - JS_FS_END -}; - -const JSPropertySpec interface_object_properties[] = { - JS_PS_END -}; - -const JSFunctionSpec interface_object_functions[] = { - JS_FS_END -}; - -const JSPropertySpec own_properties[] = { - JS_PS_END -}; - -void InitializePrototypeAndInterfaceObject( - InterfaceData* interface_data, JSContext* context, - JS::HandleObject global_object) { - DCHECK(!interface_data->prototype); - DCHECK(!interface_data->interface_object); - DCHECK(JS_IsGlobalObject(global_object)); - - JS::RootedObject parent_prototype( - context, JS_GetObjectPrototype(context, global_object)); - DCHECK(parent_prototype); - - interface_data->prototype = JS_NewObjectWithGivenProto( - context, &prototype_class_definition, parent_prototype - ); - - JS::RootedObject rooted_prototype(context, interface_data->prototype); - bool success = JS_DefineProperties( - context, - rooted_prototype, - prototype_properties); - - DCHECK(success); - success = JS_DefineFunctions( - context, rooted_prototype, prototype_functions); - DCHECK(success); - - JS::RootedObject function_prototype( - context, JS_GetFunctionPrototype(context, global_object)); - DCHECK(function_prototype); - // Create the Interface object. - interface_data->interface_object = JS_NewObjectWithGivenProto( - context, &interface_object_class_definition, - function_prototype); - - // Add the InterfaceObject.name property. - JS::RootedObject rooted_interface_object( - context, interface_data->interface_object); - JS::RootedValue name_value(context); - const char name[] = - "SomeNamedConstructor"; - name_value.setString(JS_NewStringCopyZ(context, name)); - success = JS_DefineProperty( - context, rooted_interface_object, "name", name_value, JSPROP_READONLY, - NULL, NULL); - DCHECK(success); - - // Add the InterfaceObject.length property. It is set to the length of the - // shortest argument list of all overload constructors. - JS::RootedValue length_value(context); - length_value.setInt32(0); - success = JS_DefineProperty( - context, rooted_interface_object, "length", length_value, - JSPROP_READONLY, NULL, NULL); - DCHECK(success); - - // Define interface object properties (including constants). - success = JS_DefineProperties(context, rooted_interface_object, - interface_object_properties); - DCHECK(success); - // Define interface object functions (static). - success = JS_DefineFunctions(context, rooted_interface_object, - interface_object_functions); - DCHECK(success); - - // Set the Prototype.constructor and Constructor.prototype properties. - DCHECK(interface_data->interface_object); - DCHECK(interface_data->prototype); - success = JS_LinkConstructorAndPrototype( - context, - rooted_interface_object, - rooted_prototype); - DCHECK(success); -} - -InterfaceData* GetInterfaceData(JSContext* context) { - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - // Use the address of the properties definition for this interface as a - // unique key for looking up the InterfaceData for this interface. - intptr_t key = reinterpret_cast<intptr_t>(&own_properties); - InterfaceData* interface_data = global_environment->GetInterfaceData(key); - if (!interface_data) { - interface_data = new InterfaceData(); - DCHECK(interface_data); - global_environment->CacheInterfaceData(key, interface_data); - DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key)); - } - return interface_data; -} - -} // namespace - -// static -JSObject* MozjsNamedConstructorInterface::CreateProxy( - JSContext* context, const scoped_refptr<Wrappable>& wrappable) { - DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); - JS::RootedObject global_object( - context, - MozjsGlobalEnvironment::GetFromContext(context)->global_object()); - DCHECK(global_object); - - InterfaceData* interface_data = GetInterfaceData(context); - JS::RootedObject prototype(context, GetPrototype(context, global_object)); - DCHECK(prototype); - JS::RootedObject new_object( - context, - JS_NewObjectWithGivenProto( - context, &instance_class_definition, prototype)); - DCHECK(new_object); - JS::RootedObject proxy(context, - ProxyHandler::NewProxy( - context, proxy_handler.Pointer(), new_object, prototype)); - WrapperPrivate::AddPrivateData(context, proxy, wrappable); - return proxy; -} - -// static -const JSClass* MozjsNamedConstructorInterface::PrototypeClass( - JSContext* context) { - DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); - JS::RootedObject global_object( - context, - MozjsGlobalEnvironment::GetFromContext(context)->global_object()); - DCHECK(global_object); - - JS::RootedObject prototype(context, GetPrototype(context, global_object)); - const JSClass* proto_class = JS_GetClass(prototype); - return proto_class; -} - -// static -JSObject* MozjsNamedConstructorInterface::GetPrototype( - JSContext* context, JS::HandleObject global_object) { - DCHECK(JS_IsGlobalObject(global_object)); - - InterfaceData* interface_data = GetInterfaceData(context); - if (!interface_data->prototype) { - // Create new prototype that has all the props and methods - InitializePrototypeAndInterfaceObject( - interface_data, context, global_object); - } - DCHECK(interface_data->prototype); - return interface_data->prototype; -} - -// static -JSObject* MozjsNamedConstructorInterface::GetInterfaceObject( - JSContext* context, JS::HandleObject global_object) { - DCHECK(JS_IsGlobalObject(global_object)); - - InterfaceData* interface_data = GetInterfaceData(context); - if (!interface_data->interface_object) { - InitializePrototypeAndInterfaceObject( - interface_data, context, global_object); - } - DCHECK(interface_data->interface_object); - return interface_data->interface_object; -} - - -namespace { -bool Constructor(JSContext* context, unsigned int argc, JS::Value* vp) { - MozjsExceptionState exception_state(context); - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - - scoped_refptr<NamedConstructorInterface> new_object = - new NamedConstructorInterface(); - JS::RootedValue result_value(context); - ToJSValue(context, new_object, &result_value); - DCHECK(result_value.isObject()); - args.rval().setObject(result_value.toObject()); - return true; -} -} // namespace - - -} // namespace testing -} // namespace bindings -} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsNamedConstructorInterface.h b/src/cobalt/bindings/generated/mozjs-45/testing/MozjsNamedConstructorInterface.h deleted file mode 100644 index 8d88534..0000000 --- a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsNamedConstructorInterface.h +++ /dev/null
@@ -1,54 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! -// Auto-generated from template: bindings/mozjs-45/templates/interface.h.template - -// clang-format off - -#ifndef MozjsNamedConstructorInterface_h -#define MozjsNamedConstructorInterface_h - -#include "base/hash_tables.h" -#include "base/lazy_instance.h" -#include "base/memory/ref_counted.h" -#include "base/threading/thread_checker.h" -#include "cobalt/base/polymorphic_downcast.h" -#include "cobalt/script/wrappable.h" -#include "cobalt/bindings/testing/named_constructor_interface.h" - -#include "third_party/mozjs-45/js/src/jsapi.h" - -namespace cobalt { -namespace bindings { -namespace testing { - -class MozjsNamedConstructorInterface { - public: - static JSObject* CreateProxy(JSContext* context, - const scoped_refptr<script::Wrappable>& wrappable); - static const JSClass* PrototypeClass(JSContext* context); - static JSObject* GetPrototype(JSContext* context, - JS::HandleObject global_object); - static JSObject* GetInterfaceObject(JSContext* context, - JS::HandleObject global_object); -}; - -} // namespace bindings -} // namespace testing -} // namespace cobalt - -#endif // MozjsNamedConstructorInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsNamedGetterInterface.cc b/src/cobalt/bindings/generated/mozjs-45/testing/MozjsNamedGetterInterface.cc deleted file mode 100644 index 9d8decf..0000000 --- a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsNamedGetterInterface.cc +++ /dev/null
@@ -1,659 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! -// Auto-generated from template: bindings/mozjs-45/templates/interface.cc.template - -// clang-format off - -#include "MozjsNamedGetterInterface.h" - -#include "base/debug/trace_event.h" -#include "cobalt/base/polymorphic_downcast.h" -#include "cobalt/script/global_environment.h" -#include "cobalt/script/opaque_handle.h" -#include "cobalt/script/script_object.h" - -#include "base/lazy_instance.h" -#include "cobalt/script/mozjs-45/callback_function_conversion.h" -#include "cobalt/script/exception_state.h" -#include "cobalt/script/mozjs-45/conversion_helpers.h" -#include "cobalt/script/mozjs-45/mozjs_exception_state.h" -#include "cobalt/script/mozjs-45/mozjs_callback_function.h" -#include "cobalt/script/mozjs-45/mozjs_global_environment.h" -#include "cobalt/script/mozjs-45/mozjs_object_handle.h" -#include "cobalt/script/mozjs-45/mozjs_property_enumerator.h" -#include "cobalt/script/mozjs-45/mozjs_user_object_holder.h" -#include "cobalt/script/mozjs-45/proxy_handler.h" -#include "cobalt/script/mozjs-45/type_traits.h" -#include "cobalt/script/mozjs-45/wrapper_factory.h" -#include "cobalt/script/mozjs-45/wrapper_private.h" -#include "cobalt/script/property_enumerator.h" -#include "third_party/mozjs-45/js/src/jsapi.h" -#include "third_party/mozjs-45/js/src/jsfriendapi.h" - -namespace { -using cobalt::bindings::testing::NamedGetterInterface; -using cobalt::bindings::testing::MozjsNamedGetterInterface; -using cobalt::script::CallbackInterfaceTraits; -using cobalt::script::GlobalEnvironment; -using cobalt::script::OpaqueHandle; -using cobalt::script::OpaqueHandleHolder; -using cobalt::script::ScriptObject; -using cobalt::script::Wrappable; - -using cobalt::script::CallbackFunction; -using cobalt::script::CallbackInterfaceTraits; -using cobalt::script::ExceptionState; -using cobalt::script::mozjs::FromJSValue; -using cobalt::script::mozjs::kConversionFlagNullable; -using cobalt::script::mozjs::kConversionFlagRestricted; -using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString; -using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString; -using cobalt::script::mozjs::kNoConversionFlags; -using cobalt::script::mozjs::InterfaceData; -using cobalt::script::mozjs::MozjsCallbackFunction; -using cobalt::script::mozjs::MozjsExceptionState; -using cobalt::script::mozjs::MozjsGlobalEnvironment; -using cobalt::script::mozjs::MozjsUserObjectHolder; -using cobalt::script::mozjs::MozjsPropertyEnumerator; -using cobalt::script::mozjs::ProxyHandler; -using cobalt::script::mozjs::ToJSValue; -using cobalt::script::mozjs::TypeTraits; -using cobalt::script::mozjs::WrapperPrivate; -using cobalt::script::mozjs::WrapperFactory; -using cobalt::script::Wrappable; -} // namespace - -namespace cobalt { -namespace bindings { -namespace testing { - -namespace { - -bool IsSupportedNamedProperty(JSContext* context, JS::HandleObject object, - const std::string& property_name) { - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - NamedGetterInterface* impl = - wrapper_private->wrappable<NamedGetterInterface>().get(); - return impl->CanQueryNamedProperty(property_name); -} - -void EnumerateSupportedNames(JSContext* context, JS::HandleObject object, - JS::AutoIdVector* properties) { - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - NamedGetterInterface* impl = - wrapper_private->wrappable<NamedGetterInterface>().get(); - MozjsPropertyEnumerator enumerator(context, properties); - impl->EnumerateNamedProperties(&enumerator); -} - -bool GetNamedProperty( - JSContext* context, JS::HandleObject object, JS::HandleId id, - JS::MutableHandleValue vp) { - JS::RootedValue id_value(context); - if (!JS_IdToValue(context, id, &id_value)) { - NOTREACHED(); - return false; - } - - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - NamedGetterInterface* impl = - wrapper_private->wrappable<NamedGetterInterface>().get(); - std::string property_name; - FromJSValue(context, id_value, kNoConversionFlags, &exception_state, - &property_name); - if (exception_state.is_exception_set()) { - // The ID should be an integer or a string, so we shouldn't have any - // exceptions converting to string. - NOTREACHED(); - return false; - } - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->NamedGetter(property_name), - &result_value); - } - if (!exception_state.is_exception_set()) { - vp.set(result_value); - } - return !exception_state.is_exception_set(); - -} - -bool SetNamedProperty( - JSContext* context, JS::HandleObject object, JS::HandleId id, - JS::MutableHandleValue vp, JS::ObjectOpResult& object_op_result) { - JS::RootedValue id_value(context); - if (!JS_IdToValue(context, id, &id_value)) { - NOTREACHED(); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - NamedGetterInterface* impl = - wrapper_private->wrappable<NamedGetterInterface>().get(); - std::string property_name; - FromJSValue(context, id_value, kNoConversionFlags, &exception_state, - &property_name); - if (exception_state.is_exception_set()) { - // The ID should be an integer or a string, so we shouldn't have any - // exceptions converting to string. - NOTREACHED(); - return false; - } - TypeTraits<std::string >::ConversionType value; - FromJSValue(context, vp, kNoConversionFlags, - &exception_state, &value); - if (exception_state.is_exception_set()) { - return false; - } - - impl->NamedSetter(property_name, value); - result_value.set(JS::UndefinedHandleValue); - - if (!exception_state.is_exception_set()) { - return object_op_result.succeed(); - } else { - return false; - } -} - -bool DeleteNamedProperty(JSContext* context, JS::HandleObject object, - const std::string& property_name) { - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - NamedGetterInterface* impl = - wrapper_private->wrappable<NamedGetterInterface>().get(); - - impl->NamedDeleter(property_name); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - -class MozjsNamedGetterInterfaceHandler : public ProxyHandler { - public: - MozjsNamedGetterInterfaceHandler() - : ProxyHandler(indexed_property_hooks, named_property_hooks) {} - - private: - static NamedPropertyHooks named_property_hooks; - static IndexedPropertyHooks indexed_property_hooks; -}; - -ProxyHandler::NamedPropertyHooks -MozjsNamedGetterInterfaceHandler::named_property_hooks = { - IsSupportedNamedProperty, - EnumerateSupportedNames, - GetNamedProperty, - SetNamedProperty, - DeleteNamedProperty, -}; -ProxyHandler::IndexedPropertyHooks -MozjsNamedGetterInterfaceHandler::indexed_property_hooks = { - NULL, - NULL, - NULL, - NULL, - NULL, -}; - -static base::LazyInstance<MozjsNamedGetterInterfaceHandler> - proxy_handler; - -bool HasInstance(JSContext *context, JS::HandleObject type, - JS::MutableHandleValue vp, bool *success) { - JS::RootedObject global_object( - context, JS_GetGlobalForObject(context, type)); - DCHECK(global_object); - - JS::RootedObject prototype( - context, MozjsNamedGetterInterface::GetPrototype(context, global_object)); - - // |IsDelegate| walks the prototype chain of an object returning true if - // .prototype is found. - bool is_delegate; - if (!IsDelegate(context, prototype, vp, &is_delegate)) { - *success = false; - return false; - } - - *success = is_delegate; - return true; -} - -const JSClass instance_class_definition = { - "NamedGetterInterface", - 0 | JSCLASS_HAS_PRIVATE, - NULL, // addProperty - NULL, // delProperty - NULL, // getProperty - NULL, // setProperty - NULL, // enumerate - NULL, // resolve - NULL, // mayResolve - &WrapperPrivate::Finalizer, // finalize - NULL, // call - NULL, // hasInstance - NULL, // construct - &WrapperPrivate::Trace, // trace -}; - -const JSClass prototype_class_definition = { - "NamedGetterInterfacePrototype", -}; - -const JSClass interface_object_class_definition = { - "NamedGetterInterfaceConstructor", - 0, - NULL, // addProperty - NULL, // delProperty - NULL, // getProperty - NULL, // setProperty - NULL, // enumerate - NULL, // resolve - NULL, // mayResolve - NULL, // finalize - NULL, // call - &HasInstance, - NULL, -}; - -bool fcn_namedDeleter( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, &object)) { - NOTREACHED(); - return false; - } - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<NamedGetterInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - NamedGetterInterface* impl = - wrapper_private->wrappable<NamedGetterInterface>().get(); - const size_t kMinArguments = 1; - if (args.length() < kMinArguments) { - exception_state.SetSimpleException(script::kInvalidNumberOfArguments); - return false; - } - // Non-optional arguments - TypeTraits<std::string >::ConversionType name; - - DCHECK_LT(0, args.length()); - JS::RootedValue non_optional_value0( - context, args[0]); - FromJSValue(context, - non_optional_value0, - kNoConversionFlags, - &exception_state, &name); - if (exception_state.is_exception_set()) { - return false; - } - - impl->NamedDeleter(name); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - -bool fcn_namedGetter( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, &object)) { - NOTREACHED(); - return false; - } - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<NamedGetterInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - NamedGetterInterface* impl = - wrapper_private->wrappable<NamedGetterInterface>().get(); - const size_t kMinArguments = 1; - if (args.length() < kMinArguments) { - exception_state.SetSimpleException(script::kInvalidNumberOfArguments); - return false; - } - // Non-optional arguments - TypeTraits<std::string >::ConversionType name; - - DCHECK_LT(0, args.length()); - JS::RootedValue non_optional_value0( - context, args[0]); - FromJSValue(context, - non_optional_value0, - kNoConversionFlags, - &exception_state, &name); - if (exception_state.is_exception_set()) { - return false; - } - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->NamedGetter(name), - &result_value); - } - if (!exception_state.is_exception_set()) { - args.rval().set(result_value); - } - return !exception_state.is_exception_set(); -} - -bool fcn_namedSetter( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, &object)) { - NOTREACHED(); - return false; - } - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<NamedGetterInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - NamedGetterInterface* impl = - wrapper_private->wrappable<NamedGetterInterface>().get(); - const size_t kMinArguments = 2; - if (args.length() < kMinArguments) { - exception_state.SetSimpleException(script::kInvalidNumberOfArguments); - return false; - } - // Non-optional arguments - TypeTraits<std::string >::ConversionType name; - TypeTraits<std::string >::ConversionType value; - - DCHECK_LT(0, args.length()); - JS::RootedValue non_optional_value0( - context, args[0]); - FromJSValue(context, - non_optional_value0, - kNoConversionFlags, - &exception_state, &name); - if (exception_state.is_exception_set()) { - return false; - } - - DCHECK_LT(1, args.length()); - JS::RootedValue non_optional_value1( - context, args[1]); - FromJSValue(context, - non_optional_value1, - kNoConversionFlags, - &exception_state, &value); - if (exception_state.is_exception_set()) { - return false; - } - - impl->NamedSetter(name, value); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - - - -const JSPropertySpec prototype_properties[] = { - JS_PS_END -}; - -const JSFunctionSpec prototype_functions[] = { - JS_FNSPEC( - "namedDeleter", fcn_namedDeleter, NULL, - 1, JSPROP_ENUMERATE, NULL), - JS_FNSPEC( - "namedGetter", fcn_namedGetter, NULL, - 1, JSPROP_ENUMERATE, NULL), - JS_FNSPEC( - "namedSetter", fcn_namedSetter, NULL, - 2, JSPROP_ENUMERATE, NULL), - JS_FS_END -}; - -const JSPropertySpec interface_object_properties[] = { - JS_PS_END -}; - -const JSFunctionSpec interface_object_functions[] = { - JS_FS_END -}; - -const JSPropertySpec own_properties[] = { - JS_PS_END -}; - -void InitializePrototypeAndInterfaceObject( - InterfaceData* interface_data, JSContext* context, - JS::HandleObject global_object) { - DCHECK(!interface_data->prototype); - DCHECK(!interface_data->interface_object); - DCHECK(JS_IsGlobalObject(global_object)); - - JS::RootedObject parent_prototype( - context, JS_GetObjectPrototype(context, global_object)); - DCHECK(parent_prototype); - - interface_data->prototype = JS_NewObjectWithGivenProto( - context, &prototype_class_definition, parent_prototype - ); - - JS::RootedObject rooted_prototype(context, interface_data->prototype); - bool success = JS_DefineProperties( - context, - rooted_prototype, - prototype_properties); - - DCHECK(success); - success = JS_DefineFunctions( - context, rooted_prototype, prototype_functions); - DCHECK(success); - - JS::RootedObject function_prototype( - context, JS_GetFunctionPrototype(context, global_object)); - DCHECK(function_prototype); - // Create the Interface object. - interface_data->interface_object = JS_NewObjectWithGivenProto( - context, &interface_object_class_definition, - function_prototype); - - // Add the InterfaceObject.name property. - JS::RootedObject rooted_interface_object( - context, interface_data->interface_object); - JS::RootedValue name_value(context); - const char name[] = - "NamedGetterInterface"; - name_value.setString(JS_NewStringCopyZ(context, name)); - success = JS_DefineProperty( - context, rooted_interface_object, "name", name_value, JSPROP_READONLY, - NULL, NULL); - DCHECK(success); - - // Define interface object properties (including constants). - success = JS_DefineProperties(context, rooted_interface_object, - interface_object_properties); - DCHECK(success); - // Define interface object functions (static). - success = JS_DefineFunctions(context, rooted_interface_object, - interface_object_functions); - DCHECK(success); - - // Set the Prototype.constructor and Constructor.prototype properties. - DCHECK(interface_data->interface_object); - DCHECK(interface_data->prototype); - success = JS_LinkConstructorAndPrototype( - context, - rooted_interface_object, - rooted_prototype); - DCHECK(success); -} - -InterfaceData* GetInterfaceData(JSContext* context) { - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - // Use the address of the properties definition for this interface as a - // unique key for looking up the InterfaceData for this interface. - intptr_t key = reinterpret_cast<intptr_t>(&own_properties); - InterfaceData* interface_data = global_environment->GetInterfaceData(key); - if (!interface_data) { - interface_data = new InterfaceData(); - DCHECK(interface_data); - global_environment->CacheInterfaceData(key, interface_data); - DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key)); - } - return interface_data; -} - -} // namespace - -// static -JSObject* MozjsNamedGetterInterface::CreateProxy( - JSContext* context, const scoped_refptr<Wrappable>& wrappable) { - DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); - JS::RootedObject global_object( - context, - MozjsGlobalEnvironment::GetFromContext(context)->global_object()); - DCHECK(global_object); - - InterfaceData* interface_data = GetInterfaceData(context); - JS::RootedObject prototype(context, GetPrototype(context, global_object)); - DCHECK(prototype); - JS::RootedObject new_object( - context, - JS_NewObjectWithGivenProto( - context, &instance_class_definition, prototype)); - DCHECK(new_object); - JS::RootedObject proxy(context, - ProxyHandler::NewProxy( - context, proxy_handler.Pointer(), new_object, prototype)); - WrapperPrivate::AddPrivateData(context, proxy, wrappable); - return proxy; -} - -// static -const JSClass* MozjsNamedGetterInterface::PrototypeClass( - JSContext* context) { - DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); - JS::RootedObject global_object( - context, - MozjsGlobalEnvironment::GetFromContext(context)->global_object()); - DCHECK(global_object); - - JS::RootedObject prototype(context, GetPrototype(context, global_object)); - const JSClass* proto_class = JS_GetClass(prototype); - return proto_class; -} - -// static -JSObject* MozjsNamedGetterInterface::GetPrototype( - JSContext* context, JS::HandleObject global_object) { - DCHECK(JS_IsGlobalObject(global_object)); - - InterfaceData* interface_data = GetInterfaceData(context); - if (!interface_data->prototype) { - // Create new prototype that has all the props and methods - InitializePrototypeAndInterfaceObject( - interface_data, context, global_object); - } - DCHECK(interface_data->prototype); - return interface_data->prototype; -} - -// static -JSObject* MozjsNamedGetterInterface::GetInterfaceObject( - JSContext* context, JS::HandleObject global_object) { - DCHECK(JS_IsGlobalObject(global_object)); - - InterfaceData* interface_data = GetInterfaceData(context); - if (!interface_data->interface_object) { - InitializePrototypeAndInterfaceObject( - interface_data, context, global_object); - } - DCHECK(interface_data->interface_object); - return interface_data->interface_object; -} - - -namespace { -} // namespace - - -} // namespace testing -} // namespace bindings -} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsNamedGetterInterface.h b/src/cobalt/bindings/generated/mozjs-45/testing/MozjsNamedGetterInterface.h deleted file mode 100644 index 5c1f234..0000000 --- a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsNamedGetterInterface.h +++ /dev/null
@@ -1,54 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! -// Auto-generated from template: bindings/mozjs-45/templates/interface.h.template - -// clang-format off - -#ifndef MozjsNamedGetterInterface_h -#define MozjsNamedGetterInterface_h - -#include "base/hash_tables.h" -#include "base/lazy_instance.h" -#include "base/memory/ref_counted.h" -#include "base/threading/thread_checker.h" -#include "cobalt/base/polymorphic_downcast.h" -#include "cobalt/script/wrappable.h" -#include "cobalt/bindings/testing/named_getter_interface.h" - -#include "third_party/mozjs-45/js/src/jsapi.h" - -namespace cobalt { -namespace bindings { -namespace testing { - -class MozjsNamedGetterInterface { - public: - static JSObject* CreateProxy(JSContext* context, - const scoped_refptr<script::Wrappable>& wrappable); - static const JSClass* PrototypeClass(JSContext* context); - static JSObject* GetPrototype(JSContext* context, - JS::HandleObject global_object); - static JSObject* GetInterfaceObject(JSContext* context, - JS::HandleObject global_object); -}; - -} // namespace bindings -} // namespace testing -} // namespace cobalt - -#endif // MozjsNamedGetterInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsNamedIndexedGetterInterface.cc b/src/cobalt/bindings/generated/mozjs-45/testing/MozjsNamedIndexedGetterInterface.cc deleted file mode 100644 index 8d56941..0000000 --- a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsNamedIndexedGetterInterface.cc +++ /dev/null
@@ -1,970 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! -// Auto-generated from template: bindings/mozjs-45/templates/interface.cc.template - -// clang-format off - -#include "MozjsNamedIndexedGetterInterface.h" - -#include "base/debug/trace_event.h" -#include "cobalt/base/polymorphic_downcast.h" -#include "cobalt/script/global_environment.h" -#include "cobalt/script/opaque_handle.h" -#include "cobalt/script/script_object.h" - -#include "base/lazy_instance.h" -#include "cobalt/script/mozjs-45/callback_function_conversion.h" -#include "cobalt/script/exception_state.h" -#include "cobalt/script/mozjs-45/conversion_helpers.h" -#include "cobalt/script/mozjs-45/mozjs_exception_state.h" -#include "cobalt/script/mozjs-45/mozjs_callback_function.h" -#include "cobalt/script/mozjs-45/mozjs_global_environment.h" -#include "cobalt/script/mozjs-45/mozjs_object_handle.h" -#include "cobalt/script/mozjs-45/mozjs_property_enumerator.h" -#include "cobalt/script/mozjs-45/mozjs_user_object_holder.h" -#include "cobalt/script/mozjs-45/proxy_handler.h" -#include "cobalt/script/mozjs-45/type_traits.h" -#include "cobalt/script/mozjs-45/wrapper_factory.h" -#include "cobalt/script/mozjs-45/wrapper_private.h" -#include "cobalt/script/property_enumerator.h" -#include "third_party/mozjs-45/js/src/jsapi.h" -#include "third_party/mozjs-45/js/src/jsfriendapi.h" - -namespace { -using cobalt::bindings::testing::NamedIndexedGetterInterface; -using cobalt::bindings::testing::MozjsNamedIndexedGetterInterface; -using cobalt::script::CallbackInterfaceTraits; -using cobalt::script::GlobalEnvironment; -using cobalt::script::OpaqueHandle; -using cobalt::script::OpaqueHandleHolder; -using cobalt::script::ScriptObject; -using cobalt::script::Wrappable; - -using cobalt::script::CallbackFunction; -using cobalt::script::CallbackInterfaceTraits; -using cobalt::script::ExceptionState; -using cobalt::script::mozjs::FromJSValue; -using cobalt::script::mozjs::kConversionFlagNullable; -using cobalt::script::mozjs::kConversionFlagRestricted; -using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString; -using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString; -using cobalt::script::mozjs::kNoConversionFlags; -using cobalt::script::mozjs::InterfaceData; -using cobalt::script::mozjs::MozjsCallbackFunction; -using cobalt::script::mozjs::MozjsExceptionState; -using cobalt::script::mozjs::MozjsGlobalEnvironment; -using cobalt::script::mozjs::MozjsUserObjectHolder; -using cobalt::script::mozjs::MozjsPropertyEnumerator; -using cobalt::script::mozjs::ProxyHandler; -using cobalt::script::mozjs::ToJSValue; -using cobalt::script::mozjs::TypeTraits; -using cobalt::script::mozjs::WrapperPrivate; -using cobalt::script::mozjs::WrapperFactory; -using cobalt::script::Wrappable; -} // namespace - -namespace cobalt { -namespace bindings { -namespace testing { - -namespace { - -bool IsSupportedNamedProperty(JSContext* context, JS::HandleObject object, - const std::string& property_name) { - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - NamedIndexedGetterInterface* impl = - wrapper_private->wrappable<NamedIndexedGetterInterface>().get(); - return impl->CanQueryNamedProperty(property_name); -} - -void EnumerateSupportedNames(JSContext* context, JS::HandleObject object, - JS::AutoIdVector* properties) { - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - NamedIndexedGetterInterface* impl = - wrapper_private->wrappable<NamedIndexedGetterInterface>().get(); - MozjsPropertyEnumerator enumerator(context, properties); - impl->EnumerateNamedProperties(&enumerator); -} - -bool GetNamedProperty( - JSContext* context, JS::HandleObject object, JS::HandleId id, - JS::MutableHandleValue vp) { - JS::RootedValue id_value(context); - if (!JS_IdToValue(context, id, &id_value)) { - NOTREACHED(); - return false; - } - - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - NamedIndexedGetterInterface* impl = - wrapper_private->wrappable<NamedIndexedGetterInterface>().get(); - std::string property_name; - FromJSValue(context, id_value, kNoConversionFlags, &exception_state, - &property_name); - if (exception_state.is_exception_set()) { - // The ID should be an integer or a string, so we shouldn't have any - // exceptions converting to string. - NOTREACHED(); - return false; - } - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->NamedGetter(property_name), - &result_value); - } - if (!exception_state.is_exception_set()) { - vp.set(result_value); - } - return !exception_state.is_exception_set(); - -} - -bool SetNamedProperty( - JSContext* context, JS::HandleObject object, JS::HandleId id, - JS::MutableHandleValue vp, JS::ObjectOpResult& object_op_result) { - JS::RootedValue id_value(context); - if (!JS_IdToValue(context, id, &id_value)) { - NOTREACHED(); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - NamedIndexedGetterInterface* impl = - wrapper_private->wrappable<NamedIndexedGetterInterface>().get(); - std::string property_name; - FromJSValue(context, id_value, kNoConversionFlags, &exception_state, - &property_name); - if (exception_state.is_exception_set()) { - // The ID should be an integer or a string, so we shouldn't have any - // exceptions converting to string. - NOTREACHED(); - return false; - } - TypeTraits<std::string >::ConversionType value; - FromJSValue(context, vp, kNoConversionFlags, - &exception_state, &value); - if (exception_state.is_exception_set()) { - return false; - } - - impl->NamedSetter(property_name, value); - result_value.set(JS::UndefinedHandleValue); - - if (!exception_state.is_exception_set()) { - return object_op_result.succeed(); - } else { - return false; - } -} - -bool IsSupportedIndexProperty(JSContext* context, JS::HandleObject object, - uint32_t index) { - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - NamedIndexedGetterInterface* impl = - wrapper_private->wrappable<NamedIndexedGetterInterface>().get(); - return index < impl->length(); -} - -void EnumerateSupportedIndexes(JSContext* context, JS::HandleObject object, - JS::AutoIdVector* properties) { - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - NamedIndexedGetterInterface* impl = - wrapper_private->wrappable<NamedIndexedGetterInterface>().get(); - const uint32_t kNumIndexedProperties = impl->length(); - for (uint32_t i = 0; i < kNumIndexedProperties; ++i) { - properties->append(INT_TO_JSID(i)); - } -} - -bool GetIndexedProperty( - JSContext* context, JS::HandleObject object, JS::HandleId id, - JS::MutableHandleValue vp) { - JS::RootedValue id_value(context); - if (!JS_IdToValue(context, id, &id_value)) { - NOTREACHED(); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - NamedIndexedGetterInterface* impl = - wrapper_private->wrappable<NamedIndexedGetterInterface>().get(); - uint32_t index; - FromJSValue(context, id_value, kNoConversionFlags, &exception_state, &index); - if (exception_state.is_exception_set()) { - // The ID should be an integer or a string, so we shouldn't have any - // exceptions converting to string. - NOTREACHED(); - return false; - } - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->IndexedGetter(index), - &result_value); - } - if (!exception_state.is_exception_set()) { - vp.set(result_value); - } - return !exception_state.is_exception_set(); -} - -bool SetIndexedProperty( - JSContext* context, JS::HandleObject object, JS::HandleId id, - JS::MutableHandleValue vp, JS::ObjectOpResult& object_op_result) { - JS::RootedValue id_value(context); - if (!JS_IdToValue(context, id, &id_value)) { - NOTREACHED(); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - NamedIndexedGetterInterface* impl = - wrapper_private->wrappable<NamedIndexedGetterInterface>().get(); - uint32_t index; - FromJSValue(context, id_value, kNoConversionFlags, &exception_state, &index); - if (exception_state.is_exception_set()) { - // The ID should be an integer or a string, so we shouldn't have any - // exceptions converting to string. - NOTREACHED(); - return false; - } - TypeTraits<uint32_t >::ConversionType value; - FromJSValue(context, vp, kNoConversionFlags, - &exception_state, &value); - if (exception_state.is_exception_set()) { - return false; - } - - impl->IndexedSetter(index, value); - result_value.set(JS::UndefinedHandleValue); - if (!exception_state.is_exception_set()) { - return object_op_result.succeed(); - } else { - return false; - } -} - -class MozjsNamedIndexedGetterInterfaceHandler : public ProxyHandler { - public: - MozjsNamedIndexedGetterInterfaceHandler() - : ProxyHandler(indexed_property_hooks, named_property_hooks) {} - - private: - static NamedPropertyHooks named_property_hooks; - static IndexedPropertyHooks indexed_property_hooks; -}; - -ProxyHandler::NamedPropertyHooks -MozjsNamedIndexedGetterInterfaceHandler::named_property_hooks = { - IsSupportedNamedProperty, - EnumerateSupportedNames, - GetNamedProperty, - SetNamedProperty, - NULL, -}; -ProxyHandler::IndexedPropertyHooks -MozjsNamedIndexedGetterInterfaceHandler::indexed_property_hooks = { - IsSupportedIndexProperty, - EnumerateSupportedIndexes, - GetIndexedProperty, - SetIndexedProperty, - NULL, -}; - -static base::LazyInstance<MozjsNamedIndexedGetterInterfaceHandler> - proxy_handler; - -bool HasInstance(JSContext *context, JS::HandleObject type, - JS::MutableHandleValue vp, bool *success) { - JS::RootedObject global_object( - context, JS_GetGlobalForObject(context, type)); - DCHECK(global_object); - - JS::RootedObject prototype( - context, MozjsNamedIndexedGetterInterface::GetPrototype(context, global_object)); - - // |IsDelegate| walks the prototype chain of an object returning true if - // .prototype is found. - bool is_delegate; - if (!IsDelegate(context, prototype, vp, &is_delegate)) { - *success = false; - return false; - } - - *success = is_delegate; - return true; -} - -const JSClass instance_class_definition = { - "NamedIndexedGetterInterface", - 0 | JSCLASS_HAS_PRIVATE, - NULL, // addProperty - NULL, // delProperty - NULL, // getProperty - NULL, // setProperty - NULL, // enumerate - NULL, // resolve - NULL, // mayResolve - &WrapperPrivate::Finalizer, // finalize - NULL, // call - NULL, // hasInstance - NULL, // construct - &WrapperPrivate::Trace, // trace -}; - -const JSClass prototype_class_definition = { - "NamedIndexedGetterInterfacePrototype", -}; - -const JSClass interface_object_class_definition = { - "NamedIndexedGetterInterfaceConstructor", - 0, - NULL, // addProperty - NULL, // delProperty - NULL, // getProperty - NULL, // setProperty - NULL, // enumerate - NULL, // resolve - NULL, // mayResolve - NULL, // finalize - NULL, // call - &HasInstance, - NULL, -}; - -bool get_length( - JSContext* context, unsigned argc, JS::Value* vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<NamedIndexedGetterInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - NamedIndexedGetterInterface* impl = - wrapper_private->wrappable<NamedIndexedGetterInterface>().get(); - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->length(), - &result_value); - } - if (!exception_state.is_exception_set()) { - args.rval().set(result_value); - } - return !exception_state.is_exception_set(); -} - - -bool get_propertyOnBaseClass( - JSContext* context, unsigned argc, JS::Value* vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<NamedIndexedGetterInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - NamedIndexedGetterInterface* impl = - wrapper_private->wrappable<NamedIndexedGetterInterface>().get(); - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->property_on_base_class(), - &result_value); - } - if (!exception_state.is_exception_set()) { - args.rval().set(result_value); - } - return !exception_state.is_exception_set(); -} - -bool set_propertyOnBaseClass( - JSContext* context, unsigned argc, JS::Value* vp) { - - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<NamedIndexedGetterInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - NamedIndexedGetterInterface* impl = - wrapper_private->wrappable<NamedIndexedGetterInterface>().get(); - TypeTraits<bool >::ConversionType value; - if (args.length() != 1) { - NOTREACHED(); - return false; - } - FromJSValue(context, args[0], kNoConversionFlags, &exception_state, - &value); - if (exception_state.is_exception_set()) { - return false; - } - - impl->set_property_on_base_class(value); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - -bool fcn_indexedGetter( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, &object)) { - NOTREACHED(); - return false; - } - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<NamedIndexedGetterInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - NamedIndexedGetterInterface* impl = - wrapper_private->wrappable<NamedIndexedGetterInterface>().get(); - const size_t kMinArguments = 1; - if (args.length() < kMinArguments) { - exception_state.SetSimpleException(script::kInvalidNumberOfArguments); - return false; - } - // Non-optional arguments - TypeTraits<uint32_t >::ConversionType index; - - DCHECK_LT(0, args.length()); - JS::RootedValue non_optional_value0( - context, args[0]); - FromJSValue(context, - non_optional_value0, - kNoConversionFlags, - &exception_state, &index); - if (exception_state.is_exception_set()) { - return false; - } - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->IndexedGetter(index), - &result_value); - } - if (!exception_state.is_exception_set()) { - args.rval().set(result_value); - } - return !exception_state.is_exception_set(); -} - -bool fcn_indexedSetter( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, &object)) { - NOTREACHED(); - return false; - } - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<NamedIndexedGetterInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - NamedIndexedGetterInterface* impl = - wrapper_private->wrappable<NamedIndexedGetterInterface>().get(); - const size_t kMinArguments = 2; - if (args.length() < kMinArguments) { - exception_state.SetSimpleException(script::kInvalidNumberOfArguments); - return false; - } - // Non-optional arguments - TypeTraits<uint32_t >::ConversionType index; - TypeTraits<uint32_t >::ConversionType value; - - DCHECK_LT(0, args.length()); - JS::RootedValue non_optional_value0( - context, args[0]); - FromJSValue(context, - non_optional_value0, - kNoConversionFlags, - &exception_state, &index); - if (exception_state.is_exception_set()) { - return false; - } - - DCHECK_LT(1, args.length()); - JS::RootedValue non_optional_value1( - context, args[1]); - FromJSValue(context, - non_optional_value1, - kNoConversionFlags, - &exception_state, &value); - if (exception_state.is_exception_set()) { - return false; - } - - impl->IndexedSetter(index, value); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - -bool fcn_namedGetter( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, &object)) { - NOTREACHED(); - return false; - } - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<NamedIndexedGetterInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - NamedIndexedGetterInterface* impl = - wrapper_private->wrappable<NamedIndexedGetterInterface>().get(); - const size_t kMinArguments = 1; - if (args.length() < kMinArguments) { - exception_state.SetSimpleException(script::kInvalidNumberOfArguments); - return false; - } - // Non-optional arguments - TypeTraits<std::string >::ConversionType name; - - DCHECK_LT(0, args.length()); - JS::RootedValue non_optional_value0( - context, args[0]); - FromJSValue(context, - non_optional_value0, - kNoConversionFlags, - &exception_state, &name); - if (exception_state.is_exception_set()) { - return false; - } - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->NamedGetter(name), - &result_value); - } - if (!exception_state.is_exception_set()) { - args.rval().set(result_value); - } - return !exception_state.is_exception_set(); -} - -bool fcn_namedSetter( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, &object)) { - NOTREACHED(); - return false; - } - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<NamedIndexedGetterInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - NamedIndexedGetterInterface* impl = - wrapper_private->wrappable<NamedIndexedGetterInterface>().get(); - const size_t kMinArguments = 2; - if (args.length() < kMinArguments) { - exception_state.SetSimpleException(script::kInvalidNumberOfArguments); - return false; - } - // Non-optional arguments - TypeTraits<std::string >::ConversionType name; - TypeTraits<std::string >::ConversionType value; - - DCHECK_LT(0, args.length()); - JS::RootedValue non_optional_value0( - context, args[0]); - FromJSValue(context, - non_optional_value0, - kNoConversionFlags, - &exception_state, &name); - if (exception_state.is_exception_set()) { - return false; - } - - DCHECK_LT(1, args.length()); - JS::RootedValue non_optional_value1( - context, args[1]); - FromJSValue(context, - non_optional_value1, - kNoConversionFlags, - &exception_state, &value); - if (exception_state.is_exception_set()) { - return false; - } - - impl->NamedSetter(name, value); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - -bool fcn_operationOnBaseClass( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, &object)) { - NOTREACHED(); - return false; - } - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<NamedIndexedGetterInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - NamedIndexedGetterInterface* impl = - wrapper_private->wrappable<NamedIndexedGetterInterface>().get(); - - impl->OperationOnBaseClass(); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - - - -const JSPropertySpec prototype_properties[] = { - { // Readonly attribute - "length", - JSPROP_SHARED | JSPROP_ENUMERATE, - { { &get_length, NULL } }, - JSNATIVE_WRAPPER(NULL), - }, - { // Read/Write property - "propertyOnBaseClass", - JSPROP_SHARED | JSPROP_ENUMERATE, - { { &get_propertyOnBaseClass, NULL } }, - { { &set_propertyOnBaseClass, NULL } }, - }, - JS_PS_END -}; - -const JSFunctionSpec prototype_functions[] = { - JS_FNSPEC( - "indexedGetter", fcn_indexedGetter, NULL, - 1, JSPROP_ENUMERATE, NULL), - JS_FNSPEC( - "indexedSetter", fcn_indexedSetter, NULL, - 2, JSPROP_ENUMERATE, NULL), - JS_FNSPEC( - "namedGetter", fcn_namedGetter, NULL, - 1, JSPROP_ENUMERATE, NULL), - JS_FNSPEC( - "namedSetter", fcn_namedSetter, NULL, - 2, JSPROP_ENUMERATE, NULL), - JS_FNSPEC( - "operationOnBaseClass", fcn_operationOnBaseClass, NULL, - 0, JSPROP_ENUMERATE, NULL), - JS_FS_END -}; - -const JSPropertySpec interface_object_properties[] = { - JS_PS_END -}; - -const JSFunctionSpec interface_object_functions[] = { - JS_FS_END -}; - -const JSPropertySpec own_properties[] = { - JS_PS_END -}; - -void InitializePrototypeAndInterfaceObject( - InterfaceData* interface_data, JSContext* context, - JS::HandleObject global_object) { - DCHECK(!interface_data->prototype); - DCHECK(!interface_data->interface_object); - DCHECK(JS_IsGlobalObject(global_object)); - - JS::RootedObject parent_prototype( - context, JS_GetObjectPrototype(context, global_object)); - DCHECK(parent_prototype); - - interface_data->prototype = JS_NewObjectWithGivenProto( - context, &prototype_class_definition, parent_prototype - ); - - JS::RootedObject rooted_prototype(context, interface_data->prototype); - bool success = JS_DefineProperties( - context, - rooted_prototype, - prototype_properties); - - DCHECK(success); - success = JS_DefineFunctions( - context, rooted_prototype, prototype_functions); - DCHECK(success); - - JS::RootedObject function_prototype( - context, JS_GetFunctionPrototype(context, global_object)); - DCHECK(function_prototype); - // Create the Interface object. - interface_data->interface_object = JS_NewObjectWithGivenProto( - context, &interface_object_class_definition, - function_prototype); - - // Add the InterfaceObject.name property. - JS::RootedObject rooted_interface_object( - context, interface_data->interface_object); - JS::RootedValue name_value(context); - const char name[] = - "NamedIndexedGetterInterface"; - name_value.setString(JS_NewStringCopyZ(context, name)); - success = JS_DefineProperty( - context, rooted_interface_object, "name", name_value, JSPROP_READONLY, - NULL, NULL); - DCHECK(success); - - // Define interface object properties (including constants). - success = JS_DefineProperties(context, rooted_interface_object, - interface_object_properties); - DCHECK(success); - // Define interface object functions (static). - success = JS_DefineFunctions(context, rooted_interface_object, - interface_object_functions); - DCHECK(success); - - // Set the Prototype.constructor and Constructor.prototype properties. - DCHECK(interface_data->interface_object); - DCHECK(interface_data->prototype); - success = JS_LinkConstructorAndPrototype( - context, - rooted_interface_object, - rooted_prototype); - DCHECK(success); -} - -InterfaceData* GetInterfaceData(JSContext* context) { - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - // Use the address of the properties definition for this interface as a - // unique key for looking up the InterfaceData for this interface. - intptr_t key = reinterpret_cast<intptr_t>(&own_properties); - InterfaceData* interface_data = global_environment->GetInterfaceData(key); - if (!interface_data) { - interface_data = new InterfaceData(); - DCHECK(interface_data); - global_environment->CacheInterfaceData(key, interface_data); - DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key)); - } - return interface_data; -} - -} // namespace - -// static -JSObject* MozjsNamedIndexedGetterInterface::CreateProxy( - JSContext* context, const scoped_refptr<Wrappable>& wrappable) { - DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); - JS::RootedObject global_object( - context, - MozjsGlobalEnvironment::GetFromContext(context)->global_object()); - DCHECK(global_object); - - InterfaceData* interface_data = GetInterfaceData(context); - JS::RootedObject prototype(context, GetPrototype(context, global_object)); - DCHECK(prototype); - JS::RootedObject new_object( - context, - JS_NewObjectWithGivenProto( - context, &instance_class_definition, prototype)); - DCHECK(new_object); - JS::RootedObject proxy(context, - ProxyHandler::NewProxy( - context, proxy_handler.Pointer(), new_object, prototype)); - WrapperPrivate::AddPrivateData(context, proxy, wrappable); - return proxy; -} - -// static -const JSClass* MozjsNamedIndexedGetterInterface::PrototypeClass( - JSContext* context) { - DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); - JS::RootedObject global_object( - context, - MozjsGlobalEnvironment::GetFromContext(context)->global_object()); - DCHECK(global_object); - - JS::RootedObject prototype(context, GetPrototype(context, global_object)); - const JSClass* proto_class = JS_GetClass(prototype); - return proto_class; -} - -// static -JSObject* MozjsNamedIndexedGetterInterface::GetPrototype( - JSContext* context, JS::HandleObject global_object) { - DCHECK(JS_IsGlobalObject(global_object)); - - InterfaceData* interface_data = GetInterfaceData(context); - if (!interface_data->prototype) { - // Create new prototype that has all the props and methods - InitializePrototypeAndInterfaceObject( - interface_data, context, global_object); - } - DCHECK(interface_data->prototype); - return interface_data->prototype; -} - -// static -JSObject* MozjsNamedIndexedGetterInterface::GetInterfaceObject( - JSContext* context, JS::HandleObject global_object) { - DCHECK(JS_IsGlobalObject(global_object)); - - InterfaceData* interface_data = GetInterfaceData(context); - if (!interface_data->interface_object) { - InitializePrototypeAndInterfaceObject( - interface_data, context, global_object); - } - DCHECK(interface_data->interface_object); - return interface_data->interface_object; -} - - -namespace { -} // namespace - - -} // namespace testing -} // namespace bindings -} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsNamedIndexedGetterInterface.h b/src/cobalt/bindings/generated/mozjs-45/testing/MozjsNamedIndexedGetterInterface.h deleted file mode 100644 index 5d6429b..0000000 --- a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsNamedIndexedGetterInterface.h +++ /dev/null
@@ -1,54 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! -// Auto-generated from template: bindings/mozjs-45/templates/interface.h.template - -// clang-format off - -#ifndef MozjsNamedIndexedGetterInterface_h -#define MozjsNamedIndexedGetterInterface_h - -#include "base/hash_tables.h" -#include "base/lazy_instance.h" -#include "base/memory/ref_counted.h" -#include "base/threading/thread_checker.h" -#include "cobalt/base/polymorphic_downcast.h" -#include "cobalt/script/wrappable.h" -#include "cobalt/bindings/testing/named_indexed_getter_interface.h" - -#include "third_party/mozjs-45/js/src/jsapi.h" - -namespace cobalt { -namespace bindings { -namespace testing { - -class MozjsNamedIndexedGetterInterface { - public: - static JSObject* CreateProxy(JSContext* context, - const scoped_refptr<script::Wrappable>& wrappable); - static const JSClass* PrototypeClass(JSContext* context); - static JSObject* GetPrototype(JSContext* context, - JS::HandleObject global_object); - static JSObject* GetInterfaceObject(JSContext* context, - JS::HandleObject global_object); -}; - -} // namespace bindings -} // namespace testing -} // namespace cobalt - -#endif // MozjsNamedIndexedGetterInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsNestedPutForwardsInterface.cc b/src/cobalt/bindings/generated/mozjs-45/testing/MozjsNestedPutForwardsInterface.cc deleted file mode 100644 index 4602f37..0000000 --- a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsNestedPutForwardsInterface.cc +++ /dev/null
@@ -1,456 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! -// Auto-generated from template: bindings/mozjs-45/templates/interface.cc.template - -// clang-format off - -#include "MozjsNestedPutForwardsInterface.h" - -#include "base/debug/trace_event.h" -#include "cobalt/base/polymorphic_downcast.h" -#include "cobalt/script/global_environment.h" -#include "cobalt/script/opaque_handle.h" -#include "cobalt/script/script_object.h" -#include "MozjsPutForwardsInterface.h" -#include "cobalt/bindings/testing/put_forwards_interface.h" - -#include "base/lazy_instance.h" -#include "cobalt/script/mozjs-45/callback_function_conversion.h" -#include "cobalt/script/exception_state.h" -#include "cobalt/script/mozjs-45/conversion_helpers.h" -#include "cobalt/script/mozjs-45/mozjs_exception_state.h" -#include "cobalt/script/mozjs-45/mozjs_callback_function.h" -#include "cobalt/script/mozjs-45/mozjs_global_environment.h" -#include "cobalt/script/mozjs-45/mozjs_object_handle.h" -#include "cobalt/script/mozjs-45/mozjs_property_enumerator.h" -#include "cobalt/script/mozjs-45/mozjs_user_object_holder.h" -#include "cobalt/script/mozjs-45/proxy_handler.h" -#include "cobalt/script/mozjs-45/type_traits.h" -#include "cobalt/script/mozjs-45/wrapper_factory.h" -#include "cobalt/script/mozjs-45/wrapper_private.h" -#include "cobalt/script/property_enumerator.h" -#include "third_party/mozjs-45/js/src/jsapi.h" -#include "third_party/mozjs-45/js/src/jsfriendapi.h" - -namespace { -using cobalt::bindings::testing::NestedPutForwardsInterface; -using cobalt::bindings::testing::MozjsNestedPutForwardsInterface; -using cobalt::bindings::testing::MozjsPutForwardsInterface; -using cobalt::bindings::testing::PutForwardsInterface; -using cobalt::script::CallbackInterfaceTraits; -using cobalt::script::GlobalEnvironment; -using cobalt::script::OpaqueHandle; -using cobalt::script::OpaqueHandleHolder; -using cobalt::script::ScriptObject; -using cobalt::script::Wrappable; - -using cobalt::script::CallbackFunction; -using cobalt::script::CallbackInterfaceTraits; -using cobalt::script::ExceptionState; -using cobalt::script::mozjs::FromJSValue; -using cobalt::script::mozjs::kConversionFlagNullable; -using cobalt::script::mozjs::kConversionFlagRestricted; -using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString; -using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString; -using cobalt::script::mozjs::kNoConversionFlags; -using cobalt::script::mozjs::InterfaceData; -using cobalt::script::mozjs::MozjsCallbackFunction; -using cobalt::script::mozjs::MozjsExceptionState; -using cobalt::script::mozjs::MozjsGlobalEnvironment; -using cobalt::script::mozjs::MozjsUserObjectHolder; -using cobalt::script::mozjs::MozjsPropertyEnumerator; -using cobalt::script::mozjs::ProxyHandler; -using cobalt::script::mozjs::ToJSValue; -using cobalt::script::mozjs::TypeTraits; -using cobalt::script::mozjs::WrapperPrivate; -using cobalt::script::mozjs::WrapperFactory; -using cobalt::script::Wrappable; -} // namespace - -namespace cobalt { -namespace bindings { -namespace testing { - -namespace { - -class MozjsNestedPutForwardsInterfaceHandler : public ProxyHandler { - public: - MozjsNestedPutForwardsInterfaceHandler() - : ProxyHandler(indexed_property_hooks, named_property_hooks) {} - - private: - static NamedPropertyHooks named_property_hooks; - static IndexedPropertyHooks indexed_property_hooks; -}; - -ProxyHandler::NamedPropertyHooks -MozjsNestedPutForwardsInterfaceHandler::named_property_hooks = { - NULL, - NULL, - NULL, - NULL, - NULL, -}; -ProxyHandler::IndexedPropertyHooks -MozjsNestedPutForwardsInterfaceHandler::indexed_property_hooks = { - NULL, - NULL, - NULL, - NULL, - NULL, -}; - -static base::LazyInstance<MozjsNestedPutForwardsInterfaceHandler> - proxy_handler; - -bool HasInstance(JSContext *context, JS::HandleObject type, - JS::MutableHandleValue vp, bool *success) { - JS::RootedObject global_object( - context, JS_GetGlobalForObject(context, type)); - DCHECK(global_object); - - JS::RootedObject prototype( - context, MozjsNestedPutForwardsInterface::GetPrototype(context, global_object)); - - // |IsDelegate| walks the prototype chain of an object returning true if - // .prototype is found. - bool is_delegate; - if (!IsDelegate(context, prototype, vp, &is_delegate)) { - *success = false; - return false; - } - - *success = is_delegate; - return true; -} - -const JSClass instance_class_definition = { - "NestedPutForwardsInterface", - 0 | JSCLASS_HAS_PRIVATE, - NULL, // addProperty - NULL, // delProperty - NULL, // getProperty - NULL, // setProperty - NULL, // enumerate - NULL, // resolve - NULL, // mayResolve - &WrapperPrivate::Finalizer, // finalize - NULL, // call - NULL, // hasInstance - NULL, // construct - &WrapperPrivate::Trace, // trace -}; - -const JSClass prototype_class_definition = { - "NestedPutForwardsInterfacePrototype", -}; - -const JSClass interface_object_class_definition = { - "NestedPutForwardsInterfaceConstructor", - 0, - NULL, // addProperty - NULL, // delProperty - NULL, // getProperty - NULL, // setProperty - NULL, // enumerate - NULL, // resolve - NULL, // mayResolve - NULL, // finalize - NULL, // call - &HasInstance, - NULL, -}; - -bool get_nestedForwardingAttribute( - JSContext* context, unsigned argc, JS::Value* vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<NestedPutForwardsInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - NestedPutForwardsInterface* impl = - wrapper_private->wrappable<NestedPutForwardsInterface>().get(); - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->nested_forwarding_attribute(), - &result_value); - } - if (!exception_state.is_exception_set()) { - args.rval().set(result_value); - } - return !exception_state.is_exception_set(); -} - -bool set_nestedForwardingAttribute( - JSContext* context, unsigned argc, JS::Value* vp) { - - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<NestedPutForwardsInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - NestedPutForwardsInterface* impl = - wrapper_private->wrappable<NestedPutForwardsInterface>().get(); - { // Begin scope of scoped_refptr<PutForwardsInterface> forwarded_impl. - scoped_refptr<PutForwardsInterface> forwarded_impl = - impl->nested_forwarding_attribute(); - if (!forwarded_impl) { - NOTREACHED(); - return false; - } - if (!exception_state.is_exception_set()) { - { // Begin scope of scoped_refptr<ArbitraryInterface> forwarded_forwarded_impl. - scoped_refptr<ArbitraryInterface> forwarded_forwarded_impl = - forwarded_impl->forwarding_attribute(); - if (!forwarded_forwarded_impl) { - NOTREACHED(); - return false; - } - if (!exception_state.is_exception_set()) { - TypeTraits<std::string >::ConversionType value; - if (args.length() != 1) { - NOTREACHED(); - return false; - } - FromJSValue(context, args[0], kNoConversionFlags, &exception_state, - &value); - if (exception_state.is_exception_set()) { - return false; - } - - forwarded_forwarded_impl->set_arbitrary_property(value); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - return !exception_state.is_exception_set(); - } // End scope of scoped_refptr<ArbitraryInterface> forwarded_forwarded_impl. -} - return !exception_state.is_exception_set(); - } // End scope of scoped_refptr<PutForwardsInterface> forwarded_impl. -} - - - -const JSPropertySpec prototype_properties[] = { - { // Read/Write property - "nestedForwardingAttribute", - JSPROP_SHARED | JSPROP_ENUMERATE, - { { &get_nestedForwardingAttribute, NULL } }, - { { &set_nestedForwardingAttribute, NULL } }, - }, - JS_PS_END -}; - -const JSFunctionSpec prototype_functions[] = { - JS_FS_END -}; - -const JSPropertySpec interface_object_properties[] = { - JS_PS_END -}; - -const JSFunctionSpec interface_object_functions[] = { - JS_FS_END -}; - -const JSPropertySpec own_properties[] = { - JS_PS_END -}; - -void InitializePrototypeAndInterfaceObject( - InterfaceData* interface_data, JSContext* context, - JS::HandleObject global_object) { - DCHECK(!interface_data->prototype); - DCHECK(!interface_data->interface_object); - DCHECK(JS_IsGlobalObject(global_object)); - - JS::RootedObject parent_prototype( - context, JS_GetObjectPrototype(context, global_object)); - DCHECK(parent_prototype); - - interface_data->prototype = JS_NewObjectWithGivenProto( - context, &prototype_class_definition, parent_prototype - ); - - JS::RootedObject rooted_prototype(context, interface_data->prototype); - bool success = JS_DefineProperties( - context, - rooted_prototype, - prototype_properties); - - DCHECK(success); - success = JS_DefineFunctions( - context, rooted_prototype, prototype_functions); - DCHECK(success); - - JS::RootedObject function_prototype( - context, JS_GetFunctionPrototype(context, global_object)); - DCHECK(function_prototype); - // Create the Interface object. - interface_data->interface_object = JS_NewObjectWithGivenProto( - context, &interface_object_class_definition, - function_prototype); - - // Add the InterfaceObject.name property. - JS::RootedObject rooted_interface_object( - context, interface_data->interface_object); - JS::RootedValue name_value(context); - const char name[] = - "NestedPutForwardsInterface"; - name_value.setString(JS_NewStringCopyZ(context, name)); - success = JS_DefineProperty( - context, rooted_interface_object, "name", name_value, JSPROP_READONLY, - NULL, NULL); - DCHECK(success); - - // Define interface object properties (including constants). - success = JS_DefineProperties(context, rooted_interface_object, - interface_object_properties); - DCHECK(success); - // Define interface object functions (static). - success = JS_DefineFunctions(context, rooted_interface_object, - interface_object_functions); - DCHECK(success); - - // Set the Prototype.constructor and Constructor.prototype properties. - DCHECK(interface_data->interface_object); - DCHECK(interface_data->prototype); - success = JS_LinkConstructorAndPrototype( - context, - rooted_interface_object, - rooted_prototype); - DCHECK(success); -} - -InterfaceData* GetInterfaceData(JSContext* context) { - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - // Use the address of the properties definition for this interface as a - // unique key for looking up the InterfaceData for this interface. - intptr_t key = reinterpret_cast<intptr_t>(&own_properties); - InterfaceData* interface_data = global_environment->GetInterfaceData(key); - if (!interface_data) { - interface_data = new InterfaceData(); - DCHECK(interface_data); - global_environment->CacheInterfaceData(key, interface_data); - DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key)); - } - return interface_data; -} - -} // namespace - -// static -JSObject* MozjsNestedPutForwardsInterface::CreateProxy( - JSContext* context, const scoped_refptr<Wrappable>& wrappable) { - DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); - JS::RootedObject global_object( - context, - MozjsGlobalEnvironment::GetFromContext(context)->global_object()); - DCHECK(global_object); - - InterfaceData* interface_data = GetInterfaceData(context); - JS::RootedObject prototype(context, GetPrototype(context, global_object)); - DCHECK(prototype); - JS::RootedObject new_object( - context, - JS_NewObjectWithGivenProto( - context, &instance_class_definition, prototype)); - DCHECK(new_object); - JS::RootedObject proxy(context, - ProxyHandler::NewProxy( - context, proxy_handler.Pointer(), new_object, prototype)); - WrapperPrivate::AddPrivateData(context, proxy, wrappable); - return proxy; -} - -// static -const JSClass* MozjsNestedPutForwardsInterface::PrototypeClass( - JSContext* context) { - DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); - JS::RootedObject global_object( - context, - MozjsGlobalEnvironment::GetFromContext(context)->global_object()); - DCHECK(global_object); - - JS::RootedObject prototype(context, GetPrototype(context, global_object)); - const JSClass* proto_class = JS_GetClass(prototype); - return proto_class; -} - -// static -JSObject* MozjsNestedPutForwardsInterface::GetPrototype( - JSContext* context, JS::HandleObject global_object) { - DCHECK(JS_IsGlobalObject(global_object)); - - InterfaceData* interface_data = GetInterfaceData(context); - if (!interface_data->prototype) { - // Create new prototype that has all the props and methods - InitializePrototypeAndInterfaceObject( - interface_data, context, global_object); - } - DCHECK(interface_data->prototype); - return interface_data->prototype; -} - -// static -JSObject* MozjsNestedPutForwardsInterface::GetInterfaceObject( - JSContext* context, JS::HandleObject global_object) { - DCHECK(JS_IsGlobalObject(global_object)); - - InterfaceData* interface_data = GetInterfaceData(context); - if (!interface_data->interface_object) { - InitializePrototypeAndInterfaceObject( - interface_data, context, global_object); - } - DCHECK(interface_data->interface_object); - return interface_data->interface_object; -} - - -namespace { -} // namespace - - -} // namespace testing -} // namespace bindings -} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsNestedPutForwardsInterface.h b/src/cobalt/bindings/generated/mozjs-45/testing/MozjsNestedPutForwardsInterface.h deleted file mode 100644 index 1e0abe2..0000000 --- a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsNestedPutForwardsInterface.h +++ /dev/null
@@ -1,54 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! -// Auto-generated from template: bindings/mozjs-45/templates/interface.h.template - -// clang-format off - -#ifndef MozjsNestedPutForwardsInterface_h -#define MozjsNestedPutForwardsInterface_h - -#include "base/hash_tables.h" -#include "base/lazy_instance.h" -#include "base/memory/ref_counted.h" -#include "base/threading/thread_checker.h" -#include "cobalt/base/polymorphic_downcast.h" -#include "cobalt/script/wrappable.h" -#include "cobalt/bindings/testing/nested_put_forwards_interface.h" - -#include "third_party/mozjs-45/js/src/jsapi.h" - -namespace cobalt { -namespace bindings { -namespace testing { - -class MozjsNestedPutForwardsInterface { - public: - static JSObject* CreateProxy(JSContext* context, - const scoped_refptr<script::Wrappable>& wrappable); - static const JSClass* PrototypeClass(JSContext* context); - static JSObject* GetPrototype(JSContext* context, - JS::HandleObject global_object); - static JSObject* GetInterfaceObject(JSContext* context, - JS::HandleObject global_object); -}; - -} // namespace bindings -} // namespace testing -} // namespace cobalt - -#endif // MozjsNestedPutForwardsInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsNoConstructorInterface.cc b/src/cobalt/bindings/generated/mozjs-45/testing/MozjsNoConstructorInterface.cc deleted file mode 100644 index 126bc07..0000000 --- a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsNoConstructorInterface.cc +++ /dev/null
@@ -1,354 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! -// Auto-generated from template: bindings/mozjs-45/templates/interface.cc.template - -// clang-format off - -#include "MozjsNoConstructorInterface.h" - -#include "base/debug/trace_event.h" -#include "cobalt/base/polymorphic_downcast.h" -#include "cobalt/script/global_environment.h" -#include "cobalt/script/opaque_handle.h" -#include "cobalt/script/script_object.h" - -#include "base/lazy_instance.h" -#include "cobalt/script/mozjs-45/callback_function_conversion.h" -#include "cobalt/script/exception_state.h" -#include "cobalt/script/mozjs-45/conversion_helpers.h" -#include "cobalt/script/mozjs-45/mozjs_exception_state.h" -#include "cobalt/script/mozjs-45/mozjs_callback_function.h" -#include "cobalt/script/mozjs-45/mozjs_global_environment.h" -#include "cobalt/script/mozjs-45/mozjs_object_handle.h" -#include "cobalt/script/mozjs-45/mozjs_property_enumerator.h" -#include "cobalt/script/mozjs-45/mozjs_user_object_holder.h" -#include "cobalt/script/mozjs-45/proxy_handler.h" -#include "cobalt/script/mozjs-45/type_traits.h" -#include "cobalt/script/mozjs-45/wrapper_factory.h" -#include "cobalt/script/mozjs-45/wrapper_private.h" -#include "cobalt/script/property_enumerator.h" -#include "third_party/mozjs-45/js/src/jsapi.h" -#include "third_party/mozjs-45/js/src/jsfriendapi.h" - -namespace { -using cobalt::bindings::testing::NoConstructorInterface; -using cobalt::bindings::testing::MozjsNoConstructorInterface; -using cobalt::script::CallbackInterfaceTraits; -using cobalt::script::GlobalEnvironment; -using cobalt::script::OpaqueHandle; -using cobalt::script::OpaqueHandleHolder; -using cobalt::script::ScriptObject; -using cobalt::script::Wrappable; - -using cobalt::script::CallbackFunction; -using cobalt::script::CallbackInterfaceTraits; -using cobalt::script::ExceptionState; -using cobalt::script::mozjs::FromJSValue; -using cobalt::script::mozjs::kConversionFlagNullable; -using cobalt::script::mozjs::kConversionFlagRestricted; -using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString; -using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString; -using cobalt::script::mozjs::kNoConversionFlags; -using cobalt::script::mozjs::InterfaceData; -using cobalt::script::mozjs::MozjsCallbackFunction; -using cobalt::script::mozjs::MozjsExceptionState; -using cobalt::script::mozjs::MozjsGlobalEnvironment; -using cobalt::script::mozjs::MozjsUserObjectHolder; -using cobalt::script::mozjs::MozjsPropertyEnumerator; -using cobalt::script::mozjs::ProxyHandler; -using cobalt::script::mozjs::ToJSValue; -using cobalt::script::mozjs::TypeTraits; -using cobalt::script::mozjs::WrapperPrivate; -using cobalt::script::mozjs::WrapperFactory; -using cobalt::script::Wrappable; -} // namespace - -namespace cobalt { -namespace bindings { -namespace testing { - -namespace { - -class MozjsNoConstructorInterfaceHandler : public ProxyHandler { - public: - MozjsNoConstructorInterfaceHandler() - : ProxyHandler(indexed_property_hooks, named_property_hooks) {} - - private: - static NamedPropertyHooks named_property_hooks; - static IndexedPropertyHooks indexed_property_hooks; -}; - -ProxyHandler::NamedPropertyHooks -MozjsNoConstructorInterfaceHandler::named_property_hooks = { - NULL, - NULL, - NULL, - NULL, - NULL, -}; -ProxyHandler::IndexedPropertyHooks -MozjsNoConstructorInterfaceHandler::indexed_property_hooks = { - NULL, - NULL, - NULL, - NULL, - NULL, -}; - -static base::LazyInstance<MozjsNoConstructorInterfaceHandler> - proxy_handler; - -bool HasInstance(JSContext *context, JS::HandleObject type, - JS::MutableHandleValue vp, bool *success) { - JS::RootedObject global_object( - context, JS_GetGlobalForObject(context, type)); - DCHECK(global_object); - - JS::RootedObject prototype( - context, MozjsNoConstructorInterface::GetPrototype(context, global_object)); - - // |IsDelegate| walks the prototype chain of an object returning true if - // .prototype is found. - bool is_delegate; - if (!IsDelegate(context, prototype, vp, &is_delegate)) { - *success = false; - return false; - } - - *success = is_delegate; - return true; -} - -const JSClass instance_class_definition = { - "NoConstructorInterface", - 0 | JSCLASS_HAS_PRIVATE, - NULL, // addProperty - NULL, // delProperty - NULL, // getProperty - NULL, // setProperty - NULL, // enumerate - NULL, // resolve - NULL, // mayResolve - &WrapperPrivate::Finalizer, // finalize - NULL, // call - NULL, // hasInstance - NULL, // construct - &WrapperPrivate::Trace, // trace -}; - -const JSClass prototype_class_definition = { - "NoConstructorInterfacePrototype", -}; - -const JSClass interface_object_class_definition = { - "NoConstructorInterfaceConstructor", - 0, - NULL, // addProperty - NULL, // delProperty - NULL, // getProperty - NULL, // setProperty - NULL, // enumerate - NULL, // resolve - NULL, // mayResolve - NULL, // finalize - NULL, // call - &HasInstance, - NULL, -}; - - - -const JSPropertySpec prototype_properties[] = { - JS_PS_END -}; - -const JSFunctionSpec prototype_functions[] = { - JS_FS_END -}; - -const JSPropertySpec interface_object_properties[] = { - JS_PS_END -}; - -const JSFunctionSpec interface_object_functions[] = { - JS_FS_END -}; - -const JSPropertySpec own_properties[] = { - JS_PS_END -}; - -void InitializePrototypeAndInterfaceObject( - InterfaceData* interface_data, JSContext* context, - JS::HandleObject global_object) { - DCHECK(!interface_data->prototype); - DCHECK(!interface_data->interface_object); - DCHECK(JS_IsGlobalObject(global_object)); - - JS::RootedObject parent_prototype( - context, JS_GetObjectPrototype(context, global_object)); - DCHECK(parent_prototype); - - interface_data->prototype = JS_NewObjectWithGivenProto( - context, &prototype_class_definition, parent_prototype - ); - - JS::RootedObject rooted_prototype(context, interface_data->prototype); - bool success = JS_DefineProperties( - context, - rooted_prototype, - prototype_properties); - - DCHECK(success); - success = JS_DefineFunctions( - context, rooted_prototype, prototype_functions); - DCHECK(success); - - JS::RootedObject function_prototype( - context, JS_GetFunctionPrototype(context, global_object)); - DCHECK(function_prototype); - // Create the Interface object. - interface_data->interface_object = JS_NewObjectWithGivenProto( - context, &interface_object_class_definition, - function_prototype); - - // Add the InterfaceObject.name property. - JS::RootedObject rooted_interface_object( - context, interface_data->interface_object); - JS::RootedValue name_value(context); - const char name[] = - "NoConstructorInterface"; - name_value.setString(JS_NewStringCopyZ(context, name)); - success = JS_DefineProperty( - context, rooted_interface_object, "name", name_value, JSPROP_READONLY, - NULL, NULL); - DCHECK(success); - - // Define interface object properties (including constants). - success = JS_DefineProperties(context, rooted_interface_object, - interface_object_properties); - DCHECK(success); - // Define interface object functions (static). - success = JS_DefineFunctions(context, rooted_interface_object, - interface_object_functions); - DCHECK(success); - - // Set the Prototype.constructor and Constructor.prototype properties. - DCHECK(interface_data->interface_object); - DCHECK(interface_data->prototype); - success = JS_LinkConstructorAndPrototype( - context, - rooted_interface_object, - rooted_prototype); - DCHECK(success); -} - -InterfaceData* GetInterfaceData(JSContext* context) { - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - // Use the address of the properties definition for this interface as a - // unique key for looking up the InterfaceData for this interface. - intptr_t key = reinterpret_cast<intptr_t>(&own_properties); - InterfaceData* interface_data = global_environment->GetInterfaceData(key); - if (!interface_data) { - interface_data = new InterfaceData(); - DCHECK(interface_data); - global_environment->CacheInterfaceData(key, interface_data); - DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key)); - } - return interface_data; -} - -} // namespace - -// static -JSObject* MozjsNoConstructorInterface::CreateProxy( - JSContext* context, const scoped_refptr<Wrappable>& wrappable) { - DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); - JS::RootedObject global_object( - context, - MozjsGlobalEnvironment::GetFromContext(context)->global_object()); - DCHECK(global_object); - - InterfaceData* interface_data = GetInterfaceData(context); - JS::RootedObject prototype(context, GetPrototype(context, global_object)); - DCHECK(prototype); - JS::RootedObject new_object( - context, - JS_NewObjectWithGivenProto( - context, &instance_class_definition, prototype)); - DCHECK(new_object); - JS::RootedObject proxy(context, - ProxyHandler::NewProxy( - context, proxy_handler.Pointer(), new_object, prototype)); - WrapperPrivate::AddPrivateData(context, proxy, wrappable); - return proxy; -} - -// static -const JSClass* MozjsNoConstructorInterface::PrototypeClass( - JSContext* context) { - DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); - JS::RootedObject global_object( - context, - MozjsGlobalEnvironment::GetFromContext(context)->global_object()); - DCHECK(global_object); - - JS::RootedObject prototype(context, GetPrototype(context, global_object)); - const JSClass* proto_class = JS_GetClass(prototype); - return proto_class; -} - -// static -JSObject* MozjsNoConstructorInterface::GetPrototype( - JSContext* context, JS::HandleObject global_object) { - DCHECK(JS_IsGlobalObject(global_object)); - - InterfaceData* interface_data = GetInterfaceData(context); - if (!interface_data->prototype) { - // Create new prototype that has all the props and methods - InitializePrototypeAndInterfaceObject( - interface_data, context, global_object); - } - DCHECK(interface_data->prototype); - return interface_data->prototype; -} - -// static -JSObject* MozjsNoConstructorInterface::GetInterfaceObject( - JSContext* context, JS::HandleObject global_object) { - DCHECK(JS_IsGlobalObject(global_object)); - - InterfaceData* interface_data = GetInterfaceData(context); - if (!interface_data->interface_object) { - InitializePrototypeAndInterfaceObject( - interface_data, context, global_object); - } - DCHECK(interface_data->interface_object); - return interface_data->interface_object; -} - - -namespace { -} // namespace - - -} // namespace testing -} // namespace bindings -} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsNoConstructorInterface.h b/src/cobalt/bindings/generated/mozjs-45/testing/MozjsNoConstructorInterface.h deleted file mode 100644 index 46e26c9..0000000 --- a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsNoConstructorInterface.h +++ /dev/null
@@ -1,54 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! -// Auto-generated from template: bindings/mozjs-45/templates/interface.h.template - -// clang-format off - -#ifndef MozjsNoConstructorInterface_h -#define MozjsNoConstructorInterface_h - -#include "base/hash_tables.h" -#include "base/lazy_instance.h" -#include "base/memory/ref_counted.h" -#include "base/threading/thread_checker.h" -#include "cobalt/base/polymorphic_downcast.h" -#include "cobalt/script/wrappable.h" -#include "cobalt/bindings/testing/no_constructor_interface.h" - -#include "third_party/mozjs-45/js/src/jsapi.h" - -namespace cobalt { -namespace bindings { -namespace testing { - -class MozjsNoConstructorInterface { - public: - static JSObject* CreateProxy(JSContext* context, - const scoped_refptr<script::Wrappable>& wrappable); - static const JSClass* PrototypeClass(JSContext* context); - static JSObject* GetPrototype(JSContext* context, - JS::HandleObject global_object); - static JSObject* GetInterfaceObject(JSContext* context, - JS::HandleObject global_object); -}; - -} // namespace bindings -} // namespace testing -} // namespace cobalt - -#endif // MozjsNoConstructorInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsNoInterfaceObjectInterface.cc b/src/cobalt/bindings/generated/mozjs-45/testing/MozjsNoInterfaceObjectInterface.cc deleted file mode 100644 index d445a99..0000000 --- a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsNoInterfaceObjectInterface.cc +++ /dev/null
@@ -1,303 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! -// Auto-generated from template: bindings/mozjs-45/templates/interface.cc.template - -// clang-format off - -#include "MozjsNoInterfaceObjectInterface.h" - -#include "base/debug/trace_event.h" -#include "cobalt/base/polymorphic_downcast.h" -#include "cobalt/script/global_environment.h" -#include "cobalt/script/opaque_handle.h" -#include "cobalt/script/script_object.h" - -#include "base/lazy_instance.h" -#include "cobalt/script/mozjs-45/callback_function_conversion.h" -#include "cobalt/script/exception_state.h" -#include "cobalt/script/mozjs-45/conversion_helpers.h" -#include "cobalt/script/mozjs-45/mozjs_exception_state.h" -#include "cobalt/script/mozjs-45/mozjs_callback_function.h" -#include "cobalt/script/mozjs-45/mozjs_global_environment.h" -#include "cobalt/script/mozjs-45/mozjs_object_handle.h" -#include "cobalt/script/mozjs-45/mozjs_property_enumerator.h" -#include "cobalt/script/mozjs-45/mozjs_user_object_holder.h" -#include "cobalt/script/mozjs-45/proxy_handler.h" -#include "cobalt/script/mozjs-45/type_traits.h" -#include "cobalt/script/mozjs-45/wrapper_factory.h" -#include "cobalt/script/mozjs-45/wrapper_private.h" -#include "cobalt/script/property_enumerator.h" -#include "third_party/mozjs-45/js/src/jsapi.h" -#include "third_party/mozjs-45/js/src/jsfriendapi.h" - -namespace { -using cobalt::bindings::testing::NoInterfaceObjectInterface; -using cobalt::bindings::testing::MozjsNoInterfaceObjectInterface; -using cobalt::script::CallbackInterfaceTraits; -using cobalt::script::GlobalEnvironment; -using cobalt::script::OpaqueHandle; -using cobalt::script::OpaqueHandleHolder; -using cobalt::script::ScriptObject; -using cobalt::script::Wrappable; - -using cobalt::script::CallbackFunction; -using cobalt::script::CallbackInterfaceTraits; -using cobalt::script::ExceptionState; -using cobalt::script::mozjs::FromJSValue; -using cobalt::script::mozjs::kConversionFlagNullable; -using cobalt::script::mozjs::kConversionFlagRestricted; -using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString; -using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString; -using cobalt::script::mozjs::kNoConversionFlags; -using cobalt::script::mozjs::InterfaceData; -using cobalt::script::mozjs::MozjsCallbackFunction; -using cobalt::script::mozjs::MozjsExceptionState; -using cobalt::script::mozjs::MozjsGlobalEnvironment; -using cobalt::script::mozjs::MozjsUserObjectHolder; -using cobalt::script::mozjs::MozjsPropertyEnumerator; -using cobalt::script::mozjs::ProxyHandler; -using cobalt::script::mozjs::ToJSValue; -using cobalt::script::mozjs::TypeTraits; -using cobalt::script::mozjs::WrapperPrivate; -using cobalt::script::mozjs::WrapperFactory; -using cobalt::script::Wrappable; -} // namespace - -namespace cobalt { -namespace bindings { -namespace testing { - -namespace { - -class MozjsNoInterfaceObjectInterfaceHandler : public ProxyHandler { - public: - MozjsNoInterfaceObjectInterfaceHandler() - : ProxyHandler(indexed_property_hooks, named_property_hooks) {} - - private: - static NamedPropertyHooks named_property_hooks; - static IndexedPropertyHooks indexed_property_hooks; -}; - -ProxyHandler::NamedPropertyHooks -MozjsNoInterfaceObjectInterfaceHandler::named_property_hooks = { - NULL, - NULL, - NULL, - NULL, - NULL, -}; -ProxyHandler::IndexedPropertyHooks -MozjsNoInterfaceObjectInterfaceHandler::indexed_property_hooks = { - NULL, - NULL, - NULL, - NULL, - NULL, -}; - -static base::LazyInstance<MozjsNoInterfaceObjectInterfaceHandler> - proxy_handler; - -bool HasInstance(JSContext *context, JS::HandleObject type, - JS::MutableHandleValue vp, bool *success) { - JS::RootedObject global_object( - context, JS_GetGlobalForObject(context, type)); - DCHECK(global_object); - - JS::RootedObject prototype( - context, MozjsNoInterfaceObjectInterface::GetPrototype(context, global_object)); - - // |IsDelegate| walks the prototype chain of an object returning true if - // .prototype is found. - bool is_delegate; - if (!IsDelegate(context, prototype, vp, &is_delegate)) { - *success = false; - return false; - } - - *success = is_delegate; - return true; -} - -const JSClass instance_class_definition = { - "NoInterfaceObjectInterface", - 0 | JSCLASS_HAS_PRIVATE, - NULL, // addProperty - NULL, // delProperty - NULL, // getProperty - NULL, // setProperty - NULL, // enumerate - NULL, // resolve - NULL, // mayResolve - &WrapperPrivate::Finalizer, // finalize - NULL, // call - NULL, // hasInstance - NULL, // construct - &WrapperPrivate::Trace, // trace -}; - -const JSClass prototype_class_definition = { - "NoInterfaceObjectInterfacePrototype", -}; - -const JSClass interface_object_class_definition = { - "NoInterfaceObjectInterfaceConstructor", - 0, - NULL, // addProperty - NULL, // delProperty - NULL, // getProperty - NULL, // setProperty - NULL, // enumerate - NULL, // resolve - NULL, // mayResolve - NULL, // finalize - NULL, // call - &HasInstance, - NULL, -}; - - - -const JSPropertySpec prototype_properties[] = { - JS_PS_END -}; - -const JSFunctionSpec prototype_functions[] = { - JS_FS_END -}; - -const JSPropertySpec interface_object_properties[] = { - JS_PS_END -}; - -const JSFunctionSpec interface_object_functions[] = { - JS_FS_END -}; - -const JSPropertySpec own_properties[] = { - JS_PS_END -}; - -void InitializePrototypeAndInterfaceObject( - InterfaceData* interface_data, JSContext* context, - JS::HandleObject global_object) { - DCHECK(!interface_data->prototype); - DCHECK(!interface_data->interface_object); - DCHECK(JS_IsGlobalObject(global_object)); - - JS::RootedObject parent_prototype( - context, JS_GetObjectPrototype(context, global_object)); - DCHECK(parent_prototype); - - interface_data->prototype = JS_NewObjectWithGivenProto( - context, &prototype_class_definition, parent_prototype - ); - - JS::RootedObject rooted_prototype(context, interface_data->prototype); - bool success = JS_DefineProperties( - context, - rooted_prototype, - prototype_properties); - - DCHECK(success); - success = JS_DefineFunctions( - context, rooted_prototype, prototype_functions); - DCHECK(success); - -} - -InterfaceData* GetInterfaceData(JSContext* context) { - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - // Use the address of the properties definition for this interface as a - // unique key for looking up the InterfaceData for this interface. - intptr_t key = reinterpret_cast<intptr_t>(&own_properties); - InterfaceData* interface_data = global_environment->GetInterfaceData(key); - if (!interface_data) { - interface_data = new InterfaceData(); - DCHECK(interface_data); - global_environment->CacheInterfaceData(key, interface_data); - DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key)); - } - return interface_data; -} - -} // namespace - -// static -JSObject* MozjsNoInterfaceObjectInterface::CreateProxy( - JSContext* context, const scoped_refptr<Wrappable>& wrappable) { - DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); - JS::RootedObject global_object( - context, - MozjsGlobalEnvironment::GetFromContext(context)->global_object()); - DCHECK(global_object); - - InterfaceData* interface_data = GetInterfaceData(context); - JS::RootedObject prototype(context, GetPrototype(context, global_object)); - DCHECK(prototype); - JS::RootedObject new_object( - context, - JS_NewObjectWithGivenProto( - context, &instance_class_definition, prototype)); - DCHECK(new_object); - JS::RootedObject proxy(context, - ProxyHandler::NewProxy( - context, proxy_handler.Pointer(), new_object, prototype)); - WrapperPrivate::AddPrivateData(context, proxy, wrappable); - return proxy; -} - -// static -const JSClass* MozjsNoInterfaceObjectInterface::PrototypeClass( - JSContext* context) { - DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); - JS::RootedObject global_object( - context, - MozjsGlobalEnvironment::GetFromContext(context)->global_object()); - DCHECK(global_object); - - JS::RootedObject prototype(context, GetPrototype(context, global_object)); - const JSClass* proto_class = JS_GetClass(prototype); - return proto_class; -} - -// static -JSObject* MozjsNoInterfaceObjectInterface::GetPrototype( - JSContext* context, JS::HandleObject global_object) { - DCHECK(JS_IsGlobalObject(global_object)); - - InterfaceData* interface_data = GetInterfaceData(context); - if (!interface_data->prototype) { - // Create new prototype that has all the props and methods - InitializePrototypeAndInterfaceObject( - interface_data, context, global_object); - } - DCHECK(interface_data->prototype); - return interface_data->prototype; -} - - -namespace { -} // namespace - - -} // namespace testing -} // namespace bindings -} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsNoInterfaceObjectInterface.h b/src/cobalt/bindings/generated/mozjs-45/testing/MozjsNoInterfaceObjectInterface.h deleted file mode 100644 index 8707bb5..0000000 --- a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsNoInterfaceObjectInterface.h +++ /dev/null
@@ -1,52 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! -// Auto-generated from template: bindings/mozjs-45/templates/interface.h.template - -// clang-format off - -#ifndef MozjsNoInterfaceObjectInterface_h -#define MozjsNoInterfaceObjectInterface_h - -#include "base/hash_tables.h" -#include "base/lazy_instance.h" -#include "base/memory/ref_counted.h" -#include "base/threading/thread_checker.h" -#include "cobalt/base/polymorphic_downcast.h" -#include "cobalt/script/wrappable.h" -#include "cobalt/bindings/testing/no_interface_object_interface.h" - -#include "third_party/mozjs-45/js/src/jsapi.h" - -namespace cobalt { -namespace bindings { -namespace testing { - -class MozjsNoInterfaceObjectInterface { - public: - static JSObject* CreateProxy(JSContext* context, - const scoped_refptr<script::Wrappable>& wrappable); - static const JSClass* PrototypeClass(JSContext* context); - static JSObject* GetPrototype(JSContext* context, - JS::HandleObject global_object); -}; - -} // namespace bindings -} // namespace testing -} // namespace cobalt - -#endif // MozjsNoInterfaceObjectInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsNullableTypesTestInterface.cc b/src/cobalt/bindings/generated/mozjs-45/testing/MozjsNullableTypesTestInterface.cc deleted file mode 100644 index cacc4a8..0000000 --- a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsNullableTypesTestInterface.cc +++ /dev/null
@@ -1,1078 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! -// Auto-generated from template: bindings/mozjs-45/templates/interface.cc.template - -// clang-format off - -#include "MozjsNullableTypesTestInterface.h" - -#include "base/debug/trace_event.h" -#include "cobalt/base/polymorphic_downcast.h" -#include "cobalt/script/global_environment.h" -#include "cobalt/script/opaque_handle.h" -#include "cobalt/script/script_object.h" -#include "MozjsArbitraryInterface.h" -#include "cobalt/bindings/testing/arbitrary_interface.h" - -#include "base/lazy_instance.h" -#include "cobalt/script/mozjs-45/callback_function_conversion.h" -#include "cobalt/script/exception_state.h" -#include "cobalt/script/mozjs-45/conversion_helpers.h" -#include "cobalt/script/mozjs-45/mozjs_exception_state.h" -#include "cobalt/script/mozjs-45/mozjs_callback_function.h" -#include "cobalt/script/mozjs-45/mozjs_global_environment.h" -#include "cobalt/script/mozjs-45/mozjs_object_handle.h" -#include "cobalt/script/mozjs-45/mozjs_property_enumerator.h" -#include "cobalt/script/mozjs-45/mozjs_user_object_holder.h" -#include "cobalt/script/mozjs-45/proxy_handler.h" -#include "cobalt/script/mozjs-45/type_traits.h" -#include "cobalt/script/mozjs-45/wrapper_factory.h" -#include "cobalt/script/mozjs-45/wrapper_private.h" -#include "cobalt/script/property_enumerator.h" -#include "third_party/mozjs-45/js/src/jsapi.h" -#include "third_party/mozjs-45/js/src/jsfriendapi.h" - -namespace { -using cobalt::bindings::testing::NullableTypesTestInterface; -using cobalt::bindings::testing::MozjsNullableTypesTestInterface; -using cobalt::bindings::testing::ArbitraryInterface; -using cobalt::bindings::testing::MozjsArbitraryInterface; -using cobalt::script::CallbackInterfaceTraits; -using cobalt::script::GlobalEnvironment; -using cobalt::script::OpaqueHandle; -using cobalt::script::OpaqueHandleHolder; -using cobalt::script::ScriptObject; -using cobalt::script::Wrappable; - -using cobalt::script::CallbackFunction; -using cobalt::script::CallbackInterfaceTraits; -using cobalt::script::ExceptionState; -using cobalt::script::mozjs::FromJSValue; -using cobalt::script::mozjs::kConversionFlagNullable; -using cobalt::script::mozjs::kConversionFlagRestricted; -using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString; -using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString; -using cobalt::script::mozjs::kNoConversionFlags; -using cobalt::script::mozjs::InterfaceData; -using cobalt::script::mozjs::MozjsCallbackFunction; -using cobalt::script::mozjs::MozjsExceptionState; -using cobalt::script::mozjs::MozjsGlobalEnvironment; -using cobalt::script::mozjs::MozjsUserObjectHolder; -using cobalt::script::mozjs::MozjsPropertyEnumerator; -using cobalt::script::mozjs::ProxyHandler; -using cobalt::script::mozjs::ToJSValue; -using cobalt::script::mozjs::TypeTraits; -using cobalt::script::mozjs::WrapperPrivate; -using cobalt::script::mozjs::WrapperFactory; -using cobalt::script::Wrappable; -} // namespace - -namespace cobalt { -namespace bindings { -namespace testing { - -namespace { - -class MozjsNullableTypesTestInterfaceHandler : public ProxyHandler { - public: - MozjsNullableTypesTestInterfaceHandler() - : ProxyHandler(indexed_property_hooks, named_property_hooks) {} - - private: - static NamedPropertyHooks named_property_hooks; - static IndexedPropertyHooks indexed_property_hooks; -}; - -ProxyHandler::NamedPropertyHooks -MozjsNullableTypesTestInterfaceHandler::named_property_hooks = { - NULL, - NULL, - NULL, - NULL, - NULL, -}; -ProxyHandler::IndexedPropertyHooks -MozjsNullableTypesTestInterfaceHandler::indexed_property_hooks = { - NULL, - NULL, - NULL, - NULL, - NULL, -}; - -static base::LazyInstance<MozjsNullableTypesTestInterfaceHandler> - proxy_handler; - -bool HasInstance(JSContext *context, JS::HandleObject type, - JS::MutableHandleValue vp, bool *success) { - JS::RootedObject global_object( - context, JS_GetGlobalForObject(context, type)); - DCHECK(global_object); - - JS::RootedObject prototype( - context, MozjsNullableTypesTestInterface::GetPrototype(context, global_object)); - - // |IsDelegate| walks the prototype chain of an object returning true if - // .prototype is found. - bool is_delegate; - if (!IsDelegate(context, prototype, vp, &is_delegate)) { - *success = false; - return false; - } - - *success = is_delegate; - return true; -} - -const JSClass instance_class_definition = { - "NullableTypesTestInterface", - 0 | JSCLASS_HAS_PRIVATE, - NULL, // addProperty - NULL, // delProperty - NULL, // getProperty - NULL, // setProperty - NULL, // enumerate - NULL, // resolve - NULL, // mayResolve - &WrapperPrivate::Finalizer, // finalize - NULL, // call - NULL, // hasInstance - NULL, // construct - &WrapperPrivate::Trace, // trace -}; - -const JSClass prototype_class_definition = { - "NullableTypesTestInterfacePrototype", -}; - -const JSClass interface_object_class_definition = { - "NullableTypesTestInterfaceConstructor", - 0, - NULL, // addProperty - NULL, // delProperty - NULL, // getProperty - NULL, // setProperty - NULL, // enumerate - NULL, // resolve - NULL, // mayResolve - NULL, // finalize - NULL, // call - &HasInstance, - NULL, -}; - -bool get_nullableBooleanProperty( - JSContext* context, unsigned argc, JS::Value* vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<NullableTypesTestInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - NullableTypesTestInterface* impl = - wrapper_private->wrappable<NullableTypesTestInterface>().get(); - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->nullable_boolean_property(), - &result_value); - } - if (!exception_state.is_exception_set()) { - args.rval().set(result_value); - } - return !exception_state.is_exception_set(); -} - -bool set_nullableBooleanProperty( - JSContext* context, unsigned argc, JS::Value* vp) { - - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<NullableTypesTestInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - NullableTypesTestInterface* impl = - wrapper_private->wrappable<NullableTypesTestInterface>().get(); - TypeTraits<base::optional<bool > >::ConversionType value; - if (args.length() != 1) { - NOTREACHED(); - return false; - } - FromJSValue(context, args[0], (kConversionFlagNullable), &exception_state, - &value); - if (exception_state.is_exception_set()) { - return false; - } - - impl->set_nullable_boolean_property(value); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - -bool get_nullableNumericProperty( - JSContext* context, unsigned argc, JS::Value* vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<NullableTypesTestInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - NullableTypesTestInterface* impl = - wrapper_private->wrappable<NullableTypesTestInterface>().get(); - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->nullable_numeric_property(), - &result_value); - } - if (!exception_state.is_exception_set()) { - args.rval().set(result_value); - } - return !exception_state.is_exception_set(); -} - -bool set_nullableNumericProperty( - JSContext* context, unsigned argc, JS::Value* vp) { - - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<NullableTypesTestInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - NullableTypesTestInterface* impl = - wrapper_private->wrappable<NullableTypesTestInterface>().get(); - TypeTraits<base::optional<int32_t > >::ConversionType value; - if (args.length() != 1) { - NOTREACHED(); - return false; - } - FromJSValue(context, args[0], (kConversionFlagNullable), &exception_state, - &value); - if (exception_state.is_exception_set()) { - return false; - } - - impl->set_nullable_numeric_property(value); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - -bool get_nullableStringProperty( - JSContext* context, unsigned argc, JS::Value* vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<NullableTypesTestInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - NullableTypesTestInterface* impl = - wrapper_private->wrappable<NullableTypesTestInterface>().get(); - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->nullable_string_property(), - &result_value); - } - if (!exception_state.is_exception_set()) { - args.rval().set(result_value); - } - return !exception_state.is_exception_set(); -} - -bool set_nullableStringProperty( - JSContext* context, unsigned argc, JS::Value* vp) { - - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<NullableTypesTestInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - NullableTypesTestInterface* impl = - wrapper_private->wrappable<NullableTypesTestInterface>().get(); - TypeTraits<base::optional<std::string > >::ConversionType value; - if (args.length() != 1) { - NOTREACHED(); - return false; - } - FromJSValue(context, args[0], (kConversionFlagNullable), &exception_state, - &value); - if (exception_state.is_exception_set()) { - return false; - } - - impl->set_nullable_string_property(value); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - -bool get_nullableObjectProperty( - JSContext* context, unsigned argc, JS::Value* vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<NullableTypesTestInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - NullableTypesTestInterface* impl = - wrapper_private->wrappable<NullableTypesTestInterface>().get(); - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->nullable_object_property(), - &result_value); - } - if (!exception_state.is_exception_set()) { - args.rval().set(result_value); - } - return !exception_state.is_exception_set(); -} - -bool set_nullableObjectProperty( - JSContext* context, unsigned argc, JS::Value* vp) { - - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<NullableTypesTestInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - NullableTypesTestInterface* impl = - wrapper_private->wrappable<NullableTypesTestInterface>().get(); - TypeTraits<scoped_refptr<ArbitraryInterface> >::ConversionType value; - if (args.length() != 1) { - NOTREACHED(); - return false; - } - FromJSValue(context, args[0], (kConversionFlagNullable), &exception_state, - &value); - if (exception_state.is_exception_set()) { - return false; - } - - impl->set_nullable_object_property(value); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - -bool fcn_nullableBooleanArgument( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, &object)) { - NOTREACHED(); - return false; - } - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<NullableTypesTestInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - NullableTypesTestInterface* impl = - wrapper_private->wrappable<NullableTypesTestInterface>().get(); - const size_t kMinArguments = 1; - if (args.length() < kMinArguments) { - exception_state.SetSimpleException(script::kInvalidNumberOfArguments); - return false; - } - // Non-optional arguments - TypeTraits<base::optional<bool > >::ConversionType arg; - - DCHECK_LT(0, args.length()); - JS::RootedValue non_optional_value0( - context, args[0]); - FromJSValue(context, - non_optional_value0, - (kConversionFlagNullable), - &exception_state, &arg); - if (exception_state.is_exception_set()) { - return false; - } - - impl->NullableBooleanArgument(arg); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - -bool fcn_nullableBooleanOperation( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, &object)) { - NOTREACHED(); - return false; - } - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<NullableTypesTestInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - NullableTypesTestInterface* impl = - wrapper_private->wrappable<NullableTypesTestInterface>().get(); - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->NullableBooleanOperation(), - &result_value); - } - if (!exception_state.is_exception_set()) { - args.rval().set(result_value); - } - return !exception_state.is_exception_set(); -} - -bool fcn_nullableNumericArgument( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, &object)) { - NOTREACHED(); - return false; - } - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<NullableTypesTestInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - NullableTypesTestInterface* impl = - wrapper_private->wrappable<NullableTypesTestInterface>().get(); - const size_t kMinArguments = 1; - if (args.length() < kMinArguments) { - exception_state.SetSimpleException(script::kInvalidNumberOfArguments); - return false; - } - // Non-optional arguments - TypeTraits<base::optional<int32_t > >::ConversionType arg; - - DCHECK_LT(0, args.length()); - JS::RootedValue non_optional_value0( - context, args[0]); - FromJSValue(context, - non_optional_value0, - (kConversionFlagNullable), - &exception_state, &arg); - if (exception_state.is_exception_set()) { - return false; - } - - impl->NullableNumericArgument(arg); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - -bool fcn_nullableNumericOperation( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, &object)) { - NOTREACHED(); - return false; - } - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<NullableTypesTestInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - NullableTypesTestInterface* impl = - wrapper_private->wrappable<NullableTypesTestInterface>().get(); - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->NullableNumericOperation(), - &result_value); - } - if (!exception_state.is_exception_set()) { - args.rval().set(result_value); - } - return !exception_state.is_exception_set(); -} - -bool fcn_nullableObjectArgument( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, &object)) { - NOTREACHED(); - return false; - } - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<NullableTypesTestInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - NullableTypesTestInterface* impl = - wrapper_private->wrappable<NullableTypesTestInterface>().get(); - const size_t kMinArguments = 1; - if (args.length() < kMinArguments) { - exception_state.SetSimpleException(script::kInvalidNumberOfArguments); - return false; - } - // Non-optional arguments - TypeTraits<scoped_refptr<ArbitraryInterface> >::ConversionType arg; - - DCHECK_LT(0, args.length()); - JS::RootedValue non_optional_value0( - context, args[0]); - FromJSValue(context, - non_optional_value0, - (kConversionFlagNullable), - &exception_state, &arg); - if (exception_state.is_exception_set()) { - return false; - } - - impl->NullableObjectArgument(arg); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - -bool fcn_nullableObjectOperation( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, &object)) { - NOTREACHED(); - return false; - } - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<NullableTypesTestInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - NullableTypesTestInterface* impl = - wrapper_private->wrappable<NullableTypesTestInterface>().get(); - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->NullableObjectOperation(), - &result_value); - } - if (!exception_state.is_exception_set()) { - args.rval().set(result_value); - } - return !exception_state.is_exception_set(); -} - -bool fcn_nullableStringArgument( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, &object)) { - NOTREACHED(); - return false; - } - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<NullableTypesTestInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - NullableTypesTestInterface* impl = - wrapper_private->wrappable<NullableTypesTestInterface>().get(); - const size_t kMinArguments = 1; - if (args.length() < kMinArguments) { - exception_state.SetSimpleException(script::kInvalidNumberOfArguments); - return false; - } - // Non-optional arguments - TypeTraits<base::optional<std::string > >::ConversionType arg; - - DCHECK_LT(0, args.length()); - JS::RootedValue non_optional_value0( - context, args[0]); - FromJSValue(context, - non_optional_value0, - (kConversionFlagNullable), - &exception_state, &arg); - if (exception_state.is_exception_set()) { - return false; - } - - impl->NullableStringArgument(arg); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - -bool fcn_nullableStringOperation( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, &object)) { - NOTREACHED(); - return false; - } - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<NullableTypesTestInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - NullableTypesTestInterface* impl = - wrapper_private->wrappable<NullableTypesTestInterface>().get(); - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->NullableStringOperation(), - &result_value); - } - if (!exception_state.is_exception_set()) { - args.rval().set(result_value); - } - return !exception_state.is_exception_set(); -} - - - -const JSPropertySpec prototype_properties[] = { - { // Read/Write property - "nullableBooleanProperty", - JSPROP_SHARED | JSPROP_ENUMERATE, - { { &get_nullableBooleanProperty, NULL } }, - { { &set_nullableBooleanProperty, NULL } }, - }, - { // Read/Write property - "nullableNumericProperty", - JSPROP_SHARED | JSPROP_ENUMERATE, - { { &get_nullableNumericProperty, NULL } }, - { { &set_nullableNumericProperty, NULL } }, - }, - { // Read/Write property - "nullableStringProperty", - JSPROP_SHARED | JSPROP_ENUMERATE, - { { &get_nullableStringProperty, NULL } }, - { { &set_nullableStringProperty, NULL } }, - }, - { // Read/Write property - "nullableObjectProperty", - JSPROP_SHARED | JSPROP_ENUMERATE, - { { &get_nullableObjectProperty, NULL } }, - { { &set_nullableObjectProperty, NULL } }, - }, - JS_PS_END -}; - -const JSFunctionSpec prototype_functions[] = { - JS_FNSPEC( - "nullableBooleanArgument", fcn_nullableBooleanArgument, NULL, - 1, JSPROP_ENUMERATE, NULL), - JS_FNSPEC( - "nullableBooleanOperation", fcn_nullableBooleanOperation, NULL, - 0, JSPROP_ENUMERATE, NULL), - JS_FNSPEC( - "nullableNumericArgument", fcn_nullableNumericArgument, NULL, - 1, JSPROP_ENUMERATE, NULL), - JS_FNSPEC( - "nullableNumericOperation", fcn_nullableNumericOperation, NULL, - 0, JSPROP_ENUMERATE, NULL), - JS_FNSPEC( - "nullableObjectArgument", fcn_nullableObjectArgument, NULL, - 1, JSPROP_ENUMERATE, NULL), - JS_FNSPEC( - "nullableObjectOperation", fcn_nullableObjectOperation, NULL, - 0, JSPROP_ENUMERATE, NULL), - JS_FNSPEC( - "nullableStringArgument", fcn_nullableStringArgument, NULL, - 1, JSPROP_ENUMERATE, NULL), - JS_FNSPEC( - "nullableStringOperation", fcn_nullableStringOperation, NULL, - 0, JSPROP_ENUMERATE, NULL), - JS_FS_END -}; - -const JSPropertySpec interface_object_properties[] = { - JS_PS_END -}; - -const JSFunctionSpec interface_object_functions[] = { - JS_FS_END -}; - -const JSPropertySpec own_properties[] = { - JS_PS_END -}; - -void InitializePrototypeAndInterfaceObject( - InterfaceData* interface_data, JSContext* context, - JS::HandleObject global_object) { - DCHECK(!interface_data->prototype); - DCHECK(!interface_data->interface_object); - DCHECK(JS_IsGlobalObject(global_object)); - - JS::RootedObject parent_prototype( - context, JS_GetObjectPrototype(context, global_object)); - DCHECK(parent_prototype); - - interface_data->prototype = JS_NewObjectWithGivenProto( - context, &prototype_class_definition, parent_prototype - ); - - JS::RootedObject rooted_prototype(context, interface_data->prototype); - bool success = JS_DefineProperties( - context, - rooted_prototype, - prototype_properties); - - DCHECK(success); - success = JS_DefineFunctions( - context, rooted_prototype, prototype_functions); - DCHECK(success); - - JS::RootedObject function_prototype( - context, JS_GetFunctionPrototype(context, global_object)); - DCHECK(function_prototype); - // Create the Interface object. - interface_data->interface_object = JS_NewObjectWithGivenProto( - context, &interface_object_class_definition, - function_prototype); - - // Add the InterfaceObject.name property. - JS::RootedObject rooted_interface_object( - context, interface_data->interface_object); - JS::RootedValue name_value(context); - const char name[] = - "NullableTypesTestInterface"; - name_value.setString(JS_NewStringCopyZ(context, name)); - success = JS_DefineProperty( - context, rooted_interface_object, "name", name_value, JSPROP_READONLY, - NULL, NULL); - DCHECK(success); - - // Define interface object properties (including constants). - success = JS_DefineProperties(context, rooted_interface_object, - interface_object_properties); - DCHECK(success); - // Define interface object functions (static). - success = JS_DefineFunctions(context, rooted_interface_object, - interface_object_functions); - DCHECK(success); - - // Set the Prototype.constructor and Constructor.prototype properties. - DCHECK(interface_data->interface_object); - DCHECK(interface_data->prototype); - success = JS_LinkConstructorAndPrototype( - context, - rooted_interface_object, - rooted_prototype); - DCHECK(success); -} - -InterfaceData* GetInterfaceData(JSContext* context) { - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - // Use the address of the properties definition for this interface as a - // unique key for looking up the InterfaceData for this interface. - intptr_t key = reinterpret_cast<intptr_t>(&own_properties); - InterfaceData* interface_data = global_environment->GetInterfaceData(key); - if (!interface_data) { - interface_data = new InterfaceData(); - DCHECK(interface_data); - global_environment->CacheInterfaceData(key, interface_data); - DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key)); - } - return interface_data; -} - -} // namespace - -// static -JSObject* MozjsNullableTypesTestInterface::CreateProxy( - JSContext* context, const scoped_refptr<Wrappable>& wrappable) { - DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); - JS::RootedObject global_object( - context, - MozjsGlobalEnvironment::GetFromContext(context)->global_object()); - DCHECK(global_object); - - InterfaceData* interface_data = GetInterfaceData(context); - JS::RootedObject prototype(context, GetPrototype(context, global_object)); - DCHECK(prototype); - JS::RootedObject new_object( - context, - JS_NewObjectWithGivenProto( - context, &instance_class_definition, prototype)); - DCHECK(new_object); - JS::RootedObject proxy(context, - ProxyHandler::NewProxy( - context, proxy_handler.Pointer(), new_object, prototype)); - WrapperPrivate::AddPrivateData(context, proxy, wrappable); - return proxy; -} - -// static -const JSClass* MozjsNullableTypesTestInterface::PrototypeClass( - JSContext* context) { - DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); - JS::RootedObject global_object( - context, - MozjsGlobalEnvironment::GetFromContext(context)->global_object()); - DCHECK(global_object); - - JS::RootedObject prototype(context, GetPrototype(context, global_object)); - const JSClass* proto_class = JS_GetClass(prototype); - return proto_class; -} - -// static -JSObject* MozjsNullableTypesTestInterface::GetPrototype( - JSContext* context, JS::HandleObject global_object) { - DCHECK(JS_IsGlobalObject(global_object)); - - InterfaceData* interface_data = GetInterfaceData(context); - if (!interface_data->prototype) { - // Create new prototype that has all the props and methods - InitializePrototypeAndInterfaceObject( - interface_data, context, global_object); - } - DCHECK(interface_data->prototype); - return interface_data->prototype; -} - -// static -JSObject* MozjsNullableTypesTestInterface::GetInterfaceObject( - JSContext* context, JS::HandleObject global_object) { - DCHECK(JS_IsGlobalObject(global_object)); - - InterfaceData* interface_data = GetInterfaceData(context); - if (!interface_data->interface_object) { - InitializePrototypeAndInterfaceObject( - interface_data, context, global_object); - } - DCHECK(interface_data->interface_object); - return interface_data->interface_object; -} - - -namespace { -} // namespace - - -} // namespace testing -} // namespace bindings -} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsNullableTypesTestInterface.h b/src/cobalt/bindings/generated/mozjs-45/testing/MozjsNullableTypesTestInterface.h deleted file mode 100644 index bb36253..0000000 --- a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsNullableTypesTestInterface.h +++ /dev/null
@@ -1,54 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! -// Auto-generated from template: bindings/mozjs-45/templates/interface.h.template - -// clang-format off - -#ifndef MozjsNullableTypesTestInterface_h -#define MozjsNullableTypesTestInterface_h - -#include "base/hash_tables.h" -#include "base/lazy_instance.h" -#include "base/memory/ref_counted.h" -#include "base/threading/thread_checker.h" -#include "cobalt/base/polymorphic_downcast.h" -#include "cobalt/script/wrappable.h" -#include "cobalt/bindings/testing/nullable_types_test_interface.h" - -#include "third_party/mozjs-45/js/src/jsapi.h" - -namespace cobalt { -namespace bindings { -namespace testing { - -class MozjsNullableTypesTestInterface { - public: - static JSObject* CreateProxy(JSContext* context, - const scoped_refptr<script::Wrappable>& wrappable); - static const JSClass* PrototypeClass(JSContext* context); - static JSObject* GetPrototype(JSContext* context, - JS::HandleObject global_object); - static JSObject* GetInterfaceObject(JSContext* context, - JS::HandleObject global_object); -}; - -} // namespace bindings -} // namespace testing -} // namespace cobalt - -#endif // MozjsNullableTypesTestInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsNumericTypesTestInterface.cc b/src/cobalt/bindings/generated/mozjs-45/testing/MozjsNumericTypesTestInterface.cc deleted file mode 100644 index 1cf704d..0000000 --- a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsNumericTypesTestInterface.cc +++ /dev/null
@@ -1,2154 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! -// Auto-generated from template: bindings/mozjs-45/templates/interface.cc.template - -// clang-format off - -#include "MozjsNumericTypesTestInterface.h" - -#include "base/debug/trace_event.h" -#include "cobalt/base/polymorphic_downcast.h" -#include "cobalt/script/global_environment.h" -#include "cobalt/script/opaque_handle.h" -#include "cobalt/script/script_object.h" - -#include "base/lazy_instance.h" -#include "cobalt/script/mozjs-45/callback_function_conversion.h" -#include "cobalt/script/exception_state.h" -#include "cobalt/script/mozjs-45/conversion_helpers.h" -#include "cobalt/script/mozjs-45/mozjs_exception_state.h" -#include "cobalt/script/mozjs-45/mozjs_callback_function.h" -#include "cobalt/script/mozjs-45/mozjs_global_environment.h" -#include "cobalt/script/mozjs-45/mozjs_object_handle.h" -#include "cobalt/script/mozjs-45/mozjs_property_enumerator.h" -#include "cobalt/script/mozjs-45/mozjs_user_object_holder.h" -#include "cobalt/script/mozjs-45/proxy_handler.h" -#include "cobalt/script/mozjs-45/type_traits.h" -#include "cobalt/script/mozjs-45/wrapper_factory.h" -#include "cobalt/script/mozjs-45/wrapper_private.h" -#include "cobalt/script/property_enumerator.h" -#include "third_party/mozjs-45/js/src/jsapi.h" -#include "third_party/mozjs-45/js/src/jsfriendapi.h" - -namespace { -using cobalt::bindings::testing::NumericTypesTestInterface; -using cobalt::bindings::testing::MozjsNumericTypesTestInterface; -using cobalt::script::CallbackInterfaceTraits; -using cobalt::script::GlobalEnvironment; -using cobalt::script::OpaqueHandle; -using cobalt::script::OpaqueHandleHolder; -using cobalt::script::ScriptObject; -using cobalt::script::Wrappable; - -using cobalt::script::CallbackFunction; -using cobalt::script::CallbackInterfaceTraits; -using cobalt::script::ExceptionState; -using cobalt::script::mozjs::FromJSValue; -using cobalt::script::mozjs::kConversionFlagNullable; -using cobalt::script::mozjs::kConversionFlagRestricted; -using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString; -using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString; -using cobalt::script::mozjs::kNoConversionFlags; -using cobalt::script::mozjs::InterfaceData; -using cobalt::script::mozjs::MozjsCallbackFunction; -using cobalt::script::mozjs::MozjsExceptionState; -using cobalt::script::mozjs::MozjsGlobalEnvironment; -using cobalt::script::mozjs::MozjsUserObjectHolder; -using cobalt::script::mozjs::MozjsPropertyEnumerator; -using cobalt::script::mozjs::ProxyHandler; -using cobalt::script::mozjs::ToJSValue; -using cobalt::script::mozjs::TypeTraits; -using cobalt::script::mozjs::WrapperPrivate; -using cobalt::script::mozjs::WrapperFactory; -using cobalt::script::Wrappable; -} // namespace - -namespace cobalt { -namespace bindings { -namespace testing { - -namespace { - -class MozjsNumericTypesTestInterfaceHandler : public ProxyHandler { - public: - MozjsNumericTypesTestInterfaceHandler() - : ProxyHandler(indexed_property_hooks, named_property_hooks) {} - - private: - static NamedPropertyHooks named_property_hooks; - static IndexedPropertyHooks indexed_property_hooks; -}; - -ProxyHandler::NamedPropertyHooks -MozjsNumericTypesTestInterfaceHandler::named_property_hooks = { - NULL, - NULL, - NULL, - NULL, - NULL, -}; -ProxyHandler::IndexedPropertyHooks -MozjsNumericTypesTestInterfaceHandler::indexed_property_hooks = { - NULL, - NULL, - NULL, - NULL, - NULL, -}; - -static base::LazyInstance<MozjsNumericTypesTestInterfaceHandler> - proxy_handler; - -bool HasInstance(JSContext *context, JS::HandleObject type, - JS::MutableHandleValue vp, bool *success) { - JS::RootedObject global_object( - context, JS_GetGlobalForObject(context, type)); - DCHECK(global_object); - - JS::RootedObject prototype( - context, MozjsNumericTypesTestInterface::GetPrototype(context, global_object)); - - // |IsDelegate| walks the prototype chain of an object returning true if - // .prototype is found. - bool is_delegate; - if (!IsDelegate(context, prototype, vp, &is_delegate)) { - *success = false; - return false; - } - - *success = is_delegate; - return true; -} - -const JSClass instance_class_definition = { - "NumericTypesTestInterface", - 0 | JSCLASS_HAS_PRIVATE, - NULL, // addProperty - NULL, // delProperty - NULL, // getProperty - NULL, // setProperty - NULL, // enumerate - NULL, // resolve - NULL, // mayResolve - &WrapperPrivate::Finalizer, // finalize - NULL, // call - NULL, // hasInstance - NULL, // construct - &WrapperPrivate::Trace, // trace -}; - -const JSClass prototype_class_definition = { - "NumericTypesTestInterfacePrototype", -}; - -const JSClass interface_object_class_definition = { - "NumericTypesTestInterfaceConstructor", - 0, - NULL, // addProperty - NULL, // delProperty - NULL, // getProperty - NULL, // setProperty - NULL, // enumerate - NULL, // resolve - NULL, // mayResolve - NULL, // finalize - NULL, // call - &HasInstance, - NULL, -}; - -bool get_byteProperty( - JSContext* context, unsigned argc, JS::Value* vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<NumericTypesTestInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - NumericTypesTestInterface* impl = - wrapper_private->wrappable<NumericTypesTestInterface>().get(); - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->byte_property(), - &result_value); - } - if (!exception_state.is_exception_set()) { - args.rval().set(result_value); - } - return !exception_state.is_exception_set(); -} - -bool set_byteProperty( - JSContext* context, unsigned argc, JS::Value* vp) { - - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<NumericTypesTestInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - NumericTypesTestInterface* impl = - wrapper_private->wrappable<NumericTypesTestInterface>().get(); - TypeTraits<int8_t >::ConversionType value; - if (args.length() != 1) { - NOTREACHED(); - return false; - } - FromJSValue(context, args[0], kNoConversionFlags, &exception_state, - &value); - if (exception_state.is_exception_set()) { - return false; - } - - impl->set_byte_property(value); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - -bool get_octetProperty( - JSContext* context, unsigned argc, JS::Value* vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<NumericTypesTestInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - NumericTypesTestInterface* impl = - wrapper_private->wrappable<NumericTypesTestInterface>().get(); - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->octet_property(), - &result_value); - } - if (!exception_state.is_exception_set()) { - args.rval().set(result_value); - } - return !exception_state.is_exception_set(); -} - -bool set_octetProperty( - JSContext* context, unsigned argc, JS::Value* vp) { - - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<NumericTypesTestInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - NumericTypesTestInterface* impl = - wrapper_private->wrappable<NumericTypesTestInterface>().get(); - TypeTraits<uint8_t >::ConversionType value; - if (args.length() != 1) { - NOTREACHED(); - return false; - } - FromJSValue(context, args[0], kNoConversionFlags, &exception_state, - &value); - if (exception_state.is_exception_set()) { - return false; - } - - impl->set_octet_property(value); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - -bool get_shortProperty( - JSContext* context, unsigned argc, JS::Value* vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<NumericTypesTestInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - NumericTypesTestInterface* impl = - wrapper_private->wrappable<NumericTypesTestInterface>().get(); - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->short_property(), - &result_value); - } - if (!exception_state.is_exception_set()) { - args.rval().set(result_value); - } - return !exception_state.is_exception_set(); -} - -bool set_shortProperty( - JSContext* context, unsigned argc, JS::Value* vp) { - - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<NumericTypesTestInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - NumericTypesTestInterface* impl = - wrapper_private->wrappable<NumericTypesTestInterface>().get(); - TypeTraits<int16_t >::ConversionType value; - if (args.length() != 1) { - NOTREACHED(); - return false; - } - FromJSValue(context, args[0], kNoConversionFlags, &exception_state, - &value); - if (exception_state.is_exception_set()) { - return false; - } - - impl->set_short_property(value); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - -bool get_unsignedShortProperty( - JSContext* context, unsigned argc, JS::Value* vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<NumericTypesTestInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - NumericTypesTestInterface* impl = - wrapper_private->wrappable<NumericTypesTestInterface>().get(); - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->unsigned_short_property(), - &result_value); - } - if (!exception_state.is_exception_set()) { - args.rval().set(result_value); - } - return !exception_state.is_exception_set(); -} - -bool set_unsignedShortProperty( - JSContext* context, unsigned argc, JS::Value* vp) { - - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<NumericTypesTestInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - NumericTypesTestInterface* impl = - wrapper_private->wrappable<NumericTypesTestInterface>().get(); - TypeTraits<uint16_t >::ConversionType value; - if (args.length() != 1) { - NOTREACHED(); - return false; - } - FromJSValue(context, args[0], kNoConversionFlags, &exception_state, - &value); - if (exception_state.is_exception_set()) { - return false; - } - - impl->set_unsigned_short_property(value); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - -bool get_longProperty( - JSContext* context, unsigned argc, JS::Value* vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<NumericTypesTestInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - NumericTypesTestInterface* impl = - wrapper_private->wrappable<NumericTypesTestInterface>().get(); - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->long_property(), - &result_value); - } - if (!exception_state.is_exception_set()) { - args.rval().set(result_value); - } - return !exception_state.is_exception_set(); -} - -bool set_longProperty( - JSContext* context, unsigned argc, JS::Value* vp) { - - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<NumericTypesTestInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - NumericTypesTestInterface* impl = - wrapper_private->wrappable<NumericTypesTestInterface>().get(); - TypeTraits<int32_t >::ConversionType value; - if (args.length() != 1) { - NOTREACHED(); - return false; - } - FromJSValue(context, args[0], kNoConversionFlags, &exception_state, - &value); - if (exception_state.is_exception_set()) { - return false; - } - - impl->set_long_property(value); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - -bool get_unsignedLongProperty( - JSContext* context, unsigned argc, JS::Value* vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<NumericTypesTestInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - NumericTypesTestInterface* impl = - wrapper_private->wrappable<NumericTypesTestInterface>().get(); - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->unsigned_long_property(), - &result_value); - } - if (!exception_state.is_exception_set()) { - args.rval().set(result_value); - } - return !exception_state.is_exception_set(); -} - -bool set_unsignedLongProperty( - JSContext* context, unsigned argc, JS::Value* vp) { - - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<NumericTypesTestInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - NumericTypesTestInterface* impl = - wrapper_private->wrappable<NumericTypesTestInterface>().get(); - TypeTraits<uint32_t >::ConversionType value; - if (args.length() != 1) { - NOTREACHED(); - return false; - } - FromJSValue(context, args[0], kNoConversionFlags, &exception_state, - &value); - if (exception_state.is_exception_set()) { - return false; - } - - impl->set_unsigned_long_property(value); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - -bool get_longLongProperty( - JSContext* context, unsigned argc, JS::Value* vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<NumericTypesTestInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - NumericTypesTestInterface* impl = - wrapper_private->wrappable<NumericTypesTestInterface>().get(); - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->long_long_property(), - &result_value); - } - if (!exception_state.is_exception_set()) { - args.rval().set(result_value); - } - return !exception_state.is_exception_set(); -} - -bool set_longLongProperty( - JSContext* context, unsigned argc, JS::Value* vp) { - - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<NumericTypesTestInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - NumericTypesTestInterface* impl = - wrapper_private->wrappable<NumericTypesTestInterface>().get(); - TypeTraits<int64_t >::ConversionType value; - if (args.length() != 1) { - NOTREACHED(); - return false; - } - FromJSValue(context, args[0], kNoConversionFlags, &exception_state, - &value); - if (exception_state.is_exception_set()) { - return false; - } - - impl->set_long_long_property(value); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - -bool get_unsignedLongLongProperty( - JSContext* context, unsigned argc, JS::Value* vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<NumericTypesTestInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - NumericTypesTestInterface* impl = - wrapper_private->wrappable<NumericTypesTestInterface>().get(); - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->unsigned_long_long_property(), - &result_value); - } - if (!exception_state.is_exception_set()) { - args.rval().set(result_value); - } - return !exception_state.is_exception_set(); -} - -bool set_unsignedLongLongProperty( - JSContext* context, unsigned argc, JS::Value* vp) { - - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<NumericTypesTestInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - NumericTypesTestInterface* impl = - wrapper_private->wrappable<NumericTypesTestInterface>().get(); - TypeTraits<uint64_t >::ConversionType value; - if (args.length() != 1) { - NOTREACHED(); - return false; - } - FromJSValue(context, args[0], kNoConversionFlags, &exception_state, - &value); - if (exception_state.is_exception_set()) { - return false; - } - - impl->set_unsigned_long_long_property(value); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - -bool get_doubleProperty( - JSContext* context, unsigned argc, JS::Value* vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<NumericTypesTestInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - NumericTypesTestInterface* impl = - wrapper_private->wrappable<NumericTypesTestInterface>().get(); - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->double_property(), - &result_value); - } - if (!exception_state.is_exception_set()) { - args.rval().set(result_value); - } - return !exception_state.is_exception_set(); -} - -bool set_doubleProperty( - JSContext* context, unsigned argc, JS::Value* vp) { - - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<NumericTypesTestInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - NumericTypesTestInterface* impl = - wrapper_private->wrappable<NumericTypesTestInterface>().get(); - TypeTraits<double >::ConversionType value; - if (args.length() != 1) { - NOTREACHED(); - return false; - } - FromJSValue(context, args[0], (kConversionFlagRestricted), &exception_state, - &value); - if (exception_state.is_exception_set()) { - return false; - } - - impl->set_double_property(value); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - -bool get_unrestrictedDoubleProperty( - JSContext* context, unsigned argc, JS::Value* vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<NumericTypesTestInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - NumericTypesTestInterface* impl = - wrapper_private->wrappable<NumericTypesTestInterface>().get(); - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->unrestricted_double_property(), - &result_value); - } - if (!exception_state.is_exception_set()) { - args.rval().set(result_value); - } - return !exception_state.is_exception_set(); -} - -bool set_unrestrictedDoubleProperty( - JSContext* context, unsigned argc, JS::Value* vp) { - - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<NumericTypesTestInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - NumericTypesTestInterface* impl = - wrapper_private->wrappable<NumericTypesTestInterface>().get(); - TypeTraits<double >::ConversionType value; - if (args.length() != 1) { - NOTREACHED(); - return false; - } - FromJSValue(context, args[0], kNoConversionFlags, &exception_state, - &value); - if (exception_state.is_exception_set()) { - return false; - } - - impl->set_unrestricted_double_property(value); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - -bool fcn_byteArgumentOperation( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, &object)) { - NOTREACHED(); - return false; - } - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<NumericTypesTestInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - NumericTypesTestInterface* impl = - wrapper_private->wrappable<NumericTypesTestInterface>().get(); - const size_t kMinArguments = 1; - if (args.length() < kMinArguments) { - exception_state.SetSimpleException(script::kInvalidNumberOfArguments); - return false; - } - // Non-optional arguments - TypeTraits<int8_t >::ConversionType arg1; - - DCHECK_LT(0, args.length()); - JS::RootedValue non_optional_value0( - context, args[0]); - FromJSValue(context, - non_optional_value0, - kNoConversionFlags, - &exception_state, &arg1); - if (exception_state.is_exception_set()) { - return false; - } - - impl->ByteArgumentOperation(arg1); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - -bool fcn_byteReturnOperation( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, &object)) { - NOTREACHED(); - return false; - } - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<NumericTypesTestInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - NumericTypesTestInterface* impl = - wrapper_private->wrappable<NumericTypesTestInterface>().get(); - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->ByteReturnOperation(), - &result_value); - } - if (!exception_state.is_exception_set()) { - args.rval().set(result_value); - } - return !exception_state.is_exception_set(); -} - -bool fcn_doubleArgumentOperation( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, &object)) { - NOTREACHED(); - return false; - } - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<NumericTypesTestInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - NumericTypesTestInterface* impl = - wrapper_private->wrappable<NumericTypesTestInterface>().get(); - const size_t kMinArguments = 1; - if (args.length() < kMinArguments) { - exception_state.SetSimpleException(script::kInvalidNumberOfArguments); - return false; - } - // Non-optional arguments - TypeTraits<double >::ConversionType arg1; - - DCHECK_LT(0, args.length()); - JS::RootedValue non_optional_value0( - context, args[0]); - FromJSValue(context, - non_optional_value0, - (kConversionFlagRestricted), - &exception_state, &arg1); - if (exception_state.is_exception_set()) { - return false; - } - - impl->DoubleArgumentOperation(arg1); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - -bool fcn_doubleReturnOperation( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, &object)) { - NOTREACHED(); - return false; - } - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<NumericTypesTestInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - NumericTypesTestInterface* impl = - wrapper_private->wrappable<NumericTypesTestInterface>().get(); - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->DoubleReturnOperation(), - &result_value); - } - if (!exception_state.is_exception_set()) { - args.rval().set(result_value); - } - return !exception_state.is_exception_set(); -} - -bool fcn_longArgumentOperation( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, &object)) { - NOTREACHED(); - return false; - } - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<NumericTypesTestInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - NumericTypesTestInterface* impl = - wrapper_private->wrappable<NumericTypesTestInterface>().get(); - const size_t kMinArguments = 1; - if (args.length() < kMinArguments) { - exception_state.SetSimpleException(script::kInvalidNumberOfArguments); - return false; - } - // Non-optional arguments - TypeTraits<int32_t >::ConversionType arg1; - - DCHECK_LT(0, args.length()); - JS::RootedValue non_optional_value0( - context, args[0]); - FromJSValue(context, - non_optional_value0, - kNoConversionFlags, - &exception_state, &arg1); - if (exception_state.is_exception_set()) { - return false; - } - - impl->LongArgumentOperation(arg1); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - -bool fcn_longLongArgumentOperation( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, &object)) { - NOTREACHED(); - return false; - } - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<NumericTypesTestInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - NumericTypesTestInterface* impl = - wrapper_private->wrappable<NumericTypesTestInterface>().get(); - const size_t kMinArguments = 1; - if (args.length() < kMinArguments) { - exception_state.SetSimpleException(script::kInvalidNumberOfArguments); - return false; - } - // Non-optional arguments - TypeTraits<int64_t >::ConversionType arg1; - - DCHECK_LT(0, args.length()); - JS::RootedValue non_optional_value0( - context, args[0]); - FromJSValue(context, - non_optional_value0, - kNoConversionFlags, - &exception_state, &arg1); - if (exception_state.is_exception_set()) { - return false; - } - - impl->LongLongArgumentOperation(arg1); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - -bool fcn_longLongReturnOperation( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, &object)) { - NOTREACHED(); - return false; - } - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<NumericTypesTestInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - NumericTypesTestInterface* impl = - wrapper_private->wrappable<NumericTypesTestInterface>().get(); - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->LongLongReturnOperation(), - &result_value); - } - if (!exception_state.is_exception_set()) { - args.rval().set(result_value); - } - return !exception_state.is_exception_set(); -} - -bool fcn_longReturnOperation( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, &object)) { - NOTREACHED(); - return false; - } - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<NumericTypesTestInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - NumericTypesTestInterface* impl = - wrapper_private->wrappable<NumericTypesTestInterface>().get(); - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->LongReturnOperation(), - &result_value); - } - if (!exception_state.is_exception_set()) { - args.rval().set(result_value); - } - return !exception_state.is_exception_set(); -} - -bool fcn_octetArgumentOperation( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, &object)) { - NOTREACHED(); - return false; - } - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<NumericTypesTestInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - NumericTypesTestInterface* impl = - wrapper_private->wrappable<NumericTypesTestInterface>().get(); - const size_t kMinArguments = 1; - if (args.length() < kMinArguments) { - exception_state.SetSimpleException(script::kInvalidNumberOfArguments); - return false; - } - // Non-optional arguments - TypeTraits<uint8_t >::ConversionType arg1; - - DCHECK_LT(0, args.length()); - JS::RootedValue non_optional_value0( - context, args[0]); - FromJSValue(context, - non_optional_value0, - kNoConversionFlags, - &exception_state, &arg1); - if (exception_state.is_exception_set()) { - return false; - } - - impl->OctetArgumentOperation(arg1); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - -bool fcn_octetReturnOperation( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, &object)) { - NOTREACHED(); - return false; - } - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<NumericTypesTestInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - NumericTypesTestInterface* impl = - wrapper_private->wrappable<NumericTypesTestInterface>().get(); - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->OctetReturnOperation(), - &result_value); - } - if (!exception_state.is_exception_set()) { - args.rval().set(result_value); - } - return !exception_state.is_exception_set(); -} - -bool fcn_shortArgumentOperation( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, &object)) { - NOTREACHED(); - return false; - } - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<NumericTypesTestInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - NumericTypesTestInterface* impl = - wrapper_private->wrappable<NumericTypesTestInterface>().get(); - const size_t kMinArguments = 1; - if (args.length() < kMinArguments) { - exception_state.SetSimpleException(script::kInvalidNumberOfArguments); - return false; - } - // Non-optional arguments - TypeTraits<int16_t >::ConversionType arg1; - - DCHECK_LT(0, args.length()); - JS::RootedValue non_optional_value0( - context, args[0]); - FromJSValue(context, - non_optional_value0, - kNoConversionFlags, - &exception_state, &arg1); - if (exception_state.is_exception_set()) { - return false; - } - - impl->ShortArgumentOperation(arg1); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - -bool fcn_shortReturnOperation( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, &object)) { - NOTREACHED(); - return false; - } - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<NumericTypesTestInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - NumericTypesTestInterface* impl = - wrapper_private->wrappable<NumericTypesTestInterface>().get(); - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->ShortReturnOperation(), - &result_value); - } - if (!exception_state.is_exception_set()) { - args.rval().set(result_value); - } - return !exception_state.is_exception_set(); -} - -bool fcn_unrestrictedDoubleArgumentOperation( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, &object)) { - NOTREACHED(); - return false; - } - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<NumericTypesTestInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - NumericTypesTestInterface* impl = - wrapper_private->wrappable<NumericTypesTestInterface>().get(); - const size_t kMinArguments = 1; - if (args.length() < kMinArguments) { - exception_state.SetSimpleException(script::kInvalidNumberOfArguments); - return false; - } - // Non-optional arguments - TypeTraits<double >::ConversionType arg1; - - DCHECK_LT(0, args.length()); - JS::RootedValue non_optional_value0( - context, args[0]); - FromJSValue(context, - non_optional_value0, - kNoConversionFlags, - &exception_state, &arg1); - if (exception_state.is_exception_set()) { - return false; - } - - impl->UnrestrictedDoubleArgumentOperation(arg1); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - -bool fcn_unrestrictedDoubleReturnOperation( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, &object)) { - NOTREACHED(); - return false; - } - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<NumericTypesTestInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - NumericTypesTestInterface* impl = - wrapper_private->wrappable<NumericTypesTestInterface>().get(); - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->UnrestrictedDoubleReturnOperation(), - &result_value); - } - if (!exception_state.is_exception_set()) { - args.rval().set(result_value); - } - return !exception_state.is_exception_set(); -} - -bool fcn_unsignedLongArgumentOperation( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, &object)) { - NOTREACHED(); - return false; - } - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<NumericTypesTestInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - NumericTypesTestInterface* impl = - wrapper_private->wrappable<NumericTypesTestInterface>().get(); - const size_t kMinArguments = 1; - if (args.length() < kMinArguments) { - exception_state.SetSimpleException(script::kInvalidNumberOfArguments); - return false; - } - // Non-optional arguments - TypeTraits<uint32_t >::ConversionType arg1; - - DCHECK_LT(0, args.length()); - JS::RootedValue non_optional_value0( - context, args[0]); - FromJSValue(context, - non_optional_value0, - kNoConversionFlags, - &exception_state, &arg1); - if (exception_state.is_exception_set()) { - return false; - } - - impl->UnsignedLongArgumentOperation(arg1); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - -bool fcn_unsignedLongLongArgumentOperation( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, &object)) { - NOTREACHED(); - return false; - } - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<NumericTypesTestInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - NumericTypesTestInterface* impl = - wrapper_private->wrappable<NumericTypesTestInterface>().get(); - const size_t kMinArguments = 1; - if (args.length() < kMinArguments) { - exception_state.SetSimpleException(script::kInvalidNumberOfArguments); - return false; - } - // Non-optional arguments - TypeTraits<uint64_t >::ConversionType arg1; - - DCHECK_LT(0, args.length()); - JS::RootedValue non_optional_value0( - context, args[0]); - FromJSValue(context, - non_optional_value0, - kNoConversionFlags, - &exception_state, &arg1); - if (exception_state.is_exception_set()) { - return false; - } - - impl->UnsignedLongLongArgumentOperation(arg1); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - -bool fcn_unsignedLongLongReturnOperation( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, &object)) { - NOTREACHED(); - return false; - } - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<NumericTypesTestInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - NumericTypesTestInterface* impl = - wrapper_private->wrappable<NumericTypesTestInterface>().get(); - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->UnsignedLongLongReturnOperation(), - &result_value); - } - if (!exception_state.is_exception_set()) { - args.rval().set(result_value); - } - return !exception_state.is_exception_set(); -} - -bool fcn_unsignedLongReturnOperation( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, &object)) { - NOTREACHED(); - return false; - } - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<NumericTypesTestInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - NumericTypesTestInterface* impl = - wrapper_private->wrappable<NumericTypesTestInterface>().get(); - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->UnsignedLongReturnOperation(), - &result_value); - } - if (!exception_state.is_exception_set()) { - args.rval().set(result_value); - } - return !exception_state.is_exception_set(); -} - -bool fcn_unsignedShortArgumentOperation( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, &object)) { - NOTREACHED(); - return false; - } - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<NumericTypesTestInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - NumericTypesTestInterface* impl = - wrapper_private->wrappable<NumericTypesTestInterface>().get(); - const size_t kMinArguments = 1; - if (args.length() < kMinArguments) { - exception_state.SetSimpleException(script::kInvalidNumberOfArguments); - return false; - } - // Non-optional arguments - TypeTraits<uint16_t >::ConversionType arg1; - - DCHECK_LT(0, args.length()); - JS::RootedValue non_optional_value0( - context, args[0]); - FromJSValue(context, - non_optional_value0, - kNoConversionFlags, - &exception_state, &arg1); - if (exception_state.is_exception_set()) { - return false; - } - - impl->UnsignedShortArgumentOperation(arg1); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - -bool fcn_unsignedShortReturnOperation( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, &object)) { - NOTREACHED(); - return false; - } - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<NumericTypesTestInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - NumericTypesTestInterface* impl = - wrapper_private->wrappable<NumericTypesTestInterface>().get(); - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->UnsignedShortReturnOperation(), - &result_value); - } - if (!exception_state.is_exception_set()) { - args.rval().set(result_value); - } - return !exception_state.is_exception_set(); -} - - - -const JSPropertySpec prototype_properties[] = { - { // Read/Write property - "byteProperty", - JSPROP_SHARED | JSPROP_ENUMERATE, - { { &get_byteProperty, NULL } }, - { { &set_byteProperty, NULL } }, - }, - { // Read/Write property - "octetProperty", - JSPROP_SHARED | JSPROP_ENUMERATE, - { { &get_octetProperty, NULL } }, - { { &set_octetProperty, NULL } }, - }, - { // Read/Write property - "shortProperty", - JSPROP_SHARED | JSPROP_ENUMERATE, - { { &get_shortProperty, NULL } }, - { { &set_shortProperty, NULL } }, - }, - { // Read/Write property - "unsignedShortProperty", - JSPROP_SHARED | JSPROP_ENUMERATE, - { { &get_unsignedShortProperty, NULL } }, - { { &set_unsignedShortProperty, NULL } }, - }, - { // Read/Write property - "longProperty", - JSPROP_SHARED | JSPROP_ENUMERATE, - { { &get_longProperty, NULL } }, - { { &set_longProperty, NULL } }, - }, - { // Read/Write property - "unsignedLongProperty", - JSPROP_SHARED | JSPROP_ENUMERATE, - { { &get_unsignedLongProperty, NULL } }, - { { &set_unsignedLongProperty, NULL } }, - }, - { // Read/Write property - "longLongProperty", - JSPROP_SHARED | JSPROP_ENUMERATE, - { { &get_longLongProperty, NULL } }, - { { &set_longLongProperty, NULL } }, - }, - { // Read/Write property - "unsignedLongLongProperty", - JSPROP_SHARED | JSPROP_ENUMERATE, - { { &get_unsignedLongLongProperty, NULL } }, - { { &set_unsignedLongLongProperty, NULL } }, - }, - { // Read/Write property - "doubleProperty", - JSPROP_SHARED | JSPROP_ENUMERATE, - { { &get_doubleProperty, NULL } }, - { { &set_doubleProperty, NULL } }, - }, - { // Read/Write property - "unrestrictedDoubleProperty", - JSPROP_SHARED | JSPROP_ENUMERATE, - { { &get_unrestrictedDoubleProperty, NULL } }, - { { &set_unrestrictedDoubleProperty, NULL } }, - }, - JS_PS_END -}; - -const JSFunctionSpec prototype_functions[] = { - JS_FNSPEC( - "byteArgumentOperation", fcn_byteArgumentOperation, NULL, - 1, JSPROP_ENUMERATE, NULL), - JS_FNSPEC( - "byteReturnOperation", fcn_byteReturnOperation, NULL, - 0, JSPROP_ENUMERATE, NULL), - JS_FNSPEC( - "doubleArgumentOperation", fcn_doubleArgumentOperation, NULL, - 1, JSPROP_ENUMERATE, NULL), - JS_FNSPEC( - "doubleReturnOperation", fcn_doubleReturnOperation, NULL, - 0, JSPROP_ENUMERATE, NULL), - JS_FNSPEC( - "longArgumentOperation", fcn_longArgumentOperation, NULL, - 1, JSPROP_ENUMERATE, NULL), - JS_FNSPEC( - "longLongArgumentOperation", fcn_longLongArgumentOperation, NULL, - 1, JSPROP_ENUMERATE, NULL), - JS_FNSPEC( - "longLongReturnOperation", fcn_longLongReturnOperation, NULL, - 0, JSPROP_ENUMERATE, NULL), - JS_FNSPEC( - "longReturnOperation", fcn_longReturnOperation, NULL, - 0, JSPROP_ENUMERATE, NULL), - JS_FNSPEC( - "octetArgumentOperation", fcn_octetArgumentOperation, NULL, - 1, JSPROP_ENUMERATE, NULL), - JS_FNSPEC( - "octetReturnOperation", fcn_octetReturnOperation, NULL, - 0, JSPROP_ENUMERATE, NULL), - JS_FNSPEC( - "shortArgumentOperation", fcn_shortArgumentOperation, NULL, - 1, JSPROP_ENUMERATE, NULL), - JS_FNSPEC( - "shortReturnOperation", fcn_shortReturnOperation, NULL, - 0, JSPROP_ENUMERATE, NULL), - JS_FNSPEC( - "unrestrictedDoubleArgumentOperation", fcn_unrestrictedDoubleArgumentOperation, NULL, - 1, JSPROP_ENUMERATE, NULL), - JS_FNSPEC( - "unrestrictedDoubleReturnOperation", fcn_unrestrictedDoubleReturnOperation, NULL, - 0, JSPROP_ENUMERATE, NULL), - JS_FNSPEC( - "unsignedLongArgumentOperation", fcn_unsignedLongArgumentOperation, NULL, - 1, JSPROP_ENUMERATE, NULL), - JS_FNSPEC( - "unsignedLongLongArgumentOperation", fcn_unsignedLongLongArgumentOperation, NULL, - 1, JSPROP_ENUMERATE, NULL), - JS_FNSPEC( - "unsignedLongLongReturnOperation", fcn_unsignedLongLongReturnOperation, NULL, - 0, JSPROP_ENUMERATE, NULL), - JS_FNSPEC( - "unsignedLongReturnOperation", fcn_unsignedLongReturnOperation, NULL, - 0, JSPROP_ENUMERATE, NULL), - JS_FNSPEC( - "unsignedShortArgumentOperation", fcn_unsignedShortArgumentOperation, NULL, - 1, JSPROP_ENUMERATE, NULL), - JS_FNSPEC( - "unsignedShortReturnOperation", fcn_unsignedShortReturnOperation, NULL, - 0, JSPROP_ENUMERATE, NULL), - JS_FS_END -}; - -const JSPropertySpec interface_object_properties[] = { - JS_PS_END -}; - -const JSFunctionSpec interface_object_functions[] = { - JS_FS_END -}; - -const JSPropertySpec own_properties[] = { - JS_PS_END -}; - -void InitializePrototypeAndInterfaceObject( - InterfaceData* interface_data, JSContext* context, - JS::HandleObject global_object) { - DCHECK(!interface_data->prototype); - DCHECK(!interface_data->interface_object); - DCHECK(JS_IsGlobalObject(global_object)); - - JS::RootedObject parent_prototype( - context, JS_GetObjectPrototype(context, global_object)); - DCHECK(parent_prototype); - - interface_data->prototype = JS_NewObjectWithGivenProto( - context, &prototype_class_definition, parent_prototype - ); - - JS::RootedObject rooted_prototype(context, interface_data->prototype); - bool success = JS_DefineProperties( - context, - rooted_prototype, - prototype_properties); - - DCHECK(success); - success = JS_DefineFunctions( - context, rooted_prototype, prototype_functions); - DCHECK(success); - - JS::RootedObject function_prototype( - context, JS_GetFunctionPrototype(context, global_object)); - DCHECK(function_prototype); - // Create the Interface object. - interface_data->interface_object = JS_NewObjectWithGivenProto( - context, &interface_object_class_definition, - function_prototype); - - // Add the InterfaceObject.name property. - JS::RootedObject rooted_interface_object( - context, interface_data->interface_object); - JS::RootedValue name_value(context); - const char name[] = - "NumericTypesTestInterface"; - name_value.setString(JS_NewStringCopyZ(context, name)); - success = JS_DefineProperty( - context, rooted_interface_object, "name", name_value, JSPROP_READONLY, - NULL, NULL); - DCHECK(success); - - // Define interface object properties (including constants). - success = JS_DefineProperties(context, rooted_interface_object, - interface_object_properties); - DCHECK(success); - // Define interface object functions (static). - success = JS_DefineFunctions(context, rooted_interface_object, - interface_object_functions); - DCHECK(success); - - // Set the Prototype.constructor and Constructor.prototype properties. - DCHECK(interface_data->interface_object); - DCHECK(interface_data->prototype); - success = JS_LinkConstructorAndPrototype( - context, - rooted_interface_object, - rooted_prototype); - DCHECK(success); -} - -InterfaceData* GetInterfaceData(JSContext* context) { - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - // Use the address of the properties definition for this interface as a - // unique key for looking up the InterfaceData for this interface. - intptr_t key = reinterpret_cast<intptr_t>(&own_properties); - InterfaceData* interface_data = global_environment->GetInterfaceData(key); - if (!interface_data) { - interface_data = new InterfaceData(); - DCHECK(interface_data); - global_environment->CacheInterfaceData(key, interface_data); - DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key)); - } - return interface_data; -} - -} // namespace - -// static -JSObject* MozjsNumericTypesTestInterface::CreateProxy( - JSContext* context, const scoped_refptr<Wrappable>& wrappable) { - DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); - JS::RootedObject global_object( - context, - MozjsGlobalEnvironment::GetFromContext(context)->global_object()); - DCHECK(global_object); - - InterfaceData* interface_data = GetInterfaceData(context); - JS::RootedObject prototype(context, GetPrototype(context, global_object)); - DCHECK(prototype); - JS::RootedObject new_object( - context, - JS_NewObjectWithGivenProto( - context, &instance_class_definition, prototype)); - DCHECK(new_object); - JS::RootedObject proxy(context, - ProxyHandler::NewProxy( - context, proxy_handler.Pointer(), new_object, prototype)); - WrapperPrivate::AddPrivateData(context, proxy, wrappable); - return proxy; -} - -// static -const JSClass* MozjsNumericTypesTestInterface::PrototypeClass( - JSContext* context) { - DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); - JS::RootedObject global_object( - context, - MozjsGlobalEnvironment::GetFromContext(context)->global_object()); - DCHECK(global_object); - - JS::RootedObject prototype(context, GetPrototype(context, global_object)); - const JSClass* proto_class = JS_GetClass(prototype); - return proto_class; -} - -// static -JSObject* MozjsNumericTypesTestInterface::GetPrototype( - JSContext* context, JS::HandleObject global_object) { - DCHECK(JS_IsGlobalObject(global_object)); - - InterfaceData* interface_data = GetInterfaceData(context); - if (!interface_data->prototype) { - // Create new prototype that has all the props and methods - InitializePrototypeAndInterfaceObject( - interface_data, context, global_object); - } - DCHECK(interface_data->prototype); - return interface_data->prototype; -} - -// static -JSObject* MozjsNumericTypesTestInterface::GetInterfaceObject( - JSContext* context, JS::HandleObject global_object) { - DCHECK(JS_IsGlobalObject(global_object)); - - InterfaceData* interface_data = GetInterfaceData(context); - if (!interface_data->interface_object) { - InitializePrototypeAndInterfaceObject( - interface_data, context, global_object); - } - DCHECK(interface_data->interface_object); - return interface_data->interface_object; -} - - -namespace { -} // namespace - - -} // namespace testing -} // namespace bindings -} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsNumericTypesTestInterface.h b/src/cobalt/bindings/generated/mozjs-45/testing/MozjsNumericTypesTestInterface.h deleted file mode 100644 index 5923c83..0000000 --- a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsNumericTypesTestInterface.h +++ /dev/null
@@ -1,54 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! -// Auto-generated from template: bindings/mozjs-45/templates/interface.h.template - -// clang-format off - -#ifndef MozjsNumericTypesTestInterface_h -#define MozjsNumericTypesTestInterface_h - -#include "base/hash_tables.h" -#include "base/lazy_instance.h" -#include "base/memory/ref_counted.h" -#include "base/threading/thread_checker.h" -#include "cobalt/base/polymorphic_downcast.h" -#include "cobalt/script/wrappable.h" -#include "cobalt/bindings/testing/numeric_types_test_interface.h" - -#include "third_party/mozjs-45/js/src/jsapi.h" - -namespace cobalt { -namespace bindings { -namespace testing { - -class MozjsNumericTypesTestInterface { - public: - static JSObject* CreateProxy(JSContext* context, - const scoped_refptr<script::Wrappable>& wrappable); - static const JSClass* PrototypeClass(JSContext* context); - static JSObject* GetPrototype(JSContext* context, - JS::HandleObject global_object); - static JSObject* GetInterfaceObject(JSContext* context, - JS::HandleObject global_object); -}; - -} // namespace bindings -} // namespace testing -} // namespace cobalt - -#endif // MozjsNumericTypesTestInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsObjectTypeBindingsInterface.cc b/src/cobalt/bindings/generated/mozjs-45/testing/MozjsObjectTypeBindingsInterface.cc deleted file mode 100644 index a4d0f79..0000000 --- a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsObjectTypeBindingsInterface.cc +++ /dev/null
@@ -1,633 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! -// Auto-generated from template: bindings/mozjs-45/templates/interface.cc.template - -// clang-format off - -#include "MozjsObjectTypeBindingsInterface.h" - -#include "base/debug/trace_event.h" -#include "cobalt/base/polymorphic_downcast.h" -#include "cobalt/script/global_environment.h" -#include "cobalt/script/opaque_handle.h" -#include "cobalt/script/script_object.h" -#include "MozjsArbitraryInterface.h" -#include "MozjsBaseInterface.h" -#include "MozjsDerivedInterface.h" -#include "cobalt/bindings/testing/arbitrary_interface.h" -#include "cobalt/bindings/testing/base_interface.h" -#include "cobalt/bindings/testing/derived_interface.h" - -#include "base/lazy_instance.h" -#include "cobalt/script/mozjs-45/callback_function_conversion.h" -#include "cobalt/script/exception_state.h" -#include "cobalt/script/mozjs-45/conversion_helpers.h" -#include "cobalt/script/mozjs-45/mozjs_exception_state.h" -#include "cobalt/script/mozjs-45/mozjs_callback_function.h" -#include "cobalt/script/mozjs-45/mozjs_global_environment.h" -#include "cobalt/script/mozjs-45/mozjs_object_handle.h" -#include "cobalt/script/mozjs-45/mozjs_property_enumerator.h" -#include "cobalt/script/mozjs-45/mozjs_user_object_holder.h" -#include "cobalt/script/mozjs-45/proxy_handler.h" -#include "cobalt/script/mozjs-45/type_traits.h" -#include "cobalt/script/mozjs-45/wrapper_factory.h" -#include "cobalt/script/mozjs-45/wrapper_private.h" -#include "cobalt/script/property_enumerator.h" -#include "third_party/mozjs-45/js/src/jsapi.h" -#include "third_party/mozjs-45/js/src/jsfriendapi.h" - -namespace { -using cobalt::bindings::testing::ObjectTypeBindingsInterface; -using cobalt::bindings::testing::MozjsObjectTypeBindingsInterface; -using cobalt::bindings::testing::ArbitraryInterface; -using cobalt::bindings::testing::BaseInterface; -using cobalt::bindings::testing::DerivedInterface; -using cobalt::bindings::testing::MozjsArbitraryInterface; -using cobalt::bindings::testing::MozjsBaseInterface; -using cobalt::bindings::testing::MozjsDerivedInterface; -using cobalt::script::CallbackInterfaceTraits; -using cobalt::script::GlobalEnvironment; -using cobalt::script::OpaqueHandle; -using cobalt::script::OpaqueHandleHolder; -using cobalt::script::ScriptObject; -using cobalt::script::Wrappable; - -using cobalt::script::CallbackFunction; -using cobalt::script::CallbackInterfaceTraits; -using cobalt::script::ExceptionState; -using cobalt::script::mozjs::FromJSValue; -using cobalt::script::mozjs::kConversionFlagNullable; -using cobalt::script::mozjs::kConversionFlagRestricted; -using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString; -using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString; -using cobalt::script::mozjs::kNoConversionFlags; -using cobalt::script::mozjs::InterfaceData; -using cobalt::script::mozjs::MozjsCallbackFunction; -using cobalt::script::mozjs::MozjsExceptionState; -using cobalt::script::mozjs::MozjsGlobalEnvironment; -using cobalt::script::mozjs::MozjsUserObjectHolder; -using cobalt::script::mozjs::MozjsPropertyEnumerator; -using cobalt::script::mozjs::ProxyHandler; -using cobalt::script::mozjs::ToJSValue; -using cobalt::script::mozjs::TypeTraits; -using cobalt::script::mozjs::WrapperPrivate; -using cobalt::script::mozjs::WrapperFactory; -using cobalt::script::Wrappable; -} // namespace - -namespace cobalt { -namespace bindings { -namespace testing { - -namespace { - -class MozjsObjectTypeBindingsInterfaceHandler : public ProxyHandler { - public: - MozjsObjectTypeBindingsInterfaceHandler() - : ProxyHandler(indexed_property_hooks, named_property_hooks) {} - - private: - static NamedPropertyHooks named_property_hooks; - static IndexedPropertyHooks indexed_property_hooks; -}; - -ProxyHandler::NamedPropertyHooks -MozjsObjectTypeBindingsInterfaceHandler::named_property_hooks = { - NULL, - NULL, - NULL, - NULL, - NULL, -}; -ProxyHandler::IndexedPropertyHooks -MozjsObjectTypeBindingsInterfaceHandler::indexed_property_hooks = { - NULL, - NULL, - NULL, - NULL, - NULL, -}; - -static base::LazyInstance<MozjsObjectTypeBindingsInterfaceHandler> - proxy_handler; - -bool HasInstance(JSContext *context, JS::HandleObject type, - JS::MutableHandleValue vp, bool *success) { - JS::RootedObject global_object( - context, JS_GetGlobalForObject(context, type)); - DCHECK(global_object); - - JS::RootedObject prototype( - context, MozjsObjectTypeBindingsInterface::GetPrototype(context, global_object)); - - // |IsDelegate| walks the prototype chain of an object returning true if - // .prototype is found. - bool is_delegate; - if (!IsDelegate(context, prototype, vp, &is_delegate)) { - *success = false; - return false; - } - - *success = is_delegate; - return true; -} - -const JSClass instance_class_definition = { - "ObjectTypeBindingsInterface", - 0 | JSCLASS_HAS_PRIVATE, - NULL, // addProperty - NULL, // delProperty - NULL, // getProperty - NULL, // setProperty - NULL, // enumerate - NULL, // resolve - NULL, // mayResolve - &WrapperPrivate::Finalizer, // finalize - NULL, // call - NULL, // hasInstance - NULL, // construct - &WrapperPrivate::Trace, // trace -}; - -const JSClass prototype_class_definition = { - "ObjectTypeBindingsInterfacePrototype", -}; - -const JSClass interface_object_class_definition = { - "ObjectTypeBindingsInterfaceConstructor", - 0, - NULL, // addProperty - NULL, // delProperty - NULL, // getProperty - NULL, // setProperty - NULL, // enumerate - NULL, // resolve - NULL, // mayResolve - NULL, // finalize - NULL, // call - &HasInstance, - NULL, -}; - -bool get_arbitraryObject( - JSContext* context, unsigned argc, JS::Value* vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<ObjectTypeBindingsInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - ObjectTypeBindingsInterface* impl = - wrapper_private->wrappable<ObjectTypeBindingsInterface>().get(); - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->arbitrary_object(), - &result_value); - } - if (!exception_state.is_exception_set()) { - args.rval().set(result_value); - } - return !exception_state.is_exception_set(); -} - -bool set_arbitraryObject( - JSContext* context, unsigned argc, JS::Value* vp) { - - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<ObjectTypeBindingsInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - ObjectTypeBindingsInterface* impl = - wrapper_private->wrappable<ObjectTypeBindingsInterface>().get(); - TypeTraits<scoped_refptr<ArbitraryInterface> >::ConversionType value; - if (args.length() != 1) { - NOTREACHED(); - return false; - } - FromJSValue(context, args[0], kNoConversionFlags, &exception_state, - &value); - if (exception_state.is_exception_set()) { - return false; - } - - impl->set_arbitrary_object(value); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - -bool get_baseInterface( - JSContext* context, unsigned argc, JS::Value* vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<ObjectTypeBindingsInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - ObjectTypeBindingsInterface* impl = - wrapper_private->wrappable<ObjectTypeBindingsInterface>().get(); - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->base_interface(), - &result_value); - } - if (!exception_state.is_exception_set()) { - args.rval().set(result_value); - } - return !exception_state.is_exception_set(); -} - - -bool get_derivedInterface( - JSContext* context, unsigned argc, JS::Value* vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<ObjectTypeBindingsInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - ObjectTypeBindingsInterface* impl = - wrapper_private->wrappable<ObjectTypeBindingsInterface>().get(); - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->derived_interface(), - &result_value); - } - if (!exception_state.is_exception_set()) { - args.rval().set(result_value); - } - return !exception_state.is_exception_set(); -} - -bool set_derivedInterface( - JSContext* context, unsigned argc, JS::Value* vp) { - - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<ObjectTypeBindingsInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - ObjectTypeBindingsInterface* impl = - wrapper_private->wrappable<ObjectTypeBindingsInterface>().get(); - TypeTraits<scoped_refptr<DerivedInterface> >::ConversionType value; - if (args.length() != 1) { - NOTREACHED(); - return false; - } - FromJSValue(context, args[0], kNoConversionFlags, &exception_state, - &value); - if (exception_state.is_exception_set()) { - return false; - } - - impl->set_derived_interface(value); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - -bool get_objectProperty( - JSContext* context, unsigned argc, JS::Value* vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<ObjectTypeBindingsInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - ObjectTypeBindingsInterface* impl = - wrapper_private->wrappable<ObjectTypeBindingsInterface>().get(); - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->object_property(), - &result_value); - } - if (!exception_state.is_exception_set()) { - args.rval().set(result_value); - } - return !exception_state.is_exception_set(); -} - -bool set_objectProperty( - JSContext* context, unsigned argc, JS::Value* vp) { - - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<ObjectTypeBindingsInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - ObjectTypeBindingsInterface* impl = - wrapper_private->wrappable<ObjectTypeBindingsInterface>().get(); - TypeTraits<OpaqueHandle >::ConversionType value; - if (args.length() != 1) { - NOTREACHED(); - return false; - } - FromJSValue(context, args[0], (kConversionFlagNullable), &exception_state, - &value); - if (exception_state.is_exception_set()) { - return false; - } - - impl->set_object_property(value); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - - - -const JSPropertySpec prototype_properties[] = { - { // Read/Write property - "arbitraryObject", - JSPROP_SHARED | JSPROP_ENUMERATE, - { { &get_arbitraryObject, NULL } }, - { { &set_arbitraryObject, NULL } }, - }, - { // Readonly attribute - "baseInterface", - JSPROP_SHARED | JSPROP_ENUMERATE, - { { &get_baseInterface, NULL } }, - JSNATIVE_WRAPPER(NULL), - }, - { // Read/Write property - "derivedInterface", - JSPROP_SHARED | JSPROP_ENUMERATE, - { { &get_derivedInterface, NULL } }, - { { &set_derivedInterface, NULL } }, - }, - { // Read/Write property - "objectProperty", - JSPROP_SHARED | JSPROP_ENUMERATE, - { { &get_objectProperty, NULL } }, - { { &set_objectProperty, NULL } }, - }, - JS_PS_END -}; - -const JSFunctionSpec prototype_functions[] = { - JS_FS_END -}; - -const JSPropertySpec interface_object_properties[] = { - JS_PS_END -}; - -const JSFunctionSpec interface_object_functions[] = { - JS_FS_END -}; - -const JSPropertySpec own_properties[] = { - JS_PS_END -}; - -void InitializePrototypeAndInterfaceObject( - InterfaceData* interface_data, JSContext* context, - JS::HandleObject global_object) { - DCHECK(!interface_data->prototype); - DCHECK(!interface_data->interface_object); - DCHECK(JS_IsGlobalObject(global_object)); - - JS::RootedObject parent_prototype( - context, JS_GetObjectPrototype(context, global_object)); - DCHECK(parent_prototype); - - interface_data->prototype = JS_NewObjectWithGivenProto( - context, &prototype_class_definition, parent_prototype - ); - - JS::RootedObject rooted_prototype(context, interface_data->prototype); - bool success = JS_DefineProperties( - context, - rooted_prototype, - prototype_properties); - - DCHECK(success); - success = JS_DefineFunctions( - context, rooted_prototype, prototype_functions); - DCHECK(success); - - JS::RootedObject function_prototype( - context, JS_GetFunctionPrototype(context, global_object)); - DCHECK(function_prototype); - // Create the Interface object. - interface_data->interface_object = JS_NewObjectWithGivenProto( - context, &interface_object_class_definition, - function_prototype); - - // Add the InterfaceObject.name property. - JS::RootedObject rooted_interface_object( - context, interface_data->interface_object); - JS::RootedValue name_value(context); - const char name[] = - "ObjectTypeBindingsInterface"; - name_value.setString(JS_NewStringCopyZ(context, name)); - success = JS_DefineProperty( - context, rooted_interface_object, "name", name_value, JSPROP_READONLY, - NULL, NULL); - DCHECK(success); - - // Define interface object properties (including constants). - success = JS_DefineProperties(context, rooted_interface_object, - interface_object_properties); - DCHECK(success); - // Define interface object functions (static). - success = JS_DefineFunctions(context, rooted_interface_object, - interface_object_functions); - DCHECK(success); - - // Set the Prototype.constructor and Constructor.prototype properties. - DCHECK(interface_data->interface_object); - DCHECK(interface_data->prototype); - success = JS_LinkConstructorAndPrototype( - context, - rooted_interface_object, - rooted_prototype); - DCHECK(success); -} - -InterfaceData* GetInterfaceData(JSContext* context) { - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - // Use the address of the properties definition for this interface as a - // unique key for looking up the InterfaceData for this interface. - intptr_t key = reinterpret_cast<intptr_t>(&own_properties); - InterfaceData* interface_data = global_environment->GetInterfaceData(key); - if (!interface_data) { - interface_data = new InterfaceData(); - DCHECK(interface_data); - global_environment->CacheInterfaceData(key, interface_data); - DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key)); - } - return interface_data; -} - -} // namespace - -// static -JSObject* MozjsObjectTypeBindingsInterface::CreateProxy( - JSContext* context, const scoped_refptr<Wrappable>& wrappable) { - DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); - JS::RootedObject global_object( - context, - MozjsGlobalEnvironment::GetFromContext(context)->global_object()); - DCHECK(global_object); - - InterfaceData* interface_data = GetInterfaceData(context); - JS::RootedObject prototype(context, GetPrototype(context, global_object)); - DCHECK(prototype); - JS::RootedObject new_object( - context, - JS_NewObjectWithGivenProto( - context, &instance_class_definition, prototype)); - DCHECK(new_object); - JS::RootedObject proxy(context, - ProxyHandler::NewProxy( - context, proxy_handler.Pointer(), new_object, prototype)); - WrapperPrivate::AddPrivateData(context, proxy, wrappable); - return proxy; -} - -// static -const JSClass* MozjsObjectTypeBindingsInterface::PrototypeClass( - JSContext* context) { - DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); - JS::RootedObject global_object( - context, - MozjsGlobalEnvironment::GetFromContext(context)->global_object()); - DCHECK(global_object); - - JS::RootedObject prototype(context, GetPrototype(context, global_object)); - const JSClass* proto_class = JS_GetClass(prototype); - return proto_class; -} - -// static -JSObject* MozjsObjectTypeBindingsInterface::GetPrototype( - JSContext* context, JS::HandleObject global_object) { - DCHECK(JS_IsGlobalObject(global_object)); - - InterfaceData* interface_data = GetInterfaceData(context); - if (!interface_data->prototype) { - // Create new prototype that has all the props and methods - InitializePrototypeAndInterfaceObject( - interface_data, context, global_object); - } - DCHECK(interface_data->prototype); - return interface_data->prototype; -} - -// static -JSObject* MozjsObjectTypeBindingsInterface::GetInterfaceObject( - JSContext* context, JS::HandleObject global_object) { - DCHECK(JS_IsGlobalObject(global_object)); - - InterfaceData* interface_data = GetInterfaceData(context); - if (!interface_data->interface_object) { - InitializePrototypeAndInterfaceObject( - interface_data, context, global_object); - } - DCHECK(interface_data->interface_object); - return interface_data->interface_object; -} - - -namespace { -} // namespace - - -} // namespace testing -} // namespace bindings -} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsObjectTypeBindingsInterface.h b/src/cobalt/bindings/generated/mozjs-45/testing/MozjsObjectTypeBindingsInterface.h deleted file mode 100644 index 001e9bb..0000000 --- a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsObjectTypeBindingsInterface.h +++ /dev/null
@@ -1,54 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! -// Auto-generated from template: bindings/mozjs-45/templates/interface.h.template - -// clang-format off - -#ifndef MozjsObjectTypeBindingsInterface_h -#define MozjsObjectTypeBindingsInterface_h - -#include "base/hash_tables.h" -#include "base/lazy_instance.h" -#include "base/memory/ref_counted.h" -#include "base/threading/thread_checker.h" -#include "cobalt/base/polymorphic_downcast.h" -#include "cobalt/script/wrappable.h" -#include "cobalt/bindings/testing/object_type_bindings_interface.h" - -#include "third_party/mozjs-45/js/src/jsapi.h" - -namespace cobalt { -namespace bindings { -namespace testing { - -class MozjsObjectTypeBindingsInterface { - public: - static JSObject* CreateProxy(JSContext* context, - const scoped_refptr<script::Wrappable>& wrappable); - static const JSClass* PrototypeClass(JSContext* context); - static JSObject* GetPrototype(JSContext* context, - JS::HandleObject global_object); - static JSObject* GetInterfaceObject(JSContext* context, - JS::HandleObject global_object); -}; - -} // namespace bindings -} // namespace testing -} // namespace cobalt - -#endif // MozjsObjectTypeBindingsInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsOperationsTestInterface.cc b/src/cobalt/bindings/generated/mozjs-45/testing/MozjsOperationsTestInterface.cc deleted file mode 100644 index 1212b89..0000000 --- a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsOperationsTestInterface.cc +++ /dev/null
@@ -1,1735 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! -// Auto-generated from template: bindings/mozjs-45/templates/interface.cc.template - -// clang-format off - -#include "MozjsOperationsTestInterface.h" - -#include "base/debug/trace_event.h" -#include "cobalt/base/polymorphic_downcast.h" -#include "cobalt/script/global_environment.h" -#include "cobalt/script/opaque_handle.h" -#include "cobalt/script/script_object.h" -#include "MozjsArbitraryInterface.h" -#include "cobalt/bindings/testing/arbitrary_interface.h" - -#include "base/lazy_instance.h" -#include "cobalt/script/mozjs-45/callback_function_conversion.h" -#include "cobalt/script/exception_state.h" -#include "cobalt/script/mozjs-45/conversion_helpers.h" -#include "cobalt/script/mozjs-45/mozjs_exception_state.h" -#include "cobalt/script/mozjs-45/mozjs_callback_function.h" -#include "cobalt/script/mozjs-45/mozjs_global_environment.h" -#include "cobalt/script/mozjs-45/mozjs_object_handle.h" -#include "cobalt/script/mozjs-45/mozjs_property_enumerator.h" -#include "cobalt/script/mozjs-45/mozjs_user_object_holder.h" -#include "cobalt/script/mozjs-45/proxy_handler.h" -#include "cobalt/script/mozjs-45/type_traits.h" -#include "cobalt/script/mozjs-45/wrapper_factory.h" -#include "cobalt/script/mozjs-45/wrapper_private.h" -#include "cobalt/script/property_enumerator.h" -#include "third_party/mozjs-45/js/src/jsapi.h" -#include "third_party/mozjs-45/js/src/jsfriendapi.h" - -namespace { -using cobalt::bindings::testing::OperationsTestInterface; -using cobalt::bindings::testing::MozjsOperationsTestInterface; -using cobalt::bindings::testing::ArbitraryInterface; -using cobalt::bindings::testing::MozjsArbitraryInterface; -using cobalt::script::CallbackInterfaceTraits; -using cobalt::script::GlobalEnvironment; -using cobalt::script::OpaqueHandle; -using cobalt::script::OpaqueHandleHolder; -using cobalt::script::ScriptObject; -using cobalt::script::Wrappable; - -using cobalt::script::CallbackFunction; -using cobalt::script::CallbackInterfaceTraits; -using cobalt::script::ExceptionState; -using cobalt::script::mozjs::FromJSValue; -using cobalt::script::mozjs::kConversionFlagNullable; -using cobalt::script::mozjs::kConversionFlagRestricted; -using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString; -using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString; -using cobalt::script::mozjs::kNoConversionFlags; -using cobalt::script::mozjs::InterfaceData; -using cobalt::script::mozjs::MozjsCallbackFunction; -using cobalt::script::mozjs::MozjsExceptionState; -using cobalt::script::mozjs::MozjsGlobalEnvironment; -using cobalt::script::mozjs::MozjsUserObjectHolder; -using cobalt::script::mozjs::MozjsPropertyEnumerator; -using cobalt::script::mozjs::ProxyHandler; -using cobalt::script::mozjs::ToJSValue; -using cobalt::script::mozjs::TypeTraits; -using cobalt::script::mozjs::WrapperPrivate; -using cobalt::script::mozjs::WrapperFactory; -using cobalt::script::Wrappable; -} // namespace - -namespace cobalt { -namespace bindings { -namespace testing { - -namespace { - -class MozjsOperationsTestInterfaceHandler : public ProxyHandler { - public: - MozjsOperationsTestInterfaceHandler() - : ProxyHandler(indexed_property_hooks, named_property_hooks) {} - - private: - static NamedPropertyHooks named_property_hooks; - static IndexedPropertyHooks indexed_property_hooks; -}; - -ProxyHandler::NamedPropertyHooks -MozjsOperationsTestInterfaceHandler::named_property_hooks = { - NULL, - NULL, - NULL, - NULL, - NULL, -}; -ProxyHandler::IndexedPropertyHooks -MozjsOperationsTestInterfaceHandler::indexed_property_hooks = { - NULL, - NULL, - NULL, - NULL, - NULL, -}; - -static base::LazyInstance<MozjsOperationsTestInterfaceHandler> - proxy_handler; - -bool HasInstance(JSContext *context, JS::HandleObject type, - JS::MutableHandleValue vp, bool *success) { - JS::RootedObject global_object( - context, JS_GetGlobalForObject(context, type)); - DCHECK(global_object); - - JS::RootedObject prototype( - context, MozjsOperationsTestInterface::GetPrototype(context, global_object)); - - // |IsDelegate| walks the prototype chain of an object returning true if - // .prototype is found. - bool is_delegate; - if (!IsDelegate(context, prototype, vp, &is_delegate)) { - *success = false; - return false; - } - - *success = is_delegate; - return true; -} - -const JSClass instance_class_definition = { - "OperationsTestInterface", - 0 | JSCLASS_HAS_PRIVATE, - NULL, // addProperty - NULL, // delProperty - NULL, // getProperty - NULL, // setProperty - NULL, // enumerate - NULL, // resolve - NULL, // mayResolve - &WrapperPrivate::Finalizer, // finalize - NULL, // call - NULL, // hasInstance - NULL, // construct - &WrapperPrivate::Trace, // trace -}; - -const JSClass prototype_class_definition = { - "OperationsTestInterfacePrototype", -}; - -const JSClass interface_object_class_definition = { - "OperationsTestInterfaceConstructor", - 0, - NULL, // addProperty - NULL, // delProperty - NULL, // getProperty - NULL, // setProperty - NULL, // enumerate - NULL, // resolve - NULL, // mayResolve - NULL, // finalize - NULL, // call - &HasInstance, - NULL, -}; - -bool fcn_longFunctionNoArgs( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, &object)) { - NOTREACHED(); - return false; - } - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<OperationsTestInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - OperationsTestInterface* impl = - wrapper_private->wrappable<OperationsTestInterface>().get(); - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->LongFunctionNoArgs(), - &result_value); - } - if (!exception_state.is_exception_set()) { - args.rval().set(result_value); - } - return !exception_state.is_exception_set(); -} - -bool fcn_objectFunctionNoArgs( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, &object)) { - NOTREACHED(); - return false; - } - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<OperationsTestInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - OperationsTestInterface* impl = - wrapper_private->wrappable<OperationsTestInterface>().get(); - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->ObjectFunctionNoArgs(), - &result_value); - } - if (!exception_state.is_exception_set()) { - args.rval().set(result_value); - } - return !exception_state.is_exception_set(); -} - -bool fcn_optionalArgumentWithDefault( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, &object)) { - NOTREACHED(); - return false; - } - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<OperationsTestInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - OperationsTestInterface* impl = - wrapper_private->wrappable<OperationsTestInterface>().get(); - // Optional arguments with default values - TypeTraits<double >::ConversionType arg1 = - 2.718; - size_t num_set_arguments = 1; - if (args.length() > 0) { - JS::RootedValue optional_value0( - context, args[0]); - FromJSValue(context, - optional_value0, - (kConversionFlagRestricted), - &exception_state, - &arg1); - if (exception_state.is_exception_set()) { - return false; - } - } - - impl->OptionalArgumentWithDefault(arg1); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - -bool fcn_optionalArguments( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, &object)) { - NOTREACHED(); - return false; - } - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<OperationsTestInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - OperationsTestInterface* impl = - wrapper_private->wrappable<OperationsTestInterface>().get(); - const size_t kMinArguments = 1; - if (args.length() < kMinArguments) { - exception_state.SetSimpleException(script::kInvalidNumberOfArguments); - return false; - } - // Non-optional arguments - TypeTraits<int32_t >::ConversionType arg1; - // Optional arguments - TypeTraits<int32_t >::ConversionType arg2; - TypeTraits<int32_t >::ConversionType arg3; - - DCHECK_LT(0, args.length()); - JS::RootedValue non_optional_value0( - context, args[0]); - FromJSValue(context, - non_optional_value0, - kNoConversionFlags, - &exception_state, &arg1); - if (exception_state.is_exception_set()) { - return false; - } - size_t num_set_arguments = 1; - if (args.length() > 1) { - JS::RootedValue optional_value0( - context, args[1]); - FromJSValue(context, - optional_value0, - kNoConversionFlags, - &exception_state, - &arg2); - if (exception_state.is_exception_set()) { - return false; - } - ++num_set_arguments; - } - if (args.length() > 2) { - JS::RootedValue optional_value1( - context, args[2]); - FromJSValue(context, - optional_value1, - kNoConversionFlags, - &exception_state, - &arg3); - if (exception_state.is_exception_set()) { - return false; - } - ++num_set_arguments; - } - switch (num_set_arguments) { - case 1: - { - impl->OptionalArguments(arg1); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); - } - break; - case 2: - { - impl->OptionalArguments(arg1, arg2); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); - } - break; - case 3: - { - impl->OptionalArguments(arg1, arg2, arg3); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); - } - break; - default: - NOTREACHED(); - return false; - } -} - -bool fcn_optionalNullableArgumentsWithDefaults( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, &object)) { - NOTREACHED(); - return false; - } - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<OperationsTestInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - OperationsTestInterface* impl = - wrapper_private->wrappable<OperationsTestInterface>().get(); - // Optional arguments with default values - TypeTraits<base::optional<bool > >::ConversionType arg1 = - base::nullopt; - TypeTraits<scoped_refptr<ArbitraryInterface> >::ConversionType arg2 = - NULL; - size_t num_set_arguments = 2; - if (args.length() > 0) { - JS::RootedValue optional_value0( - context, args[0]); - FromJSValue(context, - optional_value0, - (kConversionFlagNullable), - &exception_state, - &arg1); - if (exception_state.is_exception_set()) { - return false; - } - } - if (args.length() > 1) { - JS::RootedValue optional_value1( - context, args[1]); - FromJSValue(context, - optional_value1, - (kConversionFlagNullable), - &exception_state, - &arg2); - if (exception_state.is_exception_set()) { - return false; - } - } - - impl->OptionalNullableArgumentsWithDefaults(arg1, arg2); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - -bool fcn_overloadedFunction1( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, &object)) { - NOTREACHED(); - return false; - } - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<OperationsTestInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - OperationsTestInterface* impl = - wrapper_private->wrappable<OperationsTestInterface>().get(); - - impl->OverloadedFunction(); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - -bool fcn_overloadedFunction2( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, &object)) { - NOTREACHED(); - return false; - } - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<OperationsTestInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - OperationsTestInterface* impl = - wrapper_private->wrappable<OperationsTestInterface>().get(); - const size_t kMinArguments = 1; - if (args.length() < kMinArguments) { - exception_state.SetSimpleException(script::kInvalidNumberOfArguments); - return false; - } - // Non-optional arguments - TypeTraits<int32_t >::ConversionType arg; - - DCHECK_LT(0, args.length()); - JS::RootedValue non_optional_value0( - context, args[0]); - FromJSValue(context, - non_optional_value0, - kNoConversionFlags, - &exception_state, &arg); - if (exception_state.is_exception_set()) { - return false; - } - - impl->OverloadedFunction(arg); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - -bool fcn_overloadedFunction3( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, &object)) { - NOTREACHED(); - return false; - } - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<OperationsTestInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - OperationsTestInterface* impl = - wrapper_private->wrappable<OperationsTestInterface>().get(); - const size_t kMinArguments = 1; - if (args.length() < kMinArguments) { - exception_state.SetSimpleException(script::kInvalidNumberOfArguments); - return false; - } - // Non-optional arguments - TypeTraits<std::string >::ConversionType arg; - - DCHECK_LT(0, args.length()); - JS::RootedValue non_optional_value0( - context, args[0]); - FromJSValue(context, - non_optional_value0, - kNoConversionFlags, - &exception_state, &arg); - if (exception_state.is_exception_set()) { - return false; - } - - impl->OverloadedFunction(arg); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - -bool fcn_overloadedFunction4( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, &object)) { - NOTREACHED(); - return false; - } - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<OperationsTestInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - OperationsTestInterface* impl = - wrapper_private->wrappable<OperationsTestInterface>().get(); - const size_t kMinArguments = 3; - if (args.length() < kMinArguments) { - exception_state.SetSimpleException(script::kInvalidNumberOfArguments); - return false; - } - // Non-optional arguments - TypeTraits<int32_t >::ConversionType arg1; - TypeTraits<int32_t >::ConversionType arg2; - TypeTraits<int32_t >::ConversionType arg3; - - DCHECK_LT(0, args.length()); - JS::RootedValue non_optional_value0( - context, args[0]); - FromJSValue(context, - non_optional_value0, - kNoConversionFlags, - &exception_state, &arg1); - if (exception_state.is_exception_set()) { - return false; - } - - DCHECK_LT(1, args.length()); - JS::RootedValue non_optional_value1( - context, args[1]); - FromJSValue(context, - non_optional_value1, - kNoConversionFlags, - &exception_state, &arg2); - if (exception_state.is_exception_set()) { - return false; - } - - DCHECK_LT(2, args.length()); - JS::RootedValue non_optional_value2( - context, args[2]); - FromJSValue(context, - non_optional_value2, - kNoConversionFlags, - &exception_state, &arg3); - if (exception_state.is_exception_set()) { - return false; - } - - impl->OverloadedFunction(arg1, arg2, arg3); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - -bool fcn_overloadedFunction5( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, &object)) { - NOTREACHED(); - return false; - } - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<OperationsTestInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - OperationsTestInterface* impl = - wrapper_private->wrappable<OperationsTestInterface>().get(); - const size_t kMinArguments = 3; - if (args.length() < kMinArguments) { - exception_state.SetSimpleException(script::kInvalidNumberOfArguments); - return false; - } - // Non-optional arguments - TypeTraits<int32_t >::ConversionType arg1; - TypeTraits<int32_t >::ConversionType arg2; - TypeTraits<scoped_refptr<ArbitraryInterface> >::ConversionType arg3; - - DCHECK_LT(0, args.length()); - JS::RootedValue non_optional_value0( - context, args[0]); - FromJSValue(context, - non_optional_value0, - kNoConversionFlags, - &exception_state, &arg1); - if (exception_state.is_exception_set()) { - return false; - } - - DCHECK_LT(1, args.length()); - JS::RootedValue non_optional_value1( - context, args[1]); - FromJSValue(context, - non_optional_value1, - kNoConversionFlags, - &exception_state, &arg2); - if (exception_state.is_exception_set()) { - return false; - } - - DCHECK_LT(2, args.length()); - JS::RootedValue non_optional_value2( - context, args[2]); - FromJSValue(context, - non_optional_value2, - kNoConversionFlags, - &exception_state, &arg3); - if (exception_state.is_exception_set()) { - return false; - } - - impl->OverloadedFunction(arg1, arg2, arg3); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - -bool fcn_overloadedFunction( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - switch(argc) { - case(0): { - // Overload resolution algorithm details found here: - // http://heycam.github.io/webidl/#dfn-overload-resolution-algorithm - if (true) { - return fcn_overloadedFunction1( - context, argc, vp); - } - break; - } - case(1): { - // Overload resolution algorithm details found here: - // http://heycam.github.io/webidl/#dfn-overload-resolution-algorithm - JS::RootedValue arg(context, args[0]); - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - JS::RootedObject object(context); - if (arg.isObject()) { - object = JS::RootedObject(context, &arg.toObject()); - } - if (arg.isNumber()) { - return fcn_overloadedFunction2( - context, argc, vp); - } - if (true) { - return fcn_overloadedFunction3( - context, argc, vp); - } - if (true) { - return fcn_overloadedFunction2( - context, argc, vp); - } - break; - } - case(3): { - // Overload resolution algorithm details found here: - // http://heycam.github.io/webidl/#dfn-overload-resolution-algorithm - JS::RootedValue arg(context, args[2]); - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - JS::RootedObject object(context); - if (arg.isObject()) { - object = JS::RootedObject(context, &arg.toObject()); - } - if (arg.isObject() ? wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<ArbitraryInterface>()) : - false) { - return fcn_overloadedFunction5( - context, argc, vp); - } - if (true) { - return fcn_overloadedFunction4( - context, argc, vp); - } - break; - } - } - // Invalid number of args - // http://heycam.github.io/webidl/#dfn-overload-resolution-algorithm - // 4. If S is empty, then throw a TypeError. - MozjsExceptionState exception_state(context); - exception_state.SetSimpleException(script::kInvalidNumberOfArguments); - return false; -} - -bool fcn_overloadedNullable1( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, &object)) { - NOTREACHED(); - return false; - } - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<OperationsTestInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - OperationsTestInterface* impl = - wrapper_private->wrappable<OperationsTestInterface>().get(); - const size_t kMinArguments = 1; - if (args.length() < kMinArguments) { - exception_state.SetSimpleException(script::kInvalidNumberOfArguments); - return false; - } - // Non-optional arguments - TypeTraits<int32_t >::ConversionType arg; - - DCHECK_LT(0, args.length()); - JS::RootedValue non_optional_value0( - context, args[0]); - FromJSValue(context, - non_optional_value0, - kNoConversionFlags, - &exception_state, &arg); - if (exception_state.is_exception_set()) { - return false; - } - - impl->OverloadedNullable(arg); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - -bool fcn_overloadedNullable2( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, &object)) { - NOTREACHED(); - return false; - } - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<OperationsTestInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - OperationsTestInterface* impl = - wrapper_private->wrappable<OperationsTestInterface>().get(); - const size_t kMinArguments = 1; - if (args.length() < kMinArguments) { - exception_state.SetSimpleException(script::kInvalidNumberOfArguments); - return false; - } - // Non-optional arguments - TypeTraits<base::optional<bool > >::ConversionType arg; - - DCHECK_LT(0, args.length()); - JS::RootedValue non_optional_value0( - context, args[0]); - FromJSValue(context, - non_optional_value0, - (kConversionFlagNullable), - &exception_state, &arg); - if (exception_state.is_exception_set()) { - return false; - } - - impl->OverloadedNullable(arg); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - -bool fcn_overloadedNullable( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - switch(argc) { - case(1): { - // Overload resolution algorithm details found here: - // http://heycam.github.io/webidl/#dfn-overload-resolution-algorithm - JS::RootedValue arg(context, args[0]); - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - JS::RootedObject object(context); - if (arg.isObject()) { - object = JS::RootedObject(context, &arg.toObject()); - } - if (arg.isNullOrUndefined()) { - return fcn_overloadedNullable2( - context, argc, vp); - } - if (true) { - return fcn_overloadedNullable1( - context, argc, vp); - } - break; - } - } - // Invalid number of args - // http://heycam.github.io/webidl/#dfn-overload-resolution-algorithm - // 4. If S is empty, then throw a TypeError. - MozjsExceptionState exception_state(context); - exception_state.SetSimpleException(script::kInvalidNumberOfArguments); - return false; -} - -bool fcn_stringFunctionNoArgs( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, &object)) { - NOTREACHED(); - return false; - } - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<OperationsTestInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - OperationsTestInterface* impl = - wrapper_private->wrappable<OperationsTestInterface>().get(); - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->StringFunctionNoArgs(), - &result_value); - } - if (!exception_state.is_exception_set()) { - args.rval().set(result_value); - } - return !exception_state.is_exception_set(); -} - -bool fcn_variadicPrimitiveArguments( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, &object)) { - NOTREACHED(); - return false; - } - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<OperationsTestInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - OperationsTestInterface* impl = - wrapper_private->wrappable<OperationsTestInterface>().get(); - // Variadic argument - TypeTraits<std::vector<int32_t> >::ConversionType bools; - - // Get variadic arguments. - const size_t kFirstVariadicArgIndex = 0; - if (args.length() > kFirstVariadicArgIndex) { - bools.resize(args.length() - kFirstVariadicArgIndex); - for (int i = 0; i + kFirstVariadicArgIndex < args.length(); ++i) { - JS::RootedValue variadic_argument_value( - context, args[i + kFirstVariadicArgIndex]); - FromJSValue(context, - variadic_argument_value, - kNoConversionFlags, - &exception_state, - &bools[i]); - if (exception_state.is_exception_set()) { - return false; - } - } - } - - impl->VariadicPrimitiveArguments(bools); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - -bool fcn_variadicStringArgumentsAfterOptionalArgument( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, &object)) { - NOTREACHED(); - return false; - } - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<OperationsTestInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - OperationsTestInterface* impl = - wrapper_private->wrappable<OperationsTestInterface>().get(); - // Optional arguments - TypeTraits<bool >::ConversionType optional_arg; - // Variadic argument - TypeTraits<std::vector<std::string> >::ConversionType strings; - size_t num_set_arguments = 0; - if (args.length() > 0) { - JS::RootedValue optional_value0( - context, args[0]); - FromJSValue(context, - optional_value0, - kNoConversionFlags, - &exception_state, - &optional_arg); - if (exception_state.is_exception_set()) { - return false; - } - ++num_set_arguments; - } - - // Get variadic arguments. - const size_t kLastOptionalArgIndex = 1; - if (num_set_arguments == kLastOptionalArgIndex) { - // If the last optional argument has been set, we will call the overload - // that takes the variadic argument, possibly with an empty vector in the - // case that there are no more arguments left. - ++num_set_arguments; - } - const size_t kFirstVariadicArgIndex = 1; - if (args.length() > kFirstVariadicArgIndex) { - strings.resize(args.length() - kFirstVariadicArgIndex); - for (int i = 0; i + kFirstVariadicArgIndex < args.length(); ++i) { - JS::RootedValue variadic_argument_value( - context, args[i + kFirstVariadicArgIndex]); - FromJSValue(context, - variadic_argument_value, - kNoConversionFlags, - &exception_state, - &strings[i]); - if (exception_state.is_exception_set()) { - return false; - } - } - } - switch (num_set_arguments) { - case 0: - { - impl->VariadicStringArgumentsAfterOptionalArgument(); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); - } - break; - case 2: - { - impl->VariadicStringArgumentsAfterOptionalArgument(optional_arg, strings); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); - } - break; - default: - NOTREACHED(); - return false; - } -} - -bool fcn_voidFunctionLongArg( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, &object)) { - NOTREACHED(); - return false; - } - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<OperationsTestInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - OperationsTestInterface* impl = - wrapper_private->wrappable<OperationsTestInterface>().get(); - const size_t kMinArguments = 1; - if (args.length() < kMinArguments) { - exception_state.SetSimpleException(script::kInvalidNumberOfArguments); - return false; - } - // Non-optional arguments - TypeTraits<int32_t >::ConversionType arg; - - DCHECK_LT(0, args.length()); - JS::RootedValue non_optional_value0( - context, args[0]); - FromJSValue(context, - non_optional_value0, - kNoConversionFlags, - &exception_state, &arg); - if (exception_state.is_exception_set()) { - return false; - } - - impl->VoidFunctionLongArg(arg); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - -bool fcn_voidFunctionNoArgs( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, &object)) { - NOTREACHED(); - return false; - } - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<OperationsTestInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - OperationsTestInterface* impl = - wrapper_private->wrappable<OperationsTestInterface>().get(); - - impl->VoidFunctionNoArgs(); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - -bool fcn_voidFunctionObjectArg( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, &object)) { - NOTREACHED(); - return false; - } - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<OperationsTestInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - OperationsTestInterface* impl = - wrapper_private->wrappable<OperationsTestInterface>().get(); - const size_t kMinArguments = 1; - if (args.length() < kMinArguments) { - exception_state.SetSimpleException(script::kInvalidNumberOfArguments); - return false; - } - // Non-optional arguments - TypeTraits<scoped_refptr<ArbitraryInterface> >::ConversionType arg; - - DCHECK_LT(0, args.length()); - JS::RootedValue non_optional_value0( - context, args[0]); - FromJSValue(context, - non_optional_value0, - kNoConversionFlags, - &exception_state, &arg); - if (exception_state.is_exception_set()) { - return false; - } - - impl->VoidFunctionObjectArg(arg); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - -bool fcn_voidFunctionStringArg( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, &object)) { - NOTREACHED(); - return false; - } - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<OperationsTestInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - OperationsTestInterface* impl = - wrapper_private->wrappable<OperationsTestInterface>().get(); - const size_t kMinArguments = 1; - if (args.length() < kMinArguments) { - exception_state.SetSimpleException(script::kInvalidNumberOfArguments); - return false; - } - // Non-optional arguments - TypeTraits<std::string >::ConversionType arg; - - DCHECK_LT(0, args.length()); - JS::RootedValue non_optional_value0( - context, args[0]); - FromJSValue(context, - non_optional_value0, - kNoConversionFlags, - &exception_state, &arg); - if (exception_state.is_exception_set()) { - return false; - } - - impl->VoidFunctionStringArg(arg); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - -bool staticfcn_overloadedFunction1( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - const size_t kMinArguments = 1; - if (args.length() < kMinArguments) { - exception_state.SetSimpleException(script::kInvalidNumberOfArguments); - return false; - } - // Non-optional arguments - TypeTraits<double >::ConversionType arg; - - DCHECK_LT(0, args.length()); - JS::RootedValue non_optional_value0( - context, args[0]); - FromJSValue(context, - non_optional_value0, - (kConversionFlagRestricted), - &exception_state, &arg); - if (exception_state.is_exception_set()) { - return false; - } - - OperationsTestInterface::OverloadedFunction(arg); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - -bool staticfcn_overloadedFunction2( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - const size_t kMinArguments = 2; - if (args.length() < kMinArguments) { - exception_state.SetSimpleException(script::kInvalidNumberOfArguments); - return false; - } - // Non-optional arguments - TypeTraits<double >::ConversionType arg1; - TypeTraits<double >::ConversionType arg2; - - DCHECK_LT(0, args.length()); - JS::RootedValue non_optional_value0( - context, args[0]); - FromJSValue(context, - non_optional_value0, - (kConversionFlagRestricted), - &exception_state, &arg1); - if (exception_state.is_exception_set()) { - return false; - } - - DCHECK_LT(1, args.length()); - JS::RootedValue non_optional_value1( - context, args[1]); - FromJSValue(context, - non_optional_value1, - (kConversionFlagRestricted), - &exception_state, &arg2); - if (exception_state.is_exception_set()) { - return false; - } - - OperationsTestInterface::OverloadedFunction(arg1, arg2); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - -bool staticfcn_overloadedFunction( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - switch(argc) { - case(1): { - // Overload resolution algorithm details found here: - // http://heycam.github.io/webidl/#dfn-overload-resolution-algorithm - if (true) { - return staticfcn_overloadedFunction1( - context, argc, vp); - } - break; - } - case(2): { - // Overload resolution algorithm details found here: - // http://heycam.github.io/webidl/#dfn-overload-resolution-algorithm - if (true) { - return staticfcn_overloadedFunction2( - context, argc, vp); - } - break; - } - } - // Invalid number of args - // http://heycam.github.io/webidl/#dfn-overload-resolution-algorithm - // 4. If S is empty, then throw a TypeError. - MozjsExceptionState exception_state(context); - exception_state.SetSimpleException(script::kInvalidNumberOfArguments); - return false; -} - - - -const JSPropertySpec prototype_properties[] = { - JS_PS_END -}; - -const JSFunctionSpec prototype_functions[] = { - JS_FNSPEC( - "longFunctionNoArgs", fcn_longFunctionNoArgs, NULL, - 0, JSPROP_ENUMERATE, NULL), - JS_FNSPEC( - "objectFunctionNoArgs", fcn_objectFunctionNoArgs, NULL, - 0, JSPROP_ENUMERATE, NULL), - JS_FNSPEC( - "optionalArgumentWithDefault", fcn_optionalArgumentWithDefault, NULL, - 0, JSPROP_ENUMERATE, NULL), - JS_FNSPEC( - "optionalArguments", fcn_optionalArguments, NULL, - 1, JSPROP_ENUMERATE, NULL), - JS_FNSPEC( - "optionalNullableArgumentsWithDefaults", fcn_optionalNullableArgumentsWithDefaults, NULL, - 0, JSPROP_ENUMERATE, NULL), - JS_FNSPEC( - "overloadedFunction", fcn_overloadedFunction, NULL, - 0, JSPROP_ENUMERATE, NULL), - JS_FNSPEC( - "overloadedNullable", fcn_overloadedNullable, NULL, - 1, JSPROP_ENUMERATE, NULL), - JS_FNSPEC( - "stringFunctionNoArgs", fcn_stringFunctionNoArgs, NULL, - 0, JSPROP_ENUMERATE, NULL), - JS_FNSPEC( - "variadicPrimitiveArguments", fcn_variadicPrimitiveArguments, NULL, - 0, JSPROP_ENUMERATE, NULL), - JS_FNSPEC( - "variadicStringArgumentsAfterOptionalArgument", fcn_variadicStringArgumentsAfterOptionalArgument, NULL, - 0, JSPROP_ENUMERATE, NULL), - JS_FNSPEC( - "voidFunctionLongArg", fcn_voidFunctionLongArg, NULL, - 1, JSPROP_ENUMERATE, NULL), - JS_FNSPEC( - "voidFunctionNoArgs", fcn_voidFunctionNoArgs, NULL, - 0, JSPROP_ENUMERATE, NULL), - JS_FNSPEC( - "voidFunctionObjectArg", fcn_voidFunctionObjectArg, NULL, - 1, JSPROP_ENUMERATE, NULL), - JS_FNSPEC( - "voidFunctionStringArg", fcn_voidFunctionStringArg, NULL, - 1, JSPROP_ENUMERATE, NULL), - JS_FS_END -}; - -const JSPropertySpec interface_object_properties[] = { - JS_PS_END -}; - -const JSFunctionSpec interface_object_functions[] = { - JS_FNSPEC( - "overloadedFunction", staticfcn_overloadedFunction, NULL, - 1, JSPROP_ENUMERATE, NULL), - JS_FS_END -}; - -const JSPropertySpec own_properties[] = { - JS_PS_END -}; - -void InitializePrototypeAndInterfaceObject( - InterfaceData* interface_data, JSContext* context, - JS::HandleObject global_object) { - DCHECK(!interface_data->prototype); - DCHECK(!interface_data->interface_object); - DCHECK(JS_IsGlobalObject(global_object)); - - JS::RootedObject parent_prototype( - context, JS_GetObjectPrototype(context, global_object)); - DCHECK(parent_prototype); - - interface_data->prototype = JS_NewObjectWithGivenProto( - context, &prototype_class_definition, parent_prototype - ); - - JS::RootedObject rooted_prototype(context, interface_data->prototype); - bool success = JS_DefineProperties( - context, - rooted_prototype, - prototype_properties); - - DCHECK(success); - success = JS_DefineFunctions( - context, rooted_prototype, prototype_functions); - DCHECK(success); - - JS::RootedObject function_prototype( - context, JS_GetFunctionPrototype(context, global_object)); - DCHECK(function_prototype); - // Create the Interface object. - interface_data->interface_object = JS_NewObjectWithGivenProto( - context, &interface_object_class_definition, - function_prototype); - - // Add the InterfaceObject.name property. - JS::RootedObject rooted_interface_object( - context, interface_data->interface_object); - JS::RootedValue name_value(context); - const char name[] = - "OperationsTestInterface"; - name_value.setString(JS_NewStringCopyZ(context, name)); - success = JS_DefineProperty( - context, rooted_interface_object, "name", name_value, JSPROP_READONLY, - NULL, NULL); - DCHECK(success); - - // Define interface object properties (including constants). - success = JS_DefineProperties(context, rooted_interface_object, - interface_object_properties); - DCHECK(success); - // Define interface object functions (static). - success = JS_DefineFunctions(context, rooted_interface_object, - interface_object_functions); - DCHECK(success); - - // Set the Prototype.constructor and Constructor.prototype properties. - DCHECK(interface_data->interface_object); - DCHECK(interface_data->prototype); - success = JS_LinkConstructorAndPrototype( - context, - rooted_interface_object, - rooted_prototype); - DCHECK(success); -} - -InterfaceData* GetInterfaceData(JSContext* context) { - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - // Use the address of the properties definition for this interface as a - // unique key for looking up the InterfaceData for this interface. - intptr_t key = reinterpret_cast<intptr_t>(&own_properties); - InterfaceData* interface_data = global_environment->GetInterfaceData(key); - if (!interface_data) { - interface_data = new InterfaceData(); - DCHECK(interface_data); - global_environment->CacheInterfaceData(key, interface_data); - DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key)); - } - return interface_data; -} - -} // namespace - -// static -JSObject* MozjsOperationsTestInterface::CreateProxy( - JSContext* context, const scoped_refptr<Wrappable>& wrappable) { - DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); - JS::RootedObject global_object( - context, - MozjsGlobalEnvironment::GetFromContext(context)->global_object()); - DCHECK(global_object); - - InterfaceData* interface_data = GetInterfaceData(context); - JS::RootedObject prototype(context, GetPrototype(context, global_object)); - DCHECK(prototype); - JS::RootedObject new_object( - context, - JS_NewObjectWithGivenProto( - context, &instance_class_definition, prototype)); - DCHECK(new_object); - JS::RootedObject proxy(context, - ProxyHandler::NewProxy( - context, proxy_handler.Pointer(), new_object, prototype)); - WrapperPrivate::AddPrivateData(context, proxy, wrappable); - return proxy; -} - -// static -const JSClass* MozjsOperationsTestInterface::PrototypeClass( - JSContext* context) { - DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); - JS::RootedObject global_object( - context, - MozjsGlobalEnvironment::GetFromContext(context)->global_object()); - DCHECK(global_object); - - JS::RootedObject prototype(context, GetPrototype(context, global_object)); - const JSClass* proto_class = JS_GetClass(prototype); - return proto_class; -} - -// static -JSObject* MozjsOperationsTestInterface::GetPrototype( - JSContext* context, JS::HandleObject global_object) { - DCHECK(JS_IsGlobalObject(global_object)); - - InterfaceData* interface_data = GetInterfaceData(context); - if (!interface_data->prototype) { - // Create new prototype that has all the props and methods - InitializePrototypeAndInterfaceObject( - interface_data, context, global_object); - } - DCHECK(interface_data->prototype); - return interface_data->prototype; -} - -// static -JSObject* MozjsOperationsTestInterface::GetInterfaceObject( - JSContext* context, JS::HandleObject global_object) { - DCHECK(JS_IsGlobalObject(global_object)); - - InterfaceData* interface_data = GetInterfaceData(context); - if (!interface_data->interface_object) { - InitializePrototypeAndInterfaceObject( - interface_data, context, global_object); - } - DCHECK(interface_data->interface_object); - return interface_data->interface_object; -} - - -namespace { -} // namespace - - -} // namespace testing -} // namespace bindings -} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsOperationsTestInterface.h b/src/cobalt/bindings/generated/mozjs-45/testing/MozjsOperationsTestInterface.h deleted file mode 100644 index cd73b6e..0000000 --- a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsOperationsTestInterface.h +++ /dev/null
@@ -1,54 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! -// Auto-generated from template: bindings/mozjs-45/templates/interface.h.template - -// clang-format off - -#ifndef MozjsOperationsTestInterface_h -#define MozjsOperationsTestInterface_h - -#include "base/hash_tables.h" -#include "base/lazy_instance.h" -#include "base/memory/ref_counted.h" -#include "base/threading/thread_checker.h" -#include "cobalt/base/polymorphic_downcast.h" -#include "cobalt/script/wrappable.h" -#include "cobalt/bindings/testing/operations_test_interface.h" - -#include "third_party/mozjs-45/js/src/jsapi.h" - -namespace cobalt { -namespace bindings { -namespace testing { - -class MozjsOperationsTestInterface { - public: - static JSObject* CreateProxy(JSContext* context, - const scoped_refptr<script::Wrappable>& wrappable); - static const JSClass* PrototypeClass(JSContext* context); - static JSObject* GetPrototype(JSContext* context, - JS::HandleObject global_object); - static JSObject* GetInterfaceObject(JSContext* context, - JS::HandleObject global_object); -}; - -} // namespace bindings -} // namespace testing -} // namespace cobalt - -#endif // MozjsOperationsTestInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsPutForwardsInterface.cc b/src/cobalt/bindings/generated/mozjs-45/testing/MozjsPutForwardsInterface.cc deleted file mode 100644 index 7a70b0f..0000000 --- a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsPutForwardsInterface.cc +++ /dev/null
@@ -1,505 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! -// Auto-generated from template: bindings/mozjs-45/templates/interface.cc.template - -// clang-format off - -#include "MozjsPutForwardsInterface.h" - -#include "base/debug/trace_event.h" -#include "cobalt/base/polymorphic_downcast.h" -#include "cobalt/script/global_environment.h" -#include "cobalt/script/opaque_handle.h" -#include "cobalt/script/script_object.h" -#include "MozjsArbitraryInterface.h" -#include "cobalt/bindings/testing/arbitrary_interface.h" - -#include "base/lazy_instance.h" -#include "cobalt/script/mozjs-45/callback_function_conversion.h" -#include "cobalt/script/exception_state.h" -#include "cobalt/script/mozjs-45/conversion_helpers.h" -#include "cobalt/script/mozjs-45/mozjs_exception_state.h" -#include "cobalt/script/mozjs-45/mozjs_callback_function.h" -#include "cobalt/script/mozjs-45/mozjs_global_environment.h" -#include "cobalt/script/mozjs-45/mozjs_object_handle.h" -#include "cobalt/script/mozjs-45/mozjs_property_enumerator.h" -#include "cobalt/script/mozjs-45/mozjs_user_object_holder.h" -#include "cobalt/script/mozjs-45/proxy_handler.h" -#include "cobalt/script/mozjs-45/type_traits.h" -#include "cobalt/script/mozjs-45/wrapper_factory.h" -#include "cobalt/script/mozjs-45/wrapper_private.h" -#include "cobalt/script/property_enumerator.h" -#include "third_party/mozjs-45/js/src/jsapi.h" -#include "third_party/mozjs-45/js/src/jsfriendapi.h" - -namespace { -using cobalt::bindings::testing::PutForwardsInterface; -using cobalt::bindings::testing::MozjsPutForwardsInterface; -using cobalt::bindings::testing::ArbitraryInterface; -using cobalt::bindings::testing::MozjsArbitraryInterface; -using cobalt::script::CallbackInterfaceTraits; -using cobalt::script::GlobalEnvironment; -using cobalt::script::OpaqueHandle; -using cobalt::script::OpaqueHandleHolder; -using cobalt::script::ScriptObject; -using cobalt::script::Wrappable; - -using cobalt::script::CallbackFunction; -using cobalt::script::CallbackInterfaceTraits; -using cobalt::script::ExceptionState; -using cobalt::script::mozjs::FromJSValue; -using cobalt::script::mozjs::kConversionFlagNullable; -using cobalt::script::mozjs::kConversionFlagRestricted; -using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString; -using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString; -using cobalt::script::mozjs::kNoConversionFlags; -using cobalt::script::mozjs::InterfaceData; -using cobalt::script::mozjs::MozjsCallbackFunction; -using cobalt::script::mozjs::MozjsExceptionState; -using cobalt::script::mozjs::MozjsGlobalEnvironment; -using cobalt::script::mozjs::MozjsUserObjectHolder; -using cobalt::script::mozjs::MozjsPropertyEnumerator; -using cobalt::script::mozjs::ProxyHandler; -using cobalt::script::mozjs::ToJSValue; -using cobalt::script::mozjs::TypeTraits; -using cobalt::script::mozjs::WrapperPrivate; -using cobalt::script::mozjs::WrapperFactory; -using cobalt::script::Wrappable; -} // namespace - -namespace cobalt { -namespace bindings { -namespace testing { - -namespace { - -class MozjsPutForwardsInterfaceHandler : public ProxyHandler { - public: - MozjsPutForwardsInterfaceHandler() - : ProxyHandler(indexed_property_hooks, named_property_hooks) {} - - private: - static NamedPropertyHooks named_property_hooks; - static IndexedPropertyHooks indexed_property_hooks; -}; - -ProxyHandler::NamedPropertyHooks -MozjsPutForwardsInterfaceHandler::named_property_hooks = { - NULL, - NULL, - NULL, - NULL, - NULL, -}; -ProxyHandler::IndexedPropertyHooks -MozjsPutForwardsInterfaceHandler::indexed_property_hooks = { - NULL, - NULL, - NULL, - NULL, - NULL, -}; - -static base::LazyInstance<MozjsPutForwardsInterfaceHandler> - proxy_handler; - -bool HasInstance(JSContext *context, JS::HandleObject type, - JS::MutableHandleValue vp, bool *success) { - JS::RootedObject global_object( - context, JS_GetGlobalForObject(context, type)); - DCHECK(global_object); - - JS::RootedObject prototype( - context, MozjsPutForwardsInterface::GetPrototype(context, global_object)); - - // |IsDelegate| walks the prototype chain of an object returning true if - // .prototype is found. - bool is_delegate; - if (!IsDelegate(context, prototype, vp, &is_delegate)) { - *success = false; - return false; - } - - *success = is_delegate; - return true; -} - -const JSClass instance_class_definition = { - "PutForwardsInterface", - 0 | JSCLASS_HAS_PRIVATE, - NULL, // addProperty - NULL, // delProperty - NULL, // getProperty - NULL, // setProperty - NULL, // enumerate - NULL, // resolve - NULL, // mayResolve - &WrapperPrivate::Finalizer, // finalize - NULL, // call - NULL, // hasInstance - NULL, // construct - &WrapperPrivate::Trace, // trace -}; - -const JSClass prototype_class_definition = { - "PutForwardsInterfacePrototype", -}; - -const JSClass interface_object_class_definition = { - "PutForwardsInterfaceConstructor", - 0, - NULL, // addProperty - NULL, // delProperty - NULL, // getProperty - NULL, // setProperty - NULL, // enumerate - NULL, // resolve - NULL, // mayResolve - NULL, // finalize - NULL, // call - &HasInstance, - NULL, -}; - -bool get_forwardingAttribute( - JSContext* context, unsigned argc, JS::Value* vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<PutForwardsInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - PutForwardsInterface* impl = - wrapper_private->wrappable<PutForwardsInterface>().get(); - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->forwarding_attribute(), - &result_value); - } - if (!exception_state.is_exception_set()) { - args.rval().set(result_value); - } - return !exception_state.is_exception_set(); -} - -bool set_forwardingAttribute( - JSContext* context, unsigned argc, JS::Value* vp) { - - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<PutForwardsInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - PutForwardsInterface* impl = - wrapper_private->wrappable<PutForwardsInterface>().get(); - { // Begin scope of scoped_refptr<ArbitraryInterface> forwarded_impl. - scoped_refptr<ArbitraryInterface> forwarded_impl = - impl->forwarding_attribute(); - if (!forwarded_impl) { - NOTREACHED(); - return false; - } - if (!exception_state.is_exception_set()) { - TypeTraits<std::string >::ConversionType value; - if (args.length() != 1) { - NOTREACHED(); - return false; - } - FromJSValue(context, args[0], kNoConversionFlags, &exception_state, - &value); - if (exception_state.is_exception_set()) { - return false; - } - - forwarded_impl->set_arbitrary_property(value); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - return !exception_state.is_exception_set(); - } // End scope of scoped_refptr<ArbitraryInterface> forwarded_impl. -} - -bool staticget_staticForwardingAttribute( - JSContext* context, unsigned argc, JS::Value* vp) { - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - PutForwardsInterface::static_forwarding_attribute(), - &result_value); - } - if (!exception_state.is_exception_set()) { - args.rval().set(result_value); - } - return !exception_state.is_exception_set(); -} - -bool staticset_staticForwardingAttribute( - JSContext* context, unsigned argc, JS::Value* vp) { - - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - { // Begin scope of scoped_refptr<ArbitraryInterface> forwarded_impl. - scoped_refptr<ArbitraryInterface> forwarded_impl = - PutForwardsInterface::static_forwarding_attribute(); - if (!forwarded_impl) { - NOTREACHED(); - return false; - } - if (!exception_state.is_exception_set()) { - TypeTraits<std::string >::ConversionType value; - if (args.length() != 1) { - NOTREACHED(); - return false; - } - FromJSValue(context, args[0], kNoConversionFlags, &exception_state, - &value); - if (exception_state.is_exception_set()) { - return false; - } - - forwarded_impl->set_arbitrary_property(value); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - return !exception_state.is_exception_set(); - } // End scope of scoped_refptr<ArbitraryInterface> forwarded_impl. -} - - - -const JSPropertySpec prototype_properties[] = { - { // Read/Write property - "forwardingAttribute", - JSPROP_SHARED | JSPROP_ENUMERATE, - { { &get_forwardingAttribute, NULL } }, - { { &set_forwardingAttribute, NULL } }, - }, - JS_PS_END -}; - -const JSFunctionSpec prototype_functions[] = { - JS_FS_END -}; - -const JSPropertySpec interface_object_properties[] = { - { // Static read/write attribute. - "staticForwardingAttribute", - JSPROP_SHARED | JSPROP_ENUMERATE, - { { &staticget_staticForwardingAttribute, NULL } }, - { { &staticset_staticForwardingAttribute, NULL } }, - }, - JS_PS_END -}; - -const JSFunctionSpec interface_object_functions[] = { - JS_FS_END -}; - -const JSPropertySpec own_properties[] = { - JS_PS_END -}; - -void InitializePrototypeAndInterfaceObject( - InterfaceData* interface_data, JSContext* context, - JS::HandleObject global_object) { - DCHECK(!interface_data->prototype); - DCHECK(!interface_data->interface_object); - DCHECK(JS_IsGlobalObject(global_object)); - - JS::RootedObject parent_prototype( - context, JS_GetObjectPrototype(context, global_object)); - DCHECK(parent_prototype); - - interface_data->prototype = JS_NewObjectWithGivenProto( - context, &prototype_class_definition, parent_prototype - ); - - JS::RootedObject rooted_prototype(context, interface_data->prototype); - bool success = JS_DefineProperties( - context, - rooted_prototype, - prototype_properties); - - DCHECK(success); - success = JS_DefineFunctions( - context, rooted_prototype, prototype_functions); - DCHECK(success); - - JS::RootedObject function_prototype( - context, JS_GetFunctionPrototype(context, global_object)); - DCHECK(function_prototype); - // Create the Interface object. - interface_data->interface_object = JS_NewObjectWithGivenProto( - context, &interface_object_class_definition, - function_prototype); - - // Add the InterfaceObject.name property. - JS::RootedObject rooted_interface_object( - context, interface_data->interface_object); - JS::RootedValue name_value(context); - const char name[] = - "PutForwardsInterface"; - name_value.setString(JS_NewStringCopyZ(context, name)); - success = JS_DefineProperty( - context, rooted_interface_object, "name", name_value, JSPROP_READONLY, - NULL, NULL); - DCHECK(success); - - // Define interface object properties (including constants). - success = JS_DefineProperties(context, rooted_interface_object, - interface_object_properties); - DCHECK(success); - // Define interface object functions (static). - success = JS_DefineFunctions(context, rooted_interface_object, - interface_object_functions); - DCHECK(success); - - // Set the Prototype.constructor and Constructor.prototype properties. - DCHECK(interface_data->interface_object); - DCHECK(interface_data->prototype); - success = JS_LinkConstructorAndPrototype( - context, - rooted_interface_object, - rooted_prototype); - DCHECK(success); -} - -InterfaceData* GetInterfaceData(JSContext* context) { - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - // Use the address of the properties definition for this interface as a - // unique key for looking up the InterfaceData for this interface. - intptr_t key = reinterpret_cast<intptr_t>(&own_properties); - InterfaceData* interface_data = global_environment->GetInterfaceData(key); - if (!interface_data) { - interface_data = new InterfaceData(); - DCHECK(interface_data); - global_environment->CacheInterfaceData(key, interface_data); - DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key)); - } - return interface_data; -} - -} // namespace - -// static -JSObject* MozjsPutForwardsInterface::CreateProxy( - JSContext* context, const scoped_refptr<Wrappable>& wrappable) { - DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); - JS::RootedObject global_object( - context, - MozjsGlobalEnvironment::GetFromContext(context)->global_object()); - DCHECK(global_object); - - InterfaceData* interface_data = GetInterfaceData(context); - JS::RootedObject prototype(context, GetPrototype(context, global_object)); - DCHECK(prototype); - JS::RootedObject new_object( - context, - JS_NewObjectWithGivenProto( - context, &instance_class_definition, prototype)); - DCHECK(new_object); - JS::RootedObject proxy(context, - ProxyHandler::NewProxy( - context, proxy_handler.Pointer(), new_object, prototype)); - WrapperPrivate::AddPrivateData(context, proxy, wrappable); - return proxy; -} - -// static -const JSClass* MozjsPutForwardsInterface::PrototypeClass( - JSContext* context) { - DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); - JS::RootedObject global_object( - context, - MozjsGlobalEnvironment::GetFromContext(context)->global_object()); - DCHECK(global_object); - - JS::RootedObject prototype(context, GetPrototype(context, global_object)); - const JSClass* proto_class = JS_GetClass(prototype); - return proto_class; -} - -// static -JSObject* MozjsPutForwardsInterface::GetPrototype( - JSContext* context, JS::HandleObject global_object) { - DCHECK(JS_IsGlobalObject(global_object)); - - InterfaceData* interface_data = GetInterfaceData(context); - if (!interface_data->prototype) { - // Create new prototype that has all the props and methods - InitializePrototypeAndInterfaceObject( - interface_data, context, global_object); - } - DCHECK(interface_data->prototype); - return interface_data->prototype; -} - -// static -JSObject* MozjsPutForwardsInterface::GetInterfaceObject( - JSContext* context, JS::HandleObject global_object) { - DCHECK(JS_IsGlobalObject(global_object)); - - InterfaceData* interface_data = GetInterfaceData(context); - if (!interface_data->interface_object) { - InitializePrototypeAndInterfaceObject( - interface_data, context, global_object); - } - DCHECK(interface_data->interface_object); - return interface_data->interface_object; -} - - -namespace { -} // namespace - - -} // namespace testing -} // namespace bindings -} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsPutForwardsInterface.h b/src/cobalt/bindings/generated/mozjs-45/testing/MozjsPutForwardsInterface.h deleted file mode 100644 index 61e35e2..0000000 --- a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsPutForwardsInterface.h +++ /dev/null
@@ -1,54 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! -// Auto-generated from template: bindings/mozjs-45/templates/interface.h.template - -// clang-format off - -#ifndef MozjsPutForwardsInterface_h -#define MozjsPutForwardsInterface_h - -#include "base/hash_tables.h" -#include "base/lazy_instance.h" -#include "base/memory/ref_counted.h" -#include "base/threading/thread_checker.h" -#include "cobalt/base/polymorphic_downcast.h" -#include "cobalt/script/wrappable.h" -#include "cobalt/bindings/testing/put_forwards_interface.h" - -#include "third_party/mozjs-45/js/src/jsapi.h" - -namespace cobalt { -namespace bindings { -namespace testing { - -class MozjsPutForwardsInterface { - public: - static JSObject* CreateProxy(JSContext* context, - const scoped_refptr<script::Wrappable>& wrappable); - static const JSClass* PrototypeClass(JSContext* context); - static JSObject* GetPrototype(JSContext* context, - JS::HandleObject global_object); - static JSObject* GetInterfaceObject(JSContext* context, - JS::HandleObject global_object); -}; - -} // namespace bindings -} // namespace testing -} // namespace cobalt - -#endif // MozjsPutForwardsInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsSequenceUser.cc b/src/cobalt/bindings/generated/mozjs-45/testing/MozjsSequenceUser.cc deleted file mode 100644 index 47c6fb7..0000000 --- a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsSequenceUser.cc +++ /dev/null
@@ -1,1104 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! -// Auto-generated from template: bindings/mozjs-45/templates/interface.cc.template - -// clang-format off - -#include "MozjsSequenceUser.h" - -#include "base/debug/trace_event.h" -#include "cobalt/base/polymorphic_downcast.h" -#include "cobalt/script/global_environment.h" -#include "cobalt/script/opaque_handle.h" -#include "cobalt/script/script_object.h" - -#include "base/lazy_instance.h" -#include "cobalt/script/mozjs-45/callback_function_conversion.h" -#include "cobalt/script/exception_state.h" -#include "cobalt/script/mozjs-45/conversion_helpers.h" -#include "cobalt/script/mozjs-45/mozjs_exception_state.h" -#include "cobalt/script/mozjs-45/mozjs_callback_function.h" -#include "cobalt/script/mozjs-45/mozjs_global_environment.h" -#include "cobalt/script/mozjs-45/mozjs_object_handle.h" -#include "cobalt/script/mozjs-45/mozjs_property_enumerator.h" -#include "cobalt/script/mozjs-45/mozjs_user_object_holder.h" -#include "cobalt/script/mozjs-45/proxy_handler.h" -#include "cobalt/script/mozjs-45/type_traits.h" -#include "cobalt/script/mozjs-45/wrapper_factory.h" -#include "cobalt/script/mozjs-45/wrapper_private.h" -#include "cobalt/script/property_enumerator.h" -#include "third_party/mozjs-45/js/src/jsapi.h" -#include "third_party/mozjs-45/js/src/jsfriendapi.h" - -namespace { -using cobalt::bindings::testing::SequenceUser; -using cobalt::bindings::testing::MozjsSequenceUser; -using cobalt::script::CallbackInterfaceTraits; -using cobalt::script::GlobalEnvironment; -using cobalt::script::OpaqueHandle; -using cobalt::script::OpaqueHandleHolder; -using cobalt::script::ScriptObject; -using cobalt::script::Wrappable; - -using cobalt::script::CallbackFunction; -using cobalt::script::CallbackInterfaceTraits; -using cobalt::script::ExceptionState; -using cobalt::script::mozjs::FromJSValue; -using cobalt::script::mozjs::kConversionFlagNullable; -using cobalt::script::mozjs::kConversionFlagRestricted; -using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString; -using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString; -using cobalt::script::mozjs::kNoConversionFlags; -using cobalt::script::mozjs::InterfaceData; -using cobalt::script::mozjs::MozjsCallbackFunction; -using cobalt::script::mozjs::MozjsExceptionState; -using cobalt::script::mozjs::MozjsGlobalEnvironment; -using cobalt::script::mozjs::MozjsUserObjectHolder; -using cobalt::script::mozjs::MozjsPropertyEnumerator; -using cobalt::script::mozjs::ProxyHandler; -using cobalt::script::mozjs::ToJSValue; -using cobalt::script::mozjs::TypeTraits; -using cobalt::script::mozjs::WrapperPrivate; -using cobalt::script::mozjs::WrapperFactory; -using cobalt::script::Wrappable; -} // namespace - -namespace cobalt { -namespace bindings { -namespace testing { - -namespace { - -class MozjsSequenceUserHandler : public ProxyHandler { - public: - MozjsSequenceUserHandler() - : ProxyHandler(indexed_property_hooks, named_property_hooks) {} - - private: - static NamedPropertyHooks named_property_hooks; - static IndexedPropertyHooks indexed_property_hooks; -}; - -ProxyHandler::NamedPropertyHooks -MozjsSequenceUserHandler::named_property_hooks = { - NULL, - NULL, - NULL, - NULL, - NULL, -}; -ProxyHandler::IndexedPropertyHooks -MozjsSequenceUserHandler::indexed_property_hooks = { - NULL, - NULL, - NULL, - NULL, - NULL, -}; - -static base::LazyInstance<MozjsSequenceUserHandler> - proxy_handler; - -bool Constructor(JSContext* context, unsigned int argc, JS::Value* vp); -bool HasInstance(JSContext *context, JS::HandleObject type, - JS::MutableHandleValue vp, bool *success) { - JS::RootedObject global_object( - context, JS_GetGlobalForObject(context, type)); - DCHECK(global_object); - - JS::RootedObject prototype( - context, MozjsSequenceUser::GetPrototype(context, global_object)); - - // |IsDelegate| walks the prototype chain of an object returning true if - // .prototype is found. - bool is_delegate; - if (!IsDelegate(context, prototype, vp, &is_delegate)) { - *success = false; - return false; - } - - *success = is_delegate; - return true; -} - -const JSClass instance_class_definition = { - "SequenceUser", - 0 | JSCLASS_HAS_PRIVATE, - NULL, // addProperty - NULL, // delProperty - NULL, // getProperty - NULL, // setProperty - NULL, // enumerate - NULL, // resolve - NULL, // mayResolve - &WrapperPrivate::Finalizer, // finalize - NULL, // call - NULL, // hasInstance - NULL, // construct - &WrapperPrivate::Trace, // trace -}; - -const JSClass prototype_class_definition = { - "SequenceUserPrototype", -}; - -const JSClass interface_object_class_definition = { - "SequenceUserConstructor", - 0, - NULL, // addProperty - NULL, // delProperty - NULL, // getProperty - NULL, // setProperty - NULL, // enumerate - NULL, // resolve - NULL, // mayResolve - NULL, // finalize - NULL, // call - &HasInstance, - Constructor, -}; - -bool fcn_getInterfaceSequence( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, &object)) { - NOTREACHED(); - return false; - } - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<SequenceUser>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - SequenceUser* impl = - wrapper_private->wrappable<SequenceUser>().get(); - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->GetInterfaceSequence(), - &result_value); - } - if (!exception_state.is_exception_set()) { - args.rval().set(result_value); - } - return !exception_state.is_exception_set(); -} - -bool fcn_getInterfaceSequenceSequenceSequence( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, &object)) { - NOTREACHED(); - return false; - } - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<SequenceUser>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - SequenceUser* impl = - wrapper_private->wrappable<SequenceUser>().get(); - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->GetInterfaceSequenceSequenceSequence(), - &result_value); - } - if (!exception_state.is_exception_set()) { - args.rval().set(result_value); - } - return !exception_state.is_exception_set(); -} - -bool fcn_getLongSequence( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, &object)) { - NOTREACHED(); - return false; - } - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<SequenceUser>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - SequenceUser* impl = - wrapper_private->wrappable<SequenceUser>().get(); - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->GetLongSequence(), - &result_value); - } - if (!exception_state.is_exception_set()) { - args.rval().set(result_value); - } - return !exception_state.is_exception_set(); -} - -bool fcn_getStringSequence( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, &object)) { - NOTREACHED(); - return false; - } - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<SequenceUser>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - SequenceUser* impl = - wrapper_private->wrappable<SequenceUser>().get(); - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->GetStringSequence(), - &result_value); - } - if (!exception_state.is_exception_set()) { - args.rval().set(result_value); - } - return !exception_state.is_exception_set(); -} - -bool fcn_getStringSequenceSequence( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, &object)) { - NOTREACHED(); - return false; - } - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<SequenceUser>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - SequenceUser* impl = - wrapper_private->wrappable<SequenceUser>().get(); - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->GetStringSequenceSequence(), - &result_value); - } - if (!exception_state.is_exception_set()) { - args.rval().set(result_value); - } - return !exception_state.is_exception_set(); -} - -bool fcn_getUnionOfStringAndStringSequence( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, &object)) { - NOTREACHED(); - return false; - } - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<SequenceUser>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - SequenceUser* impl = - wrapper_private->wrappable<SequenceUser>().get(); - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->GetUnionOfStringAndStringSequence(), - &result_value); - } - if (!exception_state.is_exception_set()) { - args.rval().set(result_value); - } - return !exception_state.is_exception_set(); -} - -bool fcn_getUnionSequence( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, &object)) { - NOTREACHED(); - return false; - } - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<SequenceUser>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - SequenceUser* impl = - wrapper_private->wrappable<SequenceUser>().get(); - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->GetUnionSequence(), - &result_value); - } - if (!exception_state.is_exception_set()) { - args.rval().set(result_value); - } - return !exception_state.is_exception_set(); -} - -bool fcn_setInterfaceSequence( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, &object)) { - NOTREACHED(); - return false; - } - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<SequenceUser>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - SequenceUser* impl = - wrapper_private->wrappable<SequenceUser>().get(); - const size_t kMinArguments = 1; - if (args.length() < kMinArguments) { - exception_state.SetSimpleException(script::kInvalidNumberOfArguments); - return false; - } - // Non-optional arguments - TypeTraits<script::Sequence< scoped_refptr<ArbitraryInterface> > >::ConversionType elements; - - DCHECK_LT(0, args.length()); - JS::RootedValue non_optional_value0( - context, args[0]); - FromJSValue(context, - non_optional_value0, - kNoConversionFlags, - &exception_state, &elements); - if (exception_state.is_exception_set()) { - return false; - } - - impl->SetInterfaceSequence(elements); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - -bool fcn_setInterfaceSequenceSequenceSequence( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, &object)) { - NOTREACHED(); - return false; - } - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<SequenceUser>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - SequenceUser* impl = - wrapper_private->wrappable<SequenceUser>().get(); - const size_t kMinArguments = 1; - if (args.length() < kMinArguments) { - exception_state.SetSimpleException(script::kInvalidNumberOfArguments); - return false; - } - // Non-optional arguments - TypeTraits<script::Sequence< script::Sequence< script::Sequence< scoped_refptr<ArbitraryInterface> > > > >::ConversionType elements; - - DCHECK_LT(0, args.length()); - JS::RootedValue non_optional_value0( - context, args[0]); - FromJSValue(context, - non_optional_value0, - kNoConversionFlags, - &exception_state, &elements); - if (exception_state.is_exception_set()) { - return false; - } - - impl->SetInterfaceSequenceSequenceSequence(elements); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - -bool fcn_setLongSequence( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, &object)) { - NOTREACHED(); - return false; - } - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<SequenceUser>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - SequenceUser* impl = - wrapper_private->wrappable<SequenceUser>().get(); - const size_t kMinArguments = 1; - if (args.length() < kMinArguments) { - exception_state.SetSimpleException(script::kInvalidNumberOfArguments); - return false; - } - // Non-optional arguments - TypeTraits<script::Sequence< int32_t > >::ConversionType elements; - - DCHECK_LT(0, args.length()); - JS::RootedValue non_optional_value0( - context, args[0]); - FromJSValue(context, - non_optional_value0, - kNoConversionFlags, - &exception_state, &elements); - if (exception_state.is_exception_set()) { - return false; - } - - impl->SetLongSequence(elements); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - -bool fcn_setStringSequence( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, &object)) { - NOTREACHED(); - return false; - } - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<SequenceUser>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - SequenceUser* impl = - wrapper_private->wrappable<SequenceUser>().get(); - const size_t kMinArguments = 1; - if (args.length() < kMinArguments) { - exception_state.SetSimpleException(script::kInvalidNumberOfArguments); - return false; - } - // Non-optional arguments - TypeTraits<script::Sequence< std::string > >::ConversionType elements; - - DCHECK_LT(0, args.length()); - JS::RootedValue non_optional_value0( - context, args[0]); - FromJSValue(context, - non_optional_value0, - kNoConversionFlags, - &exception_state, &elements); - if (exception_state.is_exception_set()) { - return false; - } - - impl->SetStringSequence(elements); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - -bool fcn_setStringSequenceSequence( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, &object)) { - NOTREACHED(); - return false; - } - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<SequenceUser>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - SequenceUser* impl = - wrapper_private->wrappable<SequenceUser>().get(); - const size_t kMinArguments = 1; - if (args.length() < kMinArguments) { - exception_state.SetSimpleException(script::kInvalidNumberOfArguments); - return false; - } - // Non-optional arguments - TypeTraits<script::Sequence< script::Sequence< std::string > > >::ConversionType elements; - - DCHECK_LT(0, args.length()); - JS::RootedValue non_optional_value0( - context, args[0]); - FromJSValue(context, - non_optional_value0, - kNoConversionFlags, - &exception_state, &elements); - if (exception_state.is_exception_set()) { - return false; - } - - impl->SetStringSequenceSequence(elements); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - -bool fcn_setUnionOfStringAndStringSequence( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, &object)) { - NOTREACHED(); - return false; - } - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<SequenceUser>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - SequenceUser* impl = - wrapper_private->wrappable<SequenceUser>().get(); - const size_t kMinArguments = 1; - if (args.length() < kMinArguments) { - exception_state.SetSimpleException(script::kInvalidNumberOfArguments); - return false; - } - // Non-optional arguments - TypeTraits<script::UnionType2<std::string, script::Sequence< std::string > > >::ConversionType elements; - - DCHECK_LT(0, args.length()); - JS::RootedValue non_optional_value0( - context, args[0]); - FromJSValue(context, - non_optional_value0, - kNoConversionFlags, - &exception_state, &elements); - if (exception_state.is_exception_set()) { - return false; - } - - impl->SetUnionOfStringAndStringSequence(elements); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - -bool fcn_setUnionSequence( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, &object)) { - NOTREACHED(); - return false; - } - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<SequenceUser>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - SequenceUser* impl = - wrapper_private->wrappable<SequenceUser>().get(); - const size_t kMinArguments = 1; - if (args.length() < kMinArguments) { - exception_state.SetSimpleException(script::kInvalidNumberOfArguments); - return false; - } - // Non-optional arguments - TypeTraits<script::Sequence< script::UnionType2<std::string, scoped_refptr<ArbitraryInterface> > > >::ConversionType elements; - - DCHECK_LT(0, args.length()); - JS::RootedValue non_optional_value0( - context, args[0]); - FromJSValue(context, - non_optional_value0, - kNoConversionFlags, - &exception_state, &elements); - if (exception_state.is_exception_set()) { - return false; - } - - impl->SetUnionSequence(elements); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - - - -const JSPropertySpec prototype_properties[] = { - JS_PS_END -}; - -const JSFunctionSpec prototype_functions[] = { - JS_FNSPEC( - "getInterfaceSequence", fcn_getInterfaceSequence, NULL, - 0, JSPROP_ENUMERATE, NULL), - JS_FNSPEC( - "getInterfaceSequenceSequenceSequence", fcn_getInterfaceSequenceSequenceSequence, NULL, - 0, JSPROP_ENUMERATE, NULL), - JS_FNSPEC( - "getLongSequence", fcn_getLongSequence, NULL, - 0, JSPROP_ENUMERATE, NULL), - JS_FNSPEC( - "getStringSequence", fcn_getStringSequence, NULL, - 0, JSPROP_ENUMERATE, NULL), - JS_FNSPEC( - "getStringSequenceSequence", fcn_getStringSequenceSequence, NULL, - 0, JSPROP_ENUMERATE, NULL), - JS_FNSPEC( - "getUnionOfStringAndStringSequence", fcn_getUnionOfStringAndStringSequence, NULL, - 0, JSPROP_ENUMERATE, NULL), - JS_FNSPEC( - "getUnionSequence", fcn_getUnionSequence, NULL, - 0, JSPROP_ENUMERATE, NULL), - JS_FNSPEC( - "setInterfaceSequence", fcn_setInterfaceSequence, NULL, - 1, JSPROP_ENUMERATE, NULL), - JS_FNSPEC( - "setInterfaceSequenceSequenceSequence", fcn_setInterfaceSequenceSequenceSequence, NULL, - 1, JSPROP_ENUMERATE, NULL), - JS_FNSPEC( - "setLongSequence", fcn_setLongSequence, NULL, - 1, JSPROP_ENUMERATE, NULL), - JS_FNSPEC( - "setStringSequence", fcn_setStringSequence, NULL, - 1, JSPROP_ENUMERATE, NULL), - JS_FNSPEC( - "setStringSequenceSequence", fcn_setStringSequenceSequence, NULL, - 1, JSPROP_ENUMERATE, NULL), - JS_FNSPEC( - "setUnionOfStringAndStringSequence", fcn_setUnionOfStringAndStringSequence, NULL, - 1, JSPROP_ENUMERATE, NULL), - JS_FNSPEC( - "setUnionSequence", fcn_setUnionSequence, NULL, - 1, JSPROP_ENUMERATE, NULL), - JS_FS_END -}; - -const JSPropertySpec interface_object_properties[] = { - JS_PS_END -}; - -const JSFunctionSpec interface_object_functions[] = { - JS_FS_END -}; - -const JSPropertySpec own_properties[] = { - JS_PS_END -}; - -void InitializePrototypeAndInterfaceObject( - InterfaceData* interface_data, JSContext* context, - JS::HandleObject global_object) { - DCHECK(!interface_data->prototype); - DCHECK(!interface_data->interface_object); - DCHECK(JS_IsGlobalObject(global_object)); - - JS::RootedObject parent_prototype( - context, JS_GetObjectPrototype(context, global_object)); - DCHECK(parent_prototype); - - interface_data->prototype = JS_NewObjectWithGivenProto( - context, &prototype_class_definition, parent_prototype - ); - - JS::RootedObject rooted_prototype(context, interface_data->prototype); - bool success = JS_DefineProperties( - context, - rooted_prototype, - prototype_properties); - - DCHECK(success); - success = JS_DefineFunctions( - context, rooted_prototype, prototype_functions); - DCHECK(success); - - JS::RootedObject function_prototype( - context, JS_GetFunctionPrototype(context, global_object)); - DCHECK(function_prototype); - // Create the Interface object. - interface_data->interface_object = JS_NewObjectWithGivenProto( - context, &interface_object_class_definition, - function_prototype); - - // Add the InterfaceObject.name property. - JS::RootedObject rooted_interface_object( - context, interface_data->interface_object); - JS::RootedValue name_value(context); - const char name[] = - "SequenceUser"; - name_value.setString(JS_NewStringCopyZ(context, name)); - success = JS_DefineProperty( - context, rooted_interface_object, "name", name_value, JSPROP_READONLY, - NULL, NULL); - DCHECK(success); - - // Add the InterfaceObject.length property. It is set to the length of the - // shortest argument list of all overload constructors. - JS::RootedValue length_value(context); - length_value.setInt32(0); - success = JS_DefineProperty( - context, rooted_interface_object, "length", length_value, - JSPROP_READONLY, NULL, NULL); - DCHECK(success); - - // Define interface object properties (including constants). - success = JS_DefineProperties(context, rooted_interface_object, - interface_object_properties); - DCHECK(success); - // Define interface object functions (static). - success = JS_DefineFunctions(context, rooted_interface_object, - interface_object_functions); - DCHECK(success); - - // Set the Prototype.constructor and Constructor.prototype properties. - DCHECK(interface_data->interface_object); - DCHECK(interface_data->prototype); - success = JS_LinkConstructorAndPrototype( - context, - rooted_interface_object, - rooted_prototype); - DCHECK(success); -} - -InterfaceData* GetInterfaceData(JSContext* context) { - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - // Use the address of the properties definition for this interface as a - // unique key for looking up the InterfaceData for this interface. - intptr_t key = reinterpret_cast<intptr_t>(&own_properties); - InterfaceData* interface_data = global_environment->GetInterfaceData(key); - if (!interface_data) { - interface_data = new InterfaceData(); - DCHECK(interface_data); - global_environment->CacheInterfaceData(key, interface_data); - DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key)); - } - return interface_data; -} - -} // namespace - -// static -JSObject* MozjsSequenceUser::CreateProxy( - JSContext* context, const scoped_refptr<Wrappable>& wrappable) { - DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); - JS::RootedObject global_object( - context, - MozjsGlobalEnvironment::GetFromContext(context)->global_object()); - DCHECK(global_object); - - InterfaceData* interface_data = GetInterfaceData(context); - JS::RootedObject prototype(context, GetPrototype(context, global_object)); - DCHECK(prototype); - JS::RootedObject new_object( - context, - JS_NewObjectWithGivenProto( - context, &instance_class_definition, prototype)); - DCHECK(new_object); - JS::RootedObject proxy(context, - ProxyHandler::NewProxy( - context, proxy_handler.Pointer(), new_object, prototype)); - WrapperPrivate::AddPrivateData(context, proxy, wrappable); - return proxy; -} - -// static -const JSClass* MozjsSequenceUser::PrototypeClass( - JSContext* context) { - DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); - JS::RootedObject global_object( - context, - MozjsGlobalEnvironment::GetFromContext(context)->global_object()); - DCHECK(global_object); - - JS::RootedObject prototype(context, GetPrototype(context, global_object)); - const JSClass* proto_class = JS_GetClass(prototype); - return proto_class; -} - -// static -JSObject* MozjsSequenceUser::GetPrototype( - JSContext* context, JS::HandleObject global_object) { - DCHECK(JS_IsGlobalObject(global_object)); - - InterfaceData* interface_data = GetInterfaceData(context); - if (!interface_data->prototype) { - // Create new prototype that has all the props and methods - InitializePrototypeAndInterfaceObject( - interface_data, context, global_object); - } - DCHECK(interface_data->prototype); - return interface_data->prototype; -} - -// static -JSObject* MozjsSequenceUser::GetInterfaceObject( - JSContext* context, JS::HandleObject global_object) { - DCHECK(JS_IsGlobalObject(global_object)); - - InterfaceData* interface_data = GetInterfaceData(context); - if (!interface_data->interface_object) { - InitializePrototypeAndInterfaceObject( - interface_data, context, global_object); - } - DCHECK(interface_data->interface_object); - return interface_data->interface_object; -} - - -namespace { -bool Constructor(JSContext* context, unsigned int argc, JS::Value* vp) { - MozjsExceptionState exception_state(context); - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - - scoped_refptr<SequenceUser> new_object = - new SequenceUser(); - JS::RootedValue result_value(context); - ToJSValue(context, new_object, &result_value); - DCHECK(result_value.isObject()); - args.rval().setObject(result_value.toObject()); - return true; -} -} // namespace - - -} // namespace testing -} // namespace bindings -} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsSequenceUser.h b/src/cobalt/bindings/generated/mozjs-45/testing/MozjsSequenceUser.h deleted file mode 100644 index bdc2f5f..0000000 --- a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsSequenceUser.h +++ /dev/null
@@ -1,54 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! -// Auto-generated from template: bindings/mozjs-45/templates/interface.h.template - -// clang-format off - -#ifndef MozjsSequenceUser_h -#define MozjsSequenceUser_h - -#include "base/hash_tables.h" -#include "base/lazy_instance.h" -#include "base/memory/ref_counted.h" -#include "base/threading/thread_checker.h" -#include "cobalt/base/polymorphic_downcast.h" -#include "cobalt/script/wrappable.h" -#include "cobalt/bindings/testing/sequence_user.h" - -#include "third_party/mozjs-45/js/src/jsapi.h" - -namespace cobalt { -namespace bindings { -namespace testing { - -class MozjsSequenceUser { - public: - static JSObject* CreateProxy(JSContext* context, - const scoped_refptr<script::Wrappable>& wrappable); - static const JSClass* PrototypeClass(JSContext* context); - static JSObject* GetPrototype(JSContext* context, - JS::HandleObject global_object); - static JSObject* GetInterfaceObject(JSContext* context, - JS::HandleObject global_object); -}; - -} // namespace bindings -} // namespace testing -} // namespace cobalt - -#endif // MozjsSequenceUser_h
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsSingleOperationInterface.cc b/src/cobalt/bindings/generated/mozjs-45/testing/MozjsSingleOperationInterface.cc deleted file mode 100644 index 0d3ae18..0000000 --- a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsSingleOperationInterface.cc +++ /dev/null
@@ -1,111 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! -// Auto-generated from template: bindings/mozjs-45/templates/callback-interface.h.template - -// clang-format off - - -#include "MozjsSingleOperationInterface.h" -#include "MozjsArbitraryInterface.h" -#include "cobalt/bindings/testing/arbitrary_interface.h" - -#include "cobalt/script/logging_exception_state.h" -#include "cobalt/script/mozjs-45/conversion_helpers.h" -#include "cobalt/script/mozjs-45/mozjs_callback_interface.h" -#include "cobalt/script/mozjs-45/util/exception_helpers.h" -#include "third_party/mozjs-45/js/src/jsapi.h" -#include "third_party/mozjs-45/js/src/jscntxt.h" - -namespace { -using cobalt::bindings::testing::SingleOperationInterface; -using cobalt::bindings::testing::MozjsSingleOperationInterface; -using cobalt::bindings::testing::ArbitraryInterface; -using cobalt::bindings::testing::MozjsArbitraryInterface; - -using cobalt::script::LoggingExceptionState; -using cobalt::script::mozjs::FromJSValue; -using cobalt::script::mozjs::GetCallableForCallbackInterface; -using cobalt::script::mozjs::ToJSValue; -using cobalt::script::mozjs::util::GetExceptionString; -} // namespace - -namespace cobalt { -namespace bindings { -namespace testing { - -MozjsSingleOperationInterface::MozjsSingleOperationInterface( - JSContext* context, - JS::HandleObject implementing_object) - : context_(context), - implementing_object_(context, implementing_object) { } - -base::optional<int32_t > MozjsSingleOperationInterface::HandleCallback( - const scoped_refptr<script::Wrappable>& callback_this, - const scoped_refptr<ArbitraryInterface>& value, - bool* had_exception) const { - bool success = false; - base::optional<int32_t > cobalt_return_value; - JSAutoRequest auto_request(context_); - JSExceptionState* previous_exception_state = JS_SaveExceptionState(context_); - - // This could be set to NULL if it was garbage collected. - JS::RootedObject implementing_object(context_, implementing_object_.Get()); - DLOG_IF(WARNING, !implementing_object) << "Implementing object is NULL."; - if (implementing_object) { - JSAutoCompartment auto_compartment(context_, implementing_object); - - // Get callable object. - JS::RootedValue callable(context_); - if (GetCallableForCallbackInterface(context_, implementing_object, - "handleCallback", &callable)) { - // Convert the callback_this to a JSValue. - JS::RootedValue this_value(context_); - ToJSValue(context_, callback_this, &this_value); - - // Convert arguments. - const int kNumArguments = 1; - JS::AutoValueArray<kNumArguments> args(context_); - - ToJSValue(context_, value, args[0]); - - // Call the function. - JS::RootedValue return_value(context_); - JS::RootedFunction function( - context_, JS_ValueToFunction(context_, callable)); - DCHECK(function); - success = JS::Call(context_, this_value, function, args, &return_value); - DLOG_IF(WARNING, !success) << "Exception in callback: " - << GetExceptionString(context_); - if (success) { - LoggingExceptionState exception_state; - FromJSValue(context_, return_value, 0, &exception_state, - &cobalt_return_value); - success = !exception_state.is_exception_set(); - } - } - } - - *had_exception = !success; - JS_RestoreExceptionState(context_, previous_exception_state); - return cobalt_return_value; -} - -} // namespace bindings -} // namespace testing -} // namespace cobalt -
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsSingleOperationInterface.h b/src/cobalt/bindings/generated/mozjs-45/testing/MozjsSingleOperationInterface.h deleted file mode 100644 index 69a4936..0000000 --- a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsSingleOperationInterface.h +++ /dev/null
@@ -1,65 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! -// Auto-generated from template: bindings/mozjs-45/templates/callback-interface.h.template - -// clang-format off - -#ifndef MozjsSingleOperationInterface_h -#define MozjsSingleOperationInterface_h - -#include "cobalt/script/callback_interface_traits.h" -// Headers for other bindings wrapper classes -#include "cobalt/bindings/testing/single_operation_interface.h" - -#include "cobalt/script/mozjs-45/weak_heap_object.h" -#include "third_party/mozjs-45/js/src/jsapi.h" - -namespace cobalt { -namespace bindings { -namespace testing { - -class MozjsSingleOperationInterface : public SingleOperationInterface { - public: - typedef SingleOperationInterface BaseType; - - MozjsSingleOperationInterface( - JSContext* context, JS::HandleObject implementing_object); - base::optional<int32_t > HandleCallback( - const scoped_refptr<script::Wrappable>& callback_this, - const scoped_refptr<ArbitraryInterface>& value, - bool* had_exception) const OVERRIDE; - JSObject* handle() const { return implementing_object_.Get(); } - - private: - JSContext* context_; - script::mozjs::WeakHeapObject implementing_object_; -}; - -} // namespace bindings -} // namespace testing -namespace script { -// Explicit instantiation of CallbackInterfaceTraits struct so we can infer -// the type of the generated class from the type of the callback interface. -template<> -struct CallbackInterfaceTraits<bindings::testing::SingleOperationInterface> { - typedef bindings::testing::MozjsSingleOperationInterface MozjsCallbackInterfaceClass; -}; -} // namespace script -} // namespace cobalt - -#endif // MozjsSingleOperationInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsStaticPropertiesInterface.cc b/src/cobalt/bindings/generated/mozjs-45/testing/MozjsStaticPropertiesInterface.cc deleted file mode 100644 index 17f9cbd..0000000 --- a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsStaticPropertiesInterface.cc +++ /dev/null
@@ -1,660 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! -// Auto-generated from template: bindings/mozjs-45/templates/interface.cc.template - -// clang-format off - -#include "MozjsStaticPropertiesInterface.h" - -#include "base/debug/trace_event.h" -#include "cobalt/base/polymorphic_downcast.h" -#include "cobalt/script/global_environment.h" -#include "cobalt/script/opaque_handle.h" -#include "cobalt/script/script_object.h" -#include "MozjsArbitraryInterface.h" -#include "cobalt/bindings/testing/arbitrary_interface.h" - -#include "base/lazy_instance.h" -#include "cobalt/script/mozjs-45/callback_function_conversion.h" -#include "cobalt/script/exception_state.h" -#include "cobalt/script/mozjs-45/conversion_helpers.h" -#include "cobalt/script/mozjs-45/mozjs_exception_state.h" -#include "cobalt/script/mozjs-45/mozjs_callback_function.h" -#include "cobalt/script/mozjs-45/mozjs_global_environment.h" -#include "cobalt/script/mozjs-45/mozjs_object_handle.h" -#include "cobalt/script/mozjs-45/mozjs_property_enumerator.h" -#include "cobalt/script/mozjs-45/mozjs_user_object_holder.h" -#include "cobalt/script/mozjs-45/proxy_handler.h" -#include "cobalt/script/mozjs-45/type_traits.h" -#include "cobalt/script/mozjs-45/wrapper_factory.h" -#include "cobalt/script/mozjs-45/wrapper_private.h" -#include "cobalt/script/property_enumerator.h" -#include "third_party/mozjs-45/js/src/jsapi.h" -#include "third_party/mozjs-45/js/src/jsfriendapi.h" - -namespace { -using cobalt::bindings::testing::StaticPropertiesInterface; -using cobalt::bindings::testing::MozjsStaticPropertiesInterface; -using cobalt::bindings::testing::ArbitraryInterface; -using cobalt::bindings::testing::MozjsArbitraryInterface; -using cobalt::script::CallbackInterfaceTraits; -using cobalt::script::GlobalEnvironment; -using cobalt::script::OpaqueHandle; -using cobalt::script::OpaqueHandleHolder; -using cobalt::script::ScriptObject; -using cobalt::script::Wrappable; - -using cobalt::script::CallbackFunction; -using cobalt::script::CallbackInterfaceTraits; -using cobalt::script::ExceptionState; -using cobalt::script::mozjs::FromJSValue; -using cobalt::script::mozjs::kConversionFlagNullable; -using cobalt::script::mozjs::kConversionFlagRestricted; -using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString; -using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString; -using cobalt::script::mozjs::kNoConversionFlags; -using cobalt::script::mozjs::InterfaceData; -using cobalt::script::mozjs::MozjsCallbackFunction; -using cobalt::script::mozjs::MozjsExceptionState; -using cobalt::script::mozjs::MozjsGlobalEnvironment; -using cobalt::script::mozjs::MozjsUserObjectHolder; -using cobalt::script::mozjs::MozjsPropertyEnumerator; -using cobalt::script::mozjs::ProxyHandler; -using cobalt::script::mozjs::ToJSValue; -using cobalt::script::mozjs::TypeTraits; -using cobalt::script::mozjs::WrapperPrivate; -using cobalt::script::mozjs::WrapperFactory; -using cobalt::script::Wrappable; -} // namespace - -namespace cobalt { -namespace bindings { -namespace testing { - -namespace { - -class MozjsStaticPropertiesInterfaceHandler : public ProxyHandler { - public: - MozjsStaticPropertiesInterfaceHandler() - : ProxyHandler(indexed_property_hooks, named_property_hooks) {} - - private: - static NamedPropertyHooks named_property_hooks; - static IndexedPropertyHooks indexed_property_hooks; -}; - -ProxyHandler::NamedPropertyHooks -MozjsStaticPropertiesInterfaceHandler::named_property_hooks = { - NULL, - NULL, - NULL, - NULL, - NULL, -}; -ProxyHandler::IndexedPropertyHooks -MozjsStaticPropertiesInterfaceHandler::indexed_property_hooks = { - NULL, - NULL, - NULL, - NULL, - NULL, -}; - -static base::LazyInstance<MozjsStaticPropertiesInterfaceHandler> - proxy_handler; - -bool HasInstance(JSContext *context, JS::HandleObject type, - JS::MutableHandleValue vp, bool *success) { - JS::RootedObject global_object( - context, JS_GetGlobalForObject(context, type)); - DCHECK(global_object); - - JS::RootedObject prototype( - context, MozjsStaticPropertiesInterface::GetPrototype(context, global_object)); - - // |IsDelegate| walks the prototype chain of an object returning true if - // .prototype is found. - bool is_delegate; - if (!IsDelegate(context, prototype, vp, &is_delegate)) { - *success = false; - return false; - } - - *success = is_delegate; - return true; -} - -const JSClass instance_class_definition = { - "StaticPropertiesInterface", - 0 | JSCLASS_HAS_PRIVATE, - NULL, // addProperty - NULL, // delProperty - NULL, // getProperty - NULL, // setProperty - NULL, // enumerate - NULL, // resolve - NULL, // mayResolve - &WrapperPrivate::Finalizer, // finalize - NULL, // call - NULL, // hasInstance - NULL, // construct - &WrapperPrivate::Trace, // trace -}; - -const JSClass prototype_class_definition = { - "StaticPropertiesInterfacePrototype", -}; - -const JSClass interface_object_class_definition = { - "StaticPropertiesInterfaceConstructor", - 0, - NULL, // addProperty - NULL, // delProperty - NULL, // getProperty - NULL, // setProperty - NULL, // enumerate - NULL, // resolve - NULL, // mayResolve - NULL, // finalize - NULL, // call - &HasInstance, - NULL, -}; - -bool staticget_staticAttribute( - JSContext* context, unsigned argc, JS::Value* vp) { - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - StaticPropertiesInterface::static_attribute(), - &result_value); - } - if (!exception_state.is_exception_set()) { - args.rval().set(result_value); - } - return !exception_state.is_exception_set(); -} - -bool staticset_staticAttribute( - JSContext* context, unsigned argc, JS::Value* vp) { - - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - TypeTraits<std::string >::ConversionType value; - if (args.length() != 1) { - NOTREACHED(); - return false; - } - FromJSValue(context, args[0], kNoConversionFlags, &exception_state, - &value); - if (exception_state.is_exception_set()) { - return false; - } - - StaticPropertiesInterface::set_static_attribute(value); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - -bool staticfcn_staticFunction1( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - - StaticPropertiesInterface::StaticFunction(); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - -bool staticfcn_staticFunction2( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - const size_t kMinArguments = 1; - if (args.length() < kMinArguments) { - exception_state.SetSimpleException(script::kInvalidNumberOfArguments); - return false; - } - // Non-optional arguments - TypeTraits<int32_t >::ConversionType arg; - - DCHECK_LT(0, args.length()); - JS::RootedValue non_optional_value0( - context, args[0]); - FromJSValue(context, - non_optional_value0, - kNoConversionFlags, - &exception_state, &arg); - if (exception_state.is_exception_set()) { - return false; - } - - StaticPropertiesInterface::StaticFunction(arg); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - -bool staticfcn_staticFunction3( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - const size_t kMinArguments = 1; - if (args.length() < kMinArguments) { - exception_state.SetSimpleException(script::kInvalidNumberOfArguments); - return false; - } - // Non-optional arguments - TypeTraits<std::string >::ConversionType arg; - - DCHECK_LT(0, args.length()); - JS::RootedValue non_optional_value0( - context, args[0]); - FromJSValue(context, - non_optional_value0, - kNoConversionFlags, - &exception_state, &arg); - if (exception_state.is_exception_set()) { - return false; - } - - StaticPropertiesInterface::StaticFunction(arg); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - -bool staticfcn_staticFunction4( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - const size_t kMinArguments = 3; - if (args.length() < kMinArguments) { - exception_state.SetSimpleException(script::kInvalidNumberOfArguments); - return false; - } - // Non-optional arguments - TypeTraits<int32_t >::ConversionType arg1; - TypeTraits<int32_t >::ConversionType arg2; - TypeTraits<int32_t >::ConversionType arg3; - - DCHECK_LT(0, args.length()); - JS::RootedValue non_optional_value0( - context, args[0]); - FromJSValue(context, - non_optional_value0, - kNoConversionFlags, - &exception_state, &arg1); - if (exception_state.is_exception_set()) { - return false; - } - - DCHECK_LT(1, args.length()); - JS::RootedValue non_optional_value1( - context, args[1]); - FromJSValue(context, - non_optional_value1, - kNoConversionFlags, - &exception_state, &arg2); - if (exception_state.is_exception_set()) { - return false; - } - - DCHECK_LT(2, args.length()); - JS::RootedValue non_optional_value2( - context, args[2]); - FromJSValue(context, - non_optional_value2, - kNoConversionFlags, - &exception_state, &arg3); - if (exception_state.is_exception_set()) { - return false; - } - - StaticPropertiesInterface::StaticFunction(arg1, arg2, arg3); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - -bool staticfcn_staticFunction5( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - const size_t kMinArguments = 3; - if (args.length() < kMinArguments) { - exception_state.SetSimpleException(script::kInvalidNumberOfArguments); - return false; - } - // Non-optional arguments - TypeTraits<int32_t >::ConversionType arg1; - TypeTraits<int32_t >::ConversionType arg2; - TypeTraits<scoped_refptr<ArbitraryInterface> >::ConversionType arg3; - - DCHECK_LT(0, args.length()); - JS::RootedValue non_optional_value0( - context, args[0]); - FromJSValue(context, - non_optional_value0, - kNoConversionFlags, - &exception_state, &arg1); - if (exception_state.is_exception_set()) { - return false; - } - - DCHECK_LT(1, args.length()); - JS::RootedValue non_optional_value1( - context, args[1]); - FromJSValue(context, - non_optional_value1, - kNoConversionFlags, - &exception_state, &arg2); - if (exception_state.is_exception_set()) { - return false; - } - - DCHECK_LT(2, args.length()); - JS::RootedValue non_optional_value2( - context, args[2]); - FromJSValue(context, - non_optional_value2, - kNoConversionFlags, - &exception_state, &arg3); - if (exception_state.is_exception_set()) { - return false; - } - - StaticPropertiesInterface::StaticFunction(arg1, arg2, arg3); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - -bool staticfcn_staticFunction( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - switch(argc) { - case(0): { - // Overload resolution algorithm details found here: - // http://heycam.github.io/webidl/#dfn-overload-resolution-algorithm - if (true) { - return staticfcn_staticFunction1( - context, argc, vp); - } - break; - } - case(1): { - // Overload resolution algorithm details found here: - // http://heycam.github.io/webidl/#dfn-overload-resolution-algorithm - JS::RootedValue arg(context, args[0]); - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - JS::RootedObject object(context); - if (arg.isObject()) { - object = JS::RootedObject(context, &arg.toObject()); - } - if (arg.isNumber()) { - return staticfcn_staticFunction2( - context, argc, vp); - } - if (true) { - return staticfcn_staticFunction3( - context, argc, vp); - } - if (true) { - return staticfcn_staticFunction2( - context, argc, vp); - } - break; - } - case(3): { - // Overload resolution algorithm details found here: - // http://heycam.github.io/webidl/#dfn-overload-resolution-algorithm - JS::RootedValue arg(context, args[2]); - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - JS::RootedObject object(context); - if (arg.isObject()) { - object = JS::RootedObject(context, &arg.toObject()); - } - if (arg.isObject() ? wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<ArbitraryInterface>()) : - false) { - return staticfcn_staticFunction5( - context, argc, vp); - } - if (true) { - return staticfcn_staticFunction4( - context, argc, vp); - } - break; - } - } - // Invalid number of args - // http://heycam.github.io/webidl/#dfn-overload-resolution-algorithm - // 4. If S is empty, then throw a TypeError. - MozjsExceptionState exception_state(context); - exception_state.SetSimpleException(script::kInvalidNumberOfArguments); - return false; -} - - - -const JSPropertySpec prototype_properties[] = { - JS_PS_END -}; - -const JSFunctionSpec prototype_functions[] = { - JS_FS_END -}; - -const JSPropertySpec interface_object_properties[] = { - { // Static read/write attribute. - "staticAttribute", - JSPROP_SHARED | JSPROP_ENUMERATE, - { { &staticget_staticAttribute, NULL } }, - { { &staticset_staticAttribute, NULL } }, - }, - JS_PS_END -}; - -const JSFunctionSpec interface_object_functions[] = { - JS_FNSPEC( - "staticFunction", staticfcn_staticFunction, NULL, - 0, JSPROP_ENUMERATE, NULL), - JS_FS_END -}; - -const JSPropertySpec own_properties[] = { - JS_PS_END -}; - -void InitializePrototypeAndInterfaceObject( - InterfaceData* interface_data, JSContext* context, - JS::HandleObject global_object) { - DCHECK(!interface_data->prototype); - DCHECK(!interface_data->interface_object); - DCHECK(JS_IsGlobalObject(global_object)); - - JS::RootedObject parent_prototype( - context, JS_GetObjectPrototype(context, global_object)); - DCHECK(parent_prototype); - - interface_data->prototype = JS_NewObjectWithGivenProto( - context, &prototype_class_definition, parent_prototype - ); - - JS::RootedObject rooted_prototype(context, interface_data->prototype); - bool success = JS_DefineProperties( - context, - rooted_prototype, - prototype_properties); - - DCHECK(success); - success = JS_DefineFunctions( - context, rooted_prototype, prototype_functions); - DCHECK(success); - - JS::RootedObject function_prototype( - context, JS_GetFunctionPrototype(context, global_object)); - DCHECK(function_prototype); - // Create the Interface object. - interface_data->interface_object = JS_NewObjectWithGivenProto( - context, &interface_object_class_definition, - function_prototype); - - // Add the InterfaceObject.name property. - JS::RootedObject rooted_interface_object( - context, interface_data->interface_object); - JS::RootedValue name_value(context); - const char name[] = - "StaticPropertiesInterface"; - name_value.setString(JS_NewStringCopyZ(context, name)); - success = JS_DefineProperty( - context, rooted_interface_object, "name", name_value, JSPROP_READONLY, - NULL, NULL); - DCHECK(success); - - // Define interface object properties (including constants). - success = JS_DefineProperties(context, rooted_interface_object, - interface_object_properties); - DCHECK(success); - // Define interface object functions (static). - success = JS_DefineFunctions(context, rooted_interface_object, - interface_object_functions); - DCHECK(success); - - // Set the Prototype.constructor and Constructor.prototype properties. - DCHECK(interface_data->interface_object); - DCHECK(interface_data->prototype); - success = JS_LinkConstructorAndPrototype( - context, - rooted_interface_object, - rooted_prototype); - DCHECK(success); -} - -InterfaceData* GetInterfaceData(JSContext* context) { - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - // Use the address of the properties definition for this interface as a - // unique key for looking up the InterfaceData for this interface. - intptr_t key = reinterpret_cast<intptr_t>(&own_properties); - InterfaceData* interface_data = global_environment->GetInterfaceData(key); - if (!interface_data) { - interface_data = new InterfaceData(); - DCHECK(interface_data); - global_environment->CacheInterfaceData(key, interface_data); - DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key)); - } - return interface_data; -} - -} // namespace - -// static -JSObject* MozjsStaticPropertiesInterface::CreateProxy( - JSContext* context, const scoped_refptr<Wrappable>& wrappable) { - DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); - JS::RootedObject global_object( - context, - MozjsGlobalEnvironment::GetFromContext(context)->global_object()); - DCHECK(global_object); - - InterfaceData* interface_data = GetInterfaceData(context); - JS::RootedObject prototype(context, GetPrototype(context, global_object)); - DCHECK(prototype); - JS::RootedObject new_object( - context, - JS_NewObjectWithGivenProto( - context, &instance_class_definition, prototype)); - DCHECK(new_object); - JS::RootedObject proxy(context, - ProxyHandler::NewProxy( - context, proxy_handler.Pointer(), new_object, prototype)); - WrapperPrivate::AddPrivateData(context, proxy, wrappable); - return proxy; -} - -// static -const JSClass* MozjsStaticPropertiesInterface::PrototypeClass( - JSContext* context) { - DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); - JS::RootedObject global_object( - context, - MozjsGlobalEnvironment::GetFromContext(context)->global_object()); - DCHECK(global_object); - - JS::RootedObject prototype(context, GetPrototype(context, global_object)); - const JSClass* proto_class = JS_GetClass(prototype); - return proto_class; -} - -// static -JSObject* MozjsStaticPropertiesInterface::GetPrototype( - JSContext* context, JS::HandleObject global_object) { - DCHECK(JS_IsGlobalObject(global_object)); - - InterfaceData* interface_data = GetInterfaceData(context); - if (!interface_data->prototype) { - // Create new prototype that has all the props and methods - InitializePrototypeAndInterfaceObject( - interface_data, context, global_object); - } - DCHECK(interface_data->prototype); - return interface_data->prototype; -} - -// static -JSObject* MozjsStaticPropertiesInterface::GetInterfaceObject( - JSContext* context, JS::HandleObject global_object) { - DCHECK(JS_IsGlobalObject(global_object)); - - InterfaceData* interface_data = GetInterfaceData(context); - if (!interface_data->interface_object) { - InitializePrototypeAndInterfaceObject( - interface_data, context, global_object); - } - DCHECK(interface_data->interface_object); - return interface_data->interface_object; -} - - -namespace { -} // namespace - - -} // namespace testing -} // namespace bindings -} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsStaticPropertiesInterface.h b/src/cobalt/bindings/generated/mozjs-45/testing/MozjsStaticPropertiesInterface.h deleted file mode 100644 index f9317f5..0000000 --- a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsStaticPropertiesInterface.h +++ /dev/null
@@ -1,54 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! -// Auto-generated from template: bindings/mozjs-45/templates/interface.h.template - -// clang-format off - -#ifndef MozjsStaticPropertiesInterface_h -#define MozjsStaticPropertiesInterface_h - -#include "base/hash_tables.h" -#include "base/lazy_instance.h" -#include "base/memory/ref_counted.h" -#include "base/threading/thread_checker.h" -#include "cobalt/base/polymorphic_downcast.h" -#include "cobalt/script/wrappable.h" -#include "cobalt/bindings/testing/static_properties_interface.h" - -#include "third_party/mozjs-45/js/src/jsapi.h" - -namespace cobalt { -namespace bindings { -namespace testing { - -class MozjsStaticPropertiesInterface { - public: - static JSObject* CreateProxy(JSContext* context, - const scoped_refptr<script::Wrappable>& wrappable); - static const JSClass* PrototypeClass(JSContext* context); - static JSObject* GetPrototype(JSContext* context, - JS::HandleObject global_object); - static JSObject* GetInterfaceObject(JSContext* context, - JS::HandleObject global_object); -}; - -} // namespace bindings -} // namespace testing -} // namespace cobalt - -#endif // MozjsStaticPropertiesInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsStringifierAnonymousOperationInterface.cc b/src/cobalt/bindings/generated/mozjs-45/testing/MozjsStringifierAnonymousOperationInterface.cc deleted file mode 100644 index 193b821..0000000 --- a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsStringifierAnonymousOperationInterface.cc +++ /dev/null
@@ -1,387 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! -// Auto-generated from template: bindings/mozjs-45/templates/interface.cc.template - -// clang-format off - -#include "MozjsStringifierAnonymousOperationInterface.h" - -#include "base/debug/trace_event.h" -#include "cobalt/base/polymorphic_downcast.h" -#include "cobalt/script/global_environment.h" -#include "cobalt/script/opaque_handle.h" -#include "cobalt/script/script_object.h" - -#include "base/lazy_instance.h" -#include "cobalt/script/mozjs-45/callback_function_conversion.h" -#include "cobalt/script/exception_state.h" -#include "cobalt/script/mozjs-45/conversion_helpers.h" -#include "cobalt/script/mozjs-45/mozjs_exception_state.h" -#include "cobalt/script/mozjs-45/mozjs_callback_function.h" -#include "cobalt/script/mozjs-45/mozjs_global_environment.h" -#include "cobalt/script/mozjs-45/mozjs_object_handle.h" -#include "cobalt/script/mozjs-45/mozjs_property_enumerator.h" -#include "cobalt/script/mozjs-45/mozjs_user_object_holder.h" -#include "cobalt/script/mozjs-45/proxy_handler.h" -#include "cobalt/script/mozjs-45/type_traits.h" -#include "cobalt/script/mozjs-45/wrapper_factory.h" -#include "cobalt/script/mozjs-45/wrapper_private.h" -#include "cobalt/script/property_enumerator.h" -#include "third_party/mozjs-45/js/src/jsapi.h" -#include "third_party/mozjs-45/js/src/jsfriendapi.h" - -namespace { -using cobalt::bindings::testing::StringifierAnonymousOperationInterface; -using cobalt::bindings::testing::MozjsStringifierAnonymousOperationInterface; -using cobalt::script::CallbackInterfaceTraits; -using cobalt::script::GlobalEnvironment; -using cobalt::script::OpaqueHandle; -using cobalt::script::OpaqueHandleHolder; -using cobalt::script::ScriptObject; -using cobalt::script::Wrappable; - -using cobalt::script::CallbackFunction; -using cobalt::script::CallbackInterfaceTraits; -using cobalt::script::ExceptionState; -using cobalt::script::mozjs::FromJSValue; -using cobalt::script::mozjs::kConversionFlagNullable; -using cobalt::script::mozjs::kConversionFlagRestricted; -using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString; -using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString; -using cobalt::script::mozjs::kNoConversionFlags; -using cobalt::script::mozjs::InterfaceData; -using cobalt::script::mozjs::MozjsCallbackFunction; -using cobalt::script::mozjs::MozjsExceptionState; -using cobalt::script::mozjs::MozjsGlobalEnvironment; -using cobalt::script::mozjs::MozjsUserObjectHolder; -using cobalt::script::mozjs::MozjsPropertyEnumerator; -using cobalt::script::mozjs::ProxyHandler; -using cobalt::script::mozjs::ToJSValue; -using cobalt::script::mozjs::TypeTraits; -using cobalt::script::mozjs::WrapperPrivate; -using cobalt::script::mozjs::WrapperFactory; -using cobalt::script::Wrappable; -} // namespace - -namespace cobalt { -namespace bindings { -namespace testing { - -namespace { - -class MozjsStringifierAnonymousOperationInterfaceHandler : public ProxyHandler { - public: - MozjsStringifierAnonymousOperationInterfaceHandler() - : ProxyHandler(indexed_property_hooks, named_property_hooks) {} - - private: - static NamedPropertyHooks named_property_hooks; - static IndexedPropertyHooks indexed_property_hooks; -}; - -ProxyHandler::NamedPropertyHooks -MozjsStringifierAnonymousOperationInterfaceHandler::named_property_hooks = { - NULL, - NULL, - NULL, - NULL, - NULL, -}; -ProxyHandler::IndexedPropertyHooks -MozjsStringifierAnonymousOperationInterfaceHandler::indexed_property_hooks = { - NULL, - NULL, - NULL, - NULL, - NULL, -}; - -static base::LazyInstance<MozjsStringifierAnonymousOperationInterfaceHandler> - proxy_handler; - -bool HasInstance(JSContext *context, JS::HandleObject type, - JS::MutableHandleValue vp, bool *success) { - JS::RootedObject global_object( - context, JS_GetGlobalForObject(context, type)); - DCHECK(global_object); - - JS::RootedObject prototype( - context, MozjsStringifierAnonymousOperationInterface::GetPrototype(context, global_object)); - - // |IsDelegate| walks the prototype chain of an object returning true if - // .prototype is found. - bool is_delegate; - if (!IsDelegate(context, prototype, vp, &is_delegate)) { - *success = false; - return false; - } - - *success = is_delegate; - return true; -} - -const JSClass instance_class_definition = { - "StringifierAnonymousOperationInterface", - 0 | JSCLASS_HAS_PRIVATE, - NULL, // addProperty - NULL, // delProperty - NULL, // getProperty - NULL, // setProperty - NULL, // enumerate - NULL, // resolve - NULL, // mayResolve - &WrapperPrivate::Finalizer, // finalize - NULL, // call - NULL, // hasInstance - NULL, // construct - &WrapperPrivate::Trace, // trace -}; - -const JSClass prototype_class_definition = { - "StringifierAnonymousOperationInterfacePrototype", -}; - -const JSClass interface_object_class_definition = { - "StringifierAnonymousOperationInterfaceConstructor", - 0, - NULL, // addProperty - NULL, // delProperty - NULL, // getProperty - NULL, // setProperty - NULL, // enumerate - NULL, // resolve - NULL, // mayResolve - NULL, // finalize - NULL, // call - &HasInstance, - NULL, -}; - - -bool Stringifier(JSContext* context, unsigned argc, JS::Value *vp) { - MozjsExceptionState exception_state(context); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, &object)) { - NOTREACHED(); - return false; - } - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - StringifierAnonymousOperationInterface* impl = - wrapper_private->wrappable<StringifierAnonymousOperationInterface>().get(); - if (!impl) { - exception_state.SetSimpleException(cobalt::script::kStringifierProblem); - NOTREACHED(); - return false; - } - std::string stringified = impl->AnonymousStringifier(); - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedString rooted_string(context, - JS_NewStringCopyN(context, stringified.c_str(), stringified.length())); - args.rval().set(JS::StringValue(rooted_string)); - return true; -} - - -const JSPropertySpec prototype_properties[] = { - JS_PS_END -}; - -const JSFunctionSpec prototype_functions[] = { - JS_FNSPEC("toString", Stringifier, NULL, 0, JSPROP_ENUMERATE, NULL), - JS_FS_END -}; - -const JSPropertySpec interface_object_properties[] = { - JS_PS_END -}; - -const JSFunctionSpec interface_object_functions[] = { - JS_FS_END -}; - -const JSPropertySpec own_properties[] = { - JS_PS_END -}; - -void InitializePrototypeAndInterfaceObject( - InterfaceData* interface_data, JSContext* context, - JS::HandleObject global_object) { - DCHECK(!interface_data->prototype); - DCHECK(!interface_data->interface_object); - DCHECK(JS_IsGlobalObject(global_object)); - - JS::RootedObject parent_prototype( - context, JS_GetObjectPrototype(context, global_object)); - DCHECK(parent_prototype); - - interface_data->prototype = JS_NewObjectWithGivenProto( - context, &prototype_class_definition, parent_prototype - ); - - JS::RootedObject rooted_prototype(context, interface_data->prototype); - bool success = JS_DefineProperties( - context, - rooted_prototype, - prototype_properties); - - DCHECK(success); - success = JS_DefineFunctions( - context, rooted_prototype, prototype_functions); - DCHECK(success); - - JS::RootedObject function_prototype( - context, JS_GetFunctionPrototype(context, global_object)); - DCHECK(function_prototype); - // Create the Interface object. - interface_data->interface_object = JS_NewObjectWithGivenProto( - context, &interface_object_class_definition, - function_prototype); - - // Add the InterfaceObject.name property. - JS::RootedObject rooted_interface_object( - context, interface_data->interface_object); - JS::RootedValue name_value(context); - const char name[] = - "StringifierAnonymousOperationInterface"; - name_value.setString(JS_NewStringCopyZ(context, name)); - success = JS_DefineProperty( - context, rooted_interface_object, "name", name_value, JSPROP_READONLY, - NULL, NULL); - DCHECK(success); - - // Define interface object properties (including constants). - success = JS_DefineProperties(context, rooted_interface_object, - interface_object_properties); - DCHECK(success); - // Define interface object functions (static). - success = JS_DefineFunctions(context, rooted_interface_object, - interface_object_functions); - DCHECK(success); - - // Set the Prototype.constructor and Constructor.prototype properties. - DCHECK(interface_data->interface_object); - DCHECK(interface_data->prototype); - success = JS_LinkConstructorAndPrototype( - context, - rooted_interface_object, - rooted_prototype); - DCHECK(success); -} - -InterfaceData* GetInterfaceData(JSContext* context) { - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - // Use the address of the properties definition for this interface as a - // unique key for looking up the InterfaceData for this interface. - intptr_t key = reinterpret_cast<intptr_t>(&own_properties); - InterfaceData* interface_data = global_environment->GetInterfaceData(key); - if (!interface_data) { - interface_data = new InterfaceData(); - DCHECK(interface_data); - global_environment->CacheInterfaceData(key, interface_data); - DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key)); - } - return interface_data; -} - -} // namespace - -// static -JSObject* MozjsStringifierAnonymousOperationInterface::CreateProxy( - JSContext* context, const scoped_refptr<Wrappable>& wrappable) { - DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); - JS::RootedObject global_object( - context, - MozjsGlobalEnvironment::GetFromContext(context)->global_object()); - DCHECK(global_object); - - InterfaceData* interface_data = GetInterfaceData(context); - JS::RootedObject prototype(context, GetPrototype(context, global_object)); - DCHECK(prototype); - JS::RootedObject new_object( - context, - JS_NewObjectWithGivenProto( - context, &instance_class_definition, prototype)); - DCHECK(new_object); - JS::RootedObject proxy(context, - ProxyHandler::NewProxy( - context, proxy_handler.Pointer(), new_object, prototype)); - WrapperPrivate::AddPrivateData(context, proxy, wrappable); - return proxy; -} - -// static -const JSClass* MozjsStringifierAnonymousOperationInterface::PrototypeClass( - JSContext* context) { - DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); - JS::RootedObject global_object( - context, - MozjsGlobalEnvironment::GetFromContext(context)->global_object()); - DCHECK(global_object); - - JS::RootedObject prototype(context, GetPrototype(context, global_object)); - const JSClass* proto_class = JS_GetClass(prototype); - return proto_class; -} - -// static -JSObject* MozjsStringifierAnonymousOperationInterface::GetPrototype( - JSContext* context, JS::HandleObject global_object) { - DCHECK(JS_IsGlobalObject(global_object)); - - InterfaceData* interface_data = GetInterfaceData(context); - if (!interface_data->prototype) { - // Create new prototype that has all the props and methods - InitializePrototypeAndInterfaceObject( - interface_data, context, global_object); - } - DCHECK(interface_data->prototype); - return interface_data->prototype; -} - -// static -JSObject* MozjsStringifierAnonymousOperationInterface::GetInterfaceObject( - JSContext* context, JS::HandleObject global_object) { - DCHECK(JS_IsGlobalObject(global_object)); - - InterfaceData* interface_data = GetInterfaceData(context); - if (!interface_data->interface_object) { - InitializePrototypeAndInterfaceObject( - interface_data, context, global_object); - } - DCHECK(interface_data->interface_object); - return interface_data->interface_object; -} - - -namespace { -} // namespace - - -} // namespace testing -} // namespace bindings -} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsStringifierAnonymousOperationInterface.h b/src/cobalt/bindings/generated/mozjs-45/testing/MozjsStringifierAnonymousOperationInterface.h deleted file mode 100644 index 2b6f91a..0000000 --- a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsStringifierAnonymousOperationInterface.h +++ /dev/null
@@ -1,54 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! -// Auto-generated from template: bindings/mozjs-45/templates/interface.h.template - -// clang-format off - -#ifndef MozjsStringifierAnonymousOperationInterface_h -#define MozjsStringifierAnonymousOperationInterface_h - -#include "base/hash_tables.h" -#include "base/lazy_instance.h" -#include "base/memory/ref_counted.h" -#include "base/threading/thread_checker.h" -#include "cobalt/base/polymorphic_downcast.h" -#include "cobalt/script/wrappable.h" -#include "cobalt/bindings/testing/stringifier_anonymous_operation_interface.h" - -#include "third_party/mozjs-45/js/src/jsapi.h" - -namespace cobalt { -namespace bindings { -namespace testing { - -class MozjsStringifierAnonymousOperationInterface { - public: - static JSObject* CreateProxy(JSContext* context, - const scoped_refptr<script::Wrappable>& wrappable); - static const JSClass* PrototypeClass(JSContext* context); - static JSObject* GetPrototype(JSContext* context, - JS::HandleObject global_object); - static JSObject* GetInterfaceObject(JSContext* context, - JS::HandleObject global_object); -}; - -} // namespace bindings -} // namespace testing -} // namespace cobalt - -#endif // MozjsStringifierAnonymousOperationInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsStringifierAttributeInterface.cc b/src/cobalt/bindings/generated/mozjs-45/testing/MozjsStringifierAttributeInterface.cc deleted file mode 100644 index f86fd6f..0000000 --- a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsStringifierAttributeInterface.cc +++ /dev/null
@@ -1,463 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! -// Auto-generated from template: bindings/mozjs-45/templates/interface.cc.template - -// clang-format off - -#include "MozjsStringifierAttributeInterface.h" - -#include "base/debug/trace_event.h" -#include "cobalt/base/polymorphic_downcast.h" -#include "cobalt/script/global_environment.h" -#include "cobalt/script/opaque_handle.h" -#include "cobalt/script/script_object.h" - -#include "base/lazy_instance.h" -#include "cobalt/script/mozjs-45/callback_function_conversion.h" -#include "cobalt/script/exception_state.h" -#include "cobalt/script/mozjs-45/conversion_helpers.h" -#include "cobalt/script/mozjs-45/mozjs_exception_state.h" -#include "cobalt/script/mozjs-45/mozjs_callback_function.h" -#include "cobalt/script/mozjs-45/mozjs_global_environment.h" -#include "cobalt/script/mozjs-45/mozjs_object_handle.h" -#include "cobalt/script/mozjs-45/mozjs_property_enumerator.h" -#include "cobalt/script/mozjs-45/mozjs_user_object_holder.h" -#include "cobalt/script/mozjs-45/proxy_handler.h" -#include "cobalt/script/mozjs-45/type_traits.h" -#include "cobalt/script/mozjs-45/wrapper_factory.h" -#include "cobalt/script/mozjs-45/wrapper_private.h" -#include "cobalt/script/property_enumerator.h" -#include "third_party/mozjs-45/js/src/jsapi.h" -#include "third_party/mozjs-45/js/src/jsfriendapi.h" - -namespace { -using cobalt::bindings::testing::StringifierAttributeInterface; -using cobalt::bindings::testing::MozjsStringifierAttributeInterface; -using cobalt::script::CallbackInterfaceTraits; -using cobalt::script::GlobalEnvironment; -using cobalt::script::OpaqueHandle; -using cobalt::script::OpaqueHandleHolder; -using cobalt::script::ScriptObject; -using cobalt::script::Wrappable; - -using cobalt::script::CallbackFunction; -using cobalt::script::CallbackInterfaceTraits; -using cobalt::script::ExceptionState; -using cobalt::script::mozjs::FromJSValue; -using cobalt::script::mozjs::kConversionFlagNullable; -using cobalt::script::mozjs::kConversionFlagRestricted; -using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString; -using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString; -using cobalt::script::mozjs::kNoConversionFlags; -using cobalt::script::mozjs::InterfaceData; -using cobalt::script::mozjs::MozjsCallbackFunction; -using cobalt::script::mozjs::MozjsExceptionState; -using cobalt::script::mozjs::MozjsGlobalEnvironment; -using cobalt::script::mozjs::MozjsUserObjectHolder; -using cobalt::script::mozjs::MozjsPropertyEnumerator; -using cobalt::script::mozjs::ProxyHandler; -using cobalt::script::mozjs::ToJSValue; -using cobalt::script::mozjs::TypeTraits; -using cobalt::script::mozjs::WrapperPrivate; -using cobalt::script::mozjs::WrapperFactory; -using cobalt::script::Wrappable; -} // namespace - -namespace cobalt { -namespace bindings { -namespace testing { - -namespace { - -class MozjsStringifierAttributeInterfaceHandler : public ProxyHandler { - public: - MozjsStringifierAttributeInterfaceHandler() - : ProxyHandler(indexed_property_hooks, named_property_hooks) {} - - private: - static NamedPropertyHooks named_property_hooks; - static IndexedPropertyHooks indexed_property_hooks; -}; - -ProxyHandler::NamedPropertyHooks -MozjsStringifierAttributeInterfaceHandler::named_property_hooks = { - NULL, - NULL, - NULL, - NULL, - NULL, -}; -ProxyHandler::IndexedPropertyHooks -MozjsStringifierAttributeInterfaceHandler::indexed_property_hooks = { - NULL, - NULL, - NULL, - NULL, - NULL, -}; - -static base::LazyInstance<MozjsStringifierAttributeInterfaceHandler> - proxy_handler; - -bool HasInstance(JSContext *context, JS::HandleObject type, - JS::MutableHandleValue vp, bool *success) { - JS::RootedObject global_object( - context, JS_GetGlobalForObject(context, type)); - DCHECK(global_object); - - JS::RootedObject prototype( - context, MozjsStringifierAttributeInterface::GetPrototype(context, global_object)); - - // |IsDelegate| walks the prototype chain of an object returning true if - // .prototype is found. - bool is_delegate; - if (!IsDelegate(context, prototype, vp, &is_delegate)) { - *success = false; - return false; - } - - *success = is_delegate; - return true; -} - -const JSClass instance_class_definition = { - "StringifierAttributeInterface", - 0 | JSCLASS_HAS_PRIVATE, - NULL, // addProperty - NULL, // delProperty - NULL, // getProperty - NULL, // setProperty - NULL, // enumerate - NULL, // resolve - NULL, // mayResolve - &WrapperPrivate::Finalizer, // finalize - NULL, // call - NULL, // hasInstance - NULL, // construct - &WrapperPrivate::Trace, // trace -}; - -const JSClass prototype_class_definition = { - "StringifierAttributeInterfacePrototype", -}; - -const JSClass interface_object_class_definition = { - "StringifierAttributeInterfaceConstructor", - 0, - NULL, // addProperty - NULL, // delProperty - NULL, // getProperty - NULL, // setProperty - NULL, // enumerate - NULL, // resolve - NULL, // mayResolve - NULL, // finalize - NULL, // call - &HasInstance, - NULL, -}; - -bool get_theStringifierAttribute( - JSContext* context, unsigned argc, JS::Value* vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<StringifierAttributeInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - StringifierAttributeInterface* impl = - wrapper_private->wrappable<StringifierAttributeInterface>().get(); - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->the_stringifier_attribute(), - &result_value); - } - if (!exception_state.is_exception_set()) { - args.rval().set(result_value); - } - return !exception_state.is_exception_set(); -} - -bool set_theStringifierAttribute( - JSContext* context, unsigned argc, JS::Value* vp) { - - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<StringifierAttributeInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - StringifierAttributeInterface* impl = - wrapper_private->wrappable<StringifierAttributeInterface>().get(); - TypeTraits<std::string >::ConversionType value; - if (args.length() != 1) { - NOTREACHED(); - return false; - } - FromJSValue(context, args[0], kNoConversionFlags, &exception_state, - &value); - if (exception_state.is_exception_set()) { - return false; - } - - impl->set_the_stringifier_attribute(value); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - - -bool Stringifier(JSContext* context, unsigned argc, JS::Value *vp) { - MozjsExceptionState exception_state(context); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, &object)) { - NOTREACHED(); - return false; - } - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - StringifierAttributeInterface* impl = - wrapper_private->wrappable<StringifierAttributeInterface>().get(); - if (!impl) { - exception_state.SetSimpleException(cobalt::script::kStringifierProblem); - NOTREACHED(); - return false; - } - std::string stringified = impl->the_stringifier_attribute(); - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedString rooted_string(context, - JS_NewStringCopyN(context, stringified.c_str(), stringified.length())); - args.rval().set(JS::StringValue(rooted_string)); - return true; -} - - -const JSPropertySpec prototype_properties[] = { - { // Read/Write property - "theStringifierAttribute", - JSPROP_SHARED | JSPROP_ENUMERATE, - { { &get_theStringifierAttribute, NULL } }, - { { &set_theStringifierAttribute, NULL } }, - }, - JS_PS_END -}; - -const JSFunctionSpec prototype_functions[] = { - JS_FNSPEC("toString", Stringifier, NULL, 0, JSPROP_ENUMERATE, NULL), - JS_FS_END -}; - -const JSPropertySpec interface_object_properties[] = { - JS_PS_END -}; - -const JSFunctionSpec interface_object_functions[] = { - JS_FS_END -}; - -const JSPropertySpec own_properties[] = { - JS_PS_END -}; - -void InitializePrototypeAndInterfaceObject( - InterfaceData* interface_data, JSContext* context, - JS::HandleObject global_object) { - DCHECK(!interface_data->prototype); - DCHECK(!interface_data->interface_object); - DCHECK(JS_IsGlobalObject(global_object)); - - JS::RootedObject parent_prototype( - context, JS_GetObjectPrototype(context, global_object)); - DCHECK(parent_prototype); - - interface_data->prototype = JS_NewObjectWithGivenProto( - context, &prototype_class_definition, parent_prototype - ); - - JS::RootedObject rooted_prototype(context, interface_data->prototype); - bool success = JS_DefineProperties( - context, - rooted_prototype, - prototype_properties); - - DCHECK(success); - success = JS_DefineFunctions( - context, rooted_prototype, prototype_functions); - DCHECK(success); - - JS::RootedObject function_prototype( - context, JS_GetFunctionPrototype(context, global_object)); - DCHECK(function_prototype); - // Create the Interface object. - interface_data->interface_object = JS_NewObjectWithGivenProto( - context, &interface_object_class_definition, - function_prototype); - - // Add the InterfaceObject.name property. - JS::RootedObject rooted_interface_object( - context, interface_data->interface_object); - JS::RootedValue name_value(context); - const char name[] = - "StringifierAttributeInterface"; - name_value.setString(JS_NewStringCopyZ(context, name)); - success = JS_DefineProperty( - context, rooted_interface_object, "name", name_value, JSPROP_READONLY, - NULL, NULL); - DCHECK(success); - - // Define interface object properties (including constants). - success = JS_DefineProperties(context, rooted_interface_object, - interface_object_properties); - DCHECK(success); - // Define interface object functions (static). - success = JS_DefineFunctions(context, rooted_interface_object, - interface_object_functions); - DCHECK(success); - - // Set the Prototype.constructor and Constructor.prototype properties. - DCHECK(interface_data->interface_object); - DCHECK(interface_data->prototype); - success = JS_LinkConstructorAndPrototype( - context, - rooted_interface_object, - rooted_prototype); - DCHECK(success); -} - -InterfaceData* GetInterfaceData(JSContext* context) { - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - // Use the address of the properties definition for this interface as a - // unique key for looking up the InterfaceData for this interface. - intptr_t key = reinterpret_cast<intptr_t>(&own_properties); - InterfaceData* interface_data = global_environment->GetInterfaceData(key); - if (!interface_data) { - interface_data = new InterfaceData(); - DCHECK(interface_data); - global_environment->CacheInterfaceData(key, interface_data); - DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key)); - } - return interface_data; -} - -} // namespace - -// static -JSObject* MozjsStringifierAttributeInterface::CreateProxy( - JSContext* context, const scoped_refptr<Wrappable>& wrappable) { - DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); - JS::RootedObject global_object( - context, - MozjsGlobalEnvironment::GetFromContext(context)->global_object()); - DCHECK(global_object); - - InterfaceData* interface_data = GetInterfaceData(context); - JS::RootedObject prototype(context, GetPrototype(context, global_object)); - DCHECK(prototype); - JS::RootedObject new_object( - context, - JS_NewObjectWithGivenProto( - context, &instance_class_definition, prototype)); - DCHECK(new_object); - JS::RootedObject proxy(context, - ProxyHandler::NewProxy( - context, proxy_handler.Pointer(), new_object, prototype)); - WrapperPrivate::AddPrivateData(context, proxy, wrappable); - return proxy; -} - -// static -const JSClass* MozjsStringifierAttributeInterface::PrototypeClass( - JSContext* context) { - DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); - JS::RootedObject global_object( - context, - MozjsGlobalEnvironment::GetFromContext(context)->global_object()); - DCHECK(global_object); - - JS::RootedObject prototype(context, GetPrototype(context, global_object)); - const JSClass* proto_class = JS_GetClass(prototype); - return proto_class; -} - -// static -JSObject* MozjsStringifierAttributeInterface::GetPrototype( - JSContext* context, JS::HandleObject global_object) { - DCHECK(JS_IsGlobalObject(global_object)); - - InterfaceData* interface_data = GetInterfaceData(context); - if (!interface_data->prototype) { - // Create new prototype that has all the props and methods - InitializePrototypeAndInterfaceObject( - interface_data, context, global_object); - } - DCHECK(interface_data->prototype); - return interface_data->prototype; -} - -// static -JSObject* MozjsStringifierAttributeInterface::GetInterfaceObject( - JSContext* context, JS::HandleObject global_object) { - DCHECK(JS_IsGlobalObject(global_object)); - - InterfaceData* interface_data = GetInterfaceData(context); - if (!interface_data->interface_object) { - InitializePrototypeAndInterfaceObject( - interface_data, context, global_object); - } - DCHECK(interface_data->interface_object); - return interface_data->interface_object; -} - - -namespace { -} // namespace - - -} // namespace testing -} // namespace bindings -} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsStringifierAttributeInterface.h b/src/cobalt/bindings/generated/mozjs-45/testing/MozjsStringifierAttributeInterface.h deleted file mode 100644 index 5321dae..0000000 --- a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsStringifierAttributeInterface.h +++ /dev/null
@@ -1,54 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! -// Auto-generated from template: bindings/mozjs-45/templates/interface.h.template - -// clang-format off - -#ifndef MozjsStringifierAttributeInterface_h -#define MozjsStringifierAttributeInterface_h - -#include "base/hash_tables.h" -#include "base/lazy_instance.h" -#include "base/memory/ref_counted.h" -#include "base/threading/thread_checker.h" -#include "cobalt/base/polymorphic_downcast.h" -#include "cobalt/script/wrappable.h" -#include "cobalt/bindings/testing/stringifier_attribute_interface.h" - -#include "third_party/mozjs-45/js/src/jsapi.h" - -namespace cobalt { -namespace bindings { -namespace testing { - -class MozjsStringifierAttributeInterface { - public: - static JSObject* CreateProxy(JSContext* context, - const scoped_refptr<script::Wrappable>& wrappable); - static const JSClass* PrototypeClass(JSContext* context); - static JSObject* GetPrototype(JSContext* context, - JS::HandleObject global_object); - static JSObject* GetInterfaceObject(JSContext* context, - JS::HandleObject global_object); -}; - -} // namespace bindings -} // namespace testing -} // namespace cobalt - -#endif // MozjsStringifierAttributeInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsStringifierOperationInterface.cc b/src/cobalt/bindings/generated/mozjs-45/testing/MozjsStringifierOperationInterface.cc deleted file mode 100644 index b55a841..0000000 --- a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsStringifierOperationInterface.cc +++ /dev/null
@@ -1,433 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! -// Auto-generated from template: bindings/mozjs-45/templates/interface.cc.template - -// clang-format off - -#include "MozjsStringifierOperationInterface.h" - -#include "base/debug/trace_event.h" -#include "cobalt/base/polymorphic_downcast.h" -#include "cobalt/script/global_environment.h" -#include "cobalt/script/opaque_handle.h" -#include "cobalt/script/script_object.h" - -#include "base/lazy_instance.h" -#include "cobalt/script/mozjs-45/callback_function_conversion.h" -#include "cobalt/script/exception_state.h" -#include "cobalt/script/mozjs-45/conversion_helpers.h" -#include "cobalt/script/mozjs-45/mozjs_exception_state.h" -#include "cobalt/script/mozjs-45/mozjs_callback_function.h" -#include "cobalt/script/mozjs-45/mozjs_global_environment.h" -#include "cobalt/script/mozjs-45/mozjs_object_handle.h" -#include "cobalt/script/mozjs-45/mozjs_property_enumerator.h" -#include "cobalt/script/mozjs-45/mozjs_user_object_holder.h" -#include "cobalt/script/mozjs-45/proxy_handler.h" -#include "cobalt/script/mozjs-45/type_traits.h" -#include "cobalt/script/mozjs-45/wrapper_factory.h" -#include "cobalt/script/mozjs-45/wrapper_private.h" -#include "cobalt/script/property_enumerator.h" -#include "third_party/mozjs-45/js/src/jsapi.h" -#include "third_party/mozjs-45/js/src/jsfriendapi.h" - -namespace { -using cobalt::bindings::testing::StringifierOperationInterface; -using cobalt::bindings::testing::MozjsStringifierOperationInterface; -using cobalt::script::CallbackInterfaceTraits; -using cobalt::script::GlobalEnvironment; -using cobalt::script::OpaqueHandle; -using cobalt::script::OpaqueHandleHolder; -using cobalt::script::ScriptObject; -using cobalt::script::Wrappable; - -using cobalt::script::CallbackFunction; -using cobalt::script::CallbackInterfaceTraits; -using cobalt::script::ExceptionState; -using cobalt::script::mozjs::FromJSValue; -using cobalt::script::mozjs::kConversionFlagNullable; -using cobalt::script::mozjs::kConversionFlagRestricted; -using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString; -using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString; -using cobalt::script::mozjs::kNoConversionFlags; -using cobalt::script::mozjs::InterfaceData; -using cobalt::script::mozjs::MozjsCallbackFunction; -using cobalt::script::mozjs::MozjsExceptionState; -using cobalt::script::mozjs::MozjsGlobalEnvironment; -using cobalt::script::mozjs::MozjsUserObjectHolder; -using cobalt::script::mozjs::MozjsPropertyEnumerator; -using cobalt::script::mozjs::ProxyHandler; -using cobalt::script::mozjs::ToJSValue; -using cobalt::script::mozjs::TypeTraits; -using cobalt::script::mozjs::WrapperPrivate; -using cobalt::script::mozjs::WrapperFactory; -using cobalt::script::Wrappable; -} // namespace - -namespace cobalt { -namespace bindings { -namespace testing { - -namespace { - -class MozjsStringifierOperationInterfaceHandler : public ProxyHandler { - public: - MozjsStringifierOperationInterfaceHandler() - : ProxyHandler(indexed_property_hooks, named_property_hooks) {} - - private: - static NamedPropertyHooks named_property_hooks; - static IndexedPropertyHooks indexed_property_hooks; -}; - -ProxyHandler::NamedPropertyHooks -MozjsStringifierOperationInterfaceHandler::named_property_hooks = { - NULL, - NULL, - NULL, - NULL, - NULL, -}; -ProxyHandler::IndexedPropertyHooks -MozjsStringifierOperationInterfaceHandler::indexed_property_hooks = { - NULL, - NULL, - NULL, - NULL, - NULL, -}; - -static base::LazyInstance<MozjsStringifierOperationInterfaceHandler> - proxy_handler; - -bool HasInstance(JSContext *context, JS::HandleObject type, - JS::MutableHandleValue vp, bool *success) { - JS::RootedObject global_object( - context, JS_GetGlobalForObject(context, type)); - DCHECK(global_object); - - JS::RootedObject prototype( - context, MozjsStringifierOperationInterface::GetPrototype(context, global_object)); - - // |IsDelegate| walks the prototype chain of an object returning true if - // .prototype is found. - bool is_delegate; - if (!IsDelegate(context, prototype, vp, &is_delegate)) { - *success = false; - return false; - } - - *success = is_delegate; - return true; -} - -const JSClass instance_class_definition = { - "StringifierOperationInterface", - 0 | JSCLASS_HAS_PRIVATE, - NULL, // addProperty - NULL, // delProperty - NULL, // getProperty - NULL, // setProperty - NULL, // enumerate - NULL, // resolve - NULL, // mayResolve - &WrapperPrivate::Finalizer, // finalize - NULL, // call - NULL, // hasInstance - NULL, // construct - &WrapperPrivate::Trace, // trace -}; - -const JSClass prototype_class_definition = { - "StringifierOperationInterfacePrototype", -}; - -const JSClass interface_object_class_definition = { - "StringifierOperationInterfaceConstructor", - 0, - NULL, // addProperty - NULL, // delProperty - NULL, // getProperty - NULL, // setProperty - NULL, // enumerate - NULL, // resolve - NULL, // mayResolve - NULL, // finalize - NULL, // call - &HasInstance, - NULL, -}; - -bool fcn_theStringifierOperation( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, &object)) { - NOTREACHED(); - return false; - } - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<StringifierOperationInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - StringifierOperationInterface* impl = - wrapper_private->wrappable<StringifierOperationInterface>().get(); - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->TheStringifierOperation(), - &result_value); - } - if (!exception_state.is_exception_set()) { - args.rval().set(result_value); - } - return !exception_state.is_exception_set(); -} - - -bool Stringifier(JSContext* context, unsigned argc, JS::Value *vp) { - MozjsExceptionState exception_state(context); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, &object)) { - NOTREACHED(); - return false; - } - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - StringifierOperationInterface* impl = - wrapper_private->wrappable<StringifierOperationInterface>().get(); - if (!impl) { - exception_state.SetSimpleException(cobalt::script::kStringifierProblem); - NOTREACHED(); - return false; - } - std::string stringified = impl->TheStringifierOperation(); - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedString rooted_string(context, - JS_NewStringCopyN(context, stringified.c_str(), stringified.length())); - args.rval().set(JS::StringValue(rooted_string)); - return true; -} - - -const JSPropertySpec prototype_properties[] = { - JS_PS_END -}; - -const JSFunctionSpec prototype_functions[] = { - JS_FNSPEC("toString", Stringifier, NULL, 0, JSPROP_ENUMERATE, NULL), - JS_FNSPEC( - "theStringifierOperation", fcn_theStringifierOperation, NULL, - 0, JSPROP_ENUMERATE, NULL), - JS_FS_END -}; - -const JSPropertySpec interface_object_properties[] = { - JS_PS_END -}; - -const JSFunctionSpec interface_object_functions[] = { - JS_FS_END -}; - -const JSPropertySpec own_properties[] = { - JS_PS_END -}; - -void InitializePrototypeAndInterfaceObject( - InterfaceData* interface_data, JSContext* context, - JS::HandleObject global_object) { - DCHECK(!interface_data->prototype); - DCHECK(!interface_data->interface_object); - DCHECK(JS_IsGlobalObject(global_object)); - - JS::RootedObject parent_prototype( - context, JS_GetObjectPrototype(context, global_object)); - DCHECK(parent_prototype); - - interface_data->prototype = JS_NewObjectWithGivenProto( - context, &prototype_class_definition, parent_prototype - ); - - JS::RootedObject rooted_prototype(context, interface_data->prototype); - bool success = JS_DefineProperties( - context, - rooted_prototype, - prototype_properties); - - DCHECK(success); - success = JS_DefineFunctions( - context, rooted_prototype, prototype_functions); - DCHECK(success); - - JS::RootedObject function_prototype( - context, JS_GetFunctionPrototype(context, global_object)); - DCHECK(function_prototype); - // Create the Interface object. - interface_data->interface_object = JS_NewObjectWithGivenProto( - context, &interface_object_class_definition, - function_prototype); - - // Add the InterfaceObject.name property. - JS::RootedObject rooted_interface_object( - context, interface_data->interface_object); - JS::RootedValue name_value(context); - const char name[] = - "StringifierOperationInterface"; - name_value.setString(JS_NewStringCopyZ(context, name)); - success = JS_DefineProperty( - context, rooted_interface_object, "name", name_value, JSPROP_READONLY, - NULL, NULL); - DCHECK(success); - - // Define interface object properties (including constants). - success = JS_DefineProperties(context, rooted_interface_object, - interface_object_properties); - DCHECK(success); - // Define interface object functions (static). - success = JS_DefineFunctions(context, rooted_interface_object, - interface_object_functions); - DCHECK(success); - - // Set the Prototype.constructor and Constructor.prototype properties. - DCHECK(interface_data->interface_object); - DCHECK(interface_data->prototype); - success = JS_LinkConstructorAndPrototype( - context, - rooted_interface_object, - rooted_prototype); - DCHECK(success); -} - -InterfaceData* GetInterfaceData(JSContext* context) { - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - // Use the address of the properties definition for this interface as a - // unique key for looking up the InterfaceData for this interface. - intptr_t key = reinterpret_cast<intptr_t>(&own_properties); - InterfaceData* interface_data = global_environment->GetInterfaceData(key); - if (!interface_data) { - interface_data = new InterfaceData(); - DCHECK(interface_data); - global_environment->CacheInterfaceData(key, interface_data); - DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key)); - } - return interface_data; -} - -} // namespace - -// static -JSObject* MozjsStringifierOperationInterface::CreateProxy( - JSContext* context, const scoped_refptr<Wrappable>& wrappable) { - DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); - JS::RootedObject global_object( - context, - MozjsGlobalEnvironment::GetFromContext(context)->global_object()); - DCHECK(global_object); - - InterfaceData* interface_data = GetInterfaceData(context); - JS::RootedObject prototype(context, GetPrototype(context, global_object)); - DCHECK(prototype); - JS::RootedObject new_object( - context, - JS_NewObjectWithGivenProto( - context, &instance_class_definition, prototype)); - DCHECK(new_object); - JS::RootedObject proxy(context, - ProxyHandler::NewProxy( - context, proxy_handler.Pointer(), new_object, prototype)); - WrapperPrivate::AddPrivateData(context, proxy, wrappable); - return proxy; -} - -// static -const JSClass* MozjsStringifierOperationInterface::PrototypeClass( - JSContext* context) { - DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); - JS::RootedObject global_object( - context, - MozjsGlobalEnvironment::GetFromContext(context)->global_object()); - DCHECK(global_object); - - JS::RootedObject prototype(context, GetPrototype(context, global_object)); - const JSClass* proto_class = JS_GetClass(prototype); - return proto_class; -} - -// static -JSObject* MozjsStringifierOperationInterface::GetPrototype( - JSContext* context, JS::HandleObject global_object) { - DCHECK(JS_IsGlobalObject(global_object)); - - InterfaceData* interface_data = GetInterfaceData(context); - if (!interface_data->prototype) { - // Create new prototype that has all the props and methods - InitializePrototypeAndInterfaceObject( - interface_data, context, global_object); - } - DCHECK(interface_data->prototype); - return interface_data->prototype; -} - -// static -JSObject* MozjsStringifierOperationInterface::GetInterfaceObject( - JSContext* context, JS::HandleObject global_object) { - DCHECK(JS_IsGlobalObject(global_object)); - - InterfaceData* interface_data = GetInterfaceData(context); - if (!interface_data->interface_object) { - InitializePrototypeAndInterfaceObject( - interface_data, context, global_object); - } - DCHECK(interface_data->interface_object); - return interface_data->interface_object; -} - - -namespace { -} // namespace - - -} // namespace testing -} // namespace bindings -} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsStringifierOperationInterface.h b/src/cobalt/bindings/generated/mozjs-45/testing/MozjsStringifierOperationInterface.h deleted file mode 100644 index 45f397c..0000000 --- a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsStringifierOperationInterface.h +++ /dev/null
@@ -1,54 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! -// Auto-generated from template: bindings/mozjs-45/templates/interface.h.template - -// clang-format off - -#ifndef MozjsStringifierOperationInterface_h -#define MozjsStringifierOperationInterface_h - -#include "base/hash_tables.h" -#include "base/lazy_instance.h" -#include "base/memory/ref_counted.h" -#include "base/threading/thread_checker.h" -#include "cobalt/base/polymorphic_downcast.h" -#include "cobalt/script/wrappable.h" -#include "cobalt/bindings/testing/stringifier_operation_interface.h" - -#include "third_party/mozjs-45/js/src/jsapi.h" - -namespace cobalt { -namespace bindings { -namespace testing { - -class MozjsStringifierOperationInterface { - public: - static JSObject* CreateProxy(JSContext* context, - const scoped_refptr<script::Wrappable>& wrappable); - static const JSClass* PrototypeClass(JSContext* context); - static JSObject* GetPrototype(JSContext* context, - JS::HandleObject global_object); - static JSObject* GetInterfaceObject(JSContext* context, - JS::HandleObject global_object); -}; - -} // namespace bindings -} // namespace testing -} // namespace cobalt - -#endif // MozjsStringifierOperationInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsTargetInterface.cc b/src/cobalt/bindings/generated/mozjs-45/testing/MozjsTargetInterface.cc deleted file mode 100644 index 985ae9a..0000000 --- a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsTargetInterface.cc +++ /dev/null
@@ -1,434 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! -// Auto-generated from template: bindings/mozjs-45/templates/interface.cc.template - -// clang-format off - -#include "MozjsTargetInterface.h" - -#include "base/debug/trace_event.h" -#include "cobalt/base/polymorphic_downcast.h" -#include "cobalt/script/global_environment.h" -#include "cobalt/script/opaque_handle.h" -#include "cobalt/script/script_object.h" - -#include "base/lazy_instance.h" -#include "cobalt/script/mozjs-45/callback_function_conversion.h" -#include "cobalt/script/exception_state.h" -#include "cobalt/script/mozjs-45/conversion_helpers.h" -#include "cobalt/script/mozjs-45/mozjs_exception_state.h" -#include "cobalt/script/mozjs-45/mozjs_callback_function.h" -#include "cobalt/script/mozjs-45/mozjs_global_environment.h" -#include "cobalt/script/mozjs-45/mozjs_object_handle.h" -#include "cobalt/script/mozjs-45/mozjs_property_enumerator.h" -#include "cobalt/script/mozjs-45/mozjs_user_object_holder.h" -#include "cobalt/script/mozjs-45/proxy_handler.h" -#include "cobalt/script/mozjs-45/type_traits.h" -#include "cobalt/script/mozjs-45/wrapper_factory.h" -#include "cobalt/script/mozjs-45/wrapper_private.h" -#include "cobalt/script/property_enumerator.h" -#include "third_party/mozjs-45/js/src/jsapi.h" -#include "third_party/mozjs-45/js/src/jsfriendapi.h" - -namespace { -using cobalt::bindings::testing::TargetInterface; -using cobalt::bindings::testing::MozjsTargetInterface; -using cobalt::script::CallbackInterfaceTraits; -using cobalt::script::GlobalEnvironment; -using cobalt::script::OpaqueHandle; -using cobalt::script::OpaqueHandleHolder; -using cobalt::script::ScriptObject; -using cobalt::script::Wrappable; - -using cobalt::script::CallbackFunction; -using cobalt::script::CallbackInterfaceTraits; -using cobalt::script::ExceptionState; -using cobalt::script::mozjs::FromJSValue; -using cobalt::script::mozjs::kConversionFlagNullable; -using cobalt::script::mozjs::kConversionFlagRestricted; -using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString; -using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString; -using cobalt::script::mozjs::kNoConversionFlags; -using cobalt::script::mozjs::InterfaceData; -using cobalt::script::mozjs::MozjsCallbackFunction; -using cobalt::script::mozjs::MozjsExceptionState; -using cobalt::script::mozjs::MozjsGlobalEnvironment; -using cobalt::script::mozjs::MozjsUserObjectHolder; -using cobalt::script::mozjs::MozjsPropertyEnumerator; -using cobalt::script::mozjs::ProxyHandler; -using cobalt::script::mozjs::ToJSValue; -using cobalt::script::mozjs::TypeTraits; -using cobalt::script::mozjs::WrapperPrivate; -using cobalt::script::mozjs::WrapperFactory; -using cobalt::script::Wrappable; -} // namespace - -namespace cobalt { -namespace bindings { -namespace testing { - -namespace { - -class MozjsTargetInterfaceHandler : public ProxyHandler { - public: - MozjsTargetInterfaceHandler() - : ProxyHandler(indexed_property_hooks, named_property_hooks) {} - - private: - static NamedPropertyHooks named_property_hooks; - static IndexedPropertyHooks indexed_property_hooks; -}; - -ProxyHandler::NamedPropertyHooks -MozjsTargetInterfaceHandler::named_property_hooks = { - NULL, - NULL, - NULL, - NULL, - NULL, -}; -ProxyHandler::IndexedPropertyHooks -MozjsTargetInterfaceHandler::indexed_property_hooks = { - NULL, - NULL, - NULL, - NULL, - NULL, -}; - -static base::LazyInstance<MozjsTargetInterfaceHandler> - proxy_handler; - -bool HasInstance(JSContext *context, JS::HandleObject type, - JS::MutableHandleValue vp, bool *success) { - JS::RootedObject global_object( - context, JS_GetGlobalForObject(context, type)); - DCHECK(global_object); - - JS::RootedObject prototype( - context, MozjsTargetInterface::GetPrototype(context, global_object)); - - // |IsDelegate| walks the prototype chain of an object returning true if - // .prototype is found. - bool is_delegate; - if (!IsDelegate(context, prototype, vp, &is_delegate)) { - *success = false; - return false; - } - - *success = is_delegate; - return true; -} - -const JSClass instance_class_definition = { - "TargetInterface", - 0 | JSCLASS_HAS_PRIVATE, - NULL, // addProperty - NULL, // delProperty - NULL, // getProperty - NULL, // setProperty - NULL, // enumerate - NULL, // resolve - NULL, // mayResolve - &WrapperPrivate::Finalizer, // finalize - NULL, // call - NULL, // hasInstance - NULL, // construct - &WrapperPrivate::Trace, // trace -}; - -const JSClass prototype_class_definition = { - "TargetInterfacePrototype", -}; - -const JSClass interface_object_class_definition = { - "TargetInterfaceConstructor", - 0, - NULL, // addProperty - NULL, // delProperty - NULL, // getProperty - NULL, // setProperty - NULL, // enumerate - NULL, // resolve - NULL, // mayResolve - NULL, // finalize - NULL, // call - &HasInstance, - NULL, -}; - -bool fcn_implementedInterfaceFunction( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, &object)) { - NOTREACHED(); - return false; - } - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<TargetInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - TargetInterface* impl = - wrapper_private->wrappable<TargetInterface>().get(); - - impl->ImplementedInterfaceFunction(); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - -bool fcn_partialInterfaceFunction( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, &object)) { - NOTREACHED(); - return false; - } - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<TargetInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - TargetInterface* impl = - wrapper_private->wrappable<TargetInterface>().get(); - - impl->PartialInterfaceFunction(); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - - - -const JSPropertySpec prototype_properties[] = { - JS_PS_END -}; - -const JSFunctionSpec prototype_functions[] = { - JS_FNSPEC( - "implementedInterfaceFunction", fcn_implementedInterfaceFunction, NULL, - 0, JSPROP_ENUMERATE, NULL), - JS_FNSPEC( - "partialInterfaceFunction", fcn_partialInterfaceFunction, NULL, - 0, JSPROP_ENUMERATE, NULL), - JS_FS_END -}; - -const JSPropertySpec interface_object_properties[] = { - JS_PS_END -}; - -const JSFunctionSpec interface_object_functions[] = { - JS_FS_END -}; - -const JSPropertySpec own_properties[] = { - JS_PS_END -}; - -void InitializePrototypeAndInterfaceObject( - InterfaceData* interface_data, JSContext* context, - JS::HandleObject global_object) { - DCHECK(!interface_data->prototype); - DCHECK(!interface_data->interface_object); - DCHECK(JS_IsGlobalObject(global_object)); - - JS::RootedObject parent_prototype( - context, JS_GetObjectPrototype(context, global_object)); - DCHECK(parent_prototype); - - interface_data->prototype = JS_NewObjectWithGivenProto( - context, &prototype_class_definition, parent_prototype - ); - - JS::RootedObject rooted_prototype(context, interface_data->prototype); - bool success = JS_DefineProperties( - context, - rooted_prototype, - prototype_properties); - - DCHECK(success); - success = JS_DefineFunctions( - context, rooted_prototype, prototype_functions); - DCHECK(success); - - JS::RootedObject function_prototype( - context, JS_GetFunctionPrototype(context, global_object)); - DCHECK(function_prototype); - // Create the Interface object. - interface_data->interface_object = JS_NewObjectWithGivenProto( - context, &interface_object_class_definition, - function_prototype); - - // Add the InterfaceObject.name property. - JS::RootedObject rooted_interface_object( - context, interface_data->interface_object); - JS::RootedValue name_value(context); - const char name[] = - "TargetInterface"; - name_value.setString(JS_NewStringCopyZ(context, name)); - success = JS_DefineProperty( - context, rooted_interface_object, "name", name_value, JSPROP_READONLY, - NULL, NULL); - DCHECK(success); - - // Define interface object properties (including constants). - success = JS_DefineProperties(context, rooted_interface_object, - interface_object_properties); - DCHECK(success); - // Define interface object functions (static). - success = JS_DefineFunctions(context, rooted_interface_object, - interface_object_functions); - DCHECK(success); - - // Set the Prototype.constructor and Constructor.prototype properties. - DCHECK(interface_data->interface_object); - DCHECK(interface_data->prototype); - success = JS_LinkConstructorAndPrototype( - context, - rooted_interface_object, - rooted_prototype); - DCHECK(success); -} - -InterfaceData* GetInterfaceData(JSContext* context) { - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - // Use the address of the properties definition for this interface as a - // unique key for looking up the InterfaceData for this interface. - intptr_t key = reinterpret_cast<intptr_t>(&own_properties); - InterfaceData* interface_data = global_environment->GetInterfaceData(key); - if (!interface_data) { - interface_data = new InterfaceData(); - DCHECK(interface_data); - global_environment->CacheInterfaceData(key, interface_data); - DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key)); - } - return interface_data; -} - -} // namespace - -// static -JSObject* MozjsTargetInterface::CreateProxy( - JSContext* context, const scoped_refptr<Wrappable>& wrappable) { - DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); - JS::RootedObject global_object( - context, - MozjsGlobalEnvironment::GetFromContext(context)->global_object()); - DCHECK(global_object); - - InterfaceData* interface_data = GetInterfaceData(context); - JS::RootedObject prototype(context, GetPrototype(context, global_object)); - DCHECK(prototype); - JS::RootedObject new_object( - context, - JS_NewObjectWithGivenProto( - context, &instance_class_definition, prototype)); - DCHECK(new_object); - JS::RootedObject proxy(context, - ProxyHandler::NewProxy( - context, proxy_handler.Pointer(), new_object, prototype)); - WrapperPrivate::AddPrivateData(context, proxy, wrappable); - return proxy; -} - -// static -const JSClass* MozjsTargetInterface::PrototypeClass( - JSContext* context) { - DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); - JS::RootedObject global_object( - context, - MozjsGlobalEnvironment::GetFromContext(context)->global_object()); - DCHECK(global_object); - - JS::RootedObject prototype(context, GetPrototype(context, global_object)); - const JSClass* proto_class = JS_GetClass(prototype); - return proto_class; -} - -// static -JSObject* MozjsTargetInterface::GetPrototype( - JSContext* context, JS::HandleObject global_object) { - DCHECK(JS_IsGlobalObject(global_object)); - - InterfaceData* interface_data = GetInterfaceData(context); - if (!interface_data->prototype) { - // Create new prototype that has all the props and methods - InitializePrototypeAndInterfaceObject( - interface_data, context, global_object); - } - DCHECK(interface_data->prototype); - return interface_data->prototype; -} - -// static -JSObject* MozjsTargetInterface::GetInterfaceObject( - JSContext* context, JS::HandleObject global_object) { - DCHECK(JS_IsGlobalObject(global_object)); - - InterfaceData* interface_data = GetInterfaceData(context); - if (!interface_data->interface_object) { - InitializePrototypeAndInterfaceObject( - interface_data, context, global_object); - } - DCHECK(interface_data->interface_object); - return interface_data->interface_object; -} - - -namespace { -} // namespace - - -} // namespace testing -} // namespace bindings -} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsTargetInterface.h b/src/cobalt/bindings/generated/mozjs-45/testing/MozjsTargetInterface.h deleted file mode 100644 index b407533..0000000 --- a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsTargetInterface.h +++ /dev/null
@@ -1,54 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! -// Auto-generated from template: bindings/mozjs-45/templates/interface.h.template - -// clang-format off - -#ifndef MozjsTargetInterface_h -#define MozjsTargetInterface_h - -#include "base/hash_tables.h" -#include "base/lazy_instance.h" -#include "base/memory/ref_counted.h" -#include "base/threading/thread_checker.h" -#include "cobalt/base/polymorphic_downcast.h" -#include "cobalt/script/wrappable.h" -#include "cobalt/bindings/testing/target_interface.h" - -#include "third_party/mozjs-45/js/src/jsapi.h" - -namespace cobalt { -namespace bindings { -namespace testing { - -class MozjsTargetInterface { - public: - static JSObject* CreateProxy(JSContext* context, - const scoped_refptr<script::Wrappable>& wrappable); - static const JSClass* PrototypeClass(JSContext* context); - static JSObject* GetPrototype(JSContext* context, - JS::HandleObject global_object); - static JSObject* GetInterfaceObject(JSContext* context, - JS::HandleObject global_object); -}; - -} // namespace bindings -} // namespace testing -} // namespace cobalt - -#endif // MozjsTargetInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsUnionTypesInterface.cc b/src/cobalt/bindings/generated/mozjs-45/testing/MozjsUnionTypesInterface.cc deleted file mode 100644 index 861b590..0000000 --- a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsUnionTypesInterface.cc +++ /dev/null
@@ -1,666 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! -// Auto-generated from template: bindings/mozjs-45/templates/interface.cc.template - -// clang-format off - -#include "MozjsUnionTypesInterface.h" - -#include "base/debug/trace_event.h" -#include "cobalt/base/polymorphic_downcast.h" -#include "cobalt/script/global_environment.h" -#include "cobalt/script/opaque_handle.h" -#include "cobalt/script/script_object.h" -#include "MozjsArbitraryInterface.h" -#include "MozjsBaseInterface.h" -#include "cobalt/bindings/testing/arbitrary_interface.h" -#include "cobalt/bindings/testing/base_interface.h" - -#include "base/lazy_instance.h" -#include "cobalt/script/mozjs-45/callback_function_conversion.h" -#include "cobalt/script/exception_state.h" -#include "cobalt/script/mozjs-45/conversion_helpers.h" -#include "cobalt/script/mozjs-45/mozjs_exception_state.h" -#include "cobalt/script/mozjs-45/mozjs_callback_function.h" -#include "cobalt/script/mozjs-45/mozjs_global_environment.h" -#include "cobalt/script/mozjs-45/mozjs_object_handle.h" -#include "cobalt/script/mozjs-45/mozjs_property_enumerator.h" -#include "cobalt/script/mozjs-45/mozjs_user_object_holder.h" -#include "cobalt/script/mozjs-45/proxy_handler.h" -#include "cobalt/script/mozjs-45/type_traits.h" -#include "cobalt/script/mozjs-45/wrapper_factory.h" -#include "cobalt/script/mozjs-45/wrapper_private.h" -#include "cobalt/script/property_enumerator.h" -#include "third_party/mozjs-45/js/src/jsapi.h" -#include "third_party/mozjs-45/js/src/jsfriendapi.h" - -namespace { -using cobalt::bindings::testing::UnionTypesInterface; -using cobalt::bindings::testing::MozjsUnionTypesInterface; -using cobalt::bindings::testing::ArbitraryInterface; -using cobalt::bindings::testing::BaseInterface; -using cobalt::bindings::testing::MozjsArbitraryInterface; -using cobalt::bindings::testing::MozjsBaseInterface; -using cobalt::script::CallbackInterfaceTraits; -using cobalt::script::GlobalEnvironment; -using cobalt::script::OpaqueHandle; -using cobalt::script::OpaqueHandleHolder; -using cobalt::script::ScriptObject; -using cobalt::script::Wrappable; - -using cobalt::script::CallbackFunction; -using cobalt::script::CallbackInterfaceTraits; -using cobalt::script::ExceptionState; -using cobalt::script::mozjs::FromJSValue; -using cobalt::script::mozjs::kConversionFlagNullable; -using cobalt::script::mozjs::kConversionFlagRestricted; -using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString; -using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString; -using cobalt::script::mozjs::kNoConversionFlags; -using cobalt::script::mozjs::InterfaceData; -using cobalt::script::mozjs::MozjsCallbackFunction; -using cobalt::script::mozjs::MozjsExceptionState; -using cobalt::script::mozjs::MozjsGlobalEnvironment; -using cobalt::script::mozjs::MozjsUserObjectHolder; -using cobalt::script::mozjs::MozjsPropertyEnumerator; -using cobalt::script::mozjs::ProxyHandler; -using cobalt::script::mozjs::ToJSValue; -using cobalt::script::mozjs::TypeTraits; -using cobalt::script::mozjs::WrapperPrivate; -using cobalt::script::mozjs::WrapperFactory; -using cobalt::script::Wrappable; -} // namespace - -namespace cobalt { -namespace bindings { -namespace testing { - -namespace { - -class MozjsUnionTypesInterfaceHandler : public ProxyHandler { - public: - MozjsUnionTypesInterfaceHandler() - : ProxyHandler(indexed_property_hooks, named_property_hooks) {} - - private: - static NamedPropertyHooks named_property_hooks; - static IndexedPropertyHooks indexed_property_hooks; -}; - -ProxyHandler::NamedPropertyHooks -MozjsUnionTypesInterfaceHandler::named_property_hooks = { - NULL, - NULL, - NULL, - NULL, - NULL, -}; -ProxyHandler::IndexedPropertyHooks -MozjsUnionTypesInterfaceHandler::indexed_property_hooks = { - NULL, - NULL, - NULL, - NULL, - NULL, -}; - -static base::LazyInstance<MozjsUnionTypesInterfaceHandler> - proxy_handler; - -bool HasInstance(JSContext *context, JS::HandleObject type, - JS::MutableHandleValue vp, bool *success) { - JS::RootedObject global_object( - context, JS_GetGlobalForObject(context, type)); - DCHECK(global_object); - - JS::RootedObject prototype( - context, MozjsUnionTypesInterface::GetPrototype(context, global_object)); - - // |IsDelegate| walks the prototype chain of an object returning true if - // .prototype is found. - bool is_delegate; - if (!IsDelegate(context, prototype, vp, &is_delegate)) { - *success = false; - return false; - } - - *success = is_delegate; - return true; -} - -const JSClass instance_class_definition = { - "UnionTypesInterface", - 0 | JSCLASS_HAS_PRIVATE, - NULL, // addProperty - NULL, // delProperty - NULL, // getProperty - NULL, // setProperty - NULL, // enumerate - NULL, // resolve - NULL, // mayResolve - &WrapperPrivate::Finalizer, // finalize - NULL, // call - NULL, // hasInstance - NULL, // construct - &WrapperPrivate::Trace, // trace -}; - -const JSClass prototype_class_definition = { - "UnionTypesInterfacePrototype", -}; - -const JSClass interface_object_class_definition = { - "UnionTypesInterfaceConstructor", - 0, - NULL, // addProperty - NULL, // delProperty - NULL, // getProperty - NULL, // setProperty - NULL, // enumerate - NULL, // resolve - NULL, // mayResolve - NULL, // finalize - NULL, // call - &HasInstance, - NULL, -}; - -bool get_unionProperty( - JSContext* context, unsigned argc, JS::Value* vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<UnionTypesInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - UnionTypesInterface* impl = - wrapper_private->wrappable<UnionTypesInterface>().get(); - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->union_property(), - &result_value); - } - if (!exception_state.is_exception_set()) { - args.rval().set(result_value); - } - return !exception_state.is_exception_set(); -} - -bool set_unionProperty( - JSContext* context, unsigned argc, JS::Value* vp) { - - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<UnionTypesInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - UnionTypesInterface* impl = - wrapper_private->wrappable<UnionTypesInterface>().get(); - TypeTraits<script::UnionType4<std::string, bool, scoped_refptr<ArbitraryInterface>, int32_t > >::ConversionType value; - if (args.length() != 1) { - NOTREACHED(); - return false; - } - FromJSValue(context, args[0], kNoConversionFlags, &exception_state, - &value); - if (exception_state.is_exception_set()) { - return false; - } - - impl->set_union_property(value); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - -bool get_unionWithNullableMemberProperty( - JSContext* context, unsigned argc, JS::Value* vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<UnionTypesInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - UnionTypesInterface* impl = - wrapper_private->wrappable<UnionTypesInterface>().get(); - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->union_with_nullable_member_property(), - &result_value); - } - if (!exception_state.is_exception_set()) { - args.rval().set(result_value); - } - return !exception_state.is_exception_set(); -} - -bool set_unionWithNullableMemberProperty( - JSContext* context, unsigned argc, JS::Value* vp) { - - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<UnionTypesInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - UnionTypesInterface* impl = - wrapper_private->wrappable<UnionTypesInterface>().get(); - TypeTraits<base::optional<script::UnionType2<double, std::string > > >::ConversionType value; - if (args.length() != 1) { - NOTREACHED(); - return false; - } - FromJSValue(context, args[0], kNoConversionFlags, &exception_state, - &value); - if (exception_state.is_exception_set()) { - return false; - } - - impl->set_union_with_nullable_member_property(value); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - -bool get_nullableUnionProperty( - JSContext* context, unsigned argc, JS::Value* vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<UnionTypesInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - UnionTypesInterface* impl = - wrapper_private->wrappable<UnionTypesInterface>().get(); - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->nullable_union_property(), - &result_value); - } - if (!exception_state.is_exception_set()) { - args.rval().set(result_value); - } - return !exception_state.is_exception_set(); -} - -bool set_nullableUnionProperty( - JSContext* context, unsigned argc, JS::Value* vp) { - - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<UnionTypesInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - UnionTypesInterface* impl = - wrapper_private->wrappable<UnionTypesInterface>().get(); - TypeTraits<base::optional<script::UnionType2<double, std::string > > >::ConversionType value; - if (args.length() != 1) { - NOTREACHED(); - return false; - } - FromJSValue(context, args[0], (kConversionFlagNullable), &exception_state, - &value); - if (exception_state.is_exception_set()) { - return false; - } - - impl->set_nullable_union_property(value); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - -bool get_unionBaseProperty( - JSContext* context, unsigned argc, JS::Value* vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<UnionTypesInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - UnionTypesInterface* impl = - wrapper_private->wrappable<UnionTypesInterface>().get(); - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->union_base_property(), - &result_value); - } - if (!exception_state.is_exception_set()) { - args.rval().set(result_value); - } - return !exception_state.is_exception_set(); -} - -bool set_unionBaseProperty( - JSContext* context, unsigned argc, JS::Value* vp) { - - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<UnionTypesInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - UnionTypesInterface* impl = - wrapper_private->wrappable<UnionTypesInterface>().get(); - TypeTraits<script::UnionType2<scoped_refptr<BaseInterface>, std::string > >::ConversionType value; - if (args.length() != 1) { - NOTREACHED(); - return false; - } - FromJSValue(context, args[0], kNoConversionFlags, &exception_state, - &value); - if (exception_state.is_exception_set()) { - return false; - } - - impl->set_union_base_property(value); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - - - -const JSPropertySpec prototype_properties[] = { - { // Read/Write property - "unionProperty", - JSPROP_SHARED | JSPROP_ENUMERATE, - { { &get_unionProperty, NULL } }, - { { &set_unionProperty, NULL } }, - }, - { // Read/Write property - "unionWithNullableMemberProperty", - JSPROP_SHARED | JSPROP_ENUMERATE, - { { &get_unionWithNullableMemberProperty, NULL } }, - { { &set_unionWithNullableMemberProperty, NULL } }, - }, - { // Read/Write property - "nullableUnionProperty", - JSPROP_SHARED | JSPROP_ENUMERATE, - { { &get_nullableUnionProperty, NULL } }, - { { &set_nullableUnionProperty, NULL } }, - }, - { // Read/Write property - "unionBaseProperty", - JSPROP_SHARED | JSPROP_ENUMERATE, - { { &get_unionBaseProperty, NULL } }, - { { &set_unionBaseProperty, NULL } }, - }, - JS_PS_END -}; - -const JSFunctionSpec prototype_functions[] = { - JS_FS_END -}; - -const JSPropertySpec interface_object_properties[] = { - JS_PS_END -}; - -const JSFunctionSpec interface_object_functions[] = { - JS_FS_END -}; - -const JSPropertySpec own_properties[] = { - JS_PS_END -}; - -void InitializePrototypeAndInterfaceObject( - InterfaceData* interface_data, JSContext* context, - JS::HandleObject global_object) { - DCHECK(!interface_data->prototype); - DCHECK(!interface_data->interface_object); - DCHECK(JS_IsGlobalObject(global_object)); - - JS::RootedObject parent_prototype( - context, JS_GetObjectPrototype(context, global_object)); - DCHECK(parent_prototype); - - interface_data->prototype = JS_NewObjectWithGivenProto( - context, &prototype_class_definition, parent_prototype - ); - - JS::RootedObject rooted_prototype(context, interface_data->prototype); - bool success = JS_DefineProperties( - context, - rooted_prototype, - prototype_properties); - - DCHECK(success); - success = JS_DefineFunctions( - context, rooted_prototype, prototype_functions); - DCHECK(success); - - JS::RootedObject function_prototype( - context, JS_GetFunctionPrototype(context, global_object)); - DCHECK(function_prototype); - // Create the Interface object. - interface_data->interface_object = JS_NewObjectWithGivenProto( - context, &interface_object_class_definition, - function_prototype); - - // Add the InterfaceObject.name property. - JS::RootedObject rooted_interface_object( - context, interface_data->interface_object); - JS::RootedValue name_value(context); - const char name[] = - "UnionTypesInterface"; - name_value.setString(JS_NewStringCopyZ(context, name)); - success = JS_DefineProperty( - context, rooted_interface_object, "name", name_value, JSPROP_READONLY, - NULL, NULL); - DCHECK(success); - - // Define interface object properties (including constants). - success = JS_DefineProperties(context, rooted_interface_object, - interface_object_properties); - DCHECK(success); - // Define interface object functions (static). - success = JS_DefineFunctions(context, rooted_interface_object, - interface_object_functions); - DCHECK(success); - - // Set the Prototype.constructor and Constructor.prototype properties. - DCHECK(interface_data->interface_object); - DCHECK(interface_data->prototype); - success = JS_LinkConstructorAndPrototype( - context, - rooted_interface_object, - rooted_prototype); - DCHECK(success); -} - -InterfaceData* GetInterfaceData(JSContext* context) { - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - // Use the address of the properties definition for this interface as a - // unique key for looking up the InterfaceData for this interface. - intptr_t key = reinterpret_cast<intptr_t>(&own_properties); - InterfaceData* interface_data = global_environment->GetInterfaceData(key); - if (!interface_data) { - interface_data = new InterfaceData(); - DCHECK(interface_data); - global_environment->CacheInterfaceData(key, interface_data); - DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key)); - } - return interface_data; -} - -} // namespace - -// static -JSObject* MozjsUnionTypesInterface::CreateProxy( - JSContext* context, const scoped_refptr<Wrappable>& wrappable) { - DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); - JS::RootedObject global_object( - context, - MozjsGlobalEnvironment::GetFromContext(context)->global_object()); - DCHECK(global_object); - - InterfaceData* interface_data = GetInterfaceData(context); - JS::RootedObject prototype(context, GetPrototype(context, global_object)); - DCHECK(prototype); - JS::RootedObject new_object( - context, - JS_NewObjectWithGivenProto( - context, &instance_class_definition, prototype)); - DCHECK(new_object); - JS::RootedObject proxy(context, - ProxyHandler::NewProxy( - context, proxy_handler.Pointer(), new_object, prototype)); - WrapperPrivate::AddPrivateData(context, proxy, wrappable); - return proxy; -} - -// static -const JSClass* MozjsUnionTypesInterface::PrototypeClass( - JSContext* context) { - DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); - JS::RootedObject global_object( - context, - MozjsGlobalEnvironment::GetFromContext(context)->global_object()); - DCHECK(global_object); - - JS::RootedObject prototype(context, GetPrototype(context, global_object)); - const JSClass* proto_class = JS_GetClass(prototype); - return proto_class; -} - -// static -JSObject* MozjsUnionTypesInterface::GetPrototype( - JSContext* context, JS::HandleObject global_object) { - DCHECK(JS_IsGlobalObject(global_object)); - - InterfaceData* interface_data = GetInterfaceData(context); - if (!interface_data->prototype) { - // Create new prototype that has all the props and methods - InitializePrototypeAndInterfaceObject( - interface_data, context, global_object); - } - DCHECK(interface_data->prototype); - return interface_data->prototype; -} - -// static -JSObject* MozjsUnionTypesInterface::GetInterfaceObject( - JSContext* context, JS::HandleObject global_object) { - DCHECK(JS_IsGlobalObject(global_object)); - - InterfaceData* interface_data = GetInterfaceData(context); - if (!interface_data->interface_object) { - InitializePrototypeAndInterfaceObject( - interface_data, context, global_object); - } - DCHECK(interface_data->interface_object); - return interface_data->interface_object; -} - - -namespace { -} // namespace - - -} // namespace testing -} // namespace bindings -} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsUnionTypesInterface.h b/src/cobalt/bindings/generated/mozjs-45/testing/MozjsUnionTypesInterface.h deleted file mode 100644 index 36fe8f9..0000000 --- a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsUnionTypesInterface.h +++ /dev/null
@@ -1,54 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! -// Auto-generated from template: bindings/mozjs-45/templates/interface.h.template - -// clang-format off - -#ifndef MozjsUnionTypesInterface_h -#define MozjsUnionTypesInterface_h - -#include "base/hash_tables.h" -#include "base/lazy_instance.h" -#include "base/memory/ref_counted.h" -#include "base/threading/thread_checker.h" -#include "cobalt/base/polymorphic_downcast.h" -#include "cobalt/script/wrappable.h" -#include "cobalt/bindings/testing/union_types_interface.h" - -#include "third_party/mozjs-45/js/src/jsapi.h" - -namespace cobalt { -namespace bindings { -namespace testing { - -class MozjsUnionTypesInterface { - public: - static JSObject* CreateProxy(JSContext* context, - const scoped_refptr<script::Wrappable>& wrappable); - static const JSClass* PrototypeClass(JSContext* context); - static JSObject* GetPrototype(JSContext* context, - JS::HandleObject global_object); - static JSObject* GetInterfaceObject(JSContext* context, - JS::HandleObject global_object); -}; - -} // namespace bindings -} // namespace testing -} // namespace cobalt - -#endif // MozjsUnionTypesInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsWindow.cc b/src/cobalt/bindings/generated/mozjs-45/testing/MozjsWindow.cc deleted file mode 100644 index f94b803..0000000 --- a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsWindow.cc +++ /dev/null
@@ -1,990 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! -// Auto-generated from template: bindings/mozjs-45/templates/interface.cc.template - -// clang-format off - -#include "MozjsWindow.h" - -#include "base/debug/trace_event.h" -#include "cobalt/base/polymorphic_downcast.h" -#include "cobalt/script/global_environment.h" -#include "cobalt/script/opaque_handle.h" -#include "cobalt/script/script_object.h" -#include "MozjsAnonymousIndexedGetterInterface.h" -#include "MozjsAnonymousNamedGetterInterface.h" -#include "MozjsAnonymousNamedIndexedGetterInterface.h" -#include "MozjsArbitraryInterface.h" -#include "MozjsBaseInterface.h" -#include "MozjsBooleanTypeTestInterface.h" -#include "MozjsCallbackFunctionInterface.h" -#include "MozjsCallbackInterfaceInterface.h" -#include "MozjsConditionalInterface.h" -#include "MozjsConstantsInterface.h" -#include "MozjsConstructorInterface.h" -#include "MozjsConstructorWithArgumentsInterface.h" -#include "MozjsDOMStringTestInterface.h" -#include "MozjsDerivedGetterSetterInterface.h" -#include "MozjsDerivedInterface.h" -#include "MozjsDisabledInterface.h" -#include "MozjsEnumerationInterface.h" -#include "MozjsExceptionObjectInterface.h" -#include "MozjsExceptionsInterface.h" -#include "MozjsExtendedIDLAttributesInterface.h" -#include "MozjsGarbageCollectionTestInterface.h" -#include "MozjsGetOpaqueRootInterface.h" -#include "MozjsGlobalInterfaceParent.h" -#include "MozjsImplementedInterface.h" -#include "MozjsIndexedGetterInterface.h" -#include "MozjsInterfaceWithUnsupportedProperties.h" -#include "MozjsNamedConstructorInterface.h" -#include "MozjsNamedGetterInterface.h" -#include "MozjsNamedIndexedGetterInterface.h" -#include "MozjsNestedPutForwardsInterface.h" -#include "MozjsNoConstructorInterface.h" -#include "MozjsNoInterfaceObjectInterface.h" -#include "MozjsNullableTypesTestInterface.h" -#include "MozjsNumericTypesTestInterface.h" -#include "MozjsObjectTypeBindingsInterface.h" -#include "MozjsOperationsTestInterface.h" -#include "MozjsPutForwardsInterface.h" -#include "MozjsSequenceUser.h" -#include "MozjsSingleOperationInterface.h" -#include "MozjsStaticPropertiesInterface.h" -#include "MozjsStringifierAnonymousOperationInterface.h" -#include "MozjsStringifierAttributeInterface.h" -#include "MozjsStringifierOperationInterface.h" -#include "MozjsTargetInterface.h" -#include "MozjsUnionTypesInterface.h" -#include "MozjsWindow.h" -#include "cobalt/bindings/testing/anonymous_indexed_getter_interface.h" -#include "cobalt/bindings/testing/anonymous_named_getter_interface.h" -#include "cobalt/bindings/testing/anonymous_named_indexed_getter_interface.h" -#include "cobalt/bindings/testing/arbitrary_interface.h" -#include "cobalt/bindings/testing/base_interface.h" -#include "cobalt/bindings/testing/boolean_type_test_interface.h" -#include "cobalt/bindings/testing/callback_function_interface.h" -#include "cobalt/bindings/testing/callback_interface_interface.h" -#include "cobalt/bindings/testing/conditional_interface.h" -#include "cobalt/bindings/testing/constants_interface.h" -#include "cobalt/bindings/testing/constructor_interface.h" -#include "cobalt/bindings/testing/constructor_with_arguments_interface.h" -#include "cobalt/bindings/testing/derived_getter_setter_interface.h" -#include "cobalt/bindings/testing/derived_interface.h" -#include "cobalt/bindings/testing/disabled_interface.h" -#include "cobalt/bindings/testing/dom_string_test_interface.h" -#include "cobalt/bindings/testing/enumeration_interface.h" -#include "cobalt/bindings/testing/exception_object_interface.h" -#include "cobalt/bindings/testing/exceptions_interface.h" -#include "cobalt/bindings/testing/extended_idl_attributes_interface.h" -#include "cobalt/bindings/testing/garbage_collection_test_interface.h" -#include "cobalt/bindings/testing/get_opaque_root_interface.h" -#include "cobalt/bindings/testing/global_interface_parent.h" -#include "cobalt/bindings/testing/implemented_interface.h" -#include "cobalt/bindings/testing/indexed_getter_interface.h" -#include "cobalt/bindings/testing/interface_with_unsupported_properties.h" -#include "cobalt/bindings/testing/named_constructor_interface.h" -#include "cobalt/bindings/testing/named_getter_interface.h" -#include "cobalt/bindings/testing/named_indexed_getter_interface.h" -#include "cobalt/bindings/testing/nested_put_forwards_interface.h" -#include "cobalt/bindings/testing/no_constructor_interface.h" -#include "cobalt/bindings/testing/no_interface_object_interface.h" -#include "cobalt/bindings/testing/nullable_types_test_interface.h" -#include "cobalt/bindings/testing/numeric_types_test_interface.h" -#include "cobalt/bindings/testing/object_type_bindings_interface.h" -#include "cobalt/bindings/testing/operations_test_interface.h" -#include "cobalt/bindings/testing/put_forwards_interface.h" -#include "cobalt/bindings/testing/sequence_user.h" -#include "cobalt/bindings/testing/single_operation_interface.h" -#include "cobalt/bindings/testing/static_properties_interface.h" -#include "cobalt/bindings/testing/stringifier_anonymous_operation_interface.h" -#include "cobalt/bindings/testing/stringifier_attribute_interface.h" -#include "cobalt/bindings/testing/stringifier_operation_interface.h" -#include "cobalt/bindings/testing/target_interface.h" -#include "cobalt/bindings/testing/union_types_interface.h" -#include "cobalt/bindings/testing/window.h" - -#include "base/lazy_instance.h" -#include "cobalt/script/mozjs-45/callback_function_conversion.h" -#include "cobalt/script/exception_state.h" -#include "cobalt/script/mozjs-45/conversion_helpers.h" -#include "cobalt/script/mozjs-45/mozjs_exception_state.h" -#include "cobalt/script/mozjs-45/mozjs_callback_function.h" -#include "cobalt/script/mozjs-45/mozjs_global_environment.h" -#include "cobalt/script/mozjs-45/mozjs_object_handle.h" -#include "cobalt/script/mozjs-45/mozjs_property_enumerator.h" -#include "cobalt/script/mozjs-45/mozjs_user_object_holder.h" -#include "cobalt/script/mozjs-45/proxy_handler.h" -#include "cobalt/script/mozjs-45/type_traits.h" -#include "cobalt/script/mozjs-45/wrapper_factory.h" -#include "cobalt/script/mozjs-45/wrapper_private.h" -#include "cobalt/script/property_enumerator.h" -#include "third_party/mozjs-45/js/src/jsapi.h" -#include "third_party/mozjs-45/js/src/jsfriendapi.h" - -namespace { -using cobalt::bindings::testing::Window; -using cobalt::bindings::testing::MozjsWindow; -using cobalt::bindings::testing::AnonymousIndexedGetterInterface; -using cobalt::bindings::testing::AnonymousNamedGetterInterface; -using cobalt::bindings::testing::AnonymousNamedIndexedGetterInterface; -using cobalt::bindings::testing::ArbitraryInterface; -using cobalt::bindings::testing::BaseInterface; -using cobalt::bindings::testing::BooleanTypeTestInterface; -using cobalt::bindings::testing::CallbackFunctionInterface; -using cobalt::bindings::testing::CallbackInterfaceInterface; -#if defined(ENABLE_CONDITIONAL_INTERFACE) -using cobalt::bindings::testing::ConditionalInterface; -#endif // defined(ENABLE_CONDITIONAL_INTERFACE) -using cobalt::bindings::testing::ConstantsInterface; -using cobalt::bindings::testing::ConstructorInterface; -using cobalt::bindings::testing::ConstructorWithArgumentsInterface; -using cobalt::bindings::testing::DOMStringTestInterface; -using cobalt::bindings::testing::DerivedGetterSetterInterface; -using cobalt::bindings::testing::DerivedInterface; -#if defined(NO_ENABLE_CONDITIONAL_INTERFACE) -using cobalt::bindings::testing::DisabledInterface; -#endif // defined(NO_ENABLE_CONDITIONAL_INTERFACE) -using cobalt::bindings::testing::EnumerationInterface; -using cobalt::bindings::testing::ExceptionObjectInterface; -using cobalt::bindings::testing::ExceptionsInterface; -using cobalt::bindings::testing::ExtendedIDLAttributesInterface; -using cobalt::bindings::testing::GarbageCollectionTestInterface; -using cobalt::bindings::testing::GetOpaqueRootInterface; -using cobalt::bindings::testing::GlobalInterfaceParent; -using cobalt::bindings::testing::ImplementedInterface; -using cobalt::bindings::testing::IndexedGetterInterface; -using cobalt::bindings::testing::InterfaceWithUnsupportedProperties; -using cobalt::bindings::testing::MozjsAnonymousIndexedGetterInterface; -using cobalt::bindings::testing::MozjsAnonymousNamedGetterInterface; -using cobalt::bindings::testing::MozjsAnonymousNamedIndexedGetterInterface; -using cobalt::bindings::testing::MozjsArbitraryInterface; -using cobalt::bindings::testing::MozjsBaseInterface; -using cobalt::bindings::testing::MozjsBooleanTypeTestInterface; -using cobalt::bindings::testing::MozjsCallbackFunctionInterface; -using cobalt::bindings::testing::MozjsCallbackInterfaceInterface; -#if defined(ENABLE_CONDITIONAL_INTERFACE) -using cobalt::bindings::testing::MozjsConditionalInterface; -#endif // defined(ENABLE_CONDITIONAL_INTERFACE) -using cobalt::bindings::testing::MozjsConstantsInterface; -using cobalt::bindings::testing::MozjsConstructorInterface; -using cobalt::bindings::testing::MozjsConstructorWithArgumentsInterface; -using cobalt::bindings::testing::MozjsDOMStringTestInterface; -using cobalt::bindings::testing::MozjsDerivedGetterSetterInterface; -using cobalt::bindings::testing::MozjsDerivedInterface; -#if defined(NO_ENABLE_CONDITIONAL_INTERFACE) -using cobalt::bindings::testing::MozjsDisabledInterface; -#endif // defined(NO_ENABLE_CONDITIONAL_INTERFACE) -using cobalt::bindings::testing::MozjsEnumerationInterface; -using cobalt::bindings::testing::MozjsExceptionObjectInterface; -using cobalt::bindings::testing::MozjsExceptionsInterface; -using cobalt::bindings::testing::MozjsExtendedIDLAttributesInterface; -using cobalt::bindings::testing::MozjsGarbageCollectionTestInterface; -using cobalt::bindings::testing::MozjsGetOpaqueRootInterface; -using cobalt::bindings::testing::MozjsGlobalInterfaceParent; -using cobalt::bindings::testing::MozjsImplementedInterface; -using cobalt::bindings::testing::MozjsIndexedGetterInterface; -using cobalt::bindings::testing::MozjsInterfaceWithUnsupportedProperties; -using cobalt::bindings::testing::MozjsNamedConstructorInterface; -using cobalt::bindings::testing::MozjsNamedGetterInterface; -using cobalt::bindings::testing::MozjsNamedIndexedGetterInterface; -using cobalt::bindings::testing::MozjsNestedPutForwardsInterface; -using cobalt::bindings::testing::MozjsNoConstructorInterface; -using cobalt::bindings::testing::MozjsNoInterfaceObjectInterface; -using cobalt::bindings::testing::MozjsNullableTypesTestInterface; -using cobalt::bindings::testing::MozjsNumericTypesTestInterface; -using cobalt::bindings::testing::MozjsObjectTypeBindingsInterface; -using cobalt::bindings::testing::MozjsOperationsTestInterface; -using cobalt::bindings::testing::MozjsPutForwardsInterface; -using cobalt::bindings::testing::MozjsSequenceUser; -using cobalt::bindings::testing::MozjsSingleOperationInterface; -using cobalt::bindings::testing::MozjsStaticPropertiesInterface; -using cobalt::bindings::testing::MozjsStringifierAnonymousOperationInterface; -using cobalt::bindings::testing::MozjsStringifierAttributeInterface; -using cobalt::bindings::testing::MozjsStringifierOperationInterface; -using cobalt::bindings::testing::MozjsTargetInterface; -using cobalt::bindings::testing::MozjsUnionTypesInterface; -using cobalt::bindings::testing::MozjsWindow; -using cobalt::bindings::testing::NamedConstructorInterface; -using cobalt::bindings::testing::NamedGetterInterface; -using cobalt::bindings::testing::NamedIndexedGetterInterface; -using cobalt::bindings::testing::NestedPutForwardsInterface; -using cobalt::bindings::testing::NoConstructorInterface; -using cobalt::bindings::testing::NoInterfaceObjectInterface; -using cobalt::bindings::testing::NullableTypesTestInterface; -using cobalt::bindings::testing::NumericTypesTestInterface; -using cobalt::bindings::testing::ObjectTypeBindingsInterface; -using cobalt::bindings::testing::OperationsTestInterface; -using cobalt::bindings::testing::PutForwardsInterface; -using cobalt::bindings::testing::SequenceUser; -using cobalt::bindings::testing::SingleOperationInterface; -using cobalt::bindings::testing::StaticPropertiesInterface; -using cobalt::bindings::testing::StringifierAnonymousOperationInterface; -using cobalt::bindings::testing::StringifierAttributeInterface; -using cobalt::bindings::testing::StringifierOperationInterface; -using cobalt::bindings::testing::TargetInterface; -using cobalt::bindings::testing::UnionTypesInterface; -using cobalt::bindings::testing::Window; -using cobalt::script::CallbackInterfaceTraits; -using cobalt::script::GlobalEnvironment; -using cobalt::script::OpaqueHandle; -using cobalt::script::OpaqueHandleHolder; -using cobalt::script::ScriptObject; -using cobalt::script::Wrappable; - -using cobalt::script::CallbackFunction; -using cobalt::script::CallbackInterfaceTraits; -using cobalt::script::ExceptionState; -using cobalt::script::mozjs::FromJSValue; -using cobalt::script::mozjs::kConversionFlagNullable; -using cobalt::script::mozjs::kConversionFlagRestricted; -using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString; -using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString; -using cobalt::script::mozjs::kNoConversionFlags; -using cobalt::script::mozjs::InterfaceData; -using cobalt::script::mozjs::MozjsCallbackFunction; -using cobalt::script::mozjs::MozjsExceptionState; -using cobalt::script::mozjs::MozjsGlobalEnvironment; -using cobalt::script::mozjs::MozjsUserObjectHolder; -using cobalt::script::mozjs::MozjsPropertyEnumerator; -using cobalt::script::mozjs::ProxyHandler; -using cobalt::script::mozjs::ToJSValue; -using cobalt::script::mozjs::TypeTraits; -using cobalt::script::mozjs::WrapperPrivate; -using cobalt::script::mozjs::WrapperFactory; -using cobalt::script::Wrappable; -JSObject* DummyFunctor( - JSContext* context, const scoped_refptr<Wrappable>& wrappable) { - NOTREACHED(); - return NULL; -} -} // namespace - -namespace cobalt { -namespace bindings { -namespace testing { - -namespace { - -class MozjsWindowHandler : public ProxyHandler { - public: - MozjsWindowHandler() - : ProxyHandler(indexed_property_hooks, named_property_hooks) {} - - private: - static NamedPropertyHooks named_property_hooks; - static IndexedPropertyHooks indexed_property_hooks; -}; - -ProxyHandler::NamedPropertyHooks -MozjsWindowHandler::named_property_hooks = { - NULL, - NULL, - NULL, - NULL, - NULL, -}; -ProxyHandler::IndexedPropertyHooks -MozjsWindowHandler::indexed_property_hooks = { - NULL, - NULL, - NULL, - NULL, - NULL, -}; - -static base::LazyInstance<MozjsWindowHandler> - proxy_handler; - -bool HasInstance(JSContext *context, JS::HandleObject type, - JS::MutableHandleValue vp, bool *success) { - JS::RootedObject global_object( - context, JS_GetGlobalForObject(context, type)); - DCHECK(global_object); - - JS::RootedObject prototype( - context, MozjsWindow::GetPrototype(context, global_object)); - - // |IsDelegate| walks the prototype chain of an object returning true if - // .prototype is found. - bool is_delegate; - if (!IsDelegate(context, prototype, vp, &is_delegate)) { - *success = false; - return false; - } - - *success = is_delegate; - return true; -} - -const JSClass instance_class_definition = { - "Window", - JSCLASS_GLOBAL_FLAGS | JSCLASS_HAS_PRIVATE, - NULL, // addProperty - NULL, // delProperty - NULL, // getProperty - NULL, // setProperty - NULL, // enumerate - NULL, // resolve - NULL, // mayResolve - &WrapperPrivate::Finalizer, // finalize - NULL, // call - NULL, // hasInstance - NULL, // construct - JS_GlobalObjectTraceHook, // trace -}; - -const JSClass prototype_class_definition = { - "WindowPrototype", -}; - -const JSClass interface_object_class_definition = { - "WindowConstructor", - 0, - NULL, // addProperty - NULL, // delProperty - NULL, // getProperty - NULL, // setProperty - NULL, // enumerate - NULL, // resolve - NULL, // mayResolve - NULL, // finalize - NULL, // call - &HasInstance, - NULL, -}; - -bool get_windowProperty( - JSContext* context, unsigned argc, JS::Value* vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<Window>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - Window* impl = - wrapper_private->wrappable<Window>().get(); - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->window_property(), - &result_value); - } - if (!exception_state.is_exception_set()) { - args.rval().set(result_value); - } - return !exception_state.is_exception_set(); -} - -bool set_windowProperty( - JSContext* context, unsigned argc, JS::Value* vp) { - - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<Window>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - Window* impl = - wrapper_private->wrappable<Window>().get(); - TypeTraits<std::string >::ConversionType value; - if (args.length() != 1) { - NOTREACHED(); - return false; - } - FromJSValue(context, args[0], kNoConversionFlags, &exception_state, - &value); - if (exception_state.is_exception_set()) { - return false; - } - - impl->set_window_property(value); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - -bool get_window( - JSContext* context, unsigned argc, JS::Value* vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JS::RootedObject object(context, &args.thisv().toObject()); - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<Window>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - Window* impl = - wrapper_private->wrappable<Window>().get(); - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->window(), - &result_value); - } - if (!exception_state.is_exception_set()) { - args.rval().set(result_value); - } - return !exception_state.is_exception_set(); -} - - -bool fcn_getStackTrace( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, &object)) { - NOTREACHED(); - return false; - } - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<Window>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - Window* impl = - wrapper_private->wrappable<Window>().get(); - MozjsGlobalEnvironment* callwith_global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->GetStackTrace(callwith_global_environment->GetStackTrace()), - &result_value); - } - if (!exception_state.is_exception_set()) { - args.rval().set(result_value); - } - return !exception_state.is_exception_set(); -} - -bool fcn_windowOperation( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, &object)) { - NOTREACHED(); - return false; - } - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<Window>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - Window* impl = - wrapper_private->wrappable<Window>().get(); - - impl->WindowOperation(); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - - - -const JSPropertySpec prototype_properties[] = { - { // Read/Write property - "windowProperty", - JSPROP_SHARED | JSPROP_ENUMERATE, - { { &get_windowProperty, NULL } }, - { { &set_windowProperty, NULL } }, - }, - { // Readonly attribute - "window", - JSPROP_SHARED | JSPROP_ENUMERATE, - { { &get_window, NULL } }, - JSNATIVE_WRAPPER(NULL), - }, - JS_PS_END -}; - -const JSFunctionSpec prototype_functions[] = { - JS_FNSPEC( - "getStackTrace", fcn_getStackTrace, NULL, - 0, JSPROP_ENUMERATE, NULL), - JS_FNSPEC( - "windowOperation", fcn_windowOperation, NULL, - 0, JSPROP_ENUMERATE, NULL), - JS_FS_END -}; - -const JSPropertySpec interface_object_properties[] = { - JS_PS_END -}; - -const JSFunctionSpec interface_object_functions[] = { - JS_FS_END -}; - -const JSPropertySpec own_properties[] = { - JS_PS_END -}; - -void InitializePrototypeAndInterfaceObject( - InterfaceData* interface_data, JSContext* context, - JS::HandleObject global_object) { - DCHECK(!interface_data->prototype); - DCHECK(!interface_data->interface_object); - DCHECK(JS_IsGlobalObject(global_object)); - - JS::RootedObject parent_prototype( - context, bindings::testing::MozjsGlobalInterfaceParent::GetPrototype(context, global_object)); - DCHECK(parent_prototype); - - interface_data->prototype = JS_NewObjectWithGivenProto( - context, &prototype_class_definition, parent_prototype - ); - - JS::RootedObject rooted_prototype(context, interface_data->prototype); - bool success = JS_DefineProperties( - context, - rooted_prototype, - prototype_properties); - - DCHECK(success); - success = JS_DefineFunctions( - context, rooted_prototype, prototype_functions); - DCHECK(success); - - JS::RootedObject function_prototype( - context, JS_GetFunctionPrototype(context, global_object)); - DCHECK(function_prototype); - // Create the Interface object. - interface_data->interface_object = JS_NewObjectWithGivenProto( - context, &interface_object_class_definition, - function_prototype); - - // Add the InterfaceObject.name property. - JS::RootedObject rooted_interface_object( - context, interface_data->interface_object); - JS::RootedValue name_value(context); - const char name[] = - "Window"; - name_value.setString(JS_NewStringCopyZ(context, name)); - success = JS_DefineProperty( - context, rooted_interface_object, "name", name_value, JSPROP_READONLY, - NULL, NULL); - DCHECK(success); - - // Define interface object properties (including constants). - success = JS_DefineProperties(context, rooted_interface_object, - interface_object_properties); - DCHECK(success); - // Define interface object functions (static). - success = JS_DefineFunctions(context, rooted_interface_object, - interface_object_functions); - DCHECK(success); - - // Set the Prototype.constructor and Constructor.prototype properties. - DCHECK(interface_data->interface_object); - DCHECK(interface_data->prototype); - success = JS_LinkConstructorAndPrototype( - context, - rooted_interface_object, - rooted_prototype); - DCHECK(success); -} - -InterfaceData* GetInterfaceData(JSContext* context) { - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - // Use the address of the properties definition for this interface as a - // unique key for looking up the InterfaceData for this interface. - intptr_t key = reinterpret_cast<intptr_t>(&own_properties); - InterfaceData* interface_data = global_environment->GetInterfaceData(key); - if (!interface_data) { - interface_data = new InterfaceData(); - DCHECK(interface_data); - global_environment->CacheInterfaceData(key, interface_data); - DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key)); - } - return interface_data; -} - -} // namespace - -JSObject* MozjsWindow::CreateProxy( - JSContext* context, const scoped_refptr<Wrappable>& wrappable) { - - InterfaceData* interface_data = GetInterfaceData(context); - - JS::RootedObject global_object( - context, JS_NewGlobalObject(context, - &instance_class_definition, NULL, - JS::FireOnNewGlobalHook, - JS::CompartmentOptions().setTrace(WrapperPrivate::Trace))); - DCHECK(global_object); - - // Initialize standard JS constructors prototypes and top-level functions such - // as Object, isNan, etc. - JSAutoCompartment auto_compartment(context, global_object); - bool success = JS_InitStandardClasses(context, global_object); - DCHECK(success); - - JS::RootedObject prototype( - context, MozjsWindow::GetPrototype(context, global_object)); - DCHECK(prototype); - JS_SetPrototype(context, global_object, prototype); - - JS_SetImmutablePrototype(context, global_object, &success); - DCHECK(success); - - // Add own properties. - success = JS_DefineProperties(context, global_object, own_properties); - DCHECK(success); - - JS::RootedObject proxy(context, - ProxyHandler::NewProxy( - context, proxy_handler.Pointer(), global_object, prototype)); - WrapperPrivate::AddPrivateData(context, proxy, wrappable); - - // Set the global object proxy pointer, so we can access the standard classes - // such as the base Object prototype when looking up our prototype. - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - global_environment->SetGlobalObjectProxyAndWrapper(proxy, wrappable); - return proxy; -} -// static -const JSClass* MozjsWindow::PrototypeClass( - JSContext* context) { - DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); - JS::RootedObject global_object( - context, - MozjsGlobalEnvironment::GetFromContext(context)->global_object()); - DCHECK(global_object); - - JS::RootedObject prototype(context, GetPrototype(context, global_object)); - const JSClass* proto_class = JS_GetClass(prototype); - return proto_class; -} - -// static -JSObject* MozjsWindow::GetPrototype( - JSContext* context, JS::HandleObject global_object) { - DCHECK(JS_IsGlobalObject(global_object)); - - InterfaceData* interface_data = GetInterfaceData(context); - if (!interface_data->prototype) { - // Create new prototype that has all the props and methods - InitializePrototypeAndInterfaceObject( - interface_data, context, global_object); - } - DCHECK(interface_data->prototype); - return interface_data->prototype; -} - -// static -JSObject* MozjsWindow::GetInterfaceObject( - JSContext* context, JS::HandleObject global_object) { - DCHECK(JS_IsGlobalObject(global_object)); - - InterfaceData* interface_data = GetInterfaceData(context); - if (!interface_data->interface_object) { - InitializePrototypeAndInterfaceObject( - interface_data, context, global_object); - } - DCHECK(interface_data->interface_object); - return interface_data->interface_object; -} - - -namespace { -} // namespace - - -} // namespace testing -} // namespace bindings - -namespace script { - -template<> -void GlobalEnvironment::CreateGlobalObject<Window>( - const scoped_refptr<Window>& global_interface, - EnvironmentSettings* environment_settings) { - MozjsGlobalEnvironment* mozjs_global_environment = - base::polymorphic_downcast<MozjsGlobalEnvironment*>(this); - JSContext* context = mozjs_global_environment->context(); - - JSAutoRequest auto_request(context); - MozjsWindow::CreateProxy( - context, global_interface); - mozjs_global_environment->SetEnvironmentSettings(environment_settings); - - WrapperFactory* wrapper_factory = - mozjs_global_environment->wrapper_factory(); - wrapper_factory->RegisterWrappableType( - AnonymousIndexedGetterInterface::AnonymousIndexedGetterInterfaceWrappableType(), - base::Bind(MozjsAnonymousIndexedGetterInterface::CreateProxy), - base::Bind(MozjsAnonymousIndexedGetterInterface::PrototypeClass)); - wrapper_factory->RegisterWrappableType( - AnonymousNamedGetterInterface::AnonymousNamedGetterInterfaceWrappableType(), - base::Bind(MozjsAnonymousNamedGetterInterface::CreateProxy), - base::Bind(MozjsAnonymousNamedGetterInterface::PrototypeClass)); - wrapper_factory->RegisterWrappableType( - AnonymousNamedIndexedGetterInterface::AnonymousNamedIndexedGetterInterfaceWrappableType(), - base::Bind(MozjsAnonymousNamedIndexedGetterInterface::CreateProxy), - base::Bind(MozjsAnonymousNamedIndexedGetterInterface::PrototypeClass)); - wrapper_factory->RegisterWrappableType( - ArbitraryInterface::ArbitraryInterfaceWrappableType(), - base::Bind(MozjsArbitraryInterface::CreateProxy), - base::Bind(MozjsArbitraryInterface::PrototypeClass)); - wrapper_factory->RegisterWrappableType( - BaseInterface::BaseInterfaceWrappableType(), - base::Bind(MozjsBaseInterface::CreateProxy), - base::Bind(MozjsBaseInterface::PrototypeClass)); - wrapper_factory->RegisterWrappableType( - BooleanTypeTestInterface::BooleanTypeTestInterfaceWrappableType(), - base::Bind(MozjsBooleanTypeTestInterface::CreateProxy), - base::Bind(MozjsBooleanTypeTestInterface::PrototypeClass)); - wrapper_factory->RegisterWrappableType( - CallbackFunctionInterface::CallbackFunctionInterfaceWrappableType(), - base::Bind(MozjsCallbackFunctionInterface::CreateProxy), - base::Bind(MozjsCallbackFunctionInterface::PrototypeClass)); - wrapper_factory->RegisterWrappableType( - CallbackInterfaceInterface::CallbackInterfaceInterfaceWrappableType(), - base::Bind(MozjsCallbackInterfaceInterface::CreateProxy), - base::Bind(MozjsCallbackInterfaceInterface::PrototypeClass)); -#if defined(ENABLE_CONDITIONAL_INTERFACE) - wrapper_factory->RegisterWrappableType( - ConditionalInterface::ConditionalInterfaceWrappableType(), - base::Bind(MozjsConditionalInterface::CreateProxy), - base::Bind(MozjsConditionalInterface::PrototypeClass)); -#endif // defined(ENABLE_CONDITIONAL_INTERFACE) - wrapper_factory->RegisterWrappableType( - ConstantsInterface::ConstantsInterfaceWrappableType(), - base::Bind(MozjsConstantsInterface::CreateProxy), - base::Bind(MozjsConstantsInterface::PrototypeClass)); - wrapper_factory->RegisterWrappableType( - ConstructorInterface::ConstructorInterfaceWrappableType(), - base::Bind(MozjsConstructorInterface::CreateProxy), - base::Bind(MozjsConstructorInterface::PrototypeClass)); - wrapper_factory->RegisterWrappableType( - ConstructorWithArgumentsInterface::ConstructorWithArgumentsInterfaceWrappableType(), - base::Bind(MozjsConstructorWithArgumentsInterface::CreateProxy), - base::Bind(MozjsConstructorWithArgumentsInterface::PrototypeClass)); - wrapper_factory->RegisterWrappableType( - DOMStringTestInterface::DOMStringTestInterfaceWrappableType(), - base::Bind(MozjsDOMStringTestInterface::CreateProxy), - base::Bind(MozjsDOMStringTestInterface::PrototypeClass)); - wrapper_factory->RegisterWrappableType( - DerivedGetterSetterInterface::DerivedGetterSetterInterfaceWrappableType(), - base::Bind(MozjsDerivedGetterSetterInterface::CreateProxy), - base::Bind(MozjsDerivedGetterSetterInterface::PrototypeClass)); - wrapper_factory->RegisterWrappableType( - DerivedInterface::DerivedInterfaceWrappableType(), - base::Bind(MozjsDerivedInterface::CreateProxy), - base::Bind(MozjsDerivedInterface::PrototypeClass)); -#if defined(NO_ENABLE_CONDITIONAL_INTERFACE) - wrapper_factory->RegisterWrappableType( - DisabledInterface::DisabledInterfaceWrappableType(), - base::Bind(MozjsDisabledInterface::CreateProxy), - base::Bind(MozjsDisabledInterface::PrototypeClass)); -#endif // defined(NO_ENABLE_CONDITIONAL_INTERFACE) - wrapper_factory->RegisterWrappableType( - EnumerationInterface::EnumerationInterfaceWrappableType(), - base::Bind(MozjsEnumerationInterface::CreateProxy), - base::Bind(MozjsEnumerationInterface::PrototypeClass)); - wrapper_factory->RegisterWrappableType( - ExceptionObjectInterface::ExceptionObjectInterfaceWrappableType(), - base::Bind(MozjsExceptionObjectInterface::CreateProxy), - base::Bind(MozjsExceptionObjectInterface::PrototypeClass)); - wrapper_factory->RegisterWrappableType( - ExceptionsInterface::ExceptionsInterfaceWrappableType(), - base::Bind(MozjsExceptionsInterface::CreateProxy), - base::Bind(MozjsExceptionsInterface::PrototypeClass)); - wrapper_factory->RegisterWrappableType( - ExtendedIDLAttributesInterface::ExtendedIDLAttributesInterfaceWrappableType(), - base::Bind(MozjsExtendedIDLAttributesInterface::CreateProxy), - base::Bind(MozjsExtendedIDLAttributesInterface::PrototypeClass)); - wrapper_factory->RegisterWrappableType( - GarbageCollectionTestInterface::GarbageCollectionTestInterfaceWrappableType(), - base::Bind(MozjsGarbageCollectionTestInterface::CreateProxy), - base::Bind(MozjsGarbageCollectionTestInterface::PrototypeClass)); - wrapper_factory->RegisterWrappableType( - GetOpaqueRootInterface::GetOpaqueRootInterfaceWrappableType(), - base::Bind(MozjsGetOpaqueRootInterface::CreateProxy), - base::Bind(MozjsGetOpaqueRootInterface::PrototypeClass)); - wrapper_factory->RegisterWrappableType( - GlobalInterfaceParent::GlobalInterfaceParentWrappableType(), - base::Bind(MozjsGlobalInterfaceParent::CreateProxy), - base::Bind(MozjsGlobalInterfaceParent::PrototypeClass)); - wrapper_factory->RegisterWrappableType( - ImplementedInterface::ImplementedInterfaceWrappableType(), - base::Bind(MozjsImplementedInterface::CreateProxy), - base::Bind(MozjsImplementedInterface::PrototypeClass)); - wrapper_factory->RegisterWrappableType( - IndexedGetterInterface::IndexedGetterInterfaceWrappableType(), - base::Bind(MozjsIndexedGetterInterface::CreateProxy), - base::Bind(MozjsIndexedGetterInterface::PrototypeClass)); - wrapper_factory->RegisterWrappableType( - InterfaceWithUnsupportedProperties::InterfaceWithUnsupportedPropertiesWrappableType(), - base::Bind(MozjsInterfaceWithUnsupportedProperties::CreateProxy), - base::Bind(MozjsInterfaceWithUnsupportedProperties::PrototypeClass)); - wrapper_factory->RegisterWrappableType( - NamedConstructorInterface::NamedConstructorInterfaceWrappableType(), - base::Bind(MozjsNamedConstructorInterface::CreateProxy), - base::Bind(MozjsNamedConstructorInterface::PrototypeClass)); - wrapper_factory->RegisterWrappableType( - NamedGetterInterface::NamedGetterInterfaceWrappableType(), - base::Bind(MozjsNamedGetterInterface::CreateProxy), - base::Bind(MozjsNamedGetterInterface::PrototypeClass)); - wrapper_factory->RegisterWrappableType( - NamedIndexedGetterInterface::NamedIndexedGetterInterfaceWrappableType(), - base::Bind(MozjsNamedIndexedGetterInterface::CreateProxy), - base::Bind(MozjsNamedIndexedGetterInterface::PrototypeClass)); - wrapper_factory->RegisterWrappableType( - NestedPutForwardsInterface::NestedPutForwardsInterfaceWrappableType(), - base::Bind(MozjsNestedPutForwardsInterface::CreateProxy), - base::Bind(MozjsNestedPutForwardsInterface::PrototypeClass)); - wrapper_factory->RegisterWrappableType( - NoConstructorInterface::NoConstructorInterfaceWrappableType(), - base::Bind(MozjsNoConstructorInterface::CreateProxy), - base::Bind(MozjsNoConstructorInterface::PrototypeClass)); - wrapper_factory->RegisterWrappableType( - NoInterfaceObjectInterface::NoInterfaceObjectInterfaceWrappableType(), - base::Bind(MozjsNoInterfaceObjectInterface::CreateProxy), - base::Bind(MozjsNoInterfaceObjectInterface::PrototypeClass)); - wrapper_factory->RegisterWrappableType( - NullableTypesTestInterface::NullableTypesTestInterfaceWrappableType(), - base::Bind(MozjsNullableTypesTestInterface::CreateProxy), - base::Bind(MozjsNullableTypesTestInterface::PrototypeClass)); - wrapper_factory->RegisterWrappableType( - NumericTypesTestInterface::NumericTypesTestInterfaceWrappableType(), - base::Bind(MozjsNumericTypesTestInterface::CreateProxy), - base::Bind(MozjsNumericTypesTestInterface::PrototypeClass)); - wrapper_factory->RegisterWrappableType( - ObjectTypeBindingsInterface::ObjectTypeBindingsInterfaceWrappableType(), - base::Bind(MozjsObjectTypeBindingsInterface::CreateProxy), - base::Bind(MozjsObjectTypeBindingsInterface::PrototypeClass)); - wrapper_factory->RegisterWrappableType( - OperationsTestInterface::OperationsTestInterfaceWrappableType(), - base::Bind(MozjsOperationsTestInterface::CreateProxy), - base::Bind(MozjsOperationsTestInterface::PrototypeClass)); - wrapper_factory->RegisterWrappableType( - PutForwardsInterface::PutForwardsInterfaceWrappableType(), - base::Bind(MozjsPutForwardsInterface::CreateProxy), - base::Bind(MozjsPutForwardsInterface::PrototypeClass)); - wrapper_factory->RegisterWrappableType( - SequenceUser::SequenceUserWrappableType(), - base::Bind(MozjsSequenceUser::CreateProxy), - base::Bind(MozjsSequenceUser::PrototypeClass)); - wrapper_factory->RegisterWrappableType( - StaticPropertiesInterface::StaticPropertiesInterfaceWrappableType(), - base::Bind(MozjsStaticPropertiesInterface::CreateProxy), - base::Bind(MozjsStaticPropertiesInterface::PrototypeClass)); - wrapper_factory->RegisterWrappableType( - StringifierAnonymousOperationInterface::StringifierAnonymousOperationInterfaceWrappableType(), - base::Bind(MozjsStringifierAnonymousOperationInterface::CreateProxy), - base::Bind(MozjsStringifierAnonymousOperationInterface::PrototypeClass)); - wrapper_factory->RegisterWrappableType( - StringifierAttributeInterface::StringifierAttributeInterfaceWrappableType(), - base::Bind(MozjsStringifierAttributeInterface::CreateProxy), - base::Bind(MozjsStringifierAttributeInterface::PrototypeClass)); - wrapper_factory->RegisterWrappableType( - StringifierOperationInterface::StringifierOperationInterfaceWrappableType(), - base::Bind(MozjsStringifierOperationInterface::CreateProxy), - base::Bind(MozjsStringifierOperationInterface::PrototypeClass)); - wrapper_factory->RegisterWrappableType( - TargetInterface::TargetInterfaceWrappableType(), - base::Bind(MozjsTargetInterface::CreateProxy), - base::Bind(MozjsTargetInterface::PrototypeClass)); - wrapper_factory->RegisterWrappableType( - UnionTypesInterface::UnionTypesInterfaceWrappableType(), - base::Bind(MozjsUnionTypesInterface::CreateProxy), - base::Bind(MozjsUnionTypesInterface::PrototypeClass)); - wrapper_factory->RegisterWrappableType( - Window::WindowWrappableType(), - base::Bind(DummyFunctor), - base::Bind(MozjsWindow::PrototypeClass)); - -} - -// MSVS compiler does not need this explicit instantiation, and generates a -// compiler error. -#if !defined(_MSC_VER) -// Explicitly instantiate the template function for template type Window -// This is needed to prevent link errors when trying to resolve the template -// instantiation. -template -void GlobalEnvironment::CreateGlobalObject<Window>( - const scoped_refptr<Window>& global_interface, - EnvironmentSettings* environment_settings); -#endif - -} // namespace script -} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsWindow.h b/src/cobalt/bindings/generated/mozjs-45/testing/MozjsWindow.h deleted file mode 100644 index 30c4802..0000000 --- a/src/cobalt/bindings/generated/mozjs-45/testing/MozjsWindow.h +++ /dev/null
@@ -1,55 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! -// Auto-generated from template: bindings/mozjs-45/templates/interface.h.template - -// clang-format off - -#ifndef MozjsWindow_h -#define MozjsWindow_h - -#include "base/hash_tables.h" -#include "base/lazy_instance.h" -#include "base/memory/ref_counted.h" -#include "base/threading/thread_checker.h" -#include "cobalt/base/polymorphic_downcast.h" -#include "cobalt/script/wrappable.h" -#include "MozjsGlobalInterfaceParent.h" -#include "cobalt/bindings/testing/window.h" - -#include "third_party/mozjs-45/js/src/jsapi.h" - -namespace cobalt { -namespace bindings { -namespace testing { - -class MozjsWindow { - public: - static JSObject* CreateProxy(JSContext* context, - const scoped_refptr<script::Wrappable>& wrappable); - static const JSClass* PrototypeClass(JSContext* context); - static JSObject* GetPrototype(JSContext* context, - JS::HandleObject global_object); - static JSObject* GetInterfaceObject(JSContext* context, - JS::HandleObject global_object); -}; - -} // namespace bindings -} // namespace testing -} // namespace cobalt - -#endif // MozjsWindow_h
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_anonymous_indexed_getter_interface.cc b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_anonymous_indexed_getter_interface.cc new file mode 100644 index 0000000..97f7f26 --- /dev/null +++ b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_anonymous_indexed_getter_interface.cc
@@ -0,0 +1,497 @@ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// clang-format off + +// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! +// Auto-generated from template: bindings/mozjs-45/templates/interface.cc.template + +#include "cobalt/bindings/testing/mozjs_anonymous_indexed_getter_interface.h" + +#include "base/debug/trace_event.h" +#include "cobalt/base/polymorphic_downcast.h" +#include "cobalt/script/global_environment.h" +#include "cobalt/script/opaque_handle.h" +#include "cobalt/script/script_value.h" + +#include "base/lazy_instance.h" +#include "cobalt/script/exception_state.h" +#include "cobalt/script/mozjs-45/callback_function_conversion.h" +#include "cobalt/script/mozjs-45/conversion_helpers.h" +#include "cobalt/script/mozjs-45/mozjs_callback_function.h" +#include "cobalt/script/mozjs-45/mozjs_exception_state.h" +#include "cobalt/script/mozjs-45/mozjs_global_environment.h" +#include "cobalt/script/mozjs-45/mozjs_object_handle.h" +#include "cobalt/script/mozjs-45/mozjs_property_enumerator.h" +#include "cobalt/script/mozjs-45/mozjs_user_object_holder.h" +#include "cobalt/script/mozjs-45/proxy_handler.h" +#include "cobalt/script/mozjs-45/type_traits.h" +#include "cobalt/script/mozjs-45/wrapper_factory.h" +#include "cobalt/script/mozjs-45/wrapper_private.h" +#include "cobalt/script/property_enumerator.h" +#include "cobalt/script/sequence.h" +#include "third_party/mozjs-45/js/src/jsapi.h" +#include "third_party/mozjs-45/js/src/jsfriendapi.h" + +namespace { +using cobalt::bindings::testing::AnonymousIndexedGetterInterface; +using cobalt::bindings::testing::MozjsAnonymousIndexedGetterInterface; +using cobalt::script::CallbackInterfaceTraits; +using cobalt::script::GlobalEnvironment; +using cobalt::script::OpaqueHandle; +using cobalt::script::OpaqueHandleHolder; +using cobalt::script::ScriptValue; +using cobalt::script::Wrappable; + +using cobalt::script::CallbackFunction; +using cobalt::script::CallbackInterfaceTraits; +using cobalt::script::ExceptionState; +using cobalt::script::Wrappable; +using cobalt::script::mozjs::FromJSValue; +using cobalt::script::mozjs::InterfaceData; +using cobalt::script::mozjs::MozjsCallbackFunction; +using cobalt::script::mozjs::MozjsExceptionState; +using cobalt::script::mozjs::MozjsGlobalEnvironment; +using cobalt::script::mozjs::MozjsPropertyEnumerator; +using cobalt::script::mozjs::MozjsUserObjectHolder; +using cobalt::script::mozjs::ProxyHandler; +using cobalt::script::mozjs::ToJSValue; +using cobalt::script::mozjs::TypeTraits; +using cobalt::script::mozjs::WrapperFactory; +using cobalt::script::mozjs::WrapperPrivate; +using cobalt::script::mozjs::kConversionFlagNullable; +using cobalt::script::mozjs::kConversionFlagRestricted; +using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString; +using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString; +using cobalt::script::mozjs::kNoConversionFlags; +} // namespace + +namespace cobalt { +namespace bindings { +namespace testing { + +namespace { + +bool IsSupportedIndexProperty(JSContext* context, JS::HandleObject object, + uint32_t index) { + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + AnonymousIndexedGetterInterface* impl = + wrapper_private->wrappable<AnonymousIndexedGetterInterface>().get(); + return index < impl->length(); +} + +void EnumerateSupportedIndexes(JSContext* context, JS::HandleObject object, + JS::AutoIdVector* properties) { + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + AnonymousIndexedGetterInterface* impl = + wrapper_private->wrappable<AnonymousIndexedGetterInterface>().get(); + const uint32_t kNumIndexedProperties = impl->length(); + for (uint32_t i = 0; i < kNumIndexedProperties; ++i) { + properties->append(INT_TO_JSID(i)); + } +} + +bool GetIndexedProperty( + JSContext* context, JS::HandleObject object, JS::HandleId id, + JS::MutableHandleValue vp) { + JS::RootedValue id_value(context); + if (!JS_IdToValue(context, id, &id_value)) { + NOTREACHED(); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + AnonymousIndexedGetterInterface* impl = + wrapper_private->wrappable<AnonymousIndexedGetterInterface>().get(); + uint32_t index; + FromJSValue(context, id_value, kNoConversionFlags, &exception_state, &index); + if (exception_state.is_exception_set()) { + // The ID should be an integer or a string, so we shouldn't have any + // exceptions converting to string. + NOTREACHED(); + return false; + } + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->AnonymousIndexedGetter(index), + &result_value); + } + if (!exception_state.is_exception_set()) { + vp.set(result_value); + } + return !exception_state.is_exception_set(); +} + +bool SetIndexedProperty( + JSContext* context, JS::HandleObject object, JS::HandleId id, + JS::MutableHandleValue vp, JS::ObjectOpResult& object_op_result) { + JS::RootedValue id_value(context); + if (!JS_IdToValue(context, id, &id_value)) { + NOTREACHED(); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + AnonymousIndexedGetterInterface* impl = + wrapper_private->wrappable<AnonymousIndexedGetterInterface>().get(); + uint32_t index; + FromJSValue(context, id_value, kNoConversionFlags, &exception_state, &index); + if (exception_state.is_exception_set()) { + // The ID should be an integer or a string, so we shouldn't have any + // exceptions converting to string. + NOTREACHED(); + return false; + } + TypeTraits<uint32_t >::ConversionType value; + FromJSValue(context, vp, kNoConversionFlags, + &exception_state, &value); + if (exception_state.is_exception_set()) { + return false; + } + + impl->AnonymousIndexedSetter(index, value); + result_value.set(JS::UndefinedHandleValue); + if (!exception_state.is_exception_set()) { + return object_op_result.succeed(); + } else { + return false; + } +} + +class MozjsAnonymousIndexedGetterInterfaceHandler : public ProxyHandler { + public: + MozjsAnonymousIndexedGetterInterfaceHandler() + : ProxyHandler(indexed_property_hooks, named_property_hooks) {} + + private: + static NamedPropertyHooks named_property_hooks; + static IndexedPropertyHooks indexed_property_hooks; +}; + +ProxyHandler::NamedPropertyHooks +MozjsAnonymousIndexedGetterInterfaceHandler::named_property_hooks = { + NULL, + NULL, + NULL, + NULL, + NULL, +}; +ProxyHandler::IndexedPropertyHooks +MozjsAnonymousIndexedGetterInterfaceHandler::indexed_property_hooks = { + IsSupportedIndexProperty, + EnumerateSupportedIndexes, + GetIndexedProperty, + SetIndexedProperty, + NULL, +}; + +static base::LazyInstance<MozjsAnonymousIndexedGetterInterfaceHandler> + proxy_handler; + +bool HasInstance(JSContext *context, JS::HandleObject type, + JS::MutableHandleValue vp, bool *success) { + JS::RootedObject global_object( + context, JS_GetGlobalForObject(context, type)); + DCHECK(global_object); + + JS::RootedObject prototype( + context, MozjsAnonymousIndexedGetterInterface::GetPrototype(context, global_object)); + + // |IsDelegate| walks the prototype chain of an object returning true if + // .prototype is found. + bool is_delegate; + if (!IsDelegate(context, prototype, vp, &is_delegate)) { + *success = false; + return false; + } + + *success = is_delegate; + return true; +} + +const JSClass instance_class_definition = { + "AnonymousIndexedGetterInterface", + 0 | JSCLASS_HAS_PRIVATE, + NULL, // addProperty + NULL, // delProperty + NULL, // getProperty + NULL, // setProperty + NULL, // enumerate + NULL, // resolve + NULL, // mayResolve + &WrapperPrivate::Finalizer, // finalize + NULL, // call + NULL, // hasInstance + NULL, // construct + &WrapperPrivate::Trace, // trace +}; + +const JSClass prototype_class_definition = { + "AnonymousIndexedGetterInterfacePrototype", +}; + +const JSClass interface_object_class_definition = { + "AnonymousIndexedGetterInterfaceConstructor", + 0, + NULL, // addProperty + NULL, // delProperty + NULL, // getProperty + NULL, // setProperty + NULL, // enumerate + NULL, // resolve + NULL, // mayResolve + NULL, // finalize + NULL, // call + &HasInstance, + NULL, +}; + +bool get_length( + JSContext* context, unsigned argc, JS::Value* vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + const JSClass* proto_class = + MozjsAnonymousIndexedGetterInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<AnonymousIndexedGetterInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + AnonymousIndexedGetterInterface* impl = + wrapper_private->wrappable<AnonymousIndexedGetterInterface>().get(); + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->length(), + &result_value); + } + if (!exception_state.is_exception_set()) { + args.rval().set(result_value); + } + return !exception_state.is_exception_set(); +} + + + + +const JSPropertySpec prototype_properties[] = { + { // Readonly attribute + "length", + JSPROP_SHARED | JSPROP_ENUMERATE, + { { &get_length, NULL } }, + JSNATIVE_WRAPPER(NULL), + }, + JS_PS_END +}; + +const JSFunctionSpec prototype_functions[] = { + JS_FS_END +}; + +const JSPropertySpec interface_object_properties[] = { + JS_PS_END +}; + +const JSFunctionSpec interface_object_functions[] = { + JS_FS_END +}; + +const JSPropertySpec own_properties[] = { + JS_PS_END +}; + +void InitializePrototypeAndInterfaceObject( + InterfaceData* interface_data, JSContext* context, + JS::HandleObject global_object) { + DCHECK(!interface_data->prototype); + DCHECK(!interface_data->interface_object); + DCHECK(JS_IsGlobalObject(global_object)); + + JS::RootedObject parent_prototype( + context, JS_GetObjectPrototype(context, global_object)); + DCHECK(parent_prototype); + + interface_data->prototype = JS_NewObjectWithGivenProto( + context, &prototype_class_definition, parent_prototype + ); + + JS::RootedObject rooted_prototype(context, interface_data->prototype); + bool success = JS_DefineProperties( + context, + rooted_prototype, + prototype_properties); + + DCHECK(success); + success = JS_DefineFunctions( + context, rooted_prototype, prototype_functions); + DCHECK(success); + + JS::RootedObject function_prototype( + context, JS_GetFunctionPrototype(context, global_object)); + DCHECK(function_prototype); + // Create the Interface object. + interface_data->interface_object = JS_NewObjectWithGivenProto( + context, &interface_object_class_definition, + function_prototype); + + // Add the InterfaceObject.name property. + JS::RootedObject rooted_interface_object( + context, interface_data->interface_object); + JS::RootedValue name_value(context); + const char name[] = + "AnonymousIndexedGetterInterface"; + name_value.setString(JS_NewStringCopyZ(context, name)); + success = JS_DefineProperty( + context, rooted_interface_object, "name", name_value, JSPROP_READONLY, + NULL, NULL); + DCHECK(success); + + // Define interface object properties (including constants). + success = JS_DefineProperties(context, rooted_interface_object, + interface_object_properties); + DCHECK(success); + // Define interface object functions (static). + success = JS_DefineFunctions(context, rooted_interface_object, + interface_object_functions); + DCHECK(success); + + // Set the Prototype.constructor and Constructor.prototype properties. + DCHECK(interface_data->interface_object); + DCHECK(interface_data->prototype); + success = JS_LinkConstructorAndPrototype( + context, + rooted_interface_object, + rooted_prototype); + DCHECK(success); +} + +InterfaceData* GetInterfaceData(JSContext* context) { + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + // Use the address of the properties definition for this interface as a + // unique key for looking up the InterfaceData for this interface. + intptr_t key = reinterpret_cast<intptr_t>(&own_properties); + InterfaceData* interface_data = global_environment->GetInterfaceData(key); + if (!interface_data) { + interface_data = new InterfaceData(); + DCHECK(interface_data); + global_environment->CacheInterfaceData(key, interface_data); + DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key)); + } + return interface_data; +} + +} // namespace + +// static +JSObject* MozjsAnonymousIndexedGetterInterface::CreateProxy( + JSContext* context, const scoped_refptr<Wrappable>& wrappable) { + DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); + JS::RootedObject global_object( + context, + MozjsGlobalEnvironment::GetFromContext(context)->global_object()); + DCHECK(global_object); + + InterfaceData* interface_data = GetInterfaceData(context); + JS::RootedObject prototype(context, GetPrototype(context, global_object)); + DCHECK(prototype); + JS::RootedObject new_object( + context, + JS_NewObjectWithGivenProto( + context, &instance_class_definition, prototype)); + DCHECK(new_object); + JS::RootedObject proxy(context, + ProxyHandler::NewProxy( + context, proxy_handler.Pointer(), new_object, prototype)); + WrapperPrivate::AddPrivateData(context, proxy, wrappable); + return proxy; +} + +// static +const JSClass* MozjsAnonymousIndexedGetterInterface::PrototypeClass( + JSContext* context) { + DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); + JS::RootedObject global_object( + context, + MozjsGlobalEnvironment::GetFromContext(context)->global_object()); + DCHECK(global_object); + + JS::RootedObject prototype(context, GetPrototype(context, global_object)); + const JSClass* proto_class = JS_GetClass(prototype); + return proto_class; +} + +// static +JSObject* MozjsAnonymousIndexedGetterInterface::GetPrototype( + JSContext* context, JS::HandleObject global_object) { + DCHECK(JS_IsGlobalObject(global_object)); + + InterfaceData* interface_data = GetInterfaceData(context); + if (!interface_data->prototype) { + // Create new prototype that has all the props and methods + InitializePrototypeAndInterfaceObject( + interface_data, context, global_object); + } + DCHECK(interface_data->prototype); + return interface_data->prototype; +} + +// static +JSObject* MozjsAnonymousIndexedGetterInterface::GetInterfaceObject( + JSContext* context, JS::HandleObject global_object) { + DCHECK(JS_IsGlobalObject(global_object)); + + InterfaceData* interface_data = GetInterfaceData(context); + if (!interface_data->interface_object) { + InitializePrototypeAndInterfaceObject( + interface_data, context, global_object); + } + DCHECK(interface_data->interface_object); + return interface_data->interface_object; +} + + +namespace { +} // namespace + + +} // namespace testing +} // namespace bindings +} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_anonymous_indexed_getter_interface.h b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_anonymous_indexed_getter_interface.h new file mode 100644 index 0000000..bf5503d --- /dev/null +++ b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_anonymous_indexed_getter_interface.h
@@ -0,0 +1,52 @@ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// clang-format off + +// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! +// Auto-generated from template: bindings/mozjs-45/templates/interface.h.template + +#ifndef MozjsAnonymousIndexedGetterInterface_h +#define MozjsAnonymousIndexedGetterInterface_h + +#include "base/hash_tables.h" +#include "base/lazy_instance.h" +#include "base/memory/ref_counted.h" +#include "base/threading/thread_checker.h" +#include "cobalt/base/polymorphic_downcast.h" +#include "cobalt/script/wrappable.h" +#include "cobalt/bindings/testing/anonymous_indexed_getter_interface.h" + +#include "third_party/mozjs-45/js/src/jsapi.h" + +namespace cobalt { +namespace bindings { +namespace testing { + +class MozjsAnonymousIndexedGetterInterface { + public: + static JSObject* CreateProxy(JSContext* context, + const scoped_refptr<script::Wrappable>& wrappable); + static const JSClass* PrototypeClass(JSContext* context); + static JSObject* GetPrototype(JSContext* context, + JS::HandleObject global_object); + static JSObject* GetInterfaceObject(JSContext* context, + JS::HandleObject global_object); +}; + +} // namespace testing +} // namespace bindings +} // namespace cobalt + +#endif // MozjsAnonymousIndexedGetterInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_anonymous_named_getter_interface.cc b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_anonymous_named_getter_interface.cc new file mode 100644 index 0000000..1cc7194 --- /dev/null +++ b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_anonymous_named_getter_interface.cc
@@ -0,0 +1,450 @@ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// clang-format off + +// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! +// Auto-generated from template: bindings/mozjs-45/templates/interface.cc.template + +#include "cobalt/bindings/testing/mozjs_anonymous_named_getter_interface.h" + +#include "base/debug/trace_event.h" +#include "cobalt/base/polymorphic_downcast.h" +#include "cobalt/script/global_environment.h" +#include "cobalt/script/opaque_handle.h" +#include "cobalt/script/script_value.h" + +#include "base/lazy_instance.h" +#include "cobalt/script/exception_state.h" +#include "cobalt/script/mozjs-45/callback_function_conversion.h" +#include "cobalt/script/mozjs-45/conversion_helpers.h" +#include "cobalt/script/mozjs-45/mozjs_callback_function.h" +#include "cobalt/script/mozjs-45/mozjs_exception_state.h" +#include "cobalt/script/mozjs-45/mozjs_global_environment.h" +#include "cobalt/script/mozjs-45/mozjs_object_handle.h" +#include "cobalt/script/mozjs-45/mozjs_property_enumerator.h" +#include "cobalt/script/mozjs-45/mozjs_user_object_holder.h" +#include "cobalt/script/mozjs-45/proxy_handler.h" +#include "cobalt/script/mozjs-45/type_traits.h" +#include "cobalt/script/mozjs-45/wrapper_factory.h" +#include "cobalt/script/mozjs-45/wrapper_private.h" +#include "cobalt/script/property_enumerator.h" +#include "cobalt/script/sequence.h" +#include "third_party/mozjs-45/js/src/jsapi.h" +#include "third_party/mozjs-45/js/src/jsfriendapi.h" + +namespace { +using cobalt::bindings::testing::AnonymousNamedGetterInterface; +using cobalt::bindings::testing::MozjsAnonymousNamedGetterInterface; +using cobalt::script::CallbackInterfaceTraits; +using cobalt::script::GlobalEnvironment; +using cobalt::script::OpaqueHandle; +using cobalt::script::OpaqueHandleHolder; +using cobalt::script::ScriptValue; +using cobalt::script::Wrappable; + +using cobalt::script::CallbackFunction; +using cobalt::script::CallbackInterfaceTraits; +using cobalt::script::ExceptionState; +using cobalt::script::Wrappable; +using cobalt::script::mozjs::FromJSValue; +using cobalt::script::mozjs::InterfaceData; +using cobalt::script::mozjs::MozjsCallbackFunction; +using cobalt::script::mozjs::MozjsExceptionState; +using cobalt::script::mozjs::MozjsGlobalEnvironment; +using cobalt::script::mozjs::MozjsPropertyEnumerator; +using cobalt::script::mozjs::MozjsUserObjectHolder; +using cobalt::script::mozjs::ProxyHandler; +using cobalt::script::mozjs::ToJSValue; +using cobalt::script::mozjs::TypeTraits; +using cobalt::script::mozjs::WrapperFactory; +using cobalt::script::mozjs::WrapperPrivate; +using cobalt::script::mozjs::kConversionFlagNullable; +using cobalt::script::mozjs::kConversionFlagRestricted; +using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString; +using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString; +using cobalt::script::mozjs::kNoConversionFlags; +} // namespace + +namespace cobalt { +namespace bindings { +namespace testing { + +namespace { + +bool IsSupportedNamedProperty(JSContext* context, JS::HandleObject object, + const std::string& property_name) { + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + AnonymousNamedGetterInterface* impl = + wrapper_private->wrappable<AnonymousNamedGetterInterface>().get(); + return impl->CanQueryNamedProperty(property_name); +} + +void EnumerateSupportedNames(JSContext* context, JS::HandleObject object, + JS::AutoIdVector* properties) { + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + AnonymousNamedGetterInterface* impl = + wrapper_private->wrappable<AnonymousNamedGetterInterface>().get(); + MozjsPropertyEnumerator enumerator(context, properties); + impl->EnumerateNamedProperties(&enumerator); +} + +bool GetNamedProperty( + JSContext* context, JS::HandleObject object, JS::HandleId id, + JS::MutableHandleValue vp) { + JS::RootedValue id_value(context); + if (!JS_IdToValue(context, id, &id_value)) { + NOTREACHED(); + return false; + } + + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + AnonymousNamedGetterInterface* impl = + wrapper_private->wrappable<AnonymousNamedGetterInterface>().get(); + std::string property_name; + FromJSValue(context, id_value, kNoConversionFlags, &exception_state, + &property_name); + if (exception_state.is_exception_set()) { + // The ID should be an integer or a string, so we shouldn't have any + // exceptions converting to string. + NOTREACHED(); + return false; + } + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->AnonymousNamedGetter(property_name), + &result_value); + } + if (!exception_state.is_exception_set()) { + vp.set(result_value); + } + return !exception_state.is_exception_set(); +} + +bool SetNamedProperty( + JSContext* context, JS::HandleObject object, JS::HandleId id, + JS::MutableHandleValue vp, JS::ObjectOpResult& object_op_result) { + JS::RootedValue id_value(context); + if (!JS_IdToValue(context, id, &id_value)) { + NOTREACHED(); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + AnonymousNamedGetterInterface* impl = + wrapper_private->wrappable<AnonymousNamedGetterInterface>().get(); + std::string property_name; + FromJSValue(context, id_value, kNoConversionFlags, &exception_state, + &property_name); + if (exception_state.is_exception_set()) { + // The ID should be an integer or a string, so we shouldn't have any + // exceptions converting to string. + NOTREACHED(); + return false; + } + TypeTraits<std::string >::ConversionType value; + FromJSValue(context, vp, kNoConversionFlags, + &exception_state, &value); + if (exception_state.is_exception_set()) { + return false; + } + + impl->AnonymousNamedSetter(property_name, value); + result_value.set(JS::UndefinedHandleValue); + + if (!exception_state.is_exception_set()) { + return object_op_result.succeed(); + } else { + return false; + } +} + +class MozjsAnonymousNamedGetterInterfaceHandler : public ProxyHandler { + public: + MozjsAnonymousNamedGetterInterfaceHandler() + : ProxyHandler(indexed_property_hooks, named_property_hooks) {} + + private: + static NamedPropertyHooks named_property_hooks; + static IndexedPropertyHooks indexed_property_hooks; +}; + +ProxyHandler::NamedPropertyHooks +MozjsAnonymousNamedGetterInterfaceHandler::named_property_hooks = { + IsSupportedNamedProperty, + EnumerateSupportedNames, + GetNamedProperty, + SetNamedProperty, + NULL, +}; +ProxyHandler::IndexedPropertyHooks +MozjsAnonymousNamedGetterInterfaceHandler::indexed_property_hooks = { + NULL, + NULL, + NULL, + NULL, + NULL, +}; + +static base::LazyInstance<MozjsAnonymousNamedGetterInterfaceHandler> + proxy_handler; + +bool HasInstance(JSContext *context, JS::HandleObject type, + JS::MutableHandleValue vp, bool *success) { + JS::RootedObject global_object( + context, JS_GetGlobalForObject(context, type)); + DCHECK(global_object); + + JS::RootedObject prototype( + context, MozjsAnonymousNamedGetterInterface::GetPrototype(context, global_object)); + + // |IsDelegate| walks the prototype chain of an object returning true if + // .prototype is found. + bool is_delegate; + if (!IsDelegate(context, prototype, vp, &is_delegate)) { + *success = false; + return false; + } + + *success = is_delegate; + return true; +} + +const JSClass instance_class_definition = { + "AnonymousNamedGetterInterface", + 0 | JSCLASS_HAS_PRIVATE, + NULL, // addProperty + NULL, // delProperty + NULL, // getProperty + NULL, // setProperty + NULL, // enumerate + NULL, // resolve + NULL, // mayResolve + &WrapperPrivate::Finalizer, // finalize + NULL, // call + NULL, // hasInstance + NULL, // construct + &WrapperPrivate::Trace, // trace +}; + +const JSClass prototype_class_definition = { + "AnonymousNamedGetterInterfacePrototype", +}; + +const JSClass interface_object_class_definition = { + "AnonymousNamedGetterInterfaceConstructor", + 0, + NULL, // addProperty + NULL, // delProperty + NULL, // getProperty + NULL, // setProperty + NULL, // enumerate + NULL, // resolve + NULL, // mayResolve + NULL, // finalize + NULL, // call + &HasInstance, + NULL, +}; + + + +const JSPropertySpec prototype_properties[] = { + JS_PS_END +}; + +const JSFunctionSpec prototype_functions[] = { + JS_FS_END +}; + +const JSPropertySpec interface_object_properties[] = { + JS_PS_END +}; + +const JSFunctionSpec interface_object_functions[] = { + JS_FS_END +}; + +const JSPropertySpec own_properties[] = { + JS_PS_END +}; + +void InitializePrototypeAndInterfaceObject( + InterfaceData* interface_data, JSContext* context, + JS::HandleObject global_object) { + DCHECK(!interface_data->prototype); + DCHECK(!interface_data->interface_object); + DCHECK(JS_IsGlobalObject(global_object)); + + JS::RootedObject parent_prototype( + context, JS_GetObjectPrototype(context, global_object)); + DCHECK(parent_prototype); + + interface_data->prototype = JS_NewObjectWithGivenProto( + context, &prototype_class_definition, parent_prototype + ); + + JS::RootedObject rooted_prototype(context, interface_data->prototype); + bool success = JS_DefineProperties( + context, + rooted_prototype, + prototype_properties); + + DCHECK(success); + success = JS_DefineFunctions( + context, rooted_prototype, prototype_functions); + DCHECK(success); + + JS::RootedObject function_prototype( + context, JS_GetFunctionPrototype(context, global_object)); + DCHECK(function_prototype); + // Create the Interface object. + interface_data->interface_object = JS_NewObjectWithGivenProto( + context, &interface_object_class_definition, + function_prototype); + + // Add the InterfaceObject.name property. + JS::RootedObject rooted_interface_object( + context, interface_data->interface_object); + JS::RootedValue name_value(context); + const char name[] = + "AnonymousNamedGetterInterface"; + name_value.setString(JS_NewStringCopyZ(context, name)); + success = JS_DefineProperty( + context, rooted_interface_object, "name", name_value, JSPROP_READONLY, + NULL, NULL); + DCHECK(success); + + // Define interface object properties (including constants). + success = JS_DefineProperties(context, rooted_interface_object, + interface_object_properties); + DCHECK(success); + // Define interface object functions (static). + success = JS_DefineFunctions(context, rooted_interface_object, + interface_object_functions); + DCHECK(success); + + // Set the Prototype.constructor and Constructor.prototype properties. + DCHECK(interface_data->interface_object); + DCHECK(interface_data->prototype); + success = JS_LinkConstructorAndPrototype( + context, + rooted_interface_object, + rooted_prototype); + DCHECK(success); +} + +InterfaceData* GetInterfaceData(JSContext* context) { + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + // Use the address of the properties definition for this interface as a + // unique key for looking up the InterfaceData for this interface. + intptr_t key = reinterpret_cast<intptr_t>(&own_properties); + InterfaceData* interface_data = global_environment->GetInterfaceData(key); + if (!interface_data) { + interface_data = new InterfaceData(); + DCHECK(interface_data); + global_environment->CacheInterfaceData(key, interface_data); + DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key)); + } + return interface_data; +} + +} // namespace + +// static +JSObject* MozjsAnonymousNamedGetterInterface::CreateProxy( + JSContext* context, const scoped_refptr<Wrappable>& wrappable) { + DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); + JS::RootedObject global_object( + context, + MozjsGlobalEnvironment::GetFromContext(context)->global_object()); + DCHECK(global_object); + + InterfaceData* interface_data = GetInterfaceData(context); + JS::RootedObject prototype(context, GetPrototype(context, global_object)); + DCHECK(prototype); + JS::RootedObject new_object( + context, + JS_NewObjectWithGivenProto( + context, &instance_class_definition, prototype)); + DCHECK(new_object); + JS::RootedObject proxy(context, + ProxyHandler::NewProxy( + context, proxy_handler.Pointer(), new_object, prototype)); + WrapperPrivate::AddPrivateData(context, proxy, wrappable); + return proxy; +} + +// static +const JSClass* MozjsAnonymousNamedGetterInterface::PrototypeClass( + JSContext* context) { + DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); + JS::RootedObject global_object( + context, + MozjsGlobalEnvironment::GetFromContext(context)->global_object()); + DCHECK(global_object); + + JS::RootedObject prototype(context, GetPrototype(context, global_object)); + const JSClass* proto_class = JS_GetClass(prototype); + return proto_class; +} + +// static +JSObject* MozjsAnonymousNamedGetterInterface::GetPrototype( + JSContext* context, JS::HandleObject global_object) { + DCHECK(JS_IsGlobalObject(global_object)); + + InterfaceData* interface_data = GetInterfaceData(context); + if (!interface_data->prototype) { + // Create new prototype that has all the props and methods + InitializePrototypeAndInterfaceObject( + interface_data, context, global_object); + } + DCHECK(interface_data->prototype); + return interface_data->prototype; +} + +// static +JSObject* MozjsAnonymousNamedGetterInterface::GetInterfaceObject( + JSContext* context, JS::HandleObject global_object) { + DCHECK(JS_IsGlobalObject(global_object)); + + InterfaceData* interface_data = GetInterfaceData(context); + if (!interface_data->interface_object) { + InitializePrototypeAndInterfaceObject( + interface_data, context, global_object); + } + DCHECK(interface_data->interface_object); + return interface_data->interface_object; +} + + +namespace { +} // namespace + + +} // namespace testing +} // namespace bindings +} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_anonymous_named_getter_interface.h b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_anonymous_named_getter_interface.h new file mode 100644 index 0000000..be03ed7 --- /dev/null +++ b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_anonymous_named_getter_interface.h
@@ -0,0 +1,52 @@ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// clang-format off + +// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! +// Auto-generated from template: bindings/mozjs-45/templates/interface.h.template + +#ifndef MozjsAnonymousNamedGetterInterface_h +#define MozjsAnonymousNamedGetterInterface_h + +#include "base/hash_tables.h" +#include "base/lazy_instance.h" +#include "base/memory/ref_counted.h" +#include "base/threading/thread_checker.h" +#include "cobalt/base/polymorphic_downcast.h" +#include "cobalt/script/wrappable.h" +#include "cobalt/bindings/testing/anonymous_named_getter_interface.h" + +#include "third_party/mozjs-45/js/src/jsapi.h" + +namespace cobalt { +namespace bindings { +namespace testing { + +class MozjsAnonymousNamedGetterInterface { + public: + static JSObject* CreateProxy(JSContext* context, + const scoped_refptr<script::Wrappable>& wrappable); + static const JSClass* PrototypeClass(JSContext* context); + static JSObject* GetPrototype(JSContext* context, + JS::HandleObject global_object); + static JSObject* GetInterfaceObject(JSContext* context, + JS::HandleObject global_object); +}; + +} // namespace testing +} // namespace bindings +} // namespace cobalt + +#endif // MozjsAnonymousNamedGetterInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_anonymous_named_indexed_getter_interface.cc b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_anonymous_named_indexed_getter_interface.cc new file mode 100644 index 0000000..342f7ae --- /dev/null +++ b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_anonymous_named_indexed_getter_interface.cc
@@ -0,0 +1,594 @@ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// clang-format off + +// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! +// Auto-generated from template: bindings/mozjs-45/templates/interface.cc.template + +#include "cobalt/bindings/testing/mozjs_anonymous_named_indexed_getter_interface.h" + +#include "base/debug/trace_event.h" +#include "cobalt/base/polymorphic_downcast.h" +#include "cobalt/script/global_environment.h" +#include "cobalt/script/opaque_handle.h" +#include "cobalt/script/script_value.h" + +#include "base/lazy_instance.h" +#include "cobalt/script/exception_state.h" +#include "cobalt/script/mozjs-45/callback_function_conversion.h" +#include "cobalt/script/mozjs-45/conversion_helpers.h" +#include "cobalt/script/mozjs-45/mozjs_callback_function.h" +#include "cobalt/script/mozjs-45/mozjs_exception_state.h" +#include "cobalt/script/mozjs-45/mozjs_global_environment.h" +#include "cobalt/script/mozjs-45/mozjs_object_handle.h" +#include "cobalt/script/mozjs-45/mozjs_property_enumerator.h" +#include "cobalt/script/mozjs-45/mozjs_user_object_holder.h" +#include "cobalt/script/mozjs-45/proxy_handler.h" +#include "cobalt/script/mozjs-45/type_traits.h" +#include "cobalt/script/mozjs-45/wrapper_factory.h" +#include "cobalt/script/mozjs-45/wrapper_private.h" +#include "cobalt/script/property_enumerator.h" +#include "cobalt/script/sequence.h" +#include "third_party/mozjs-45/js/src/jsapi.h" +#include "third_party/mozjs-45/js/src/jsfriendapi.h" + +namespace { +using cobalt::bindings::testing::AnonymousNamedIndexedGetterInterface; +using cobalt::bindings::testing::MozjsAnonymousNamedIndexedGetterInterface; +using cobalt::script::CallbackInterfaceTraits; +using cobalt::script::GlobalEnvironment; +using cobalt::script::OpaqueHandle; +using cobalt::script::OpaqueHandleHolder; +using cobalt::script::ScriptValue; +using cobalt::script::Wrappable; + +using cobalt::script::CallbackFunction; +using cobalt::script::CallbackInterfaceTraits; +using cobalt::script::ExceptionState; +using cobalt::script::Wrappable; +using cobalt::script::mozjs::FromJSValue; +using cobalt::script::mozjs::InterfaceData; +using cobalt::script::mozjs::MozjsCallbackFunction; +using cobalt::script::mozjs::MozjsExceptionState; +using cobalt::script::mozjs::MozjsGlobalEnvironment; +using cobalt::script::mozjs::MozjsPropertyEnumerator; +using cobalt::script::mozjs::MozjsUserObjectHolder; +using cobalt::script::mozjs::ProxyHandler; +using cobalt::script::mozjs::ToJSValue; +using cobalt::script::mozjs::TypeTraits; +using cobalt::script::mozjs::WrapperFactory; +using cobalt::script::mozjs::WrapperPrivate; +using cobalt::script::mozjs::kConversionFlagNullable; +using cobalt::script::mozjs::kConversionFlagRestricted; +using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString; +using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString; +using cobalt::script::mozjs::kNoConversionFlags; +} // namespace + +namespace cobalt { +namespace bindings { +namespace testing { + +namespace { + +bool IsSupportedNamedProperty(JSContext* context, JS::HandleObject object, + const std::string& property_name) { + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + AnonymousNamedIndexedGetterInterface* impl = + wrapper_private->wrappable<AnonymousNamedIndexedGetterInterface>().get(); + return impl->CanQueryNamedProperty(property_name); +} + +void EnumerateSupportedNames(JSContext* context, JS::HandleObject object, + JS::AutoIdVector* properties) { + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + AnonymousNamedIndexedGetterInterface* impl = + wrapper_private->wrappable<AnonymousNamedIndexedGetterInterface>().get(); + MozjsPropertyEnumerator enumerator(context, properties); + impl->EnumerateNamedProperties(&enumerator); +} + +bool GetNamedProperty( + JSContext* context, JS::HandleObject object, JS::HandleId id, + JS::MutableHandleValue vp) { + JS::RootedValue id_value(context); + if (!JS_IdToValue(context, id, &id_value)) { + NOTREACHED(); + return false; + } + + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + AnonymousNamedIndexedGetterInterface* impl = + wrapper_private->wrappable<AnonymousNamedIndexedGetterInterface>().get(); + std::string property_name; + FromJSValue(context, id_value, kNoConversionFlags, &exception_state, + &property_name); + if (exception_state.is_exception_set()) { + // The ID should be an integer or a string, so we shouldn't have any + // exceptions converting to string. + NOTREACHED(); + return false; + } + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->AnonymousNamedGetter(property_name), + &result_value); + } + if (!exception_state.is_exception_set()) { + vp.set(result_value); + } + return !exception_state.is_exception_set(); +} + +bool SetNamedProperty( + JSContext* context, JS::HandleObject object, JS::HandleId id, + JS::MutableHandleValue vp, JS::ObjectOpResult& object_op_result) { + JS::RootedValue id_value(context); + if (!JS_IdToValue(context, id, &id_value)) { + NOTREACHED(); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + AnonymousNamedIndexedGetterInterface* impl = + wrapper_private->wrappable<AnonymousNamedIndexedGetterInterface>().get(); + std::string property_name; + FromJSValue(context, id_value, kNoConversionFlags, &exception_state, + &property_name); + if (exception_state.is_exception_set()) { + // The ID should be an integer or a string, so we shouldn't have any + // exceptions converting to string. + NOTREACHED(); + return false; + } + TypeTraits<std::string >::ConversionType value; + FromJSValue(context, vp, kNoConversionFlags, + &exception_state, &value); + if (exception_state.is_exception_set()) { + return false; + } + + impl->AnonymousNamedSetter(property_name, value); + result_value.set(JS::UndefinedHandleValue); + + if (!exception_state.is_exception_set()) { + return object_op_result.succeed(); + } else { + return false; + } +} + +bool IsSupportedIndexProperty(JSContext* context, JS::HandleObject object, + uint32_t index) { + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + AnonymousNamedIndexedGetterInterface* impl = + wrapper_private->wrappable<AnonymousNamedIndexedGetterInterface>().get(); + return index < impl->length(); +} + +void EnumerateSupportedIndexes(JSContext* context, JS::HandleObject object, + JS::AutoIdVector* properties) { + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + AnonymousNamedIndexedGetterInterface* impl = + wrapper_private->wrappable<AnonymousNamedIndexedGetterInterface>().get(); + const uint32_t kNumIndexedProperties = impl->length(); + for (uint32_t i = 0; i < kNumIndexedProperties; ++i) { + properties->append(INT_TO_JSID(i)); + } +} + +bool GetIndexedProperty( + JSContext* context, JS::HandleObject object, JS::HandleId id, + JS::MutableHandleValue vp) { + JS::RootedValue id_value(context); + if (!JS_IdToValue(context, id, &id_value)) { + NOTREACHED(); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + AnonymousNamedIndexedGetterInterface* impl = + wrapper_private->wrappable<AnonymousNamedIndexedGetterInterface>().get(); + uint32_t index; + FromJSValue(context, id_value, kNoConversionFlags, &exception_state, &index); + if (exception_state.is_exception_set()) { + // The ID should be an integer or a string, so we shouldn't have any + // exceptions converting to string. + NOTREACHED(); + return false; + } + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->AnonymousIndexedGetter(index), + &result_value); + } + if (!exception_state.is_exception_set()) { + vp.set(result_value); + } + return !exception_state.is_exception_set(); +} + +bool SetIndexedProperty( + JSContext* context, JS::HandleObject object, JS::HandleId id, + JS::MutableHandleValue vp, JS::ObjectOpResult& object_op_result) { + JS::RootedValue id_value(context); + if (!JS_IdToValue(context, id, &id_value)) { + NOTREACHED(); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + AnonymousNamedIndexedGetterInterface* impl = + wrapper_private->wrappable<AnonymousNamedIndexedGetterInterface>().get(); + uint32_t index; + FromJSValue(context, id_value, kNoConversionFlags, &exception_state, &index); + if (exception_state.is_exception_set()) { + // The ID should be an integer or a string, so we shouldn't have any + // exceptions converting to string. + NOTREACHED(); + return false; + } + TypeTraits<uint32_t >::ConversionType value; + FromJSValue(context, vp, kNoConversionFlags, + &exception_state, &value); + if (exception_state.is_exception_set()) { + return false; + } + + impl->AnonymousIndexedSetter(index, value); + result_value.set(JS::UndefinedHandleValue); + if (!exception_state.is_exception_set()) { + return object_op_result.succeed(); + } else { + return false; + } +} + +class MozjsAnonymousNamedIndexedGetterInterfaceHandler : public ProxyHandler { + public: + MozjsAnonymousNamedIndexedGetterInterfaceHandler() + : ProxyHandler(indexed_property_hooks, named_property_hooks) {} + + private: + static NamedPropertyHooks named_property_hooks; + static IndexedPropertyHooks indexed_property_hooks; +}; + +ProxyHandler::NamedPropertyHooks +MozjsAnonymousNamedIndexedGetterInterfaceHandler::named_property_hooks = { + IsSupportedNamedProperty, + EnumerateSupportedNames, + GetNamedProperty, + SetNamedProperty, + NULL, +}; +ProxyHandler::IndexedPropertyHooks +MozjsAnonymousNamedIndexedGetterInterfaceHandler::indexed_property_hooks = { + IsSupportedIndexProperty, + EnumerateSupportedIndexes, + GetIndexedProperty, + SetIndexedProperty, + NULL, +}; + +static base::LazyInstance<MozjsAnonymousNamedIndexedGetterInterfaceHandler> + proxy_handler; + +bool HasInstance(JSContext *context, JS::HandleObject type, + JS::MutableHandleValue vp, bool *success) { + JS::RootedObject global_object( + context, JS_GetGlobalForObject(context, type)); + DCHECK(global_object); + + JS::RootedObject prototype( + context, MozjsAnonymousNamedIndexedGetterInterface::GetPrototype(context, global_object)); + + // |IsDelegate| walks the prototype chain of an object returning true if + // .prototype is found. + bool is_delegate; + if (!IsDelegate(context, prototype, vp, &is_delegate)) { + *success = false; + return false; + } + + *success = is_delegate; + return true; +} + +const JSClass instance_class_definition = { + "AnonymousNamedIndexedGetterInterface", + 0 | JSCLASS_HAS_PRIVATE, + NULL, // addProperty + NULL, // delProperty + NULL, // getProperty + NULL, // setProperty + NULL, // enumerate + NULL, // resolve + NULL, // mayResolve + &WrapperPrivate::Finalizer, // finalize + NULL, // call + NULL, // hasInstance + NULL, // construct + &WrapperPrivate::Trace, // trace +}; + +const JSClass prototype_class_definition = { + "AnonymousNamedIndexedGetterInterfacePrototype", +}; + +const JSClass interface_object_class_definition = { + "AnonymousNamedIndexedGetterInterfaceConstructor", + 0, + NULL, // addProperty + NULL, // delProperty + NULL, // getProperty + NULL, // setProperty + NULL, // enumerate + NULL, // resolve + NULL, // mayResolve + NULL, // finalize + NULL, // call + &HasInstance, + NULL, +}; + +bool get_length( + JSContext* context, unsigned argc, JS::Value* vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + const JSClass* proto_class = + MozjsAnonymousNamedIndexedGetterInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<AnonymousNamedIndexedGetterInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + AnonymousNamedIndexedGetterInterface* impl = + wrapper_private->wrappable<AnonymousNamedIndexedGetterInterface>().get(); + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->length(), + &result_value); + } + if (!exception_state.is_exception_set()) { + args.rval().set(result_value); + } + return !exception_state.is_exception_set(); +} + + + + +const JSPropertySpec prototype_properties[] = { + { // Readonly attribute + "length", + JSPROP_SHARED | JSPROP_ENUMERATE, + { { &get_length, NULL } }, + JSNATIVE_WRAPPER(NULL), + }, + JS_PS_END +}; + +const JSFunctionSpec prototype_functions[] = { + JS_FS_END +}; + +const JSPropertySpec interface_object_properties[] = { + JS_PS_END +}; + +const JSFunctionSpec interface_object_functions[] = { + JS_FS_END +}; + +const JSPropertySpec own_properties[] = { + JS_PS_END +}; + +void InitializePrototypeAndInterfaceObject( + InterfaceData* interface_data, JSContext* context, + JS::HandleObject global_object) { + DCHECK(!interface_data->prototype); + DCHECK(!interface_data->interface_object); + DCHECK(JS_IsGlobalObject(global_object)); + + JS::RootedObject parent_prototype( + context, JS_GetObjectPrototype(context, global_object)); + DCHECK(parent_prototype); + + interface_data->prototype = JS_NewObjectWithGivenProto( + context, &prototype_class_definition, parent_prototype + ); + + JS::RootedObject rooted_prototype(context, interface_data->prototype); + bool success = JS_DefineProperties( + context, + rooted_prototype, + prototype_properties); + + DCHECK(success); + success = JS_DefineFunctions( + context, rooted_prototype, prototype_functions); + DCHECK(success); + + JS::RootedObject function_prototype( + context, JS_GetFunctionPrototype(context, global_object)); + DCHECK(function_prototype); + // Create the Interface object. + interface_data->interface_object = JS_NewObjectWithGivenProto( + context, &interface_object_class_definition, + function_prototype); + + // Add the InterfaceObject.name property. + JS::RootedObject rooted_interface_object( + context, interface_data->interface_object); + JS::RootedValue name_value(context); + const char name[] = + "AnonymousNamedIndexedGetterInterface"; + name_value.setString(JS_NewStringCopyZ(context, name)); + success = JS_DefineProperty( + context, rooted_interface_object, "name", name_value, JSPROP_READONLY, + NULL, NULL); + DCHECK(success); + + // Define interface object properties (including constants). + success = JS_DefineProperties(context, rooted_interface_object, + interface_object_properties); + DCHECK(success); + // Define interface object functions (static). + success = JS_DefineFunctions(context, rooted_interface_object, + interface_object_functions); + DCHECK(success); + + // Set the Prototype.constructor and Constructor.prototype properties. + DCHECK(interface_data->interface_object); + DCHECK(interface_data->prototype); + success = JS_LinkConstructorAndPrototype( + context, + rooted_interface_object, + rooted_prototype); + DCHECK(success); +} + +InterfaceData* GetInterfaceData(JSContext* context) { + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + // Use the address of the properties definition for this interface as a + // unique key for looking up the InterfaceData for this interface. + intptr_t key = reinterpret_cast<intptr_t>(&own_properties); + InterfaceData* interface_data = global_environment->GetInterfaceData(key); + if (!interface_data) { + interface_data = new InterfaceData(); + DCHECK(interface_data); + global_environment->CacheInterfaceData(key, interface_data); + DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key)); + } + return interface_data; +} + +} // namespace + +// static +JSObject* MozjsAnonymousNamedIndexedGetterInterface::CreateProxy( + JSContext* context, const scoped_refptr<Wrappable>& wrappable) { + DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); + JS::RootedObject global_object( + context, + MozjsGlobalEnvironment::GetFromContext(context)->global_object()); + DCHECK(global_object); + + InterfaceData* interface_data = GetInterfaceData(context); + JS::RootedObject prototype(context, GetPrototype(context, global_object)); + DCHECK(prototype); + JS::RootedObject new_object( + context, + JS_NewObjectWithGivenProto( + context, &instance_class_definition, prototype)); + DCHECK(new_object); + JS::RootedObject proxy(context, + ProxyHandler::NewProxy( + context, proxy_handler.Pointer(), new_object, prototype)); + WrapperPrivate::AddPrivateData(context, proxy, wrappable); + return proxy; +} + +// static +const JSClass* MozjsAnonymousNamedIndexedGetterInterface::PrototypeClass( + JSContext* context) { + DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); + JS::RootedObject global_object( + context, + MozjsGlobalEnvironment::GetFromContext(context)->global_object()); + DCHECK(global_object); + + JS::RootedObject prototype(context, GetPrototype(context, global_object)); + const JSClass* proto_class = JS_GetClass(prototype); + return proto_class; +} + +// static +JSObject* MozjsAnonymousNamedIndexedGetterInterface::GetPrototype( + JSContext* context, JS::HandleObject global_object) { + DCHECK(JS_IsGlobalObject(global_object)); + + InterfaceData* interface_data = GetInterfaceData(context); + if (!interface_data->prototype) { + // Create new prototype that has all the props and methods + InitializePrototypeAndInterfaceObject( + interface_data, context, global_object); + } + DCHECK(interface_data->prototype); + return interface_data->prototype; +} + +// static +JSObject* MozjsAnonymousNamedIndexedGetterInterface::GetInterfaceObject( + JSContext* context, JS::HandleObject global_object) { + DCHECK(JS_IsGlobalObject(global_object)); + + InterfaceData* interface_data = GetInterfaceData(context); + if (!interface_data->interface_object) { + InitializePrototypeAndInterfaceObject( + interface_data, context, global_object); + } + DCHECK(interface_data->interface_object); + return interface_data->interface_object; +} + + +namespace { +} // namespace + + +} // namespace testing +} // namespace bindings +} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_anonymous_named_indexed_getter_interface.h b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_anonymous_named_indexed_getter_interface.h new file mode 100644 index 0000000..37ff9bd --- /dev/null +++ b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_anonymous_named_indexed_getter_interface.h
@@ -0,0 +1,52 @@ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// clang-format off + +// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! +// Auto-generated from template: bindings/mozjs-45/templates/interface.h.template + +#ifndef MozjsAnonymousNamedIndexedGetterInterface_h +#define MozjsAnonymousNamedIndexedGetterInterface_h + +#include "base/hash_tables.h" +#include "base/lazy_instance.h" +#include "base/memory/ref_counted.h" +#include "base/threading/thread_checker.h" +#include "cobalt/base/polymorphic_downcast.h" +#include "cobalt/script/wrappable.h" +#include "cobalt/bindings/testing/anonymous_named_indexed_getter_interface.h" + +#include "third_party/mozjs-45/js/src/jsapi.h" + +namespace cobalt { +namespace bindings { +namespace testing { + +class MozjsAnonymousNamedIndexedGetterInterface { + public: + static JSObject* CreateProxy(JSContext* context, + const scoped_refptr<script::Wrappable>& wrappable); + static const JSClass* PrototypeClass(JSContext* context); + static JSObject* GetPrototype(JSContext* context, + JS::HandleObject global_object); + static JSObject* GetInterfaceObject(JSContext* context, + JS::HandleObject global_object); +}; + +} // namespace testing +} // namespace bindings +} // namespace cobalt + +#endif // MozjsAnonymousNamedIndexedGetterInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_arbitrary_interface.cc b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_arbitrary_interface.cc new file mode 100644 index 0000000..9883f3e --- /dev/null +++ b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_arbitrary_interface.cc
@@ -0,0 +1,521 @@ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// clang-format off + +// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! +// Auto-generated from template: bindings/mozjs-45/templates/interface.cc.template + +#include "cobalt/bindings/testing/mozjs_arbitrary_interface.h" + +#include "base/debug/trace_event.h" +#include "cobalt/base/polymorphic_downcast.h" +#include "cobalt/script/global_environment.h" +#include "cobalt/script/opaque_handle.h" +#include "cobalt/script/script_value.h" + +#include "base/lazy_instance.h" +#include "cobalt/script/exception_state.h" +#include "cobalt/script/mozjs-45/callback_function_conversion.h" +#include "cobalt/script/mozjs-45/conversion_helpers.h" +#include "cobalt/script/mozjs-45/mozjs_callback_function.h" +#include "cobalt/script/mozjs-45/mozjs_exception_state.h" +#include "cobalt/script/mozjs-45/mozjs_global_environment.h" +#include "cobalt/script/mozjs-45/mozjs_object_handle.h" +#include "cobalt/script/mozjs-45/mozjs_property_enumerator.h" +#include "cobalt/script/mozjs-45/mozjs_user_object_holder.h" +#include "cobalt/script/mozjs-45/proxy_handler.h" +#include "cobalt/script/mozjs-45/type_traits.h" +#include "cobalt/script/mozjs-45/wrapper_factory.h" +#include "cobalt/script/mozjs-45/wrapper_private.h" +#include "cobalt/script/property_enumerator.h" +#include "cobalt/script/sequence.h" +#include "third_party/mozjs-45/js/src/jsapi.h" +#include "third_party/mozjs-45/js/src/jsfriendapi.h" + +namespace { +using cobalt::bindings::testing::ArbitraryInterface; +using cobalt::bindings::testing::MozjsArbitraryInterface; +using cobalt::script::CallbackInterfaceTraits; +using cobalt::script::GlobalEnvironment; +using cobalt::script::OpaqueHandle; +using cobalt::script::OpaqueHandleHolder; +using cobalt::script::ScriptValue; +using cobalt::script::Wrappable; + +using cobalt::script::CallbackFunction; +using cobalt::script::CallbackInterfaceTraits; +using cobalt::script::ExceptionState; +using cobalt::script::Wrappable; +using cobalt::script::mozjs::FromJSValue; +using cobalt::script::mozjs::InterfaceData; +using cobalt::script::mozjs::MozjsCallbackFunction; +using cobalt::script::mozjs::MozjsExceptionState; +using cobalt::script::mozjs::MozjsGlobalEnvironment; +using cobalt::script::mozjs::MozjsPropertyEnumerator; +using cobalt::script::mozjs::MozjsUserObjectHolder; +using cobalt::script::mozjs::ProxyHandler; +using cobalt::script::mozjs::ToJSValue; +using cobalt::script::mozjs::TypeTraits; +using cobalt::script::mozjs::WrapperFactory; +using cobalt::script::mozjs::WrapperPrivate; +using cobalt::script::mozjs::kConversionFlagNullable; +using cobalt::script::mozjs::kConversionFlagRestricted; +using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString; +using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString; +using cobalt::script::mozjs::kNoConversionFlags; +} // namespace + +namespace cobalt { +namespace bindings { +namespace testing { + +namespace { + +class MozjsArbitraryInterfaceHandler : public ProxyHandler { + public: + MozjsArbitraryInterfaceHandler() + : ProxyHandler(indexed_property_hooks, named_property_hooks) {} + + private: + static NamedPropertyHooks named_property_hooks; + static IndexedPropertyHooks indexed_property_hooks; +}; + +ProxyHandler::NamedPropertyHooks +MozjsArbitraryInterfaceHandler::named_property_hooks = { + NULL, + NULL, + NULL, + NULL, + NULL, +}; +ProxyHandler::IndexedPropertyHooks +MozjsArbitraryInterfaceHandler::indexed_property_hooks = { + NULL, + NULL, + NULL, + NULL, + NULL, +}; + +static base::LazyInstance<MozjsArbitraryInterfaceHandler> + proxy_handler; + +bool Constructor(JSContext* context, unsigned int argc, JS::Value* vp); +bool HasInstance(JSContext *context, JS::HandleObject type, + JS::MutableHandleValue vp, bool *success) { + JS::RootedObject global_object( + context, JS_GetGlobalForObject(context, type)); + DCHECK(global_object); + + JS::RootedObject prototype( + context, MozjsArbitraryInterface::GetPrototype(context, global_object)); + + // |IsDelegate| walks the prototype chain of an object returning true if + // .prototype is found. + bool is_delegate; + if (!IsDelegate(context, prototype, vp, &is_delegate)) { + *success = false; + return false; + } + + *success = is_delegate; + return true; +} + +const JSClass instance_class_definition = { + "ArbitraryInterface", + 0 | JSCLASS_HAS_PRIVATE, + NULL, // addProperty + NULL, // delProperty + NULL, // getProperty + NULL, // setProperty + NULL, // enumerate + NULL, // resolve + NULL, // mayResolve + &WrapperPrivate::Finalizer, // finalize + NULL, // call + NULL, // hasInstance + NULL, // construct + &WrapperPrivate::Trace, // trace +}; + +const JSClass prototype_class_definition = { + "ArbitraryInterfacePrototype", +}; + +const JSClass interface_object_class_definition = { + "ArbitraryInterfaceConstructor", + 0, + NULL, // addProperty + NULL, // delProperty + NULL, // getProperty + NULL, // setProperty + NULL, // enumerate + NULL, // resolve + NULL, // mayResolve + NULL, // finalize + NULL, // call + &HasInstance, + Constructor, +}; + +bool get_arbitraryProperty( + JSContext* context, unsigned argc, JS::Value* vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + const JSClass* proto_class = + MozjsArbitraryInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<ArbitraryInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + ArbitraryInterface* impl = + wrapper_private->wrappable<ArbitraryInterface>().get(); + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->arbitrary_property(), + &result_value); + } + if (!exception_state.is_exception_set()) { + args.rval().set(result_value); + } + return !exception_state.is_exception_set(); +} + +bool set_arbitraryProperty( + JSContext* context, unsigned argc, JS::Value* vp) { + + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + + const JSClass* proto_class = + MozjsArbitraryInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<ArbitraryInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + ArbitraryInterface* impl = + wrapper_private->wrappable<ArbitraryInterface>().get(); + TypeTraits<std::string >::ConversionType value; + if (args.length() != 1) { + NOTREACHED(); + return false; + } + FromJSValue(context, args[0], kNoConversionFlags, &exception_state, + &value); + if (exception_state.is_exception_set()) { + return false; + } + + impl->set_arbitrary_property(value); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + +bool fcn_arbitraryFunction( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + const JSClass* proto_class = + MozjsArbitraryInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<ArbitraryInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + ArbitraryInterface* impl = + wrapper_private->wrappable<ArbitraryInterface>().get(); + + impl->ArbitraryFunction(); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + + + +const JSPropertySpec prototype_properties[] = { + { // Read/Write property + "arbitraryProperty", + JSPROP_SHARED | JSPROP_ENUMERATE, + { { &get_arbitraryProperty, NULL } }, + { { &set_arbitraryProperty, NULL } }, + }, + JS_PS_END +}; + +const JSFunctionSpec prototype_functions[] = { + JS_FNSPEC( + "arbitraryFunction", fcn_arbitraryFunction, NULL, + 0, JSPROP_ENUMERATE, NULL), + JS_FS_END +}; + +const JSPropertySpec interface_object_properties[] = { + JS_PS_END +}; + +const JSFunctionSpec interface_object_functions[] = { + JS_FS_END +}; + +const JSPropertySpec own_properties[] = { + JS_PS_END +}; + +void InitializePrototypeAndInterfaceObject( + InterfaceData* interface_data, JSContext* context, + JS::HandleObject global_object) { + DCHECK(!interface_data->prototype); + DCHECK(!interface_data->interface_object); + DCHECK(JS_IsGlobalObject(global_object)); + + JS::RootedObject parent_prototype( + context, JS_GetObjectPrototype(context, global_object)); + DCHECK(parent_prototype); + + interface_data->prototype = JS_NewObjectWithGivenProto( + context, &prototype_class_definition, parent_prototype + ); + + JS::RootedObject rooted_prototype(context, interface_data->prototype); + bool success = JS_DefineProperties( + context, + rooted_prototype, + prototype_properties); + + DCHECK(success); + success = JS_DefineFunctions( + context, rooted_prototype, prototype_functions); + DCHECK(success); + + JS::RootedObject function_prototype( + context, JS_GetFunctionPrototype(context, global_object)); + DCHECK(function_prototype); + // Create the Interface object. + interface_data->interface_object = JS_NewObjectWithGivenProto( + context, &interface_object_class_definition, + function_prototype); + + // Add the InterfaceObject.name property. + JS::RootedObject rooted_interface_object( + context, interface_data->interface_object); + JS::RootedValue name_value(context); + const char name[] = + "ArbitraryInterface"; + name_value.setString(JS_NewStringCopyZ(context, name)); + success = JS_DefineProperty( + context, rooted_interface_object, "name", name_value, JSPROP_READONLY, + NULL, NULL); + DCHECK(success); + + // Add the InterfaceObject.length property. It is set to the length of the + // shortest argument list of all overload constructors. + JS::RootedValue length_value(context); + length_value.setInt32(0); + success = JS_DefineProperty( + context, rooted_interface_object, "length", length_value, + JSPROP_READONLY, NULL, NULL); + DCHECK(success); + + // Define interface object properties (including constants). + success = JS_DefineProperties(context, rooted_interface_object, + interface_object_properties); + DCHECK(success); + // Define interface object functions (static). + success = JS_DefineFunctions(context, rooted_interface_object, + interface_object_functions); + DCHECK(success); + + // Set the Prototype.constructor and Constructor.prototype properties. + DCHECK(interface_data->interface_object); + DCHECK(interface_data->prototype); + success = JS_LinkConstructorAndPrototype( + context, + rooted_interface_object, + rooted_prototype); + DCHECK(success); +} + +InterfaceData* GetInterfaceData(JSContext* context) { + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + // Use the address of the properties definition for this interface as a + // unique key for looking up the InterfaceData for this interface. + intptr_t key = reinterpret_cast<intptr_t>(&own_properties); + InterfaceData* interface_data = global_environment->GetInterfaceData(key); + if (!interface_data) { + interface_data = new InterfaceData(); + DCHECK(interface_data); + global_environment->CacheInterfaceData(key, interface_data); + DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key)); + } + return interface_data; +} + +} // namespace + +// static +JSObject* MozjsArbitraryInterface::CreateProxy( + JSContext* context, const scoped_refptr<Wrappable>& wrappable) { + DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); + JS::RootedObject global_object( + context, + MozjsGlobalEnvironment::GetFromContext(context)->global_object()); + DCHECK(global_object); + + InterfaceData* interface_data = GetInterfaceData(context); + JS::RootedObject prototype(context, GetPrototype(context, global_object)); + DCHECK(prototype); + JS::RootedObject new_object( + context, + JS_NewObjectWithGivenProto( + context, &instance_class_definition, prototype)); + DCHECK(new_object); + JS::RootedObject proxy(context, + ProxyHandler::NewProxy( + context, proxy_handler.Pointer(), new_object, prototype)); + WrapperPrivate::AddPrivateData(context, proxy, wrappable); + return proxy; +} + +// static +const JSClass* MozjsArbitraryInterface::PrototypeClass( + JSContext* context) { + DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); + JS::RootedObject global_object( + context, + MozjsGlobalEnvironment::GetFromContext(context)->global_object()); + DCHECK(global_object); + + JS::RootedObject prototype(context, GetPrototype(context, global_object)); + const JSClass* proto_class = JS_GetClass(prototype); + return proto_class; +} + +// static +JSObject* MozjsArbitraryInterface::GetPrototype( + JSContext* context, JS::HandleObject global_object) { + DCHECK(JS_IsGlobalObject(global_object)); + + InterfaceData* interface_data = GetInterfaceData(context); + if (!interface_data->prototype) { + // Create new prototype that has all the props and methods + InitializePrototypeAndInterfaceObject( + interface_data, context, global_object); + } + DCHECK(interface_data->prototype); + return interface_data->prototype; +} + +// static +JSObject* MozjsArbitraryInterface::GetInterfaceObject( + JSContext* context, JS::HandleObject global_object) { + DCHECK(JS_IsGlobalObject(global_object)); + + InterfaceData* interface_data = GetInterfaceData(context); + if (!interface_data->interface_object) { + InitializePrototypeAndInterfaceObject( + interface_data, context, global_object); + } + DCHECK(interface_data->interface_object); + return interface_data->interface_object; +} + + +namespace { +bool Constructor(JSContext* context, unsigned int argc, JS::Value* vp) { + MozjsExceptionState exception_state(context); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + + scoped_refptr<ArbitraryInterface> new_object = + new ArbitraryInterface(); + JS::RootedValue result_value(context); + ToJSValue(context, new_object, &result_value); + DCHECK(result_value.isObject()); + args.rval().setObject(result_value.toObject()); + return true; +} +} // namespace + + +} // namespace testing +} // namespace bindings +} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_arbitrary_interface.h b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_arbitrary_interface.h new file mode 100644 index 0000000..f6422d9 --- /dev/null +++ b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_arbitrary_interface.h
@@ -0,0 +1,52 @@ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// clang-format off + +// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! +// Auto-generated from template: bindings/mozjs-45/templates/interface.h.template + +#ifndef MozjsArbitraryInterface_h +#define MozjsArbitraryInterface_h + +#include "base/hash_tables.h" +#include "base/lazy_instance.h" +#include "base/memory/ref_counted.h" +#include "base/threading/thread_checker.h" +#include "cobalt/base/polymorphic_downcast.h" +#include "cobalt/script/wrappable.h" +#include "cobalt/bindings/testing/arbitrary_interface.h" + +#include "third_party/mozjs-45/js/src/jsapi.h" + +namespace cobalt { +namespace bindings { +namespace testing { + +class MozjsArbitraryInterface { + public: + static JSObject* CreateProxy(JSContext* context, + const scoped_refptr<script::Wrappable>& wrappable); + static const JSClass* PrototypeClass(JSContext* context); + static JSObject* GetPrototype(JSContext* context, + JS::HandleObject global_object); + static JSObject* GetInterfaceObject(JSContext* context, + JS::HandleObject global_object); +}; + +} // namespace testing +} // namespace bindings +} // namespace cobalt + +#endif // MozjsArbitraryInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_base_interface.cc b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_base_interface.cc new file mode 100644 index 0000000..b221579 --- /dev/null +++ b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_base_interface.cc
@@ -0,0 +1,474 @@ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// clang-format off + +// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! +// Auto-generated from template: bindings/mozjs-45/templates/interface.cc.template + +#include "cobalt/bindings/testing/mozjs_base_interface.h" + +#include "base/debug/trace_event.h" +#include "cobalt/base/polymorphic_downcast.h" +#include "cobalt/script/global_environment.h" +#include "cobalt/script/opaque_handle.h" +#include "cobalt/script/script_value.h" + +#include "base/lazy_instance.h" +#include "cobalt/script/exception_state.h" +#include "cobalt/script/mozjs-45/callback_function_conversion.h" +#include "cobalt/script/mozjs-45/conversion_helpers.h" +#include "cobalt/script/mozjs-45/mozjs_callback_function.h" +#include "cobalt/script/mozjs-45/mozjs_exception_state.h" +#include "cobalt/script/mozjs-45/mozjs_global_environment.h" +#include "cobalt/script/mozjs-45/mozjs_object_handle.h" +#include "cobalt/script/mozjs-45/mozjs_property_enumerator.h" +#include "cobalt/script/mozjs-45/mozjs_user_object_holder.h" +#include "cobalt/script/mozjs-45/proxy_handler.h" +#include "cobalt/script/mozjs-45/type_traits.h" +#include "cobalt/script/mozjs-45/wrapper_factory.h" +#include "cobalt/script/mozjs-45/wrapper_private.h" +#include "cobalt/script/property_enumerator.h" +#include "cobalt/script/sequence.h" +#include "third_party/mozjs-45/js/src/jsapi.h" +#include "third_party/mozjs-45/js/src/jsfriendapi.h" + +namespace { +using cobalt::bindings::testing::BaseInterface; +using cobalt::bindings::testing::MozjsBaseInterface; +using cobalt::script::CallbackInterfaceTraits; +using cobalt::script::GlobalEnvironment; +using cobalt::script::OpaqueHandle; +using cobalt::script::OpaqueHandleHolder; +using cobalt::script::ScriptValue; +using cobalt::script::Wrappable; + +using cobalt::script::CallbackFunction; +using cobalt::script::CallbackInterfaceTraits; +using cobalt::script::ExceptionState; +using cobalt::script::Wrappable; +using cobalt::script::mozjs::FromJSValue; +using cobalt::script::mozjs::InterfaceData; +using cobalt::script::mozjs::MozjsCallbackFunction; +using cobalt::script::mozjs::MozjsExceptionState; +using cobalt::script::mozjs::MozjsGlobalEnvironment; +using cobalt::script::mozjs::MozjsPropertyEnumerator; +using cobalt::script::mozjs::MozjsUserObjectHolder; +using cobalt::script::mozjs::ProxyHandler; +using cobalt::script::mozjs::ToJSValue; +using cobalt::script::mozjs::TypeTraits; +using cobalt::script::mozjs::WrapperFactory; +using cobalt::script::mozjs::WrapperPrivate; +using cobalt::script::mozjs::kConversionFlagNullable; +using cobalt::script::mozjs::kConversionFlagRestricted; +using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString; +using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString; +using cobalt::script::mozjs::kNoConversionFlags; +} // namespace + +namespace cobalt { +namespace bindings { +namespace testing { + +namespace { + +class MozjsBaseInterfaceHandler : public ProxyHandler { + public: + MozjsBaseInterfaceHandler() + : ProxyHandler(indexed_property_hooks, named_property_hooks) {} + + private: + static NamedPropertyHooks named_property_hooks; + static IndexedPropertyHooks indexed_property_hooks; +}; + +ProxyHandler::NamedPropertyHooks +MozjsBaseInterfaceHandler::named_property_hooks = { + NULL, + NULL, + NULL, + NULL, + NULL, +}; +ProxyHandler::IndexedPropertyHooks +MozjsBaseInterfaceHandler::indexed_property_hooks = { + NULL, + NULL, + NULL, + NULL, + NULL, +}; + +static base::LazyInstance<MozjsBaseInterfaceHandler> + proxy_handler; + +bool Constructor(JSContext* context, unsigned int argc, JS::Value* vp); +bool HasInstance(JSContext *context, JS::HandleObject type, + JS::MutableHandleValue vp, bool *success) { + JS::RootedObject global_object( + context, JS_GetGlobalForObject(context, type)); + DCHECK(global_object); + + JS::RootedObject prototype( + context, MozjsBaseInterface::GetPrototype(context, global_object)); + + // |IsDelegate| walks the prototype chain of an object returning true if + // .prototype is found. + bool is_delegate; + if (!IsDelegate(context, prototype, vp, &is_delegate)) { + *success = false; + return false; + } + + *success = is_delegate; + return true; +} + +const JSClass instance_class_definition = { + "BaseInterface", + 0 | JSCLASS_HAS_PRIVATE, + NULL, // addProperty + NULL, // delProperty + NULL, // getProperty + NULL, // setProperty + NULL, // enumerate + NULL, // resolve + NULL, // mayResolve + &WrapperPrivate::Finalizer, // finalize + NULL, // call + NULL, // hasInstance + NULL, // construct + &WrapperPrivate::Trace, // trace +}; + +const JSClass prototype_class_definition = { + "BaseInterfacePrototype", +}; + +const JSClass interface_object_class_definition = { + "BaseInterfaceConstructor", + 0, + NULL, // addProperty + NULL, // delProperty + NULL, // getProperty + NULL, // setProperty + NULL, // enumerate + NULL, // resolve + NULL, // mayResolve + NULL, // finalize + NULL, // call + &HasInstance, + Constructor, +}; + +bool get_baseAttribute( + JSContext* context, unsigned argc, JS::Value* vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + const JSClass* proto_class = + MozjsBaseInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<BaseInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + BaseInterface* impl = + wrapper_private->wrappable<BaseInterface>().get(); + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->base_attribute(), + &result_value); + } + if (!exception_state.is_exception_set()) { + args.rval().set(result_value); + } + return !exception_state.is_exception_set(); +} + + +bool fcn_baseOperation( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + const JSClass* proto_class = + MozjsBaseInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<BaseInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + BaseInterface* impl = + wrapper_private->wrappable<BaseInterface>().get(); + + impl->BaseOperation(); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + + + +const JSPropertySpec prototype_properties[] = { + { // Readonly attribute + "baseAttribute", + JSPROP_SHARED | JSPROP_ENUMERATE, + { { &get_baseAttribute, NULL } }, + JSNATIVE_WRAPPER(NULL), + }, + JS_PS_END +}; + +const JSFunctionSpec prototype_functions[] = { + JS_FNSPEC( + "baseOperation", fcn_baseOperation, NULL, + 0, JSPROP_ENUMERATE, NULL), + JS_FS_END +}; + +const JSPropertySpec interface_object_properties[] = { + JS_PS_END +}; + +const JSFunctionSpec interface_object_functions[] = { + JS_FS_END +}; + +const JSPropertySpec own_properties[] = { + JS_PS_END +}; + +void InitializePrototypeAndInterfaceObject( + InterfaceData* interface_data, JSContext* context, + JS::HandleObject global_object) { + DCHECK(!interface_data->prototype); + DCHECK(!interface_data->interface_object); + DCHECK(JS_IsGlobalObject(global_object)); + + JS::RootedObject parent_prototype( + context, JS_GetObjectPrototype(context, global_object)); + DCHECK(parent_prototype); + + interface_data->prototype = JS_NewObjectWithGivenProto( + context, &prototype_class_definition, parent_prototype + ); + + JS::RootedObject rooted_prototype(context, interface_data->prototype); + bool success = JS_DefineProperties( + context, + rooted_prototype, + prototype_properties); + + DCHECK(success); + success = JS_DefineFunctions( + context, rooted_prototype, prototype_functions); + DCHECK(success); + + JS::RootedObject function_prototype( + context, JS_GetFunctionPrototype(context, global_object)); + DCHECK(function_prototype); + // Create the Interface object. + interface_data->interface_object = JS_NewObjectWithGivenProto( + context, &interface_object_class_definition, + function_prototype); + + // Add the InterfaceObject.name property. + JS::RootedObject rooted_interface_object( + context, interface_data->interface_object); + JS::RootedValue name_value(context); + const char name[] = + "BaseInterface"; + name_value.setString(JS_NewStringCopyZ(context, name)); + success = JS_DefineProperty( + context, rooted_interface_object, "name", name_value, JSPROP_READONLY, + NULL, NULL); + DCHECK(success); + + // Add the InterfaceObject.length property. It is set to the length of the + // shortest argument list of all overload constructors. + JS::RootedValue length_value(context); + length_value.setInt32(0); + success = JS_DefineProperty( + context, rooted_interface_object, "length", length_value, + JSPROP_READONLY, NULL, NULL); + DCHECK(success); + + // Define interface object properties (including constants). + success = JS_DefineProperties(context, rooted_interface_object, + interface_object_properties); + DCHECK(success); + // Define interface object functions (static). + success = JS_DefineFunctions(context, rooted_interface_object, + interface_object_functions); + DCHECK(success); + + // Set the Prototype.constructor and Constructor.prototype properties. + DCHECK(interface_data->interface_object); + DCHECK(interface_data->prototype); + success = JS_LinkConstructorAndPrototype( + context, + rooted_interface_object, + rooted_prototype); + DCHECK(success); +} + +InterfaceData* GetInterfaceData(JSContext* context) { + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + // Use the address of the properties definition for this interface as a + // unique key for looking up the InterfaceData for this interface. + intptr_t key = reinterpret_cast<intptr_t>(&own_properties); + InterfaceData* interface_data = global_environment->GetInterfaceData(key); + if (!interface_data) { + interface_data = new InterfaceData(); + DCHECK(interface_data); + global_environment->CacheInterfaceData(key, interface_data); + DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key)); + } + return interface_data; +} + +} // namespace + +// static +JSObject* MozjsBaseInterface::CreateProxy( + JSContext* context, const scoped_refptr<Wrappable>& wrappable) { + DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); + JS::RootedObject global_object( + context, + MozjsGlobalEnvironment::GetFromContext(context)->global_object()); + DCHECK(global_object); + + InterfaceData* interface_data = GetInterfaceData(context); + JS::RootedObject prototype(context, GetPrototype(context, global_object)); + DCHECK(prototype); + JS::RootedObject new_object( + context, + JS_NewObjectWithGivenProto( + context, &instance_class_definition, prototype)); + DCHECK(new_object); + JS::RootedObject proxy(context, + ProxyHandler::NewProxy( + context, proxy_handler.Pointer(), new_object, prototype)); + WrapperPrivate::AddPrivateData(context, proxy, wrappable); + return proxy; +} + +// static +const JSClass* MozjsBaseInterface::PrototypeClass( + JSContext* context) { + DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); + JS::RootedObject global_object( + context, + MozjsGlobalEnvironment::GetFromContext(context)->global_object()); + DCHECK(global_object); + + JS::RootedObject prototype(context, GetPrototype(context, global_object)); + const JSClass* proto_class = JS_GetClass(prototype); + return proto_class; +} + +// static +JSObject* MozjsBaseInterface::GetPrototype( + JSContext* context, JS::HandleObject global_object) { + DCHECK(JS_IsGlobalObject(global_object)); + + InterfaceData* interface_data = GetInterfaceData(context); + if (!interface_data->prototype) { + // Create new prototype that has all the props and methods + InitializePrototypeAndInterfaceObject( + interface_data, context, global_object); + } + DCHECK(interface_data->prototype); + return interface_data->prototype; +} + +// static +JSObject* MozjsBaseInterface::GetInterfaceObject( + JSContext* context, JS::HandleObject global_object) { + DCHECK(JS_IsGlobalObject(global_object)); + + InterfaceData* interface_data = GetInterfaceData(context); + if (!interface_data->interface_object) { + InitializePrototypeAndInterfaceObject( + interface_data, context, global_object); + } + DCHECK(interface_data->interface_object); + return interface_data->interface_object; +} + + +namespace { +bool Constructor(JSContext* context, unsigned int argc, JS::Value* vp) { + MozjsExceptionState exception_state(context); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + + scoped_refptr<BaseInterface> new_object = + new BaseInterface(); + JS::RootedValue result_value(context); + ToJSValue(context, new_object, &result_value); + DCHECK(result_value.isObject()); + args.rval().setObject(result_value.toObject()); + return true; +} +} // namespace + + +} // namespace testing +} // namespace bindings +} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_base_interface.h b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_base_interface.h new file mode 100644 index 0000000..de4df28 --- /dev/null +++ b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_base_interface.h
@@ -0,0 +1,52 @@ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// clang-format off + +// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! +// Auto-generated from template: bindings/mozjs-45/templates/interface.h.template + +#ifndef MozjsBaseInterface_h +#define MozjsBaseInterface_h + +#include "base/hash_tables.h" +#include "base/lazy_instance.h" +#include "base/memory/ref_counted.h" +#include "base/threading/thread_checker.h" +#include "cobalt/base/polymorphic_downcast.h" +#include "cobalt/script/wrappable.h" +#include "cobalt/bindings/testing/base_interface.h" + +#include "third_party/mozjs-45/js/src/jsapi.h" + +namespace cobalt { +namespace bindings { +namespace testing { + +class MozjsBaseInterface { + public: + static JSObject* CreateProxy(JSContext* context, + const scoped_refptr<script::Wrappable>& wrappable); + static const JSClass* PrototypeClass(JSContext* context); + static JSObject* GetPrototype(JSContext* context, + JS::HandleObject global_object); + static JSObject* GetInterfaceObject(JSContext* context, + JS::HandleObject global_object); +}; + +} // namespace testing +} // namespace bindings +} // namespace cobalt + +#endif // MozjsBaseInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_boolean_type_test_interface.cc b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_boolean_type_test_interface.cc new file mode 100644 index 0000000..b3ae25f --- /dev/null +++ b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_boolean_type_test_interface.cc
@@ -0,0 +1,573 @@ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// clang-format off + +// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! +// Auto-generated from template: bindings/mozjs-45/templates/interface.cc.template + +#include "cobalt/bindings/testing/mozjs_boolean_type_test_interface.h" + +#include "base/debug/trace_event.h" +#include "cobalt/base/polymorphic_downcast.h" +#include "cobalt/script/global_environment.h" +#include "cobalt/script/opaque_handle.h" +#include "cobalt/script/script_value.h" + +#include "base/lazy_instance.h" +#include "cobalt/script/exception_state.h" +#include "cobalt/script/mozjs-45/callback_function_conversion.h" +#include "cobalt/script/mozjs-45/conversion_helpers.h" +#include "cobalt/script/mozjs-45/mozjs_callback_function.h" +#include "cobalt/script/mozjs-45/mozjs_exception_state.h" +#include "cobalt/script/mozjs-45/mozjs_global_environment.h" +#include "cobalt/script/mozjs-45/mozjs_object_handle.h" +#include "cobalt/script/mozjs-45/mozjs_property_enumerator.h" +#include "cobalt/script/mozjs-45/mozjs_user_object_holder.h" +#include "cobalt/script/mozjs-45/proxy_handler.h" +#include "cobalt/script/mozjs-45/type_traits.h" +#include "cobalt/script/mozjs-45/wrapper_factory.h" +#include "cobalt/script/mozjs-45/wrapper_private.h" +#include "cobalt/script/property_enumerator.h" +#include "cobalt/script/sequence.h" +#include "third_party/mozjs-45/js/src/jsapi.h" +#include "third_party/mozjs-45/js/src/jsfriendapi.h" + +namespace { +using cobalt::bindings::testing::BooleanTypeTestInterface; +using cobalt::bindings::testing::MozjsBooleanTypeTestInterface; +using cobalt::script::CallbackInterfaceTraits; +using cobalt::script::GlobalEnvironment; +using cobalt::script::OpaqueHandle; +using cobalt::script::OpaqueHandleHolder; +using cobalt::script::ScriptValue; +using cobalt::script::Wrappable; + +using cobalt::script::CallbackFunction; +using cobalt::script::CallbackInterfaceTraits; +using cobalt::script::ExceptionState; +using cobalt::script::Wrappable; +using cobalt::script::mozjs::FromJSValue; +using cobalt::script::mozjs::InterfaceData; +using cobalt::script::mozjs::MozjsCallbackFunction; +using cobalt::script::mozjs::MozjsExceptionState; +using cobalt::script::mozjs::MozjsGlobalEnvironment; +using cobalt::script::mozjs::MozjsPropertyEnumerator; +using cobalt::script::mozjs::MozjsUserObjectHolder; +using cobalt::script::mozjs::ProxyHandler; +using cobalt::script::mozjs::ToJSValue; +using cobalt::script::mozjs::TypeTraits; +using cobalt::script::mozjs::WrapperFactory; +using cobalt::script::mozjs::WrapperPrivate; +using cobalt::script::mozjs::kConversionFlagNullable; +using cobalt::script::mozjs::kConversionFlagRestricted; +using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString; +using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString; +using cobalt::script::mozjs::kNoConversionFlags; +} // namespace + +namespace cobalt { +namespace bindings { +namespace testing { + +namespace { + +class MozjsBooleanTypeTestInterfaceHandler : public ProxyHandler { + public: + MozjsBooleanTypeTestInterfaceHandler() + : ProxyHandler(indexed_property_hooks, named_property_hooks) {} + + private: + static NamedPropertyHooks named_property_hooks; + static IndexedPropertyHooks indexed_property_hooks; +}; + +ProxyHandler::NamedPropertyHooks +MozjsBooleanTypeTestInterfaceHandler::named_property_hooks = { + NULL, + NULL, + NULL, + NULL, + NULL, +}; +ProxyHandler::IndexedPropertyHooks +MozjsBooleanTypeTestInterfaceHandler::indexed_property_hooks = { + NULL, + NULL, + NULL, + NULL, + NULL, +}; + +static base::LazyInstance<MozjsBooleanTypeTestInterfaceHandler> + proxy_handler; + +bool HasInstance(JSContext *context, JS::HandleObject type, + JS::MutableHandleValue vp, bool *success) { + JS::RootedObject global_object( + context, JS_GetGlobalForObject(context, type)); + DCHECK(global_object); + + JS::RootedObject prototype( + context, MozjsBooleanTypeTestInterface::GetPrototype(context, global_object)); + + // |IsDelegate| walks the prototype chain of an object returning true if + // .prototype is found. + bool is_delegate; + if (!IsDelegate(context, prototype, vp, &is_delegate)) { + *success = false; + return false; + } + + *success = is_delegate; + return true; +} + +const JSClass instance_class_definition = { + "BooleanTypeTestInterface", + 0 | JSCLASS_HAS_PRIVATE, + NULL, // addProperty + NULL, // delProperty + NULL, // getProperty + NULL, // setProperty + NULL, // enumerate + NULL, // resolve + NULL, // mayResolve + &WrapperPrivate::Finalizer, // finalize + NULL, // call + NULL, // hasInstance + NULL, // construct + &WrapperPrivate::Trace, // trace +}; + +const JSClass prototype_class_definition = { + "BooleanTypeTestInterfacePrototype", +}; + +const JSClass interface_object_class_definition = { + "BooleanTypeTestInterfaceConstructor", + 0, + NULL, // addProperty + NULL, // delProperty + NULL, // getProperty + NULL, // setProperty + NULL, // enumerate + NULL, // resolve + NULL, // mayResolve + NULL, // finalize + NULL, // call + &HasInstance, + NULL, +}; + +bool get_booleanProperty( + JSContext* context, unsigned argc, JS::Value* vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + const JSClass* proto_class = + MozjsBooleanTypeTestInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<BooleanTypeTestInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + BooleanTypeTestInterface* impl = + wrapper_private->wrappable<BooleanTypeTestInterface>().get(); + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->boolean_property(), + &result_value); + } + if (!exception_state.is_exception_set()) { + args.rval().set(result_value); + } + return !exception_state.is_exception_set(); +} + +bool set_booleanProperty( + JSContext* context, unsigned argc, JS::Value* vp) { + + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + + const JSClass* proto_class = + MozjsBooleanTypeTestInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<BooleanTypeTestInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + BooleanTypeTestInterface* impl = + wrapper_private->wrappable<BooleanTypeTestInterface>().get(); + TypeTraits<bool >::ConversionType value; + if (args.length() != 1) { + NOTREACHED(); + return false; + } + FromJSValue(context, args[0], kNoConversionFlags, &exception_state, + &value); + if (exception_state.is_exception_set()) { + return false; + } + + impl->set_boolean_property(value); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + +bool fcn_booleanArgumentOperation( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + const JSClass* proto_class = + MozjsBooleanTypeTestInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<BooleanTypeTestInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + BooleanTypeTestInterface* impl = + wrapper_private->wrappable<BooleanTypeTestInterface>().get(); + const size_t kMinArguments = 1; + if (args.length() < kMinArguments) { + exception_state.SetSimpleException(script::kInvalidNumberOfArguments); + return false; + } + // Non-optional arguments + TypeTraits<bool >::ConversionType arg1; + + DCHECK_LT(0, args.length()); + JS::RootedValue non_optional_value0( + context, args[0]); + FromJSValue(context, + non_optional_value0, + kNoConversionFlags, + &exception_state, &arg1); + if (exception_state.is_exception_set()) { + return false; + } + + impl->BooleanArgumentOperation(arg1); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + +bool fcn_booleanReturnOperation( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + const JSClass* proto_class = + MozjsBooleanTypeTestInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<BooleanTypeTestInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + BooleanTypeTestInterface* impl = + wrapper_private->wrappable<BooleanTypeTestInterface>().get(); + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->BooleanReturnOperation(), + &result_value); + } + if (!exception_state.is_exception_set()) { + args.rval().set(result_value); + } + return !exception_state.is_exception_set(); +} + + + +const JSPropertySpec prototype_properties[] = { + { // Read/Write property + "booleanProperty", + JSPROP_SHARED | JSPROP_ENUMERATE, + { { &get_booleanProperty, NULL } }, + { { &set_booleanProperty, NULL } }, + }, + JS_PS_END +}; + +const JSFunctionSpec prototype_functions[] = { + JS_FNSPEC( + "booleanArgumentOperation", fcn_booleanArgumentOperation, NULL, + 1, JSPROP_ENUMERATE, NULL), + JS_FNSPEC( + "booleanReturnOperation", fcn_booleanReturnOperation, NULL, + 0, JSPROP_ENUMERATE, NULL), + JS_FS_END +}; + +const JSPropertySpec interface_object_properties[] = { + JS_PS_END +}; + +const JSFunctionSpec interface_object_functions[] = { + JS_FS_END +}; + +const JSPropertySpec own_properties[] = { + JS_PS_END +}; + +void InitializePrototypeAndInterfaceObject( + InterfaceData* interface_data, JSContext* context, + JS::HandleObject global_object) { + DCHECK(!interface_data->prototype); + DCHECK(!interface_data->interface_object); + DCHECK(JS_IsGlobalObject(global_object)); + + JS::RootedObject parent_prototype( + context, JS_GetObjectPrototype(context, global_object)); + DCHECK(parent_prototype); + + interface_data->prototype = JS_NewObjectWithGivenProto( + context, &prototype_class_definition, parent_prototype + ); + + JS::RootedObject rooted_prototype(context, interface_data->prototype); + bool success = JS_DefineProperties( + context, + rooted_prototype, + prototype_properties); + + DCHECK(success); + success = JS_DefineFunctions( + context, rooted_prototype, prototype_functions); + DCHECK(success); + + JS::RootedObject function_prototype( + context, JS_GetFunctionPrototype(context, global_object)); + DCHECK(function_prototype); + // Create the Interface object. + interface_data->interface_object = JS_NewObjectWithGivenProto( + context, &interface_object_class_definition, + function_prototype); + + // Add the InterfaceObject.name property. + JS::RootedObject rooted_interface_object( + context, interface_data->interface_object); + JS::RootedValue name_value(context); + const char name[] = + "BooleanTypeTestInterface"; + name_value.setString(JS_NewStringCopyZ(context, name)); + success = JS_DefineProperty( + context, rooted_interface_object, "name", name_value, JSPROP_READONLY, + NULL, NULL); + DCHECK(success); + + // Define interface object properties (including constants). + success = JS_DefineProperties(context, rooted_interface_object, + interface_object_properties); + DCHECK(success); + // Define interface object functions (static). + success = JS_DefineFunctions(context, rooted_interface_object, + interface_object_functions); + DCHECK(success); + + // Set the Prototype.constructor and Constructor.prototype properties. + DCHECK(interface_data->interface_object); + DCHECK(interface_data->prototype); + success = JS_LinkConstructorAndPrototype( + context, + rooted_interface_object, + rooted_prototype); + DCHECK(success); +} + +InterfaceData* GetInterfaceData(JSContext* context) { + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + // Use the address of the properties definition for this interface as a + // unique key for looking up the InterfaceData for this interface. + intptr_t key = reinterpret_cast<intptr_t>(&own_properties); + InterfaceData* interface_data = global_environment->GetInterfaceData(key); + if (!interface_data) { + interface_data = new InterfaceData(); + DCHECK(interface_data); + global_environment->CacheInterfaceData(key, interface_data); + DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key)); + } + return interface_data; +} + +} // namespace + +// static +JSObject* MozjsBooleanTypeTestInterface::CreateProxy( + JSContext* context, const scoped_refptr<Wrappable>& wrappable) { + DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); + JS::RootedObject global_object( + context, + MozjsGlobalEnvironment::GetFromContext(context)->global_object()); + DCHECK(global_object); + + InterfaceData* interface_data = GetInterfaceData(context); + JS::RootedObject prototype(context, GetPrototype(context, global_object)); + DCHECK(prototype); + JS::RootedObject new_object( + context, + JS_NewObjectWithGivenProto( + context, &instance_class_definition, prototype)); + DCHECK(new_object); + JS::RootedObject proxy(context, + ProxyHandler::NewProxy( + context, proxy_handler.Pointer(), new_object, prototype)); + WrapperPrivate::AddPrivateData(context, proxy, wrappable); + return proxy; +} + +// static +const JSClass* MozjsBooleanTypeTestInterface::PrototypeClass( + JSContext* context) { + DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); + JS::RootedObject global_object( + context, + MozjsGlobalEnvironment::GetFromContext(context)->global_object()); + DCHECK(global_object); + + JS::RootedObject prototype(context, GetPrototype(context, global_object)); + const JSClass* proto_class = JS_GetClass(prototype); + return proto_class; +} + +// static +JSObject* MozjsBooleanTypeTestInterface::GetPrototype( + JSContext* context, JS::HandleObject global_object) { + DCHECK(JS_IsGlobalObject(global_object)); + + InterfaceData* interface_data = GetInterfaceData(context); + if (!interface_data->prototype) { + // Create new prototype that has all the props and methods + InitializePrototypeAndInterfaceObject( + interface_data, context, global_object); + } + DCHECK(interface_data->prototype); + return interface_data->prototype; +} + +// static +JSObject* MozjsBooleanTypeTestInterface::GetInterfaceObject( + JSContext* context, JS::HandleObject global_object) { + DCHECK(JS_IsGlobalObject(global_object)); + + InterfaceData* interface_data = GetInterfaceData(context); + if (!interface_data->interface_object) { + InitializePrototypeAndInterfaceObject( + interface_data, context, global_object); + } + DCHECK(interface_data->interface_object); + return interface_data->interface_object; +} + + +namespace { +} // namespace + + +} // namespace testing +} // namespace bindings +} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_boolean_type_test_interface.h b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_boolean_type_test_interface.h new file mode 100644 index 0000000..f91f6ce --- /dev/null +++ b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_boolean_type_test_interface.h
@@ -0,0 +1,52 @@ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// clang-format off + +// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! +// Auto-generated from template: bindings/mozjs-45/templates/interface.h.template + +#ifndef MozjsBooleanTypeTestInterface_h +#define MozjsBooleanTypeTestInterface_h + +#include "base/hash_tables.h" +#include "base/lazy_instance.h" +#include "base/memory/ref_counted.h" +#include "base/threading/thread_checker.h" +#include "cobalt/base/polymorphic_downcast.h" +#include "cobalt/script/wrappable.h" +#include "cobalt/bindings/testing/boolean_type_test_interface.h" + +#include "third_party/mozjs-45/js/src/jsapi.h" + +namespace cobalt { +namespace bindings { +namespace testing { + +class MozjsBooleanTypeTestInterface { + public: + static JSObject* CreateProxy(JSContext* context, + const scoped_refptr<script::Wrappable>& wrappable); + static const JSClass* PrototypeClass(JSContext* context); + static JSObject* GetPrototype(JSContext* context, + JS::HandleObject global_object); + static JSObject* GetInterfaceObject(JSContext* context, + JS::HandleObject global_object); +}; + +} // namespace testing +} // namespace bindings +} // namespace cobalt + +#endif // MozjsBooleanTypeTestInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_callback_function_interface.cc b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_callback_function_interface.cc new file mode 100644 index 0000000..de26a40 --- /dev/null +++ b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_callback_function_interface.cc
@@ -0,0 +1,889 @@ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// clang-format off + +// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! +// Auto-generated from template: bindings/mozjs-45/templates/interface.cc.template + +#include "cobalt/bindings/testing/mozjs_callback_function_interface.h" + +#include "base/debug/trace_event.h" +#include "cobalt/base/polymorphic_downcast.h" +#include "cobalt/script/global_environment.h" +#include "cobalt/script/opaque_handle.h" +#include "cobalt/script/script_value.h" +#include "cobalt/bindings/testing/arbitrary_interface.h" +#include "cobalt/bindings/testing/mozjs_arbitrary_interface.h" + +#include "base/lazy_instance.h" +#include "cobalt/script/exception_state.h" +#include "cobalt/script/mozjs-45/callback_function_conversion.h" +#include "cobalt/script/mozjs-45/conversion_helpers.h" +#include "cobalt/script/mozjs-45/mozjs_callback_function.h" +#include "cobalt/script/mozjs-45/mozjs_exception_state.h" +#include "cobalt/script/mozjs-45/mozjs_global_environment.h" +#include "cobalt/script/mozjs-45/mozjs_object_handle.h" +#include "cobalt/script/mozjs-45/mozjs_property_enumerator.h" +#include "cobalt/script/mozjs-45/mozjs_user_object_holder.h" +#include "cobalt/script/mozjs-45/proxy_handler.h" +#include "cobalt/script/mozjs-45/type_traits.h" +#include "cobalt/script/mozjs-45/wrapper_factory.h" +#include "cobalt/script/mozjs-45/wrapper_private.h" +#include "cobalt/script/property_enumerator.h" +#include "cobalt/script/sequence.h" +#include "third_party/mozjs-45/js/src/jsapi.h" +#include "third_party/mozjs-45/js/src/jsfriendapi.h" + +namespace { +using cobalt::bindings::testing::CallbackFunctionInterface; +using cobalt::bindings::testing::MozjsCallbackFunctionInterface; +using cobalt::bindings::testing::ArbitraryInterface; +using cobalt::bindings::testing::MozjsArbitraryInterface; +using cobalt::script::CallbackInterfaceTraits; +using cobalt::script::GlobalEnvironment; +using cobalt::script::OpaqueHandle; +using cobalt::script::OpaqueHandleHolder; +using cobalt::script::ScriptValue; +using cobalt::script::Wrappable; + +using cobalt::script::CallbackFunction; +using cobalt::script::CallbackInterfaceTraits; +using cobalt::script::ExceptionState; +using cobalt::script::Wrappable; +using cobalt::script::mozjs::FromJSValue; +using cobalt::script::mozjs::InterfaceData; +using cobalt::script::mozjs::MozjsCallbackFunction; +using cobalt::script::mozjs::MozjsExceptionState; +using cobalt::script::mozjs::MozjsGlobalEnvironment; +using cobalt::script::mozjs::MozjsPropertyEnumerator; +using cobalt::script::mozjs::MozjsUserObjectHolder; +using cobalt::script::mozjs::ProxyHandler; +using cobalt::script::mozjs::ToJSValue; +using cobalt::script::mozjs::TypeTraits; +using cobalt::script::mozjs::WrapperFactory; +using cobalt::script::mozjs::WrapperPrivate; +using cobalt::script::mozjs::kConversionFlagNullable; +using cobalt::script::mozjs::kConversionFlagRestricted; +using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString; +using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString; +using cobalt::script::mozjs::kNoConversionFlags; +} // namespace + +namespace cobalt { +namespace bindings { +namespace testing { + +namespace { + +class MozjsCallbackFunctionInterfaceHandler : public ProxyHandler { + public: + MozjsCallbackFunctionInterfaceHandler() + : ProxyHandler(indexed_property_hooks, named_property_hooks) {} + + private: + static NamedPropertyHooks named_property_hooks; + static IndexedPropertyHooks indexed_property_hooks; +}; + +ProxyHandler::NamedPropertyHooks +MozjsCallbackFunctionInterfaceHandler::named_property_hooks = { + NULL, + NULL, + NULL, + NULL, + NULL, +}; +ProxyHandler::IndexedPropertyHooks +MozjsCallbackFunctionInterfaceHandler::indexed_property_hooks = { + NULL, + NULL, + NULL, + NULL, + NULL, +}; + +static base::LazyInstance<MozjsCallbackFunctionInterfaceHandler> + proxy_handler; + +bool HasInstance(JSContext *context, JS::HandleObject type, + JS::MutableHandleValue vp, bool *success) { + JS::RootedObject global_object( + context, JS_GetGlobalForObject(context, type)); + DCHECK(global_object); + + JS::RootedObject prototype( + context, MozjsCallbackFunctionInterface::GetPrototype(context, global_object)); + + // |IsDelegate| walks the prototype chain of an object returning true if + // .prototype is found. + bool is_delegate; + if (!IsDelegate(context, prototype, vp, &is_delegate)) { + *success = false; + return false; + } + + *success = is_delegate; + return true; +} + +const JSClass instance_class_definition = { + "CallbackFunctionInterface", + 0 | JSCLASS_HAS_PRIVATE, + NULL, // addProperty + NULL, // delProperty + NULL, // getProperty + NULL, // setProperty + NULL, // enumerate + NULL, // resolve + NULL, // mayResolve + &WrapperPrivate::Finalizer, // finalize + NULL, // call + NULL, // hasInstance + NULL, // construct + &WrapperPrivate::Trace, // trace +}; + +const JSClass prototype_class_definition = { + "CallbackFunctionInterfacePrototype", +}; + +const JSClass interface_object_class_definition = { + "CallbackFunctionInterfaceConstructor", + 0, + NULL, // addProperty + NULL, // delProperty + NULL, // getProperty + NULL, // setProperty + NULL, // enumerate + NULL, // resolve + NULL, // mayResolve + NULL, // finalize + NULL, // call + &HasInstance, + NULL, +}; + +bool get_callbackAttribute( + JSContext* context, unsigned argc, JS::Value* vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + const JSClass* proto_class = + MozjsCallbackFunctionInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<CallbackFunctionInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + CallbackFunctionInterface* impl = + wrapper_private->wrappable<CallbackFunctionInterface>().get(); + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->callback_attribute(), + &result_value); + } + if (!exception_state.is_exception_set()) { + args.rval().set(result_value); + } + return !exception_state.is_exception_set(); +} + +bool set_callbackAttribute( + JSContext* context, unsigned argc, JS::Value* vp) { + + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + + const JSClass* proto_class = + MozjsCallbackFunctionInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<CallbackFunctionInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + CallbackFunctionInterface* impl = + wrapper_private->wrappable<CallbackFunctionInterface>().get(); + TypeTraits<CallbackFunctionInterface::VoidFunction >::ConversionType value; + if (args.length() != 1) { + NOTREACHED(); + return false; + } + FromJSValue(context, args[0], kNoConversionFlags, &exception_state, + &value); + if (exception_state.is_exception_set()) { + return false; + } + + impl->set_callback_attribute(value); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + +bool get_nullableCallbackAttribute( + JSContext* context, unsigned argc, JS::Value* vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + const JSClass* proto_class = + MozjsCallbackFunctionInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<CallbackFunctionInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + CallbackFunctionInterface* impl = + wrapper_private->wrappable<CallbackFunctionInterface>().get(); + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->nullable_callback_attribute(), + &result_value); + } + if (!exception_state.is_exception_set()) { + args.rval().set(result_value); + } + return !exception_state.is_exception_set(); +} + +bool set_nullableCallbackAttribute( + JSContext* context, unsigned argc, JS::Value* vp) { + + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + + const JSClass* proto_class = + MozjsCallbackFunctionInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<CallbackFunctionInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + CallbackFunctionInterface* impl = + wrapper_private->wrappable<CallbackFunctionInterface>().get(); + TypeTraits<CallbackFunctionInterface::VoidFunction >::ConversionType value; + if (args.length() != 1) { + NOTREACHED(); + return false; + } + FromJSValue(context, args[0], (kConversionFlagNullable), &exception_state, + &value); + if (exception_state.is_exception_set()) { + return false; + } + + impl->set_nullable_callback_attribute(value); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + +bool fcn_takesFunctionThatReturnsString( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + const JSClass* proto_class = + MozjsCallbackFunctionInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<CallbackFunctionInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + CallbackFunctionInterface* impl = + wrapper_private->wrappable<CallbackFunctionInterface>().get(); + const size_t kMinArguments = 1; + if (args.length() < kMinArguments) { + exception_state.SetSimpleException(script::kInvalidNumberOfArguments); + return false; + } + // Non-optional arguments + TypeTraits<CallbackFunctionInterface::FunctionThatReturnsString >::ConversionType cb; + + DCHECK_LT(0, args.length()); + JS::RootedValue non_optional_value0( + context, args[0]); + FromJSValue(context, + non_optional_value0, + kNoConversionFlags, + &exception_state, &cb); + if (exception_state.is_exception_set()) { + return false; + } + + impl->TakesFunctionThatReturnsString(cb); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + +bool fcn_takesFunctionWithNullableParameters( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + const JSClass* proto_class = + MozjsCallbackFunctionInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<CallbackFunctionInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + CallbackFunctionInterface* impl = + wrapper_private->wrappable<CallbackFunctionInterface>().get(); + const size_t kMinArguments = 1; + if (args.length() < kMinArguments) { + exception_state.SetSimpleException(script::kInvalidNumberOfArguments); + return false; + } + // Non-optional arguments + TypeTraits<CallbackFunctionInterface::FunctionWithNullableParameters >::ConversionType cb; + + DCHECK_LT(0, args.length()); + JS::RootedValue non_optional_value0( + context, args[0]); + FromJSValue(context, + non_optional_value0, + kNoConversionFlags, + &exception_state, &cb); + if (exception_state.is_exception_set()) { + return false; + } + + impl->TakesFunctionWithNullableParameters(cb); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + +bool fcn_takesFunctionWithOneParameter( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + const JSClass* proto_class = + MozjsCallbackFunctionInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<CallbackFunctionInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + CallbackFunctionInterface* impl = + wrapper_private->wrappable<CallbackFunctionInterface>().get(); + const size_t kMinArguments = 1; + if (args.length() < kMinArguments) { + exception_state.SetSimpleException(script::kInvalidNumberOfArguments); + return false; + } + // Non-optional arguments + TypeTraits<CallbackFunctionInterface::FunctionWithOneParameter >::ConversionType cb; + + DCHECK_LT(0, args.length()); + JS::RootedValue non_optional_value0( + context, args[0]); + FromJSValue(context, + non_optional_value0, + kNoConversionFlags, + &exception_state, &cb); + if (exception_state.is_exception_set()) { + return false; + } + + impl->TakesFunctionWithOneParameter(cb); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + +bool fcn_takesFunctionWithSeveralParameters( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + const JSClass* proto_class = + MozjsCallbackFunctionInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<CallbackFunctionInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + CallbackFunctionInterface* impl = + wrapper_private->wrappable<CallbackFunctionInterface>().get(); + const size_t kMinArguments = 1; + if (args.length() < kMinArguments) { + exception_state.SetSimpleException(script::kInvalidNumberOfArguments); + return false; + } + // Non-optional arguments + TypeTraits<CallbackFunctionInterface::FunctionWithSeveralParameters >::ConversionType cb; + + DCHECK_LT(0, args.length()); + JS::RootedValue non_optional_value0( + context, args[0]); + FromJSValue(context, + non_optional_value0, + kNoConversionFlags, + &exception_state, &cb); + if (exception_state.is_exception_set()) { + return false; + } + + impl->TakesFunctionWithSeveralParameters(cb); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + +bool fcn_takesVoidFunction( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + const JSClass* proto_class = + MozjsCallbackFunctionInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<CallbackFunctionInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + CallbackFunctionInterface* impl = + wrapper_private->wrappable<CallbackFunctionInterface>().get(); + const size_t kMinArguments = 1; + if (args.length() < kMinArguments) { + exception_state.SetSimpleException(script::kInvalidNumberOfArguments); + return false; + } + // Non-optional arguments + TypeTraits<CallbackFunctionInterface::VoidFunction >::ConversionType cb; + + DCHECK_LT(0, args.length()); + JS::RootedValue non_optional_value0( + context, args[0]); + FromJSValue(context, + non_optional_value0, + kNoConversionFlags, + &exception_state, &cb); + if (exception_state.is_exception_set()) { + return false; + } + + impl->TakesVoidFunction(cb); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + + + +const JSPropertySpec prototype_properties[] = { + { // Read/Write property + "callbackAttribute", + JSPROP_SHARED | JSPROP_ENUMERATE, + { { &get_callbackAttribute, NULL } }, + { { &set_callbackAttribute, NULL } }, + }, + { // Read/Write property + "nullableCallbackAttribute", + JSPROP_SHARED | JSPROP_ENUMERATE, + { { &get_nullableCallbackAttribute, NULL } }, + { { &set_nullableCallbackAttribute, NULL } }, + }, + JS_PS_END +}; + +const JSFunctionSpec prototype_functions[] = { + JS_FNSPEC( + "takesFunctionThatReturnsString", fcn_takesFunctionThatReturnsString, NULL, + 1, JSPROP_ENUMERATE, NULL), + JS_FNSPEC( + "takesFunctionWithNullableParameters", fcn_takesFunctionWithNullableParameters, NULL, + 1, JSPROP_ENUMERATE, NULL), + JS_FNSPEC( + "takesFunctionWithOneParameter", fcn_takesFunctionWithOneParameter, NULL, + 1, JSPROP_ENUMERATE, NULL), + JS_FNSPEC( + "takesFunctionWithSeveralParameters", fcn_takesFunctionWithSeveralParameters, NULL, + 1, JSPROP_ENUMERATE, NULL), + JS_FNSPEC( + "takesVoidFunction", fcn_takesVoidFunction, NULL, + 1, JSPROP_ENUMERATE, NULL), + JS_FS_END +}; + +const JSPropertySpec interface_object_properties[] = { + JS_PS_END +}; + +const JSFunctionSpec interface_object_functions[] = { + JS_FS_END +}; + +const JSPropertySpec own_properties[] = { + JS_PS_END +}; + +void InitializePrototypeAndInterfaceObject( + InterfaceData* interface_data, JSContext* context, + JS::HandleObject global_object) { + DCHECK(!interface_data->prototype); + DCHECK(!interface_data->interface_object); + DCHECK(JS_IsGlobalObject(global_object)); + + JS::RootedObject parent_prototype( + context, JS_GetObjectPrototype(context, global_object)); + DCHECK(parent_prototype); + + interface_data->prototype = JS_NewObjectWithGivenProto( + context, &prototype_class_definition, parent_prototype + ); + + JS::RootedObject rooted_prototype(context, interface_data->prototype); + bool success = JS_DefineProperties( + context, + rooted_prototype, + prototype_properties); + + DCHECK(success); + success = JS_DefineFunctions( + context, rooted_prototype, prototype_functions); + DCHECK(success); + + JS::RootedObject function_prototype( + context, JS_GetFunctionPrototype(context, global_object)); + DCHECK(function_prototype); + // Create the Interface object. + interface_data->interface_object = JS_NewObjectWithGivenProto( + context, &interface_object_class_definition, + function_prototype); + + // Add the InterfaceObject.name property. + JS::RootedObject rooted_interface_object( + context, interface_data->interface_object); + JS::RootedValue name_value(context); + const char name[] = + "CallbackFunctionInterface"; + name_value.setString(JS_NewStringCopyZ(context, name)); + success = JS_DefineProperty( + context, rooted_interface_object, "name", name_value, JSPROP_READONLY, + NULL, NULL); + DCHECK(success); + + // Define interface object properties (including constants). + success = JS_DefineProperties(context, rooted_interface_object, + interface_object_properties); + DCHECK(success); + // Define interface object functions (static). + success = JS_DefineFunctions(context, rooted_interface_object, + interface_object_functions); + DCHECK(success); + + // Set the Prototype.constructor and Constructor.prototype properties. + DCHECK(interface_data->interface_object); + DCHECK(interface_data->prototype); + success = JS_LinkConstructorAndPrototype( + context, + rooted_interface_object, + rooted_prototype); + DCHECK(success); +} + +InterfaceData* GetInterfaceData(JSContext* context) { + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + // Use the address of the properties definition for this interface as a + // unique key for looking up the InterfaceData for this interface. + intptr_t key = reinterpret_cast<intptr_t>(&own_properties); + InterfaceData* interface_data = global_environment->GetInterfaceData(key); + if (!interface_data) { + interface_data = new InterfaceData(); + DCHECK(interface_data); + global_environment->CacheInterfaceData(key, interface_data); + DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key)); + } + return interface_data; +} + +} // namespace + +// static +JSObject* MozjsCallbackFunctionInterface::CreateProxy( + JSContext* context, const scoped_refptr<Wrappable>& wrappable) { + DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); + JS::RootedObject global_object( + context, + MozjsGlobalEnvironment::GetFromContext(context)->global_object()); + DCHECK(global_object); + + InterfaceData* interface_data = GetInterfaceData(context); + JS::RootedObject prototype(context, GetPrototype(context, global_object)); + DCHECK(prototype); + JS::RootedObject new_object( + context, + JS_NewObjectWithGivenProto( + context, &instance_class_definition, prototype)); + DCHECK(new_object); + JS::RootedObject proxy(context, + ProxyHandler::NewProxy( + context, proxy_handler.Pointer(), new_object, prototype)); + WrapperPrivate::AddPrivateData(context, proxy, wrappable); + return proxy; +} + +// static +const JSClass* MozjsCallbackFunctionInterface::PrototypeClass( + JSContext* context) { + DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); + JS::RootedObject global_object( + context, + MozjsGlobalEnvironment::GetFromContext(context)->global_object()); + DCHECK(global_object); + + JS::RootedObject prototype(context, GetPrototype(context, global_object)); + const JSClass* proto_class = JS_GetClass(prototype); + return proto_class; +} + +// static +JSObject* MozjsCallbackFunctionInterface::GetPrototype( + JSContext* context, JS::HandleObject global_object) { + DCHECK(JS_IsGlobalObject(global_object)); + + InterfaceData* interface_data = GetInterfaceData(context); + if (!interface_data->prototype) { + // Create new prototype that has all the props and methods + InitializePrototypeAndInterfaceObject( + interface_data, context, global_object); + } + DCHECK(interface_data->prototype); + return interface_data->prototype; +} + +// static +JSObject* MozjsCallbackFunctionInterface::GetInterfaceObject( + JSContext* context, JS::HandleObject global_object) { + DCHECK(JS_IsGlobalObject(global_object)); + + InterfaceData* interface_data = GetInterfaceData(context); + if (!interface_data->interface_object) { + InitializePrototypeAndInterfaceObject( + interface_data, context, global_object); + } + DCHECK(interface_data->interface_object); + return interface_data->interface_object; +} + + +namespace { +} // namespace + + +} // namespace testing +} // namespace bindings +} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_callback_function_interface.h b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_callback_function_interface.h new file mode 100644 index 0000000..19bc4f0 --- /dev/null +++ b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_callback_function_interface.h
@@ -0,0 +1,52 @@ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// clang-format off + +// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! +// Auto-generated from template: bindings/mozjs-45/templates/interface.h.template + +#ifndef MozjsCallbackFunctionInterface_h +#define MozjsCallbackFunctionInterface_h + +#include "base/hash_tables.h" +#include "base/lazy_instance.h" +#include "base/memory/ref_counted.h" +#include "base/threading/thread_checker.h" +#include "cobalt/base/polymorphic_downcast.h" +#include "cobalt/script/wrappable.h" +#include "cobalt/bindings/testing/callback_function_interface.h" + +#include "third_party/mozjs-45/js/src/jsapi.h" + +namespace cobalt { +namespace bindings { +namespace testing { + +class MozjsCallbackFunctionInterface { + public: + static JSObject* CreateProxy(JSContext* context, + const scoped_refptr<script::Wrappable>& wrappable); + static const JSClass* PrototypeClass(JSContext* context); + static JSObject* GetPrototype(JSContext* context, + JS::HandleObject global_object); + static JSObject* GetInterfaceObject(JSContext* context, + JS::HandleObject global_object); +}; + +} // namespace testing +} // namespace bindings +} // namespace cobalt + +#endif // MozjsCallbackFunctionInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_callback_interface_interface.cc b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_callback_interface_interface.cc new file mode 100644 index 0000000..f912c7d --- /dev/null +++ b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_callback_interface_interface.cc
@@ -0,0 +1,571 @@ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// clang-format off + +// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! +// Auto-generated from template: bindings/mozjs-45/templates/interface.cc.template + +#include "cobalt/bindings/testing/mozjs_callback_interface_interface.h" + +#include "base/debug/trace_event.h" +#include "cobalt/base/polymorphic_downcast.h" +#include "cobalt/script/global_environment.h" +#include "cobalt/script/opaque_handle.h" +#include "cobalt/script/script_value.h" +#include "cobalt/bindings/testing/mozjs_single_operation_interface.h" +#include "cobalt/bindings/testing/single_operation_interface.h" + +#include "base/lazy_instance.h" +#include "cobalt/script/exception_state.h" +#include "cobalt/script/mozjs-45/callback_function_conversion.h" +#include "cobalt/script/mozjs-45/conversion_helpers.h" +#include "cobalt/script/mozjs-45/mozjs_callback_function.h" +#include "cobalt/script/mozjs-45/mozjs_exception_state.h" +#include "cobalt/script/mozjs-45/mozjs_global_environment.h" +#include "cobalt/script/mozjs-45/mozjs_object_handle.h" +#include "cobalt/script/mozjs-45/mozjs_property_enumerator.h" +#include "cobalt/script/mozjs-45/mozjs_user_object_holder.h" +#include "cobalt/script/mozjs-45/proxy_handler.h" +#include "cobalt/script/mozjs-45/type_traits.h" +#include "cobalt/script/mozjs-45/wrapper_factory.h" +#include "cobalt/script/mozjs-45/wrapper_private.h" +#include "cobalt/script/property_enumerator.h" +#include "cobalt/script/sequence.h" +#include "third_party/mozjs-45/js/src/jsapi.h" +#include "third_party/mozjs-45/js/src/jsfriendapi.h" + +namespace { +using cobalt::bindings::testing::CallbackInterfaceInterface; +using cobalt::bindings::testing::MozjsCallbackInterfaceInterface; +using cobalt::bindings::testing::MozjsSingleOperationInterface; +using cobalt::bindings::testing::SingleOperationInterface; +using cobalt::script::CallbackInterfaceTraits; +using cobalt::script::GlobalEnvironment; +using cobalt::script::OpaqueHandle; +using cobalt::script::OpaqueHandleHolder; +using cobalt::script::ScriptValue; +using cobalt::script::Wrappable; + +using cobalt::script::CallbackFunction; +using cobalt::script::CallbackInterfaceTraits; +using cobalt::script::ExceptionState; +using cobalt::script::Wrappable; +using cobalt::script::mozjs::FromJSValue; +using cobalt::script::mozjs::InterfaceData; +using cobalt::script::mozjs::MozjsCallbackFunction; +using cobalt::script::mozjs::MozjsExceptionState; +using cobalt::script::mozjs::MozjsGlobalEnvironment; +using cobalt::script::mozjs::MozjsPropertyEnumerator; +using cobalt::script::mozjs::MozjsUserObjectHolder; +using cobalt::script::mozjs::ProxyHandler; +using cobalt::script::mozjs::ToJSValue; +using cobalt::script::mozjs::TypeTraits; +using cobalt::script::mozjs::WrapperFactory; +using cobalt::script::mozjs::WrapperPrivate; +using cobalt::script::mozjs::kConversionFlagNullable; +using cobalt::script::mozjs::kConversionFlagRestricted; +using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString; +using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString; +using cobalt::script::mozjs::kNoConversionFlags; +} // namespace + +namespace cobalt { +namespace bindings { +namespace testing { + +namespace { + +class MozjsCallbackInterfaceInterfaceHandler : public ProxyHandler { + public: + MozjsCallbackInterfaceInterfaceHandler() + : ProxyHandler(indexed_property_hooks, named_property_hooks) {} + + private: + static NamedPropertyHooks named_property_hooks; + static IndexedPropertyHooks indexed_property_hooks; +}; + +ProxyHandler::NamedPropertyHooks +MozjsCallbackInterfaceInterfaceHandler::named_property_hooks = { + NULL, + NULL, + NULL, + NULL, + NULL, +}; +ProxyHandler::IndexedPropertyHooks +MozjsCallbackInterfaceInterfaceHandler::indexed_property_hooks = { + NULL, + NULL, + NULL, + NULL, + NULL, +}; + +static base::LazyInstance<MozjsCallbackInterfaceInterfaceHandler> + proxy_handler; + +bool HasInstance(JSContext *context, JS::HandleObject type, + JS::MutableHandleValue vp, bool *success) { + JS::RootedObject global_object( + context, JS_GetGlobalForObject(context, type)); + DCHECK(global_object); + + JS::RootedObject prototype( + context, MozjsCallbackInterfaceInterface::GetPrototype(context, global_object)); + + // |IsDelegate| walks the prototype chain of an object returning true if + // .prototype is found. + bool is_delegate; + if (!IsDelegate(context, prototype, vp, &is_delegate)) { + *success = false; + return false; + } + + *success = is_delegate; + return true; +} + +const JSClass instance_class_definition = { + "CallbackInterfaceInterface", + 0 | JSCLASS_HAS_PRIVATE, + NULL, // addProperty + NULL, // delProperty + NULL, // getProperty + NULL, // setProperty + NULL, // enumerate + NULL, // resolve + NULL, // mayResolve + &WrapperPrivate::Finalizer, // finalize + NULL, // call + NULL, // hasInstance + NULL, // construct + &WrapperPrivate::Trace, // trace +}; + +const JSClass prototype_class_definition = { + "CallbackInterfaceInterfacePrototype", +}; + +const JSClass interface_object_class_definition = { + "CallbackInterfaceInterfaceConstructor", + 0, + NULL, // addProperty + NULL, // delProperty + NULL, // getProperty + NULL, // setProperty + NULL, // enumerate + NULL, // resolve + NULL, // mayResolve + NULL, // finalize + NULL, // call + &HasInstance, + NULL, +}; + +bool get_callbackAttribute( + JSContext* context, unsigned argc, JS::Value* vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + const JSClass* proto_class = + MozjsCallbackInterfaceInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<CallbackInterfaceInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + CallbackInterfaceInterface* impl = + wrapper_private->wrappable<CallbackInterfaceInterface>().get(); + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->callback_attribute(), + &result_value); + } + if (!exception_state.is_exception_set()) { + args.rval().set(result_value); + } + return !exception_state.is_exception_set(); +} + +bool set_callbackAttribute( + JSContext* context, unsigned argc, JS::Value* vp) { + + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + + const JSClass* proto_class = + MozjsCallbackInterfaceInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<CallbackInterfaceInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + CallbackInterfaceInterface* impl = + wrapper_private->wrappable<CallbackInterfaceInterface>().get(); + TypeTraits<CallbackInterfaceTraits<SingleOperationInterface > >::ConversionType value; + if (args.length() != 1) { + NOTREACHED(); + return false; + } + FromJSValue(context, args[0], (kConversionFlagNullable), &exception_state, + &value); + if (exception_state.is_exception_set()) { + return false; + } + + impl->set_callback_attribute(value); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + +bool fcn_registerCallback( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + const JSClass* proto_class = + MozjsCallbackInterfaceInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<CallbackInterfaceInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + CallbackInterfaceInterface* impl = + wrapper_private->wrappable<CallbackInterfaceInterface>().get(); + const size_t kMinArguments = 1; + if (args.length() < kMinArguments) { + exception_state.SetSimpleException(script::kInvalidNumberOfArguments); + return false; + } + // Non-optional arguments + TypeTraits<CallbackInterfaceTraits<SingleOperationInterface > >::ConversionType callback_interface; + + DCHECK_LT(0, args.length()); + JS::RootedValue non_optional_value0( + context, args[0]); + FromJSValue(context, + non_optional_value0, + kNoConversionFlags, + &exception_state, &callback_interface); + if (exception_state.is_exception_set()) { + return false; + } + + impl->RegisterCallback(callback_interface); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + +bool fcn_someOperation( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + const JSClass* proto_class = + MozjsCallbackInterfaceInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<CallbackInterfaceInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + CallbackInterfaceInterface* impl = + wrapper_private->wrappable<CallbackInterfaceInterface>().get(); + + impl->SomeOperation(); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + + + +const JSPropertySpec prototype_properties[] = { + { // Read/Write property + "callbackAttribute", + JSPROP_SHARED | JSPROP_ENUMERATE, + { { &get_callbackAttribute, NULL } }, + { { &set_callbackAttribute, NULL } }, + }, + JS_PS_END +}; + +const JSFunctionSpec prototype_functions[] = { + JS_FNSPEC( + "registerCallback", fcn_registerCallback, NULL, + 1, JSPROP_ENUMERATE, NULL), + JS_FNSPEC( + "someOperation", fcn_someOperation, NULL, + 0, JSPROP_ENUMERATE, NULL), + JS_FS_END +}; + +const JSPropertySpec interface_object_properties[] = { + JS_PS_END +}; + +const JSFunctionSpec interface_object_functions[] = { + JS_FS_END +}; + +const JSPropertySpec own_properties[] = { + JS_PS_END +}; + +void InitializePrototypeAndInterfaceObject( + InterfaceData* interface_data, JSContext* context, + JS::HandleObject global_object) { + DCHECK(!interface_data->prototype); + DCHECK(!interface_data->interface_object); + DCHECK(JS_IsGlobalObject(global_object)); + + JS::RootedObject parent_prototype( + context, JS_GetObjectPrototype(context, global_object)); + DCHECK(parent_prototype); + + interface_data->prototype = JS_NewObjectWithGivenProto( + context, &prototype_class_definition, parent_prototype + ); + + JS::RootedObject rooted_prototype(context, interface_data->prototype); + bool success = JS_DefineProperties( + context, + rooted_prototype, + prototype_properties); + + DCHECK(success); + success = JS_DefineFunctions( + context, rooted_prototype, prototype_functions); + DCHECK(success); + + JS::RootedObject function_prototype( + context, JS_GetFunctionPrototype(context, global_object)); + DCHECK(function_prototype); + // Create the Interface object. + interface_data->interface_object = JS_NewObjectWithGivenProto( + context, &interface_object_class_definition, + function_prototype); + + // Add the InterfaceObject.name property. + JS::RootedObject rooted_interface_object( + context, interface_data->interface_object); + JS::RootedValue name_value(context); + const char name[] = + "CallbackInterfaceInterface"; + name_value.setString(JS_NewStringCopyZ(context, name)); + success = JS_DefineProperty( + context, rooted_interface_object, "name", name_value, JSPROP_READONLY, + NULL, NULL); + DCHECK(success); + + // Define interface object properties (including constants). + success = JS_DefineProperties(context, rooted_interface_object, + interface_object_properties); + DCHECK(success); + // Define interface object functions (static). + success = JS_DefineFunctions(context, rooted_interface_object, + interface_object_functions); + DCHECK(success); + + // Set the Prototype.constructor and Constructor.prototype properties. + DCHECK(interface_data->interface_object); + DCHECK(interface_data->prototype); + success = JS_LinkConstructorAndPrototype( + context, + rooted_interface_object, + rooted_prototype); + DCHECK(success); +} + +InterfaceData* GetInterfaceData(JSContext* context) { + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + // Use the address of the properties definition for this interface as a + // unique key for looking up the InterfaceData for this interface. + intptr_t key = reinterpret_cast<intptr_t>(&own_properties); + InterfaceData* interface_data = global_environment->GetInterfaceData(key); + if (!interface_data) { + interface_data = new InterfaceData(); + DCHECK(interface_data); + global_environment->CacheInterfaceData(key, interface_data); + DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key)); + } + return interface_data; +} + +} // namespace + +// static +JSObject* MozjsCallbackInterfaceInterface::CreateProxy( + JSContext* context, const scoped_refptr<Wrappable>& wrappable) { + DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); + JS::RootedObject global_object( + context, + MozjsGlobalEnvironment::GetFromContext(context)->global_object()); + DCHECK(global_object); + + InterfaceData* interface_data = GetInterfaceData(context); + JS::RootedObject prototype(context, GetPrototype(context, global_object)); + DCHECK(prototype); + JS::RootedObject new_object( + context, + JS_NewObjectWithGivenProto( + context, &instance_class_definition, prototype)); + DCHECK(new_object); + JS::RootedObject proxy(context, + ProxyHandler::NewProxy( + context, proxy_handler.Pointer(), new_object, prototype)); + WrapperPrivate::AddPrivateData(context, proxy, wrappable); + return proxy; +} + +// static +const JSClass* MozjsCallbackInterfaceInterface::PrototypeClass( + JSContext* context) { + DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); + JS::RootedObject global_object( + context, + MozjsGlobalEnvironment::GetFromContext(context)->global_object()); + DCHECK(global_object); + + JS::RootedObject prototype(context, GetPrototype(context, global_object)); + const JSClass* proto_class = JS_GetClass(prototype); + return proto_class; +} + +// static +JSObject* MozjsCallbackInterfaceInterface::GetPrototype( + JSContext* context, JS::HandleObject global_object) { + DCHECK(JS_IsGlobalObject(global_object)); + + InterfaceData* interface_data = GetInterfaceData(context); + if (!interface_data->prototype) { + // Create new prototype that has all the props and methods + InitializePrototypeAndInterfaceObject( + interface_data, context, global_object); + } + DCHECK(interface_data->prototype); + return interface_data->prototype; +} + +// static +JSObject* MozjsCallbackInterfaceInterface::GetInterfaceObject( + JSContext* context, JS::HandleObject global_object) { + DCHECK(JS_IsGlobalObject(global_object)); + + InterfaceData* interface_data = GetInterfaceData(context); + if (!interface_data->interface_object) { + InitializePrototypeAndInterfaceObject( + interface_data, context, global_object); + } + DCHECK(interface_data->interface_object); + return interface_data->interface_object; +} + + +namespace { +} // namespace + + +} // namespace testing +} // namespace bindings +} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_callback_interface_interface.h b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_callback_interface_interface.h new file mode 100644 index 0000000..7a46e30 --- /dev/null +++ b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_callback_interface_interface.h
@@ -0,0 +1,52 @@ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// clang-format off + +// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! +// Auto-generated from template: bindings/mozjs-45/templates/interface.h.template + +#ifndef MozjsCallbackInterfaceInterface_h +#define MozjsCallbackInterfaceInterface_h + +#include "base/hash_tables.h" +#include "base/lazy_instance.h" +#include "base/memory/ref_counted.h" +#include "base/threading/thread_checker.h" +#include "cobalt/base/polymorphic_downcast.h" +#include "cobalt/script/wrappable.h" +#include "cobalt/bindings/testing/callback_interface_interface.h" + +#include "third_party/mozjs-45/js/src/jsapi.h" + +namespace cobalt { +namespace bindings { +namespace testing { + +class MozjsCallbackInterfaceInterface { + public: + static JSObject* CreateProxy(JSContext* context, + const scoped_refptr<script::Wrappable>& wrappable); + static const JSClass* PrototypeClass(JSContext* context); + static JSObject* GetPrototype(JSContext* context, + JS::HandleObject global_object); + static JSObject* GetInterfaceObject(JSContext* context, + JS::HandleObject global_object); +}; + +} // namespace testing +} // namespace bindings +} // namespace cobalt + +#endif // MozjsCallbackInterfaceInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_conditional_interface.cc b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_conditional_interface.cc new file mode 100644 index 0000000..80f3921 --- /dev/null +++ b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_conditional_interface.cc
@@ -0,0 +1,668 @@ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// clang-format off + +// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! +// Auto-generated from template: bindings/mozjs-45/templates/interface.cc.template + +#if defined(ENABLE_CONDITIONAL_INTERFACE) + +#include "cobalt/bindings/testing/mozjs_conditional_interface.h" + +#include "base/debug/trace_event.h" +#include "cobalt/base/polymorphic_downcast.h" +#include "cobalt/script/global_environment.h" +#include "cobalt/script/opaque_handle.h" +#include "cobalt/script/script_value.h" + +#include "base/lazy_instance.h" +#include "cobalt/script/exception_state.h" +#include "cobalt/script/mozjs-45/callback_function_conversion.h" +#include "cobalt/script/mozjs-45/conversion_helpers.h" +#include "cobalt/script/mozjs-45/mozjs_callback_function.h" +#include "cobalt/script/mozjs-45/mozjs_exception_state.h" +#include "cobalt/script/mozjs-45/mozjs_global_environment.h" +#include "cobalt/script/mozjs-45/mozjs_object_handle.h" +#include "cobalt/script/mozjs-45/mozjs_property_enumerator.h" +#include "cobalt/script/mozjs-45/mozjs_user_object_holder.h" +#include "cobalt/script/mozjs-45/proxy_handler.h" +#include "cobalt/script/mozjs-45/type_traits.h" +#include "cobalt/script/mozjs-45/wrapper_factory.h" +#include "cobalt/script/mozjs-45/wrapper_private.h" +#include "cobalt/script/property_enumerator.h" +#include "cobalt/script/sequence.h" +#include "third_party/mozjs-45/js/src/jsapi.h" +#include "third_party/mozjs-45/js/src/jsfriendapi.h" + +namespace { +using cobalt::bindings::testing::ConditionalInterface; +using cobalt::bindings::testing::MozjsConditionalInterface; +using cobalt::script::CallbackInterfaceTraits; +using cobalt::script::GlobalEnvironment; +using cobalt::script::OpaqueHandle; +using cobalt::script::OpaqueHandleHolder; +using cobalt::script::ScriptValue; +using cobalt::script::Wrappable; + +using cobalt::script::CallbackFunction; +using cobalt::script::CallbackInterfaceTraits; +using cobalt::script::ExceptionState; +using cobalt::script::Wrappable; +using cobalt::script::mozjs::FromJSValue; +using cobalt::script::mozjs::InterfaceData; +using cobalt::script::mozjs::MozjsCallbackFunction; +using cobalt::script::mozjs::MozjsExceptionState; +using cobalt::script::mozjs::MozjsGlobalEnvironment; +using cobalt::script::mozjs::MozjsPropertyEnumerator; +using cobalt::script::mozjs::MozjsUserObjectHolder; +using cobalt::script::mozjs::ProxyHandler; +using cobalt::script::mozjs::ToJSValue; +using cobalt::script::mozjs::TypeTraits; +using cobalt::script::mozjs::WrapperFactory; +using cobalt::script::mozjs::WrapperPrivate; +using cobalt::script::mozjs::kConversionFlagNullable; +using cobalt::script::mozjs::kConversionFlagRestricted; +using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString; +using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString; +using cobalt::script::mozjs::kNoConversionFlags; +} // namespace + +namespace cobalt { +namespace bindings { +namespace testing { + +namespace { + +class MozjsConditionalInterfaceHandler : public ProxyHandler { + public: + MozjsConditionalInterfaceHandler() + : ProxyHandler(indexed_property_hooks, named_property_hooks) {} + + private: + static NamedPropertyHooks named_property_hooks; + static IndexedPropertyHooks indexed_property_hooks; +}; + +ProxyHandler::NamedPropertyHooks +MozjsConditionalInterfaceHandler::named_property_hooks = { + NULL, + NULL, + NULL, + NULL, + NULL, +}; +ProxyHandler::IndexedPropertyHooks +MozjsConditionalInterfaceHandler::indexed_property_hooks = { + NULL, + NULL, + NULL, + NULL, + NULL, +}; + +static base::LazyInstance<MozjsConditionalInterfaceHandler> + proxy_handler; + +bool HasInstance(JSContext *context, JS::HandleObject type, + JS::MutableHandleValue vp, bool *success) { + JS::RootedObject global_object( + context, JS_GetGlobalForObject(context, type)); + DCHECK(global_object); + + JS::RootedObject prototype( + context, MozjsConditionalInterface::GetPrototype(context, global_object)); + + // |IsDelegate| walks the prototype chain of an object returning true if + // .prototype is found. + bool is_delegate; + if (!IsDelegate(context, prototype, vp, &is_delegate)) { + *success = false; + return false; + } + + *success = is_delegate; + return true; +} + +const JSClass instance_class_definition = { + "ConditionalInterface", + 0 | JSCLASS_HAS_PRIVATE, + NULL, // addProperty + NULL, // delProperty + NULL, // getProperty + NULL, // setProperty + NULL, // enumerate + NULL, // resolve + NULL, // mayResolve + &WrapperPrivate::Finalizer, // finalize + NULL, // call + NULL, // hasInstance + NULL, // construct + &WrapperPrivate::Trace, // trace +}; + +const JSClass prototype_class_definition = { + "ConditionalInterfacePrototype", +}; + +const JSClass interface_object_class_definition = { + "ConditionalInterfaceConstructor", + 0, + NULL, // addProperty + NULL, // delProperty + NULL, // getProperty + NULL, // setProperty + NULL, // enumerate + NULL, // resolve + NULL, // mayResolve + NULL, // finalize + NULL, // call + &HasInstance, + NULL, +}; + +#if defined(ENABLE_CONDITIONAL_PROPERTY) +bool get_enabledAttribute( + JSContext* context, unsigned argc, JS::Value* vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + const JSClass* proto_class = + MozjsConditionalInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<ConditionalInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + ConditionalInterface* impl = + wrapper_private->wrappable<ConditionalInterface>().get(); + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->enabled_attribute(), + &result_value); + } + if (!exception_state.is_exception_set()) { + args.rval().set(result_value); + } + return !exception_state.is_exception_set(); +} + +bool set_enabledAttribute( + JSContext* context, unsigned argc, JS::Value* vp) { + + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + + const JSClass* proto_class = + MozjsConditionalInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<ConditionalInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + ConditionalInterface* impl = + wrapper_private->wrappable<ConditionalInterface>().get(); + TypeTraits<int32_t >::ConversionType value; + if (args.length() != 1) { + NOTREACHED(); + return false; + } + FromJSValue(context, args[0], kNoConversionFlags, &exception_state, + &value); + if (exception_state.is_exception_set()) { + return false; + } + + impl->set_enabled_attribute(value); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + +#endif // ENABLE_CONDITIONAL_PROPERTY +#if defined(NO_ENABLE_CONDITIONAL_PROPERTY) +bool get_disabledAttribute( + JSContext* context, unsigned argc, JS::Value* vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + const JSClass* proto_class = + MozjsConditionalInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<ConditionalInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + ConditionalInterface* impl = + wrapper_private->wrappable<ConditionalInterface>().get(); + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->disabled_attribute(), + &result_value); + } + if (!exception_state.is_exception_set()) { + args.rval().set(result_value); + } + return !exception_state.is_exception_set(); +} + +bool set_disabledAttribute( + JSContext* context, unsigned argc, JS::Value* vp) { + + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + + const JSClass* proto_class = + MozjsConditionalInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<ConditionalInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + ConditionalInterface* impl = + wrapper_private->wrappable<ConditionalInterface>().get(); + TypeTraits<int32_t >::ConversionType value; + if (args.length() != 1) { + NOTREACHED(); + return false; + } + FromJSValue(context, args[0], kNoConversionFlags, &exception_state, + &value); + if (exception_state.is_exception_set()) { + return false; + } + + impl->set_disabled_attribute(value); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + +#endif // NO_ENABLE_CONDITIONAL_PROPERTY +#if defined(NO_ENABLE_CONDITIONAL_PROPERTY) +bool fcn_disabledOperation( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + const JSClass* proto_class = + MozjsConditionalInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<ConditionalInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + ConditionalInterface* impl = + wrapper_private->wrappable<ConditionalInterface>().get(); + + impl->DisabledOperation(); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + +#endif // NO_ENABLE_CONDITIONAL_PROPERTY +#if defined(ENABLE_CONDITIONAL_PROPERTY) +bool fcn_enabledOperation( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + const JSClass* proto_class = + MozjsConditionalInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<ConditionalInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + ConditionalInterface* impl = + wrapper_private->wrappable<ConditionalInterface>().get(); + + impl->EnabledOperation(); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + +#endif // ENABLE_CONDITIONAL_PROPERTY + + +const JSPropertySpec prototype_properties[] = { +#if defined(ENABLE_CONDITIONAL_PROPERTY) + { // Read/Write property + "enabledAttribute", + JSPROP_SHARED | JSPROP_ENUMERATE, + { { &get_enabledAttribute, NULL } }, + { { &set_enabledAttribute, NULL } }, + }, +#endif // ENABLE_CONDITIONAL_PROPERTY +#if defined(NO_ENABLE_CONDITIONAL_PROPERTY) + { // Read/Write property + "disabledAttribute", + JSPROP_SHARED | JSPROP_ENUMERATE, + { { &get_disabledAttribute, NULL } }, + { { &set_disabledAttribute, NULL } }, + }, +#endif // NO_ENABLE_CONDITIONAL_PROPERTY + JS_PS_END +}; + +const JSFunctionSpec prototype_functions[] = { + +#if defined(NO_ENABLE_CONDITIONAL_PROPERTY) + + JS_FNSPEC( + "disabledOperation", fcn_disabledOperation, NULL, + 0, JSPROP_ENUMERATE, NULL), +#endif // NO_ENABLE_CONDITIONAL_PROPERTY + +#if defined(ENABLE_CONDITIONAL_PROPERTY) + + JS_FNSPEC( + "enabledOperation", fcn_enabledOperation, NULL, + 0, JSPROP_ENUMERATE, NULL), +#endif // ENABLE_CONDITIONAL_PROPERTY + JS_FS_END +}; + +const JSPropertySpec interface_object_properties[] = { + JS_PS_END +}; + +const JSFunctionSpec interface_object_functions[] = { + JS_FS_END +}; + +const JSPropertySpec own_properties[] = { + JS_PS_END +}; + +void InitializePrototypeAndInterfaceObject( + InterfaceData* interface_data, JSContext* context, + JS::HandleObject global_object) { + DCHECK(!interface_data->prototype); + DCHECK(!interface_data->interface_object); + DCHECK(JS_IsGlobalObject(global_object)); + + JS::RootedObject parent_prototype( + context, JS_GetObjectPrototype(context, global_object)); + DCHECK(parent_prototype); + + interface_data->prototype = JS_NewObjectWithGivenProto( + context, &prototype_class_definition, parent_prototype + ); + + JS::RootedObject rooted_prototype(context, interface_data->prototype); + bool success = JS_DefineProperties( + context, + rooted_prototype, + prototype_properties); + + DCHECK(success); + success = JS_DefineFunctions( + context, rooted_prototype, prototype_functions); + DCHECK(success); + + JS::RootedObject function_prototype( + context, JS_GetFunctionPrototype(context, global_object)); + DCHECK(function_prototype); + // Create the Interface object. + interface_data->interface_object = JS_NewObjectWithGivenProto( + context, &interface_object_class_definition, + function_prototype); + + // Add the InterfaceObject.name property. + JS::RootedObject rooted_interface_object( + context, interface_data->interface_object); + JS::RootedValue name_value(context); + const char name[] = + "ConditionalInterface"; + name_value.setString(JS_NewStringCopyZ(context, name)); + success = JS_DefineProperty( + context, rooted_interface_object, "name", name_value, JSPROP_READONLY, + NULL, NULL); + DCHECK(success); + + // Define interface object properties (including constants). + success = JS_DefineProperties(context, rooted_interface_object, + interface_object_properties); + DCHECK(success); + // Define interface object functions (static). + success = JS_DefineFunctions(context, rooted_interface_object, + interface_object_functions); + DCHECK(success); + + // Set the Prototype.constructor and Constructor.prototype properties. + DCHECK(interface_data->interface_object); + DCHECK(interface_data->prototype); + success = JS_LinkConstructorAndPrototype( + context, + rooted_interface_object, + rooted_prototype); + DCHECK(success); +} + +InterfaceData* GetInterfaceData(JSContext* context) { + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + // Use the address of the properties definition for this interface as a + // unique key for looking up the InterfaceData for this interface. + intptr_t key = reinterpret_cast<intptr_t>(&own_properties); + InterfaceData* interface_data = global_environment->GetInterfaceData(key); + if (!interface_data) { + interface_data = new InterfaceData(); + DCHECK(interface_data); + global_environment->CacheInterfaceData(key, interface_data); + DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key)); + } + return interface_data; +} + +} // namespace + +// static +JSObject* MozjsConditionalInterface::CreateProxy( + JSContext* context, const scoped_refptr<Wrappable>& wrappable) { + DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); + JS::RootedObject global_object( + context, + MozjsGlobalEnvironment::GetFromContext(context)->global_object()); + DCHECK(global_object); + + InterfaceData* interface_data = GetInterfaceData(context); + JS::RootedObject prototype(context, GetPrototype(context, global_object)); + DCHECK(prototype); + JS::RootedObject new_object( + context, + JS_NewObjectWithGivenProto( + context, &instance_class_definition, prototype)); + DCHECK(new_object); + JS::RootedObject proxy(context, + ProxyHandler::NewProxy( + context, proxy_handler.Pointer(), new_object, prototype)); + WrapperPrivate::AddPrivateData(context, proxy, wrappable); + return proxy; +} + +// static +const JSClass* MozjsConditionalInterface::PrototypeClass( + JSContext* context) { + DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); + JS::RootedObject global_object( + context, + MozjsGlobalEnvironment::GetFromContext(context)->global_object()); + DCHECK(global_object); + + JS::RootedObject prototype(context, GetPrototype(context, global_object)); + const JSClass* proto_class = JS_GetClass(prototype); + return proto_class; +} + +// static +JSObject* MozjsConditionalInterface::GetPrototype( + JSContext* context, JS::HandleObject global_object) { + DCHECK(JS_IsGlobalObject(global_object)); + + InterfaceData* interface_data = GetInterfaceData(context); + if (!interface_data->prototype) { + // Create new prototype that has all the props and methods + InitializePrototypeAndInterfaceObject( + interface_data, context, global_object); + } + DCHECK(interface_data->prototype); + return interface_data->prototype; +} + +// static +JSObject* MozjsConditionalInterface::GetInterfaceObject( + JSContext* context, JS::HandleObject global_object) { + DCHECK(JS_IsGlobalObject(global_object)); + + InterfaceData* interface_data = GetInterfaceData(context); + if (!interface_data->interface_object) { + InitializePrototypeAndInterfaceObject( + interface_data, context, global_object); + } + DCHECK(interface_data->interface_object); + return interface_data->interface_object; +} + + +namespace { +} // namespace + + +} // namespace testing +} // namespace bindings +} // namespace cobalt +#endif // defined(ENABLE_CONDITIONAL_INTERFACE)
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_conditional_interface.h b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_conditional_interface.h new file mode 100644 index 0000000..a1a84c4 --- /dev/null +++ b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_conditional_interface.h
@@ -0,0 +1,56 @@ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// clang-format off + +// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! +// Auto-generated from template: bindings/mozjs-45/templates/interface.h.template + +#ifndef MozjsConditionalInterface_h +#define MozjsConditionalInterface_h + +#if defined(ENABLE_CONDITIONAL_INTERFACE) + +#include "base/hash_tables.h" +#include "base/lazy_instance.h" +#include "base/memory/ref_counted.h" +#include "base/threading/thread_checker.h" +#include "cobalt/base/polymorphic_downcast.h" +#include "cobalt/script/wrappable.h" +#include "cobalt/bindings/testing/conditional_interface.h" + +#include "third_party/mozjs-45/js/src/jsapi.h" + +namespace cobalt { +namespace bindings { +namespace testing { + +class MozjsConditionalInterface { + public: + static JSObject* CreateProxy(JSContext* context, + const scoped_refptr<script::Wrappable>& wrappable); + static const JSClass* PrototypeClass(JSContext* context); + static JSObject* GetPrototype(JSContext* context, + JS::HandleObject global_object); + static JSObject* GetInterfaceObject(JSContext* context, + JS::HandleObject global_object); +}; + +} // namespace testing +} // namespace bindings +} // namespace cobalt + +#endif // defined(ENABLE_CONDITIONAL_INTERFACE) + +#endif // MozjsConditionalInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_constants_interface.cc b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_constants_interface.cc new file mode 100644 index 0000000..7264542 --- /dev/null +++ b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_constants_interface.cc
@@ -0,0 +1,410 @@ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// clang-format off + +// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! +// Auto-generated from template: bindings/mozjs-45/templates/interface.cc.template + +#include "cobalt/bindings/testing/mozjs_constants_interface.h" + +#include "base/debug/trace_event.h" +#include "cobalt/base/polymorphic_downcast.h" +#include "cobalt/script/global_environment.h" +#include "cobalt/script/opaque_handle.h" +#include "cobalt/script/script_value.h" + +#include "base/lazy_instance.h" +#include "cobalt/script/exception_state.h" +#include "cobalt/script/mozjs-45/callback_function_conversion.h" +#include "cobalt/script/mozjs-45/conversion_helpers.h" +#include "cobalt/script/mozjs-45/mozjs_callback_function.h" +#include "cobalt/script/mozjs-45/mozjs_exception_state.h" +#include "cobalt/script/mozjs-45/mozjs_global_environment.h" +#include "cobalt/script/mozjs-45/mozjs_object_handle.h" +#include "cobalt/script/mozjs-45/mozjs_property_enumerator.h" +#include "cobalt/script/mozjs-45/mozjs_user_object_holder.h" +#include "cobalt/script/mozjs-45/proxy_handler.h" +#include "cobalt/script/mozjs-45/type_traits.h" +#include "cobalt/script/mozjs-45/wrapper_factory.h" +#include "cobalt/script/mozjs-45/wrapper_private.h" +#include "cobalt/script/property_enumerator.h" +#include "cobalt/script/sequence.h" +#include "third_party/mozjs-45/js/src/jsapi.h" +#include "third_party/mozjs-45/js/src/jsfriendapi.h" + +namespace { +using cobalt::bindings::testing::ConstantsInterface; +using cobalt::bindings::testing::MozjsConstantsInterface; +using cobalt::script::CallbackInterfaceTraits; +using cobalt::script::GlobalEnvironment; +using cobalt::script::OpaqueHandle; +using cobalt::script::OpaqueHandleHolder; +using cobalt::script::ScriptValue; +using cobalt::script::Wrappable; + +using cobalt::script::CallbackFunction; +using cobalt::script::CallbackInterfaceTraits; +using cobalt::script::ExceptionState; +using cobalt::script::Wrappable; +using cobalt::script::mozjs::FromJSValue; +using cobalt::script::mozjs::InterfaceData; +using cobalt::script::mozjs::MozjsCallbackFunction; +using cobalt::script::mozjs::MozjsExceptionState; +using cobalt::script::mozjs::MozjsGlobalEnvironment; +using cobalt::script::mozjs::MozjsPropertyEnumerator; +using cobalt::script::mozjs::MozjsUserObjectHolder; +using cobalt::script::mozjs::ProxyHandler; +using cobalt::script::mozjs::ToJSValue; +using cobalt::script::mozjs::TypeTraits; +using cobalt::script::mozjs::WrapperFactory; +using cobalt::script::mozjs::WrapperPrivate; +using cobalt::script::mozjs::kConversionFlagNullable; +using cobalt::script::mozjs::kConversionFlagRestricted; +using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString; +using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString; +using cobalt::script::mozjs::kNoConversionFlags; +} // namespace + +namespace cobalt { +namespace bindings { +namespace testing { + +namespace { + +class MozjsConstantsInterfaceHandler : public ProxyHandler { + public: + MozjsConstantsInterfaceHandler() + : ProxyHandler(indexed_property_hooks, named_property_hooks) {} + + private: + static NamedPropertyHooks named_property_hooks; + static IndexedPropertyHooks indexed_property_hooks; +}; + +ProxyHandler::NamedPropertyHooks +MozjsConstantsInterfaceHandler::named_property_hooks = { + NULL, + NULL, + NULL, + NULL, + NULL, +}; +ProxyHandler::IndexedPropertyHooks +MozjsConstantsInterfaceHandler::indexed_property_hooks = { + NULL, + NULL, + NULL, + NULL, + NULL, +}; + +static base::LazyInstance<MozjsConstantsInterfaceHandler> + proxy_handler; + +bool get_INTEGER_CONSTANT( + JSContext* context, unsigned argc, JS::Value* vp) { + COMPILE_ASSERT(ConstantsInterface::kIntegerConstant == 5, + ValueForConstantsInterface_kIntegerConstantDoesNotMatchIDL); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + ToJSValue(context, 5, &result_value); + if (!exception_state.is_exception_set()) { + args.rval().set(result_value); + } + return !exception_state.is_exception_set(); +} + +bool get_DOUBLE_CONSTANT( + JSContext* context, unsigned argc, JS::Value* vp) { + DCHECK_EQ(2.718, ConstantsInterface::kDoubleConstant) << + "The value for ConstantsInterface::kDoubleConstant does not match " + "the value in the interface definition."; + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + ToJSValue(context, 2.718, &result_value); + if (!exception_state.is_exception_set()) { + args.rval().set(result_value); + } + return !exception_state.is_exception_set(); +} + +bool HasInstance(JSContext *context, JS::HandleObject type, + JS::MutableHandleValue vp, bool *success) { + JS::RootedObject global_object( + context, JS_GetGlobalForObject(context, type)); + DCHECK(global_object); + + JS::RootedObject prototype( + context, MozjsConstantsInterface::GetPrototype(context, global_object)); + + // |IsDelegate| walks the prototype chain of an object returning true if + // .prototype is found. + bool is_delegate; + if (!IsDelegate(context, prototype, vp, &is_delegate)) { + *success = false; + return false; + } + + *success = is_delegate; + return true; +} + +const JSClass instance_class_definition = { + "ConstantsInterface", + 0 | JSCLASS_HAS_PRIVATE, + NULL, // addProperty + NULL, // delProperty + NULL, // getProperty + NULL, // setProperty + NULL, // enumerate + NULL, // resolve + NULL, // mayResolve + &WrapperPrivate::Finalizer, // finalize + NULL, // call + NULL, // hasInstance + NULL, // construct + &WrapperPrivate::Trace, // trace +}; + +const JSClass prototype_class_definition = { + "ConstantsInterfacePrototype", +}; + +const JSClass interface_object_class_definition = { + "ConstantsInterfaceConstructor", + 0, + NULL, // addProperty + NULL, // delProperty + NULL, // getProperty + NULL, // setProperty + NULL, // enumerate + NULL, // resolve + NULL, // mayResolve + NULL, // finalize + NULL, // call + &HasInstance, + NULL, +}; + + + +const JSPropertySpec prototype_properties[] = { + { + "INTEGER_CONSTANT", + JSPROP_PERMANENT | JSPROP_SHARED | JSPROP_ENUMERATE, + { { &get_INTEGER_CONSTANT, NULL } }, + JSNATIVE_WRAPPER(NULL) + }, + { + "DOUBLE_CONSTANT", + JSPROP_PERMANENT | JSPROP_SHARED | JSPROP_ENUMERATE, + { { &get_DOUBLE_CONSTANT, NULL } }, + JSNATIVE_WRAPPER(NULL) + }, + JS_PS_END +}; + +const JSFunctionSpec prototype_functions[] = { + JS_FS_END +}; + +const JSPropertySpec interface_object_properties[] = { + { + "INTEGER_CONSTANT", + JSPROP_SHARED | JSPROP_ENUMERATE, + { { &get_INTEGER_CONSTANT, NULL } }, + JSNATIVE_WRAPPER(NULL), + }, + + { + "DOUBLE_CONSTANT", + JSPROP_SHARED | JSPROP_ENUMERATE, + { { &get_DOUBLE_CONSTANT, NULL } }, + JSNATIVE_WRAPPER(NULL), + }, + + JS_PS_END +}; + +const JSFunctionSpec interface_object_functions[] = { + JS_FS_END +}; + +const JSPropertySpec own_properties[] = { + JS_PS_END +}; + +void InitializePrototypeAndInterfaceObject( + InterfaceData* interface_data, JSContext* context, + JS::HandleObject global_object) { + DCHECK(!interface_data->prototype); + DCHECK(!interface_data->interface_object); + DCHECK(JS_IsGlobalObject(global_object)); + + JS::RootedObject parent_prototype( + context, JS_GetObjectPrototype(context, global_object)); + DCHECK(parent_prototype); + + interface_data->prototype = JS_NewObjectWithGivenProto( + context, &prototype_class_definition, parent_prototype + ); + + JS::RootedObject rooted_prototype(context, interface_data->prototype); + bool success = JS_DefineProperties( + context, + rooted_prototype, + prototype_properties); + + DCHECK(success); + success = JS_DefineFunctions( + context, rooted_prototype, prototype_functions); + DCHECK(success); + + JS::RootedObject function_prototype( + context, JS_GetFunctionPrototype(context, global_object)); + DCHECK(function_prototype); + // Create the Interface object. + interface_data->interface_object = JS_NewObjectWithGivenProto( + context, &interface_object_class_definition, + function_prototype); + + // Add the InterfaceObject.name property. + JS::RootedObject rooted_interface_object( + context, interface_data->interface_object); + JS::RootedValue name_value(context); + const char name[] = + "ConstantsInterface"; + name_value.setString(JS_NewStringCopyZ(context, name)); + success = JS_DefineProperty( + context, rooted_interface_object, "name", name_value, JSPROP_READONLY, + NULL, NULL); + DCHECK(success); + + // Define interface object properties (including constants). + success = JS_DefineProperties(context, rooted_interface_object, + interface_object_properties); + DCHECK(success); + // Define interface object functions (static). + success = JS_DefineFunctions(context, rooted_interface_object, + interface_object_functions); + DCHECK(success); + + // Set the Prototype.constructor and Constructor.prototype properties. + DCHECK(interface_data->interface_object); + DCHECK(interface_data->prototype); + success = JS_LinkConstructorAndPrototype( + context, + rooted_interface_object, + rooted_prototype); + DCHECK(success); +} + +InterfaceData* GetInterfaceData(JSContext* context) { + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + // Use the address of the properties definition for this interface as a + // unique key for looking up the InterfaceData for this interface. + intptr_t key = reinterpret_cast<intptr_t>(&own_properties); + InterfaceData* interface_data = global_environment->GetInterfaceData(key); + if (!interface_data) { + interface_data = new InterfaceData(); + DCHECK(interface_data); + global_environment->CacheInterfaceData(key, interface_data); + DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key)); + } + return interface_data; +} + +} // namespace + +// static +JSObject* MozjsConstantsInterface::CreateProxy( + JSContext* context, const scoped_refptr<Wrappable>& wrappable) { + DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); + JS::RootedObject global_object( + context, + MozjsGlobalEnvironment::GetFromContext(context)->global_object()); + DCHECK(global_object); + + InterfaceData* interface_data = GetInterfaceData(context); + JS::RootedObject prototype(context, GetPrototype(context, global_object)); + DCHECK(prototype); + JS::RootedObject new_object( + context, + JS_NewObjectWithGivenProto( + context, &instance_class_definition, prototype)); + DCHECK(new_object); + JS::RootedObject proxy(context, + ProxyHandler::NewProxy( + context, proxy_handler.Pointer(), new_object, prototype)); + WrapperPrivate::AddPrivateData(context, proxy, wrappable); + return proxy; +} + +// static +const JSClass* MozjsConstantsInterface::PrototypeClass( + JSContext* context) { + DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); + JS::RootedObject global_object( + context, + MozjsGlobalEnvironment::GetFromContext(context)->global_object()); + DCHECK(global_object); + + JS::RootedObject prototype(context, GetPrototype(context, global_object)); + const JSClass* proto_class = JS_GetClass(prototype); + return proto_class; +} + +// static +JSObject* MozjsConstantsInterface::GetPrototype( + JSContext* context, JS::HandleObject global_object) { + DCHECK(JS_IsGlobalObject(global_object)); + + InterfaceData* interface_data = GetInterfaceData(context); + if (!interface_data->prototype) { + // Create new prototype that has all the props and methods + InitializePrototypeAndInterfaceObject( + interface_data, context, global_object); + } + DCHECK(interface_data->prototype); + return interface_data->prototype; +} + +// static +JSObject* MozjsConstantsInterface::GetInterfaceObject( + JSContext* context, JS::HandleObject global_object) { + DCHECK(JS_IsGlobalObject(global_object)); + + InterfaceData* interface_data = GetInterfaceData(context); + if (!interface_data->interface_object) { + InitializePrototypeAndInterfaceObject( + interface_data, context, global_object); + } + DCHECK(interface_data->interface_object); + return interface_data->interface_object; +} + + +namespace { +} // namespace + + +} // namespace testing +} // namespace bindings +} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_constants_interface.h b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_constants_interface.h new file mode 100644 index 0000000..b9c75c1 --- /dev/null +++ b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_constants_interface.h
@@ -0,0 +1,52 @@ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// clang-format off + +// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! +// Auto-generated from template: bindings/mozjs-45/templates/interface.h.template + +#ifndef MozjsConstantsInterface_h +#define MozjsConstantsInterface_h + +#include "base/hash_tables.h" +#include "base/lazy_instance.h" +#include "base/memory/ref_counted.h" +#include "base/threading/thread_checker.h" +#include "cobalt/base/polymorphic_downcast.h" +#include "cobalt/script/wrappable.h" +#include "cobalt/bindings/testing/constants_interface.h" + +#include "third_party/mozjs-45/js/src/jsapi.h" + +namespace cobalt { +namespace bindings { +namespace testing { + +class MozjsConstantsInterface { + public: + static JSObject* CreateProxy(JSContext* context, + const scoped_refptr<script::Wrappable>& wrappable); + static const JSClass* PrototypeClass(JSContext* context); + static JSObject* GetPrototype(JSContext* context, + JS::HandleObject global_object); + static JSObject* GetInterfaceObject(JSContext* context, + JS::HandleObject global_object); +}; + +} // namespace testing +} // namespace bindings +} // namespace cobalt + +#endif // MozjsConstantsInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_constructor_interface.cc b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_constructor_interface.cc new file mode 100644 index 0000000..0b636d7 --- /dev/null +++ b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_constructor_interface.cc
@@ -0,0 +1,438 @@ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// clang-format off + +// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! +// Auto-generated from template: bindings/mozjs-45/templates/interface.cc.template + +#include "cobalt/bindings/testing/mozjs_constructor_interface.h" + +#include "base/debug/trace_event.h" +#include "cobalt/base/polymorphic_downcast.h" +#include "cobalt/script/global_environment.h" +#include "cobalt/script/opaque_handle.h" +#include "cobalt/script/script_value.h" + +#include "base/lazy_instance.h" +#include "cobalt/script/exception_state.h" +#include "cobalt/script/mozjs-45/callback_function_conversion.h" +#include "cobalt/script/mozjs-45/conversion_helpers.h" +#include "cobalt/script/mozjs-45/mozjs_callback_function.h" +#include "cobalt/script/mozjs-45/mozjs_exception_state.h" +#include "cobalt/script/mozjs-45/mozjs_global_environment.h" +#include "cobalt/script/mozjs-45/mozjs_object_handle.h" +#include "cobalt/script/mozjs-45/mozjs_property_enumerator.h" +#include "cobalt/script/mozjs-45/mozjs_user_object_holder.h" +#include "cobalt/script/mozjs-45/proxy_handler.h" +#include "cobalt/script/mozjs-45/type_traits.h" +#include "cobalt/script/mozjs-45/wrapper_factory.h" +#include "cobalt/script/mozjs-45/wrapper_private.h" +#include "cobalt/script/property_enumerator.h" +#include "cobalt/script/sequence.h" +#include "third_party/mozjs-45/js/src/jsapi.h" +#include "third_party/mozjs-45/js/src/jsfriendapi.h" + +namespace { +using cobalt::bindings::testing::ConstructorInterface; +using cobalt::bindings::testing::MozjsConstructorInterface; +using cobalt::script::CallbackInterfaceTraits; +using cobalt::script::GlobalEnvironment; +using cobalt::script::OpaqueHandle; +using cobalt::script::OpaqueHandleHolder; +using cobalt::script::ScriptValue; +using cobalt::script::Wrappable; + +using cobalt::script::CallbackFunction; +using cobalt::script::CallbackInterfaceTraits; +using cobalt::script::ExceptionState; +using cobalt::script::Wrappable; +using cobalt::script::mozjs::FromJSValue; +using cobalt::script::mozjs::InterfaceData; +using cobalt::script::mozjs::MozjsCallbackFunction; +using cobalt::script::mozjs::MozjsExceptionState; +using cobalt::script::mozjs::MozjsGlobalEnvironment; +using cobalt::script::mozjs::MozjsPropertyEnumerator; +using cobalt::script::mozjs::MozjsUserObjectHolder; +using cobalt::script::mozjs::ProxyHandler; +using cobalt::script::mozjs::ToJSValue; +using cobalt::script::mozjs::TypeTraits; +using cobalt::script::mozjs::WrapperFactory; +using cobalt::script::mozjs::WrapperPrivate; +using cobalt::script::mozjs::kConversionFlagNullable; +using cobalt::script::mozjs::kConversionFlagRestricted; +using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString; +using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString; +using cobalt::script::mozjs::kNoConversionFlags; +} // namespace + +namespace cobalt { +namespace bindings { +namespace testing { + +namespace { + +class MozjsConstructorInterfaceHandler : public ProxyHandler { + public: + MozjsConstructorInterfaceHandler() + : ProxyHandler(indexed_property_hooks, named_property_hooks) {} + + private: + static NamedPropertyHooks named_property_hooks; + static IndexedPropertyHooks indexed_property_hooks; +}; + +ProxyHandler::NamedPropertyHooks +MozjsConstructorInterfaceHandler::named_property_hooks = { + NULL, + NULL, + NULL, + NULL, + NULL, +}; +ProxyHandler::IndexedPropertyHooks +MozjsConstructorInterfaceHandler::indexed_property_hooks = { + NULL, + NULL, + NULL, + NULL, + NULL, +}; + +static base::LazyInstance<MozjsConstructorInterfaceHandler> + proxy_handler; + +bool Constructor(JSContext* context, unsigned int argc, JS::Value* vp); +bool HasInstance(JSContext *context, JS::HandleObject type, + JS::MutableHandleValue vp, bool *success) { + JS::RootedObject global_object( + context, JS_GetGlobalForObject(context, type)); + DCHECK(global_object); + + JS::RootedObject prototype( + context, MozjsConstructorInterface::GetPrototype(context, global_object)); + + // |IsDelegate| walks the prototype chain of an object returning true if + // .prototype is found. + bool is_delegate; + if (!IsDelegate(context, prototype, vp, &is_delegate)) { + *success = false; + return false; + } + + *success = is_delegate; + return true; +} + +const JSClass instance_class_definition = { + "ConstructorInterface", + 0 | JSCLASS_HAS_PRIVATE, + NULL, // addProperty + NULL, // delProperty + NULL, // getProperty + NULL, // setProperty + NULL, // enumerate + NULL, // resolve + NULL, // mayResolve + &WrapperPrivate::Finalizer, // finalize + NULL, // call + NULL, // hasInstance + NULL, // construct + &WrapperPrivate::Trace, // trace +}; + +const JSClass prototype_class_definition = { + "ConstructorInterfacePrototype", +}; + +const JSClass interface_object_class_definition = { + "ConstructorInterfaceConstructor", + 0, + NULL, // addProperty + NULL, // delProperty + NULL, // getProperty + NULL, // setProperty + NULL, // enumerate + NULL, // resolve + NULL, // mayResolve + NULL, // finalize + NULL, // call + &HasInstance, + Constructor, +}; + + + +const JSPropertySpec prototype_properties[] = { + JS_PS_END +}; + +const JSFunctionSpec prototype_functions[] = { + JS_FS_END +}; + +const JSPropertySpec interface_object_properties[] = { + JS_PS_END +}; + +const JSFunctionSpec interface_object_functions[] = { + JS_FS_END +}; + +const JSPropertySpec own_properties[] = { + JS_PS_END +}; + +void InitializePrototypeAndInterfaceObject( + InterfaceData* interface_data, JSContext* context, + JS::HandleObject global_object) { + DCHECK(!interface_data->prototype); + DCHECK(!interface_data->interface_object); + DCHECK(JS_IsGlobalObject(global_object)); + + JS::RootedObject parent_prototype( + context, JS_GetObjectPrototype(context, global_object)); + DCHECK(parent_prototype); + + interface_data->prototype = JS_NewObjectWithGivenProto( + context, &prototype_class_definition, parent_prototype + ); + + JS::RootedObject rooted_prototype(context, interface_data->prototype); + bool success = JS_DefineProperties( + context, + rooted_prototype, + prototype_properties); + + DCHECK(success); + success = JS_DefineFunctions( + context, rooted_prototype, prototype_functions); + DCHECK(success); + + JS::RootedObject function_prototype( + context, JS_GetFunctionPrototype(context, global_object)); + DCHECK(function_prototype); + // Create the Interface object. + interface_data->interface_object = JS_NewObjectWithGivenProto( + context, &interface_object_class_definition, + function_prototype); + + // Add the InterfaceObject.name property. + JS::RootedObject rooted_interface_object( + context, interface_data->interface_object); + JS::RootedValue name_value(context); + const char name[] = + "ConstructorInterface"; + name_value.setString(JS_NewStringCopyZ(context, name)); + success = JS_DefineProperty( + context, rooted_interface_object, "name", name_value, JSPROP_READONLY, + NULL, NULL); + DCHECK(success); + + // Add the InterfaceObject.length property. It is set to the length of the + // shortest argument list of all overload constructors. + JS::RootedValue length_value(context); + length_value.setInt32(0); + success = JS_DefineProperty( + context, rooted_interface_object, "length", length_value, + JSPROP_READONLY, NULL, NULL); + DCHECK(success); + + // Define interface object properties (including constants). + success = JS_DefineProperties(context, rooted_interface_object, + interface_object_properties); + DCHECK(success); + // Define interface object functions (static). + success = JS_DefineFunctions(context, rooted_interface_object, + interface_object_functions); + DCHECK(success); + + // Set the Prototype.constructor and Constructor.prototype properties. + DCHECK(interface_data->interface_object); + DCHECK(interface_data->prototype); + success = JS_LinkConstructorAndPrototype( + context, + rooted_interface_object, + rooted_prototype); + DCHECK(success); +} + +InterfaceData* GetInterfaceData(JSContext* context) { + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + // Use the address of the properties definition for this interface as a + // unique key for looking up the InterfaceData for this interface. + intptr_t key = reinterpret_cast<intptr_t>(&own_properties); + InterfaceData* interface_data = global_environment->GetInterfaceData(key); + if (!interface_data) { + interface_data = new InterfaceData(); + DCHECK(interface_data); + global_environment->CacheInterfaceData(key, interface_data); + DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key)); + } + return interface_data; +} + +} // namespace + +// static +JSObject* MozjsConstructorInterface::CreateProxy( + JSContext* context, const scoped_refptr<Wrappable>& wrappable) { + DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); + JS::RootedObject global_object( + context, + MozjsGlobalEnvironment::GetFromContext(context)->global_object()); + DCHECK(global_object); + + InterfaceData* interface_data = GetInterfaceData(context); + JS::RootedObject prototype(context, GetPrototype(context, global_object)); + DCHECK(prototype); + JS::RootedObject new_object( + context, + JS_NewObjectWithGivenProto( + context, &instance_class_definition, prototype)); + DCHECK(new_object); + JS::RootedObject proxy(context, + ProxyHandler::NewProxy( + context, proxy_handler.Pointer(), new_object, prototype)); + WrapperPrivate::AddPrivateData(context, proxy, wrappable); + return proxy; +} + +// static +const JSClass* MozjsConstructorInterface::PrototypeClass( + JSContext* context) { + DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); + JS::RootedObject global_object( + context, + MozjsGlobalEnvironment::GetFromContext(context)->global_object()); + DCHECK(global_object); + + JS::RootedObject prototype(context, GetPrototype(context, global_object)); + const JSClass* proto_class = JS_GetClass(prototype); + return proto_class; +} + +// static +JSObject* MozjsConstructorInterface::GetPrototype( + JSContext* context, JS::HandleObject global_object) { + DCHECK(JS_IsGlobalObject(global_object)); + + InterfaceData* interface_data = GetInterfaceData(context); + if (!interface_data->prototype) { + // Create new prototype that has all the props and methods + InitializePrototypeAndInterfaceObject( + interface_data, context, global_object); + } + DCHECK(interface_data->prototype); + return interface_data->prototype; +} + +// static +JSObject* MozjsConstructorInterface::GetInterfaceObject( + JSContext* context, JS::HandleObject global_object) { + DCHECK(JS_IsGlobalObject(global_object)); + + InterfaceData* interface_data = GetInterfaceData(context); + if (!interface_data->interface_object) { + InitializePrototypeAndInterfaceObject( + interface_data, context, global_object); + } + DCHECK(interface_data->interface_object); + return interface_data->interface_object; +} + + +namespace { +bool Constructor1( + JSContext* context, unsigned int argc, JS::Value* vp) { + MozjsExceptionState exception_state(context); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + + scoped_refptr<ConstructorInterface> new_object = + new ConstructorInterface(); + JS::RootedValue result_value(context); + ToJSValue(context, new_object, &result_value); + DCHECK(result_value.isObject()); + args.rval().setObject(result_value.toObject()); + return true; +} + +bool Constructor2( + JSContext* context, unsigned int argc, JS::Value* vp) { + MozjsExceptionState exception_state(context); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + const size_t kMinArguments = 1; + if (args.length() < kMinArguments) { + exception_state.SetSimpleException(script::kInvalidNumberOfArguments); + return false; + } + // Non-optional arguments + TypeTraits<bool >::ConversionType arg; + + DCHECK_LT(0, args.length()); + JS::RootedValue non_optional_value0( + context, args[0]); + FromJSValue(context, + non_optional_value0, + kNoConversionFlags, + &exception_state, &arg); + if (exception_state.is_exception_set()) { + return false; + } + + scoped_refptr<ConstructorInterface> new_object = + new ConstructorInterface(arg); + JS::RootedValue result_value(context); + ToJSValue(context, new_object, &result_value); + DCHECK(result_value.isObject()); + args.rval().setObject(result_value.toObject()); + return true; +} + +bool Constructor(JSContext* context, unsigned int argc, JS::Value* vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + switch(argc) { + case(0): { + // Overload resolution algorithm details found here: + // http://heycam.github.io/webidl/#dfn-overload-resolution-algorithm + if (true) { + return Constructor1( + context, argc, vp); + } + break; + } + case(1): { + // Overload resolution algorithm details found here: + // http://heycam.github.io/webidl/#dfn-overload-resolution-algorithm + if (true) { + return Constructor2( + context, argc, vp); + } + break; + } + } + // Invalid number of args + // http://heycam.github.io/webidl/#dfn-overload-resolution-algorithm + // 4. If S is empty, then throw a TypeError. + MozjsExceptionState exception_state(context); + exception_state.SetSimpleException(script::kInvalidNumberOfArguments); + return false; +} +} // namespace + + +} // namespace testing +} // namespace bindings +} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_constructor_interface.h b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_constructor_interface.h new file mode 100644 index 0000000..6e0407e --- /dev/null +++ b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_constructor_interface.h
@@ -0,0 +1,52 @@ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// clang-format off + +// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! +// Auto-generated from template: bindings/mozjs-45/templates/interface.h.template + +#ifndef MozjsConstructorInterface_h +#define MozjsConstructorInterface_h + +#include "base/hash_tables.h" +#include "base/lazy_instance.h" +#include "base/memory/ref_counted.h" +#include "base/threading/thread_checker.h" +#include "cobalt/base/polymorphic_downcast.h" +#include "cobalt/script/wrappable.h" +#include "cobalt/bindings/testing/constructor_interface.h" + +#include "third_party/mozjs-45/js/src/jsapi.h" + +namespace cobalt { +namespace bindings { +namespace testing { + +class MozjsConstructorInterface { + public: + static JSObject* CreateProxy(JSContext* context, + const scoped_refptr<script::Wrappable>& wrappable); + static const JSClass* PrototypeClass(JSContext* context); + static JSObject* GetPrototype(JSContext* context, + JS::HandleObject global_object); + static JSObject* GetInterfaceObject(JSContext* context, + JS::HandleObject global_object); +}; + +} // namespace testing +} // namespace bindings +} // namespace cobalt + +#endif // MozjsConstructorInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_constructor_with_arguments_interface.cc b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_constructor_with_arguments_interface.cc new file mode 100644 index 0000000..6cad5bb --- /dev/null +++ b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_constructor_with_arguments_interface.cc
@@ -0,0 +1,568 @@ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// clang-format off + +// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! +// Auto-generated from template: bindings/mozjs-45/templates/interface.cc.template + +#include "cobalt/bindings/testing/mozjs_constructor_with_arguments_interface.h" + +#include "base/debug/trace_event.h" +#include "cobalt/base/polymorphic_downcast.h" +#include "cobalt/script/global_environment.h" +#include "cobalt/script/opaque_handle.h" +#include "cobalt/script/script_value.h" + +#include "base/lazy_instance.h" +#include "cobalt/script/exception_state.h" +#include "cobalt/script/mozjs-45/callback_function_conversion.h" +#include "cobalt/script/mozjs-45/conversion_helpers.h" +#include "cobalt/script/mozjs-45/mozjs_callback_function.h" +#include "cobalt/script/mozjs-45/mozjs_exception_state.h" +#include "cobalt/script/mozjs-45/mozjs_global_environment.h" +#include "cobalt/script/mozjs-45/mozjs_object_handle.h" +#include "cobalt/script/mozjs-45/mozjs_property_enumerator.h" +#include "cobalt/script/mozjs-45/mozjs_user_object_holder.h" +#include "cobalt/script/mozjs-45/proxy_handler.h" +#include "cobalt/script/mozjs-45/type_traits.h" +#include "cobalt/script/mozjs-45/wrapper_factory.h" +#include "cobalt/script/mozjs-45/wrapper_private.h" +#include "cobalt/script/property_enumerator.h" +#include "cobalt/script/sequence.h" +#include "third_party/mozjs-45/js/src/jsapi.h" +#include "third_party/mozjs-45/js/src/jsfriendapi.h" + +namespace { +using cobalt::bindings::testing::ConstructorWithArgumentsInterface; +using cobalt::bindings::testing::MozjsConstructorWithArgumentsInterface; +using cobalt::script::CallbackInterfaceTraits; +using cobalt::script::GlobalEnvironment; +using cobalt::script::OpaqueHandle; +using cobalt::script::OpaqueHandleHolder; +using cobalt::script::ScriptValue; +using cobalt::script::Wrappable; + +using cobalt::script::CallbackFunction; +using cobalt::script::CallbackInterfaceTraits; +using cobalt::script::ExceptionState; +using cobalt::script::Wrappable; +using cobalt::script::mozjs::FromJSValue; +using cobalt::script::mozjs::InterfaceData; +using cobalt::script::mozjs::MozjsCallbackFunction; +using cobalt::script::mozjs::MozjsExceptionState; +using cobalt::script::mozjs::MozjsGlobalEnvironment; +using cobalt::script::mozjs::MozjsPropertyEnumerator; +using cobalt::script::mozjs::MozjsUserObjectHolder; +using cobalt::script::mozjs::ProxyHandler; +using cobalt::script::mozjs::ToJSValue; +using cobalt::script::mozjs::TypeTraits; +using cobalt::script::mozjs::WrapperFactory; +using cobalt::script::mozjs::WrapperPrivate; +using cobalt::script::mozjs::kConversionFlagNullable; +using cobalt::script::mozjs::kConversionFlagRestricted; +using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString; +using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString; +using cobalt::script::mozjs::kNoConversionFlags; +} // namespace + +namespace cobalt { +namespace bindings { +namespace testing { + +namespace { + +class MozjsConstructorWithArgumentsInterfaceHandler : public ProxyHandler { + public: + MozjsConstructorWithArgumentsInterfaceHandler() + : ProxyHandler(indexed_property_hooks, named_property_hooks) {} + + private: + static NamedPropertyHooks named_property_hooks; + static IndexedPropertyHooks indexed_property_hooks; +}; + +ProxyHandler::NamedPropertyHooks +MozjsConstructorWithArgumentsInterfaceHandler::named_property_hooks = { + NULL, + NULL, + NULL, + NULL, + NULL, +}; +ProxyHandler::IndexedPropertyHooks +MozjsConstructorWithArgumentsInterfaceHandler::indexed_property_hooks = { + NULL, + NULL, + NULL, + NULL, + NULL, +}; + +static base::LazyInstance<MozjsConstructorWithArgumentsInterfaceHandler> + proxy_handler; + +bool Constructor(JSContext* context, unsigned int argc, JS::Value* vp); +bool HasInstance(JSContext *context, JS::HandleObject type, + JS::MutableHandleValue vp, bool *success) { + JS::RootedObject global_object( + context, JS_GetGlobalForObject(context, type)); + DCHECK(global_object); + + JS::RootedObject prototype( + context, MozjsConstructorWithArgumentsInterface::GetPrototype(context, global_object)); + + // |IsDelegate| walks the prototype chain of an object returning true if + // .prototype is found. + bool is_delegate; + if (!IsDelegate(context, prototype, vp, &is_delegate)) { + *success = false; + return false; + } + + *success = is_delegate; + return true; +} + +const JSClass instance_class_definition = { + "ConstructorWithArgumentsInterface", + 0 | JSCLASS_HAS_PRIVATE, + NULL, // addProperty + NULL, // delProperty + NULL, // getProperty + NULL, // setProperty + NULL, // enumerate + NULL, // resolve + NULL, // mayResolve + &WrapperPrivate::Finalizer, // finalize + NULL, // call + NULL, // hasInstance + NULL, // construct + &WrapperPrivate::Trace, // trace +}; + +const JSClass prototype_class_definition = { + "ConstructorWithArgumentsInterfacePrototype", +}; + +const JSClass interface_object_class_definition = { + "ConstructorWithArgumentsInterfaceConstructor", + 0, + NULL, // addProperty + NULL, // delProperty + NULL, // getProperty + NULL, // setProperty + NULL, // enumerate + NULL, // resolve + NULL, // mayResolve + NULL, // finalize + NULL, // call + &HasInstance, + Constructor, +}; + +bool get_longArg( + JSContext* context, unsigned argc, JS::Value* vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + const JSClass* proto_class = + MozjsConstructorWithArgumentsInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<ConstructorWithArgumentsInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + ConstructorWithArgumentsInterface* impl = + wrapper_private->wrappable<ConstructorWithArgumentsInterface>().get(); + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->long_arg(), + &result_value); + } + if (!exception_state.is_exception_set()) { + args.rval().set(result_value); + } + return !exception_state.is_exception_set(); +} + + +bool get_booleanArg( + JSContext* context, unsigned argc, JS::Value* vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + const JSClass* proto_class = + MozjsConstructorWithArgumentsInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<ConstructorWithArgumentsInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + ConstructorWithArgumentsInterface* impl = + wrapper_private->wrappable<ConstructorWithArgumentsInterface>().get(); + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->boolean_arg(), + &result_value); + } + if (!exception_state.is_exception_set()) { + args.rval().set(result_value); + } + return !exception_state.is_exception_set(); +} + + +bool get_stringArg( + JSContext* context, unsigned argc, JS::Value* vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + const JSClass* proto_class = + MozjsConstructorWithArgumentsInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<ConstructorWithArgumentsInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + ConstructorWithArgumentsInterface* impl = + wrapper_private->wrappable<ConstructorWithArgumentsInterface>().get(); + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->string_arg(), + &result_value); + } + if (!exception_state.is_exception_set()) { + args.rval().set(result_value); + } + return !exception_state.is_exception_set(); +} + + + + +const JSPropertySpec prototype_properties[] = { + { // Readonly attribute + "longArg", + JSPROP_SHARED | JSPROP_ENUMERATE, + { { &get_longArg, NULL } }, + JSNATIVE_WRAPPER(NULL), + }, + { // Readonly attribute + "booleanArg", + JSPROP_SHARED | JSPROP_ENUMERATE, + { { &get_booleanArg, NULL } }, + JSNATIVE_WRAPPER(NULL), + }, + { // Readonly attribute + "stringArg", + JSPROP_SHARED | JSPROP_ENUMERATE, + { { &get_stringArg, NULL } }, + JSNATIVE_WRAPPER(NULL), + }, + JS_PS_END +}; + +const JSFunctionSpec prototype_functions[] = { + JS_FS_END +}; + +const JSPropertySpec interface_object_properties[] = { + JS_PS_END +}; + +const JSFunctionSpec interface_object_functions[] = { + JS_FS_END +}; + +const JSPropertySpec own_properties[] = { + JS_PS_END +}; + +void InitializePrototypeAndInterfaceObject( + InterfaceData* interface_data, JSContext* context, + JS::HandleObject global_object) { + DCHECK(!interface_data->prototype); + DCHECK(!interface_data->interface_object); + DCHECK(JS_IsGlobalObject(global_object)); + + JS::RootedObject parent_prototype( + context, JS_GetObjectPrototype(context, global_object)); + DCHECK(parent_prototype); + + interface_data->prototype = JS_NewObjectWithGivenProto( + context, &prototype_class_definition, parent_prototype + ); + + JS::RootedObject rooted_prototype(context, interface_data->prototype); + bool success = JS_DefineProperties( + context, + rooted_prototype, + prototype_properties); + + DCHECK(success); + success = JS_DefineFunctions( + context, rooted_prototype, prototype_functions); + DCHECK(success); + + JS::RootedObject function_prototype( + context, JS_GetFunctionPrototype(context, global_object)); + DCHECK(function_prototype); + // Create the Interface object. + interface_data->interface_object = JS_NewObjectWithGivenProto( + context, &interface_object_class_definition, + function_prototype); + + // Add the InterfaceObject.name property. + JS::RootedObject rooted_interface_object( + context, interface_data->interface_object); + JS::RootedValue name_value(context); + const char name[] = + "ConstructorWithArgumentsInterface"; + name_value.setString(JS_NewStringCopyZ(context, name)); + success = JS_DefineProperty( + context, rooted_interface_object, "name", name_value, JSPROP_READONLY, + NULL, NULL); + DCHECK(success); + + // Add the InterfaceObject.length property. It is set to the length of the + // shortest argument list of all overload constructors. + JS::RootedValue length_value(context); + length_value.setInt32(2); + success = JS_DefineProperty( + context, rooted_interface_object, "length", length_value, + JSPROP_READONLY, NULL, NULL); + DCHECK(success); + + // Define interface object properties (including constants). + success = JS_DefineProperties(context, rooted_interface_object, + interface_object_properties); + DCHECK(success); + // Define interface object functions (static). + success = JS_DefineFunctions(context, rooted_interface_object, + interface_object_functions); + DCHECK(success); + + // Set the Prototype.constructor and Constructor.prototype properties. + DCHECK(interface_data->interface_object); + DCHECK(interface_data->prototype); + success = JS_LinkConstructorAndPrototype( + context, + rooted_interface_object, + rooted_prototype); + DCHECK(success); +} + +InterfaceData* GetInterfaceData(JSContext* context) { + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + // Use the address of the properties definition for this interface as a + // unique key for looking up the InterfaceData for this interface. + intptr_t key = reinterpret_cast<intptr_t>(&own_properties); + InterfaceData* interface_data = global_environment->GetInterfaceData(key); + if (!interface_data) { + interface_data = new InterfaceData(); + DCHECK(interface_data); + global_environment->CacheInterfaceData(key, interface_data); + DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key)); + } + return interface_data; +} + +} // namespace + +// static +JSObject* MozjsConstructorWithArgumentsInterface::CreateProxy( + JSContext* context, const scoped_refptr<Wrappable>& wrappable) { + DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); + JS::RootedObject global_object( + context, + MozjsGlobalEnvironment::GetFromContext(context)->global_object()); + DCHECK(global_object); + + InterfaceData* interface_data = GetInterfaceData(context); + JS::RootedObject prototype(context, GetPrototype(context, global_object)); + DCHECK(prototype); + JS::RootedObject new_object( + context, + JS_NewObjectWithGivenProto( + context, &instance_class_definition, prototype)); + DCHECK(new_object); + JS::RootedObject proxy(context, + ProxyHandler::NewProxy( + context, proxy_handler.Pointer(), new_object, prototype)); + WrapperPrivate::AddPrivateData(context, proxy, wrappable); + return proxy; +} + +// static +const JSClass* MozjsConstructorWithArgumentsInterface::PrototypeClass( + JSContext* context) { + DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); + JS::RootedObject global_object( + context, + MozjsGlobalEnvironment::GetFromContext(context)->global_object()); + DCHECK(global_object); + + JS::RootedObject prototype(context, GetPrototype(context, global_object)); + const JSClass* proto_class = JS_GetClass(prototype); + return proto_class; +} + +// static +JSObject* MozjsConstructorWithArgumentsInterface::GetPrototype( + JSContext* context, JS::HandleObject global_object) { + DCHECK(JS_IsGlobalObject(global_object)); + + InterfaceData* interface_data = GetInterfaceData(context); + if (!interface_data->prototype) { + // Create new prototype that has all the props and methods + InitializePrototypeAndInterfaceObject( + interface_data, context, global_object); + } + DCHECK(interface_data->prototype); + return interface_data->prototype; +} + +// static +JSObject* MozjsConstructorWithArgumentsInterface::GetInterfaceObject( + JSContext* context, JS::HandleObject global_object) { + DCHECK(JS_IsGlobalObject(global_object)); + + InterfaceData* interface_data = GetInterfaceData(context); + if (!interface_data->interface_object) { + InitializePrototypeAndInterfaceObject( + interface_data, context, global_object); + } + DCHECK(interface_data->interface_object); + return interface_data->interface_object; +} + + +namespace { +bool Constructor(JSContext* context, unsigned int argc, JS::Value* vp) { + MozjsExceptionState exception_state(context); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + const size_t kMinArguments = 2; + if (args.length() < kMinArguments) { + exception_state.SetSimpleException(script::kInvalidNumberOfArguments); + return false; + } + // Non-optional arguments + TypeTraits<int32_t >::ConversionType arg1; + TypeTraits<bool >::ConversionType arg2; + // Optional arguments with default values + TypeTraits<std::string >::ConversionType default_arg = + "default"; + + DCHECK_LT(0, args.length()); + JS::RootedValue non_optional_value0( + context, args[0]); + FromJSValue(context, + non_optional_value0, + kNoConversionFlags, + &exception_state, &arg1); + if (exception_state.is_exception_set()) { + return false; + } + + DCHECK_LT(1, args.length()); + JS::RootedValue non_optional_value1( + context, args[1]); + FromJSValue(context, + non_optional_value1, + kNoConversionFlags, + &exception_state, &arg2); + if (exception_state.is_exception_set()) { + return false; + } + size_t num_set_arguments = 3; + if (args.length() > 2) { + JS::RootedValue optional_value0( + context, args[2]); + FromJSValue(context, + optional_value0, + kNoConversionFlags, + &exception_state, + &default_arg); + if (exception_state.is_exception_set()) { + return false; + } + } + + scoped_refptr<ConstructorWithArgumentsInterface> new_object = + new ConstructorWithArgumentsInterface(arg1, arg2, default_arg); + JS::RootedValue result_value(context); + ToJSValue(context, new_object, &result_value); + DCHECK(result_value.isObject()); + args.rval().setObject(result_value.toObject()); + return true; +} +} // namespace + + +} // namespace testing +} // namespace bindings +} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_constructor_with_arguments_interface.h b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_constructor_with_arguments_interface.h new file mode 100644 index 0000000..eca04d8 --- /dev/null +++ b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_constructor_with_arguments_interface.h
@@ -0,0 +1,52 @@ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// clang-format off + +// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! +// Auto-generated from template: bindings/mozjs-45/templates/interface.h.template + +#ifndef MozjsConstructorWithArgumentsInterface_h +#define MozjsConstructorWithArgumentsInterface_h + +#include "base/hash_tables.h" +#include "base/lazy_instance.h" +#include "base/memory/ref_counted.h" +#include "base/threading/thread_checker.h" +#include "cobalt/base/polymorphic_downcast.h" +#include "cobalt/script/wrappable.h" +#include "cobalt/bindings/testing/constructor_with_arguments_interface.h" + +#include "third_party/mozjs-45/js/src/jsapi.h" + +namespace cobalt { +namespace bindings { +namespace testing { + +class MozjsConstructorWithArgumentsInterface { + public: + static JSObject* CreateProxy(JSContext* context, + const scoped_refptr<script::Wrappable>& wrappable); + static const JSClass* PrototypeClass(JSContext* context); + static JSObject* GetPrototype(JSContext* context, + JS::HandleObject global_object); + static JSObject* GetInterfaceObject(JSContext* context, + JS::HandleObject global_object); +}; + +} // namespace testing +} // namespace bindings +} // namespace cobalt + +#endif // MozjsConstructorWithArgumentsInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_derived_getter_setter_interface.cc b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_derived_getter_setter_interface.cc new file mode 100644 index 0000000..d527f33 --- /dev/null +++ b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_derived_getter_setter_interface.cc
@@ -0,0 +1,898 @@ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// clang-format off + +// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! +// Auto-generated from template: bindings/mozjs-45/templates/interface.cc.template + +#include "cobalt/bindings/testing/mozjs_derived_getter_setter_interface.h" + +#include "base/debug/trace_event.h" +#include "cobalt/base/polymorphic_downcast.h" +#include "cobalt/script/global_environment.h" +#include "cobalt/script/opaque_handle.h" +#include "cobalt/script/script_value.h" +#include "cobalt/bindings/testing/mozjs_named_indexed_getter_interface.h" +#include "cobalt/bindings/testing/named_indexed_getter_interface.h" + +#include "base/lazy_instance.h" +#include "cobalt/script/exception_state.h" +#include "cobalt/script/mozjs-45/callback_function_conversion.h" +#include "cobalt/script/mozjs-45/conversion_helpers.h" +#include "cobalt/script/mozjs-45/mozjs_callback_function.h" +#include "cobalt/script/mozjs-45/mozjs_exception_state.h" +#include "cobalt/script/mozjs-45/mozjs_global_environment.h" +#include "cobalt/script/mozjs-45/mozjs_object_handle.h" +#include "cobalt/script/mozjs-45/mozjs_property_enumerator.h" +#include "cobalt/script/mozjs-45/mozjs_user_object_holder.h" +#include "cobalt/script/mozjs-45/proxy_handler.h" +#include "cobalt/script/mozjs-45/type_traits.h" +#include "cobalt/script/mozjs-45/wrapper_factory.h" +#include "cobalt/script/mozjs-45/wrapper_private.h" +#include "cobalt/script/property_enumerator.h" +#include "cobalt/script/sequence.h" +#include "third_party/mozjs-45/js/src/jsapi.h" +#include "third_party/mozjs-45/js/src/jsfriendapi.h" + +namespace { +using cobalt::bindings::testing::DerivedGetterSetterInterface; +using cobalt::bindings::testing::MozjsDerivedGetterSetterInterface; +using cobalt::bindings::testing::MozjsNamedIndexedGetterInterface; +using cobalt::bindings::testing::NamedIndexedGetterInterface; +using cobalt::script::CallbackInterfaceTraits; +using cobalt::script::GlobalEnvironment; +using cobalt::script::OpaqueHandle; +using cobalt::script::OpaqueHandleHolder; +using cobalt::script::ScriptValue; +using cobalt::script::Wrappable; + +using cobalt::script::CallbackFunction; +using cobalt::script::CallbackInterfaceTraits; +using cobalt::script::ExceptionState; +using cobalt::script::Wrappable; +using cobalt::script::mozjs::FromJSValue; +using cobalt::script::mozjs::InterfaceData; +using cobalt::script::mozjs::MozjsCallbackFunction; +using cobalt::script::mozjs::MozjsExceptionState; +using cobalt::script::mozjs::MozjsGlobalEnvironment; +using cobalt::script::mozjs::MozjsPropertyEnumerator; +using cobalt::script::mozjs::MozjsUserObjectHolder; +using cobalt::script::mozjs::ProxyHandler; +using cobalt::script::mozjs::ToJSValue; +using cobalt::script::mozjs::TypeTraits; +using cobalt::script::mozjs::WrapperFactory; +using cobalt::script::mozjs::WrapperPrivate; +using cobalt::script::mozjs::kConversionFlagNullable; +using cobalt::script::mozjs::kConversionFlagRestricted; +using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString; +using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString; +using cobalt::script::mozjs::kNoConversionFlags; +} // namespace + +namespace cobalt { +namespace bindings { +namespace testing { + +namespace { + +bool IsSupportedNamedProperty(JSContext* context, JS::HandleObject object, + const std::string& property_name) { + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + DerivedGetterSetterInterface* impl = + wrapper_private->wrappable<DerivedGetterSetterInterface>().get(); + return impl->CanQueryNamedProperty(property_name); +} + +void EnumerateSupportedNames(JSContext* context, JS::HandleObject object, + JS::AutoIdVector* properties) { + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + DerivedGetterSetterInterface* impl = + wrapper_private->wrappable<DerivedGetterSetterInterface>().get(); + MozjsPropertyEnumerator enumerator(context, properties); + impl->EnumerateNamedProperties(&enumerator); +} + +bool GetNamedProperty( + JSContext* context, JS::HandleObject object, JS::HandleId id, + JS::MutableHandleValue vp) { + JS::RootedValue id_value(context); + if (!JS_IdToValue(context, id, &id_value)) { + NOTREACHED(); + return false; + } + + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + DerivedGetterSetterInterface* impl = + wrapper_private->wrappable<DerivedGetterSetterInterface>().get(); + std::string property_name; + FromJSValue(context, id_value, kNoConversionFlags, &exception_state, + &property_name); + if (exception_state.is_exception_set()) { + // The ID should be an integer or a string, so we shouldn't have any + // exceptions converting to string. + NOTREACHED(); + return false; + } + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->AnonymousNamedGetter(property_name), + &result_value); + } + if (!exception_state.is_exception_set()) { + vp.set(result_value); + } + return !exception_state.is_exception_set(); +} + +bool SetNamedProperty( + JSContext* context, JS::HandleObject object, JS::HandleId id, + JS::MutableHandleValue vp, JS::ObjectOpResult& object_op_result) { + JS::RootedValue id_value(context); + if (!JS_IdToValue(context, id, &id_value)) { + NOTREACHED(); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + DerivedGetterSetterInterface* impl = + wrapper_private->wrappable<DerivedGetterSetterInterface>().get(); + std::string property_name; + FromJSValue(context, id_value, kNoConversionFlags, &exception_state, + &property_name); + if (exception_state.is_exception_set()) { + // The ID should be an integer or a string, so we shouldn't have any + // exceptions converting to string. + NOTREACHED(); + return false; + } + TypeTraits<std::string >::ConversionType value; + FromJSValue(context, vp, kNoConversionFlags, + &exception_state, &value); + if (exception_state.is_exception_set()) { + return false; + } + + impl->AnonymousNamedSetter(property_name, value); + result_value.set(JS::UndefinedHandleValue); + + if (!exception_state.is_exception_set()) { + return object_op_result.succeed(); + } else { + return false; + } +} + +bool IsSupportedIndexProperty(JSContext* context, JS::HandleObject object, + uint32_t index) { + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + DerivedGetterSetterInterface* impl = + wrapper_private->wrappable<DerivedGetterSetterInterface>().get(); + return index < impl->length(); +} + +void EnumerateSupportedIndexes(JSContext* context, JS::HandleObject object, + JS::AutoIdVector* properties) { + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + DerivedGetterSetterInterface* impl = + wrapper_private->wrappable<DerivedGetterSetterInterface>().get(); + const uint32_t kNumIndexedProperties = impl->length(); + for (uint32_t i = 0; i < kNumIndexedProperties; ++i) { + properties->append(INT_TO_JSID(i)); + } +} + +bool GetIndexedProperty( + JSContext* context, JS::HandleObject object, JS::HandleId id, + JS::MutableHandleValue vp) { + JS::RootedValue id_value(context); + if (!JS_IdToValue(context, id, &id_value)) { + NOTREACHED(); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + DerivedGetterSetterInterface* impl = + wrapper_private->wrappable<DerivedGetterSetterInterface>().get(); + uint32_t index; + FromJSValue(context, id_value, kNoConversionFlags, &exception_state, &index); + if (exception_state.is_exception_set()) { + // The ID should be an integer or a string, so we shouldn't have any + // exceptions converting to string. + NOTREACHED(); + return false; + } + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->DerivedIndexedGetter(index), + &result_value); + } + if (!exception_state.is_exception_set()) { + vp.set(result_value); + } + return !exception_state.is_exception_set(); +} + +bool SetIndexedProperty( + JSContext* context, JS::HandleObject object, JS::HandleId id, + JS::MutableHandleValue vp, JS::ObjectOpResult& object_op_result) { + JS::RootedValue id_value(context); + if (!JS_IdToValue(context, id, &id_value)) { + NOTREACHED(); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + DerivedGetterSetterInterface* impl = + wrapper_private->wrappable<DerivedGetterSetterInterface>().get(); + uint32_t index; + FromJSValue(context, id_value, kNoConversionFlags, &exception_state, &index); + if (exception_state.is_exception_set()) { + // The ID should be an integer or a string, so we shouldn't have any + // exceptions converting to string. + NOTREACHED(); + return false; + } + TypeTraits<uint32_t >::ConversionType value; + FromJSValue(context, vp, kNoConversionFlags, + &exception_state, &value); + if (exception_state.is_exception_set()) { + return false; + } + + impl->DerivedIndexedSetter(index, value); + result_value.set(JS::UndefinedHandleValue); + if (!exception_state.is_exception_set()) { + return object_op_result.succeed(); + } else { + return false; + } +} + +class MozjsDerivedGetterSetterInterfaceHandler : public ProxyHandler { + public: + MozjsDerivedGetterSetterInterfaceHandler() + : ProxyHandler(indexed_property_hooks, named_property_hooks) {} + + private: + static NamedPropertyHooks named_property_hooks; + static IndexedPropertyHooks indexed_property_hooks; +}; + +ProxyHandler::NamedPropertyHooks +MozjsDerivedGetterSetterInterfaceHandler::named_property_hooks = { + IsSupportedNamedProperty, + EnumerateSupportedNames, + GetNamedProperty, + SetNamedProperty, + NULL, +}; +ProxyHandler::IndexedPropertyHooks +MozjsDerivedGetterSetterInterfaceHandler::indexed_property_hooks = { + IsSupportedIndexProperty, + EnumerateSupportedIndexes, + GetIndexedProperty, + SetIndexedProperty, + NULL, +}; + +static base::LazyInstance<MozjsDerivedGetterSetterInterfaceHandler> + proxy_handler; + +bool HasInstance(JSContext *context, JS::HandleObject type, + JS::MutableHandleValue vp, bool *success) { + JS::RootedObject global_object( + context, JS_GetGlobalForObject(context, type)); + DCHECK(global_object); + + JS::RootedObject prototype( + context, MozjsDerivedGetterSetterInterface::GetPrototype(context, global_object)); + + // |IsDelegate| walks the prototype chain of an object returning true if + // .prototype is found. + bool is_delegate; + if (!IsDelegate(context, prototype, vp, &is_delegate)) { + *success = false; + return false; + } + + *success = is_delegate; + return true; +} + +const JSClass instance_class_definition = { + "DerivedGetterSetterInterface", + 0 | JSCLASS_HAS_PRIVATE, + NULL, // addProperty + NULL, // delProperty + NULL, // getProperty + NULL, // setProperty + NULL, // enumerate + NULL, // resolve + NULL, // mayResolve + &WrapperPrivate::Finalizer, // finalize + NULL, // call + NULL, // hasInstance + NULL, // construct + &WrapperPrivate::Trace, // trace +}; + +const JSClass prototype_class_definition = { + "DerivedGetterSetterInterfacePrototype", +}; + +const JSClass interface_object_class_definition = { + "DerivedGetterSetterInterfaceConstructor", + 0, + NULL, // addProperty + NULL, // delProperty + NULL, // getProperty + NULL, // setProperty + NULL, // enumerate + NULL, // resolve + NULL, // mayResolve + NULL, // finalize + NULL, // call + &HasInstance, + NULL, +}; + +bool get_length( + JSContext* context, unsigned argc, JS::Value* vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + const JSClass* proto_class = + MozjsDerivedGetterSetterInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<DerivedGetterSetterInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + DerivedGetterSetterInterface* impl = + wrapper_private->wrappable<DerivedGetterSetterInterface>().get(); + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->length(), + &result_value); + } + if (!exception_state.is_exception_set()) { + args.rval().set(result_value); + } + return !exception_state.is_exception_set(); +} + + +bool get_propertyOnDerivedClass( + JSContext* context, unsigned argc, JS::Value* vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + const JSClass* proto_class = + MozjsDerivedGetterSetterInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<DerivedGetterSetterInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + DerivedGetterSetterInterface* impl = + wrapper_private->wrappable<DerivedGetterSetterInterface>().get(); + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->property_on_derived_class(), + &result_value); + } + if (!exception_state.is_exception_set()) { + args.rval().set(result_value); + } + return !exception_state.is_exception_set(); +} + +bool set_propertyOnDerivedClass( + JSContext* context, unsigned argc, JS::Value* vp) { + + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + + const JSClass* proto_class = + MozjsDerivedGetterSetterInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<DerivedGetterSetterInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + DerivedGetterSetterInterface* impl = + wrapper_private->wrappable<DerivedGetterSetterInterface>().get(); + TypeTraits<bool >::ConversionType value; + if (args.length() != 1) { + NOTREACHED(); + return false; + } + FromJSValue(context, args[0], kNoConversionFlags, &exception_state, + &value); + if (exception_state.is_exception_set()) { + return false; + } + + impl->set_property_on_derived_class(value); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + +bool fcn_derivedIndexedGetter( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + const JSClass* proto_class = + MozjsDerivedGetterSetterInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<DerivedGetterSetterInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + DerivedGetterSetterInterface* impl = + wrapper_private->wrappable<DerivedGetterSetterInterface>().get(); + const size_t kMinArguments = 1; + if (args.length() < kMinArguments) { + exception_state.SetSimpleException(script::kInvalidNumberOfArguments); + return false; + } + // Non-optional arguments + TypeTraits<uint32_t >::ConversionType index; + + DCHECK_LT(0, args.length()); + JS::RootedValue non_optional_value0( + context, args[0]); + FromJSValue(context, + non_optional_value0, + kNoConversionFlags, + &exception_state, &index); + if (exception_state.is_exception_set()) { + return false; + } + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->DerivedIndexedGetter(index), + &result_value); + } + if (!exception_state.is_exception_set()) { + args.rval().set(result_value); + } + return !exception_state.is_exception_set(); +} + +bool fcn_derivedIndexedSetter( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + const JSClass* proto_class = + MozjsDerivedGetterSetterInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<DerivedGetterSetterInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + DerivedGetterSetterInterface* impl = + wrapper_private->wrappable<DerivedGetterSetterInterface>().get(); + const size_t kMinArguments = 2; + if (args.length() < kMinArguments) { + exception_state.SetSimpleException(script::kInvalidNumberOfArguments); + return false; + } + // Non-optional arguments + TypeTraits<uint32_t >::ConversionType index; + TypeTraits<uint32_t >::ConversionType value; + + DCHECK_LT(0, args.length()); + JS::RootedValue non_optional_value0( + context, args[0]); + FromJSValue(context, + non_optional_value0, + kNoConversionFlags, + &exception_state, &index); + if (exception_state.is_exception_set()) { + return false; + } + + DCHECK_LT(1, args.length()); + JS::RootedValue non_optional_value1( + context, args[1]); + FromJSValue(context, + non_optional_value1, + kNoConversionFlags, + &exception_state, &value); + if (exception_state.is_exception_set()) { + return false; + } + + impl->DerivedIndexedSetter(index, value); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + +bool fcn_operationOnDerivedClass( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + const JSClass* proto_class = + MozjsDerivedGetterSetterInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<DerivedGetterSetterInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + DerivedGetterSetterInterface* impl = + wrapper_private->wrappable<DerivedGetterSetterInterface>().get(); + + impl->OperationOnDerivedClass(); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + + + +const JSPropertySpec prototype_properties[] = { + { // Readonly attribute + "length", + JSPROP_SHARED | JSPROP_ENUMERATE, + { { &get_length, NULL } }, + JSNATIVE_WRAPPER(NULL), + }, + { // Read/Write property + "propertyOnDerivedClass", + JSPROP_SHARED | JSPROP_ENUMERATE, + { { &get_propertyOnDerivedClass, NULL } }, + { { &set_propertyOnDerivedClass, NULL } }, + }, + JS_PS_END +}; + +const JSFunctionSpec prototype_functions[] = { + JS_FNSPEC( + "derivedIndexedGetter", fcn_derivedIndexedGetter, NULL, + 1, JSPROP_ENUMERATE, NULL), + JS_FNSPEC( + "derivedIndexedSetter", fcn_derivedIndexedSetter, NULL, + 2, JSPROP_ENUMERATE, NULL), + JS_FNSPEC( + "operationOnDerivedClass", fcn_operationOnDerivedClass, NULL, + 0, JSPROP_ENUMERATE, NULL), + JS_FS_END +}; + +const JSPropertySpec interface_object_properties[] = { + JS_PS_END +}; + +const JSFunctionSpec interface_object_functions[] = { + JS_FS_END +}; + +const JSPropertySpec own_properties[] = { + JS_PS_END +}; + +void InitializePrototypeAndInterfaceObject( + InterfaceData* interface_data, JSContext* context, + JS::HandleObject global_object) { + DCHECK(!interface_data->prototype); + DCHECK(!interface_data->interface_object); + DCHECK(JS_IsGlobalObject(global_object)); + + JS::RootedObject parent_prototype( + context, MozjsNamedIndexedGetterInterface::GetPrototype(context, global_object)); + DCHECK(parent_prototype); + + interface_data->prototype = JS_NewObjectWithGivenProto( + context, &prototype_class_definition, parent_prototype + ); + + JS::RootedObject rooted_prototype(context, interface_data->prototype); + bool success = JS_DefineProperties( + context, + rooted_prototype, + prototype_properties); + + DCHECK(success); + success = JS_DefineFunctions( + context, rooted_prototype, prototype_functions); + DCHECK(success); + + JS::RootedObject function_prototype( + context, JS_GetFunctionPrototype(context, global_object)); + DCHECK(function_prototype); + // Create the Interface object. + interface_data->interface_object = JS_NewObjectWithGivenProto( + context, &interface_object_class_definition, + function_prototype); + + // Add the InterfaceObject.name property. + JS::RootedObject rooted_interface_object( + context, interface_data->interface_object); + JS::RootedValue name_value(context); + const char name[] = + "DerivedGetterSetterInterface"; + name_value.setString(JS_NewStringCopyZ(context, name)); + success = JS_DefineProperty( + context, rooted_interface_object, "name", name_value, JSPROP_READONLY, + NULL, NULL); + DCHECK(success); + + // Define interface object properties (including constants). + success = JS_DefineProperties(context, rooted_interface_object, + interface_object_properties); + DCHECK(success); + // Define interface object functions (static). + success = JS_DefineFunctions(context, rooted_interface_object, + interface_object_functions); + DCHECK(success); + + // Set the Prototype.constructor and Constructor.prototype properties. + DCHECK(interface_data->interface_object); + DCHECK(interface_data->prototype); + success = JS_LinkConstructorAndPrototype( + context, + rooted_interface_object, + rooted_prototype); + DCHECK(success); +} + +InterfaceData* GetInterfaceData(JSContext* context) { + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + // Use the address of the properties definition for this interface as a + // unique key for looking up the InterfaceData for this interface. + intptr_t key = reinterpret_cast<intptr_t>(&own_properties); + InterfaceData* interface_data = global_environment->GetInterfaceData(key); + if (!interface_data) { + interface_data = new InterfaceData(); + DCHECK(interface_data); + global_environment->CacheInterfaceData(key, interface_data); + DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key)); + } + return interface_data; +} + +} // namespace + +// static +JSObject* MozjsDerivedGetterSetterInterface::CreateProxy( + JSContext* context, const scoped_refptr<Wrappable>& wrappable) { + DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); + JS::RootedObject global_object( + context, + MozjsGlobalEnvironment::GetFromContext(context)->global_object()); + DCHECK(global_object); + + InterfaceData* interface_data = GetInterfaceData(context); + JS::RootedObject prototype(context, GetPrototype(context, global_object)); + DCHECK(prototype); + JS::RootedObject new_object( + context, + JS_NewObjectWithGivenProto( + context, &instance_class_definition, prototype)); + DCHECK(new_object); + JS::RootedObject proxy(context, + ProxyHandler::NewProxy( + context, proxy_handler.Pointer(), new_object, prototype)); + WrapperPrivate::AddPrivateData(context, proxy, wrappable); + return proxy; +} + +// static +const JSClass* MozjsDerivedGetterSetterInterface::PrototypeClass( + JSContext* context) { + DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); + JS::RootedObject global_object( + context, + MozjsGlobalEnvironment::GetFromContext(context)->global_object()); + DCHECK(global_object); + + JS::RootedObject prototype(context, GetPrototype(context, global_object)); + const JSClass* proto_class = JS_GetClass(prototype); + return proto_class; +} + +// static +JSObject* MozjsDerivedGetterSetterInterface::GetPrototype( + JSContext* context, JS::HandleObject global_object) { + DCHECK(JS_IsGlobalObject(global_object)); + + InterfaceData* interface_data = GetInterfaceData(context); + if (!interface_data->prototype) { + // Create new prototype that has all the props and methods + InitializePrototypeAndInterfaceObject( + interface_data, context, global_object); + } + DCHECK(interface_data->prototype); + return interface_data->prototype; +} + +// static +JSObject* MozjsDerivedGetterSetterInterface::GetInterfaceObject( + JSContext* context, JS::HandleObject global_object) { + DCHECK(JS_IsGlobalObject(global_object)); + + InterfaceData* interface_data = GetInterfaceData(context); + if (!interface_data->interface_object) { + InitializePrototypeAndInterfaceObject( + interface_data, context, global_object); + } + DCHECK(interface_data->interface_object); + return interface_data->interface_object; +} + + +namespace { +} // namespace + + +} // namespace testing +} // namespace bindings +} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_derived_getter_setter_interface.h b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_derived_getter_setter_interface.h new file mode 100644 index 0000000..7c9b164 --- /dev/null +++ b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_derived_getter_setter_interface.h
@@ -0,0 +1,53 @@ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// clang-format off + +// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! +// Auto-generated from template: bindings/mozjs-45/templates/interface.h.template + +#ifndef MozjsDerivedGetterSetterInterface_h +#define MozjsDerivedGetterSetterInterface_h + +#include "base/hash_tables.h" +#include "base/lazy_instance.h" +#include "base/memory/ref_counted.h" +#include "base/threading/thread_checker.h" +#include "cobalt/base/polymorphic_downcast.h" +#include "cobalt/script/wrappable.h" +#include "cobalt/bindings/testing/derived_getter_setter_interface.h" +#include "cobalt/bindings/testing/mozjs_named_indexed_getter_interface.h" + +#include "third_party/mozjs-45/js/src/jsapi.h" + +namespace cobalt { +namespace bindings { +namespace testing { + +class MozjsDerivedGetterSetterInterface { + public: + static JSObject* CreateProxy(JSContext* context, + const scoped_refptr<script::Wrappable>& wrappable); + static const JSClass* PrototypeClass(JSContext* context); + static JSObject* GetPrototype(JSContext* context, + JS::HandleObject global_object); + static JSObject* GetInterfaceObject(JSContext* context, + JS::HandleObject global_object); +}; + +} // namespace testing +} // namespace bindings +} // namespace cobalt + +#endif // MozjsDerivedGetterSetterInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_derived_interface.cc b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_derived_interface.cc new file mode 100644 index 0000000..9bbd224 --- /dev/null +++ b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_derived_interface.cc
@@ -0,0 +1,478 @@ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// clang-format off + +// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! +// Auto-generated from template: bindings/mozjs-45/templates/interface.cc.template + +#include "cobalt/bindings/testing/mozjs_derived_interface.h" + +#include "base/debug/trace_event.h" +#include "cobalt/base/polymorphic_downcast.h" +#include "cobalt/script/global_environment.h" +#include "cobalt/script/opaque_handle.h" +#include "cobalt/script/script_value.h" +#include "cobalt/bindings/testing/base_interface.h" +#include "cobalt/bindings/testing/mozjs_base_interface.h" + +#include "base/lazy_instance.h" +#include "cobalt/script/exception_state.h" +#include "cobalt/script/mozjs-45/callback_function_conversion.h" +#include "cobalt/script/mozjs-45/conversion_helpers.h" +#include "cobalt/script/mozjs-45/mozjs_callback_function.h" +#include "cobalt/script/mozjs-45/mozjs_exception_state.h" +#include "cobalt/script/mozjs-45/mozjs_global_environment.h" +#include "cobalt/script/mozjs-45/mozjs_object_handle.h" +#include "cobalt/script/mozjs-45/mozjs_property_enumerator.h" +#include "cobalt/script/mozjs-45/mozjs_user_object_holder.h" +#include "cobalt/script/mozjs-45/proxy_handler.h" +#include "cobalt/script/mozjs-45/type_traits.h" +#include "cobalt/script/mozjs-45/wrapper_factory.h" +#include "cobalt/script/mozjs-45/wrapper_private.h" +#include "cobalt/script/property_enumerator.h" +#include "cobalt/script/sequence.h" +#include "third_party/mozjs-45/js/src/jsapi.h" +#include "third_party/mozjs-45/js/src/jsfriendapi.h" + +namespace { +using cobalt::bindings::testing::DerivedInterface; +using cobalt::bindings::testing::MozjsDerivedInterface; +using cobalt::bindings::testing::BaseInterface; +using cobalt::bindings::testing::MozjsBaseInterface; +using cobalt::script::CallbackInterfaceTraits; +using cobalt::script::GlobalEnvironment; +using cobalt::script::OpaqueHandle; +using cobalt::script::OpaqueHandleHolder; +using cobalt::script::ScriptValue; +using cobalt::script::Wrappable; + +using cobalt::script::CallbackFunction; +using cobalt::script::CallbackInterfaceTraits; +using cobalt::script::ExceptionState; +using cobalt::script::Wrappable; +using cobalt::script::mozjs::FromJSValue; +using cobalt::script::mozjs::InterfaceData; +using cobalt::script::mozjs::MozjsCallbackFunction; +using cobalt::script::mozjs::MozjsExceptionState; +using cobalt::script::mozjs::MozjsGlobalEnvironment; +using cobalt::script::mozjs::MozjsPropertyEnumerator; +using cobalt::script::mozjs::MozjsUserObjectHolder; +using cobalt::script::mozjs::ProxyHandler; +using cobalt::script::mozjs::ToJSValue; +using cobalt::script::mozjs::TypeTraits; +using cobalt::script::mozjs::WrapperFactory; +using cobalt::script::mozjs::WrapperPrivate; +using cobalt::script::mozjs::kConversionFlagNullable; +using cobalt::script::mozjs::kConversionFlagRestricted; +using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString; +using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString; +using cobalt::script::mozjs::kNoConversionFlags; +} // namespace + +namespace cobalt { +namespace bindings { +namespace testing { + +namespace { + +class MozjsDerivedInterfaceHandler : public ProxyHandler { + public: + MozjsDerivedInterfaceHandler() + : ProxyHandler(indexed_property_hooks, named_property_hooks) {} + + private: + static NamedPropertyHooks named_property_hooks; + static IndexedPropertyHooks indexed_property_hooks; +}; + +ProxyHandler::NamedPropertyHooks +MozjsDerivedInterfaceHandler::named_property_hooks = { + NULL, + NULL, + NULL, + NULL, + NULL, +}; +ProxyHandler::IndexedPropertyHooks +MozjsDerivedInterfaceHandler::indexed_property_hooks = { + NULL, + NULL, + NULL, + NULL, + NULL, +}; + +static base::LazyInstance<MozjsDerivedInterfaceHandler> + proxy_handler; + +bool Constructor(JSContext* context, unsigned int argc, JS::Value* vp); +bool HasInstance(JSContext *context, JS::HandleObject type, + JS::MutableHandleValue vp, bool *success) { + JS::RootedObject global_object( + context, JS_GetGlobalForObject(context, type)); + DCHECK(global_object); + + JS::RootedObject prototype( + context, MozjsDerivedInterface::GetPrototype(context, global_object)); + + // |IsDelegate| walks the prototype chain of an object returning true if + // .prototype is found. + bool is_delegate; + if (!IsDelegate(context, prototype, vp, &is_delegate)) { + *success = false; + return false; + } + + *success = is_delegate; + return true; +} + +const JSClass instance_class_definition = { + "DerivedInterface", + 0 | JSCLASS_HAS_PRIVATE, + NULL, // addProperty + NULL, // delProperty + NULL, // getProperty + NULL, // setProperty + NULL, // enumerate + NULL, // resolve + NULL, // mayResolve + &WrapperPrivate::Finalizer, // finalize + NULL, // call + NULL, // hasInstance + NULL, // construct + &WrapperPrivate::Trace, // trace +}; + +const JSClass prototype_class_definition = { + "DerivedInterfacePrototype", +}; + +const JSClass interface_object_class_definition = { + "DerivedInterfaceConstructor", + 0, + NULL, // addProperty + NULL, // delProperty + NULL, // getProperty + NULL, // setProperty + NULL, // enumerate + NULL, // resolve + NULL, // mayResolve + NULL, // finalize + NULL, // call + &HasInstance, + Constructor, +}; + +bool get_derivedAttribute( + JSContext* context, unsigned argc, JS::Value* vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + const JSClass* proto_class = + MozjsDerivedInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<DerivedInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + DerivedInterface* impl = + wrapper_private->wrappable<DerivedInterface>().get(); + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->derived_attribute(), + &result_value); + } + if (!exception_state.is_exception_set()) { + args.rval().set(result_value); + } + return !exception_state.is_exception_set(); +} + + +bool fcn_derivedOperation( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + const JSClass* proto_class = + MozjsDerivedInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<DerivedInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + DerivedInterface* impl = + wrapper_private->wrappable<DerivedInterface>().get(); + + impl->DerivedOperation(); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + + + +const JSPropertySpec prototype_properties[] = { + { // Readonly attribute + "derivedAttribute", + JSPROP_SHARED | JSPROP_ENUMERATE, + { { &get_derivedAttribute, NULL } }, + JSNATIVE_WRAPPER(NULL), + }, + JS_PS_END +}; + +const JSFunctionSpec prototype_functions[] = { + JS_FNSPEC( + "derivedOperation", fcn_derivedOperation, NULL, + 0, JSPROP_ENUMERATE, NULL), + JS_FS_END +}; + +const JSPropertySpec interface_object_properties[] = { + JS_PS_END +}; + +const JSFunctionSpec interface_object_functions[] = { + JS_FS_END +}; + +const JSPropertySpec own_properties[] = { + JS_PS_END +}; + +void InitializePrototypeAndInterfaceObject( + InterfaceData* interface_data, JSContext* context, + JS::HandleObject global_object) { + DCHECK(!interface_data->prototype); + DCHECK(!interface_data->interface_object); + DCHECK(JS_IsGlobalObject(global_object)); + + JS::RootedObject parent_prototype( + context, MozjsBaseInterface::GetPrototype(context, global_object)); + DCHECK(parent_prototype); + + interface_data->prototype = JS_NewObjectWithGivenProto( + context, &prototype_class_definition, parent_prototype + ); + + JS::RootedObject rooted_prototype(context, interface_data->prototype); + bool success = JS_DefineProperties( + context, + rooted_prototype, + prototype_properties); + + DCHECK(success); + success = JS_DefineFunctions( + context, rooted_prototype, prototype_functions); + DCHECK(success); + + JS::RootedObject function_prototype( + context, JS_GetFunctionPrototype(context, global_object)); + DCHECK(function_prototype); + // Create the Interface object. + interface_data->interface_object = JS_NewObjectWithGivenProto( + context, &interface_object_class_definition, + function_prototype); + + // Add the InterfaceObject.name property. + JS::RootedObject rooted_interface_object( + context, interface_data->interface_object); + JS::RootedValue name_value(context); + const char name[] = + "DerivedInterface"; + name_value.setString(JS_NewStringCopyZ(context, name)); + success = JS_DefineProperty( + context, rooted_interface_object, "name", name_value, JSPROP_READONLY, + NULL, NULL); + DCHECK(success); + + // Add the InterfaceObject.length property. It is set to the length of the + // shortest argument list of all overload constructors. + JS::RootedValue length_value(context); + length_value.setInt32(0); + success = JS_DefineProperty( + context, rooted_interface_object, "length", length_value, + JSPROP_READONLY, NULL, NULL); + DCHECK(success); + + // Define interface object properties (including constants). + success = JS_DefineProperties(context, rooted_interface_object, + interface_object_properties); + DCHECK(success); + // Define interface object functions (static). + success = JS_DefineFunctions(context, rooted_interface_object, + interface_object_functions); + DCHECK(success); + + // Set the Prototype.constructor and Constructor.prototype properties. + DCHECK(interface_data->interface_object); + DCHECK(interface_data->prototype); + success = JS_LinkConstructorAndPrototype( + context, + rooted_interface_object, + rooted_prototype); + DCHECK(success); +} + +InterfaceData* GetInterfaceData(JSContext* context) { + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + // Use the address of the properties definition for this interface as a + // unique key for looking up the InterfaceData for this interface. + intptr_t key = reinterpret_cast<intptr_t>(&own_properties); + InterfaceData* interface_data = global_environment->GetInterfaceData(key); + if (!interface_data) { + interface_data = new InterfaceData(); + DCHECK(interface_data); + global_environment->CacheInterfaceData(key, interface_data); + DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key)); + } + return interface_data; +} + +} // namespace + +// static +JSObject* MozjsDerivedInterface::CreateProxy( + JSContext* context, const scoped_refptr<Wrappable>& wrappable) { + DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); + JS::RootedObject global_object( + context, + MozjsGlobalEnvironment::GetFromContext(context)->global_object()); + DCHECK(global_object); + + InterfaceData* interface_data = GetInterfaceData(context); + JS::RootedObject prototype(context, GetPrototype(context, global_object)); + DCHECK(prototype); + JS::RootedObject new_object( + context, + JS_NewObjectWithGivenProto( + context, &instance_class_definition, prototype)); + DCHECK(new_object); + JS::RootedObject proxy(context, + ProxyHandler::NewProxy( + context, proxy_handler.Pointer(), new_object, prototype)); + WrapperPrivate::AddPrivateData(context, proxy, wrappable); + return proxy; +} + +// static +const JSClass* MozjsDerivedInterface::PrototypeClass( + JSContext* context) { + DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); + JS::RootedObject global_object( + context, + MozjsGlobalEnvironment::GetFromContext(context)->global_object()); + DCHECK(global_object); + + JS::RootedObject prototype(context, GetPrototype(context, global_object)); + const JSClass* proto_class = JS_GetClass(prototype); + return proto_class; +} + +// static +JSObject* MozjsDerivedInterface::GetPrototype( + JSContext* context, JS::HandleObject global_object) { + DCHECK(JS_IsGlobalObject(global_object)); + + InterfaceData* interface_data = GetInterfaceData(context); + if (!interface_data->prototype) { + // Create new prototype that has all the props and methods + InitializePrototypeAndInterfaceObject( + interface_data, context, global_object); + } + DCHECK(interface_data->prototype); + return interface_data->prototype; +} + +// static +JSObject* MozjsDerivedInterface::GetInterfaceObject( + JSContext* context, JS::HandleObject global_object) { + DCHECK(JS_IsGlobalObject(global_object)); + + InterfaceData* interface_data = GetInterfaceData(context); + if (!interface_data->interface_object) { + InitializePrototypeAndInterfaceObject( + interface_data, context, global_object); + } + DCHECK(interface_data->interface_object); + return interface_data->interface_object; +} + + +namespace { +bool Constructor(JSContext* context, unsigned int argc, JS::Value* vp) { + MozjsExceptionState exception_state(context); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + + scoped_refptr<DerivedInterface> new_object = + new DerivedInterface(); + JS::RootedValue result_value(context); + ToJSValue(context, new_object, &result_value); + DCHECK(result_value.isObject()); + args.rval().setObject(result_value.toObject()); + return true; +} +} // namespace + + +} // namespace testing +} // namespace bindings +} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_derived_interface.h b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_derived_interface.h new file mode 100644 index 0000000..ba2bd25 --- /dev/null +++ b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_derived_interface.h
@@ -0,0 +1,53 @@ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// clang-format off + +// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! +// Auto-generated from template: bindings/mozjs-45/templates/interface.h.template + +#ifndef MozjsDerivedInterface_h +#define MozjsDerivedInterface_h + +#include "base/hash_tables.h" +#include "base/lazy_instance.h" +#include "base/memory/ref_counted.h" +#include "base/threading/thread_checker.h" +#include "cobalt/base/polymorphic_downcast.h" +#include "cobalt/script/wrappable.h" +#include "cobalt/bindings/testing/derived_interface.h" +#include "cobalt/bindings/testing/mozjs_base_interface.h" + +#include "third_party/mozjs-45/js/src/jsapi.h" + +namespace cobalt { +namespace bindings { +namespace testing { + +class MozjsDerivedInterface { + public: + static JSObject* CreateProxy(JSContext* context, + const scoped_refptr<script::Wrappable>& wrappable); + static const JSClass* PrototypeClass(JSContext* context); + static JSObject* GetPrototype(JSContext* context, + JS::HandleObject global_object); + static JSObject* GetInterfaceObject(JSContext* context, + JS::HandleObject global_object); +}; + +} // namespace testing +} // namespace bindings +} // namespace cobalt + +#endif // MozjsDerivedInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_dictionary_interface.cc b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_dictionary_interface.cc new file mode 100644 index 0000000..a55b701 --- /dev/null +++ b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_dictionary_interface.cc
@@ -0,0 +1,423 @@ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// clang-format off + +// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! +// Auto-generated from template: bindings/mozjs-45/templates/interface.cc.template + +#include "cobalt/bindings/testing/mozjs_dictionary_interface.h" + +#include "base/debug/trace_event.h" +#include "cobalt/base/polymorphic_downcast.h" +#include "cobalt/script/global_environment.h" +#include "cobalt/script/opaque_handle.h" +#include "cobalt/script/script_value.h" +#include "cobalt/bindings/testing/mozjs_test_dictionary.h" + +#include "base/lazy_instance.h" +#include "cobalt/script/exception_state.h" +#include "cobalt/script/mozjs-45/callback_function_conversion.h" +#include "cobalt/script/mozjs-45/conversion_helpers.h" +#include "cobalt/script/mozjs-45/mozjs_callback_function.h" +#include "cobalt/script/mozjs-45/mozjs_exception_state.h" +#include "cobalt/script/mozjs-45/mozjs_global_environment.h" +#include "cobalt/script/mozjs-45/mozjs_object_handle.h" +#include "cobalt/script/mozjs-45/mozjs_property_enumerator.h" +#include "cobalt/script/mozjs-45/mozjs_user_object_holder.h" +#include "cobalt/script/mozjs-45/proxy_handler.h" +#include "cobalt/script/mozjs-45/type_traits.h" +#include "cobalt/script/mozjs-45/wrapper_factory.h" +#include "cobalt/script/mozjs-45/wrapper_private.h" +#include "cobalt/script/property_enumerator.h" +#include "cobalt/script/sequence.h" +#include "third_party/mozjs-45/js/src/jsapi.h" +#include "third_party/mozjs-45/js/src/jsfriendapi.h" + +namespace { +using cobalt::bindings::testing::DictionaryInterface; +using cobalt::bindings::testing::MozjsDictionaryInterface; +using cobalt::bindings::testing::TestDictionary; +using cobalt::script::CallbackInterfaceTraits; +using cobalt::script::GlobalEnvironment; +using cobalt::script::OpaqueHandle; +using cobalt::script::OpaqueHandleHolder; +using cobalt::script::ScriptValue; +using cobalt::script::Wrappable; + +using cobalt::script::CallbackFunction; +using cobalt::script::CallbackInterfaceTraits; +using cobalt::script::ExceptionState; +using cobalt::script::Wrappable; +using cobalt::script::mozjs::FromJSValue; +using cobalt::script::mozjs::InterfaceData; +using cobalt::script::mozjs::MozjsCallbackFunction; +using cobalt::script::mozjs::MozjsExceptionState; +using cobalt::script::mozjs::MozjsGlobalEnvironment; +using cobalt::script::mozjs::MozjsPropertyEnumerator; +using cobalt::script::mozjs::MozjsUserObjectHolder; +using cobalt::script::mozjs::ProxyHandler; +using cobalt::script::mozjs::ToJSValue; +using cobalt::script::mozjs::TypeTraits; +using cobalt::script::mozjs::WrapperFactory; +using cobalt::script::mozjs::WrapperPrivate; +using cobalt::script::mozjs::kConversionFlagNullable; +using cobalt::script::mozjs::kConversionFlagRestricted; +using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString; +using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString; +using cobalt::script::mozjs::kNoConversionFlags; +} // namespace + +namespace cobalt { +namespace bindings { +namespace testing { + +namespace { + +class MozjsDictionaryInterfaceHandler : public ProxyHandler { + public: + MozjsDictionaryInterfaceHandler() + : ProxyHandler(indexed_property_hooks, named_property_hooks) {} + + private: + static NamedPropertyHooks named_property_hooks; + static IndexedPropertyHooks indexed_property_hooks; +}; + +ProxyHandler::NamedPropertyHooks +MozjsDictionaryInterfaceHandler::named_property_hooks = { + NULL, + NULL, + NULL, + NULL, + NULL, +}; +ProxyHandler::IndexedPropertyHooks +MozjsDictionaryInterfaceHandler::indexed_property_hooks = { + NULL, + NULL, + NULL, + NULL, + NULL, +}; + +static base::LazyInstance<MozjsDictionaryInterfaceHandler> + proxy_handler; + +bool HasInstance(JSContext *context, JS::HandleObject type, + JS::MutableHandleValue vp, bool *success) { + JS::RootedObject global_object( + context, JS_GetGlobalForObject(context, type)); + DCHECK(global_object); + + JS::RootedObject prototype( + context, MozjsDictionaryInterface::GetPrototype(context, global_object)); + + // |IsDelegate| walks the prototype chain of an object returning true if + // .prototype is found. + bool is_delegate; + if (!IsDelegate(context, prototype, vp, &is_delegate)) { + *success = false; + return false; + } + + *success = is_delegate; + return true; +} + +const JSClass instance_class_definition = { + "DictionaryInterface", + 0 | JSCLASS_HAS_PRIVATE, + NULL, // addProperty + NULL, // delProperty + NULL, // getProperty + NULL, // setProperty + NULL, // enumerate + NULL, // resolve + NULL, // mayResolve + &WrapperPrivate::Finalizer, // finalize + NULL, // call + NULL, // hasInstance + NULL, // construct + &WrapperPrivate::Trace, // trace +}; + +const JSClass prototype_class_definition = { + "DictionaryInterfacePrototype", +}; + +const JSClass interface_object_class_definition = { + "DictionaryInterfaceConstructor", + 0, + NULL, // addProperty + NULL, // delProperty + NULL, // getProperty + NULL, // setProperty + NULL, // enumerate + NULL, // resolve + NULL, // mayResolve + NULL, // finalize + NULL, // call + &HasInstance, + NULL, +}; + +bool fcn_dictionaryOperation( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + const JSClass* proto_class = + MozjsDictionaryInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<DictionaryInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + DictionaryInterface* impl = + wrapper_private->wrappable<DictionaryInterface>().get(); + const size_t kMinArguments = 1; + if (args.length() < kMinArguments) { + exception_state.SetSimpleException(script::kInvalidNumberOfArguments); + return false; + } + // Non-optional arguments + TypeTraits<TestDictionary >::ConversionType dictionary; + + DCHECK_LT(0, args.length()); + JS::RootedValue non_optional_value0( + context, args[0]); + FromJSValue(context, + non_optional_value0, + kNoConversionFlags, + &exception_state, &dictionary); + if (exception_state.is_exception_set()) { + return false; + } + + impl->DictionaryOperation(dictionary); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + + + +const JSPropertySpec prototype_properties[] = { + JS_PS_END +}; + +const JSFunctionSpec prototype_functions[] = { + JS_FNSPEC( + "dictionaryOperation", fcn_dictionaryOperation, NULL, + 1, JSPROP_ENUMERATE, NULL), + JS_FS_END +}; + +const JSPropertySpec interface_object_properties[] = { + JS_PS_END +}; + +const JSFunctionSpec interface_object_functions[] = { + JS_FS_END +}; + +const JSPropertySpec own_properties[] = { + JS_PS_END +}; + +void InitializePrototypeAndInterfaceObject( + InterfaceData* interface_data, JSContext* context, + JS::HandleObject global_object) { + DCHECK(!interface_data->prototype); + DCHECK(!interface_data->interface_object); + DCHECK(JS_IsGlobalObject(global_object)); + + JS::RootedObject parent_prototype( + context, JS_GetObjectPrototype(context, global_object)); + DCHECK(parent_prototype); + + interface_data->prototype = JS_NewObjectWithGivenProto( + context, &prototype_class_definition, parent_prototype + ); + + JS::RootedObject rooted_prototype(context, interface_data->prototype); + bool success = JS_DefineProperties( + context, + rooted_prototype, + prototype_properties); + + DCHECK(success); + success = JS_DefineFunctions( + context, rooted_prototype, prototype_functions); + DCHECK(success); + + JS::RootedObject function_prototype( + context, JS_GetFunctionPrototype(context, global_object)); + DCHECK(function_prototype); + // Create the Interface object. + interface_data->interface_object = JS_NewObjectWithGivenProto( + context, &interface_object_class_definition, + function_prototype); + + // Add the InterfaceObject.name property. + JS::RootedObject rooted_interface_object( + context, interface_data->interface_object); + JS::RootedValue name_value(context); + const char name[] = + "DictionaryInterface"; + name_value.setString(JS_NewStringCopyZ(context, name)); + success = JS_DefineProperty( + context, rooted_interface_object, "name", name_value, JSPROP_READONLY, + NULL, NULL); + DCHECK(success); + + // Define interface object properties (including constants). + success = JS_DefineProperties(context, rooted_interface_object, + interface_object_properties); + DCHECK(success); + // Define interface object functions (static). + success = JS_DefineFunctions(context, rooted_interface_object, + interface_object_functions); + DCHECK(success); + + // Set the Prototype.constructor and Constructor.prototype properties. + DCHECK(interface_data->interface_object); + DCHECK(interface_data->prototype); + success = JS_LinkConstructorAndPrototype( + context, + rooted_interface_object, + rooted_prototype); + DCHECK(success); +} + +InterfaceData* GetInterfaceData(JSContext* context) { + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + // Use the address of the properties definition for this interface as a + // unique key for looking up the InterfaceData for this interface. + intptr_t key = reinterpret_cast<intptr_t>(&own_properties); + InterfaceData* interface_data = global_environment->GetInterfaceData(key); + if (!interface_data) { + interface_data = new InterfaceData(); + DCHECK(interface_data); + global_environment->CacheInterfaceData(key, interface_data); + DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key)); + } + return interface_data; +} + +} // namespace + +// static +JSObject* MozjsDictionaryInterface::CreateProxy( + JSContext* context, const scoped_refptr<Wrappable>& wrappable) { + DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); + JS::RootedObject global_object( + context, + MozjsGlobalEnvironment::GetFromContext(context)->global_object()); + DCHECK(global_object); + + InterfaceData* interface_data = GetInterfaceData(context); + JS::RootedObject prototype(context, GetPrototype(context, global_object)); + DCHECK(prototype); + JS::RootedObject new_object( + context, + JS_NewObjectWithGivenProto( + context, &instance_class_definition, prototype)); + DCHECK(new_object); + JS::RootedObject proxy(context, + ProxyHandler::NewProxy( + context, proxy_handler.Pointer(), new_object, prototype)); + WrapperPrivate::AddPrivateData(context, proxy, wrappable); + return proxy; +} + +// static +const JSClass* MozjsDictionaryInterface::PrototypeClass( + JSContext* context) { + DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); + JS::RootedObject global_object( + context, + MozjsGlobalEnvironment::GetFromContext(context)->global_object()); + DCHECK(global_object); + + JS::RootedObject prototype(context, GetPrototype(context, global_object)); + const JSClass* proto_class = JS_GetClass(prototype); + return proto_class; +} + +// static +JSObject* MozjsDictionaryInterface::GetPrototype( + JSContext* context, JS::HandleObject global_object) { + DCHECK(JS_IsGlobalObject(global_object)); + + InterfaceData* interface_data = GetInterfaceData(context); + if (!interface_data->prototype) { + // Create new prototype that has all the props and methods + InitializePrototypeAndInterfaceObject( + interface_data, context, global_object); + } + DCHECK(interface_data->prototype); + return interface_data->prototype; +} + +// static +JSObject* MozjsDictionaryInterface::GetInterfaceObject( + JSContext* context, JS::HandleObject global_object) { + DCHECK(JS_IsGlobalObject(global_object)); + + InterfaceData* interface_data = GetInterfaceData(context); + if (!interface_data->interface_object) { + InitializePrototypeAndInterfaceObject( + interface_data, context, global_object); + } + DCHECK(interface_data->interface_object); + return interface_data->interface_object; +} + + +namespace { +} // namespace + + +} // namespace testing +} // namespace bindings +} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_dictionary_interface.h b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_dictionary_interface.h new file mode 100644 index 0000000..e4f1d5b --- /dev/null +++ b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_dictionary_interface.h
@@ -0,0 +1,52 @@ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// clang-format off + +// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! +// Auto-generated from template: bindings/mozjs-45/templates/interface.h.template + +#ifndef MozjsDictionaryInterface_h +#define MozjsDictionaryInterface_h + +#include "base/hash_tables.h" +#include "base/lazy_instance.h" +#include "base/memory/ref_counted.h" +#include "base/threading/thread_checker.h" +#include "cobalt/base/polymorphic_downcast.h" +#include "cobalt/script/wrappable.h" +#include "cobalt/bindings/testing/dictionary_interface.h" + +#include "third_party/mozjs-45/js/src/jsapi.h" + +namespace cobalt { +namespace bindings { +namespace testing { + +class MozjsDictionaryInterface { + public: + static JSObject* CreateProxy(JSContext* context, + const scoped_refptr<script::Wrappable>& wrappable); + static const JSClass* PrototypeClass(JSContext* context); + static JSObject* GetPrototype(JSContext* context, + JS::HandleObject global_object); + static JSObject* GetInterfaceObject(JSContext* context, + JS::HandleObject global_object); +}; + +} // namespace testing +} // namespace bindings +} // namespace cobalt + +#endif // MozjsDictionaryInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_disabled_interface.cc b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_disabled_interface.cc new file mode 100644 index 0000000..ddfe206 --- /dev/null +++ b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_disabled_interface.cc
@@ -0,0 +1,502 @@ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// clang-format off + +// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! +// Auto-generated from template: bindings/mozjs-45/templates/interface.cc.template + +#if defined(NO_ENABLE_CONDITIONAL_INTERFACE) + +#include "cobalt/bindings/testing/mozjs_disabled_interface.h" + +#include "base/debug/trace_event.h" +#include "cobalt/base/polymorphic_downcast.h" +#include "cobalt/script/global_environment.h" +#include "cobalt/script/opaque_handle.h" +#include "cobalt/script/script_value.h" + +#include "base/lazy_instance.h" +#include "cobalt/script/exception_state.h" +#include "cobalt/script/mozjs-45/callback_function_conversion.h" +#include "cobalt/script/mozjs-45/conversion_helpers.h" +#include "cobalt/script/mozjs-45/mozjs_callback_function.h" +#include "cobalt/script/mozjs-45/mozjs_exception_state.h" +#include "cobalt/script/mozjs-45/mozjs_global_environment.h" +#include "cobalt/script/mozjs-45/mozjs_object_handle.h" +#include "cobalt/script/mozjs-45/mozjs_property_enumerator.h" +#include "cobalt/script/mozjs-45/mozjs_user_object_holder.h" +#include "cobalt/script/mozjs-45/proxy_handler.h" +#include "cobalt/script/mozjs-45/type_traits.h" +#include "cobalt/script/mozjs-45/wrapper_factory.h" +#include "cobalt/script/mozjs-45/wrapper_private.h" +#include "cobalt/script/property_enumerator.h" +#include "cobalt/script/sequence.h" +#include "third_party/mozjs-45/js/src/jsapi.h" +#include "third_party/mozjs-45/js/src/jsfriendapi.h" + +namespace { +using cobalt::bindings::testing::DisabledInterface; +using cobalt::bindings::testing::MozjsDisabledInterface; +using cobalt::script::CallbackInterfaceTraits; +using cobalt::script::GlobalEnvironment; +using cobalt::script::OpaqueHandle; +using cobalt::script::OpaqueHandleHolder; +using cobalt::script::ScriptValue; +using cobalt::script::Wrappable; + +using cobalt::script::CallbackFunction; +using cobalt::script::CallbackInterfaceTraits; +using cobalt::script::ExceptionState; +using cobalt::script::Wrappable; +using cobalt::script::mozjs::FromJSValue; +using cobalt::script::mozjs::InterfaceData; +using cobalt::script::mozjs::MozjsCallbackFunction; +using cobalt::script::mozjs::MozjsExceptionState; +using cobalt::script::mozjs::MozjsGlobalEnvironment; +using cobalt::script::mozjs::MozjsPropertyEnumerator; +using cobalt::script::mozjs::MozjsUserObjectHolder; +using cobalt::script::mozjs::ProxyHandler; +using cobalt::script::mozjs::ToJSValue; +using cobalt::script::mozjs::TypeTraits; +using cobalt::script::mozjs::WrapperFactory; +using cobalt::script::mozjs::WrapperPrivate; +using cobalt::script::mozjs::kConversionFlagNullable; +using cobalt::script::mozjs::kConversionFlagRestricted; +using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString; +using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString; +using cobalt::script::mozjs::kNoConversionFlags; +} // namespace + +namespace cobalt { +namespace bindings { +namespace testing { + +namespace { + +class MozjsDisabledInterfaceHandler : public ProxyHandler { + public: + MozjsDisabledInterfaceHandler() + : ProxyHandler(indexed_property_hooks, named_property_hooks) {} + + private: + static NamedPropertyHooks named_property_hooks; + static IndexedPropertyHooks indexed_property_hooks; +}; + +ProxyHandler::NamedPropertyHooks +MozjsDisabledInterfaceHandler::named_property_hooks = { + NULL, + NULL, + NULL, + NULL, + NULL, +}; +ProxyHandler::IndexedPropertyHooks +MozjsDisabledInterfaceHandler::indexed_property_hooks = { + NULL, + NULL, + NULL, + NULL, + NULL, +}; + +static base::LazyInstance<MozjsDisabledInterfaceHandler> + proxy_handler; + +bool HasInstance(JSContext *context, JS::HandleObject type, + JS::MutableHandleValue vp, bool *success) { + JS::RootedObject global_object( + context, JS_GetGlobalForObject(context, type)); + DCHECK(global_object); + + JS::RootedObject prototype( + context, MozjsDisabledInterface::GetPrototype(context, global_object)); + + // |IsDelegate| walks the prototype chain of an object returning true if + // .prototype is found. + bool is_delegate; + if (!IsDelegate(context, prototype, vp, &is_delegate)) { + *success = false; + return false; + } + + *success = is_delegate; + return true; +} + +const JSClass instance_class_definition = { + "DisabledInterface", + 0 | JSCLASS_HAS_PRIVATE, + NULL, // addProperty + NULL, // delProperty + NULL, // getProperty + NULL, // setProperty + NULL, // enumerate + NULL, // resolve + NULL, // mayResolve + &WrapperPrivate::Finalizer, // finalize + NULL, // call + NULL, // hasInstance + NULL, // construct + &WrapperPrivate::Trace, // trace +}; + +const JSClass prototype_class_definition = { + "DisabledInterfacePrototype", +}; + +const JSClass interface_object_class_definition = { + "DisabledInterfaceConstructor", + 0, + NULL, // addProperty + NULL, // delProperty + NULL, // getProperty + NULL, // setProperty + NULL, // enumerate + NULL, // resolve + NULL, // mayResolve + NULL, // finalize + NULL, // call + &HasInstance, + NULL, +}; + +bool get_disabledProperty( + JSContext* context, unsigned argc, JS::Value* vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + const JSClass* proto_class = + MozjsDisabledInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<DisabledInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + DisabledInterface* impl = + wrapper_private->wrappable<DisabledInterface>().get(); + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->disabled_property(), + &result_value); + } + if (!exception_state.is_exception_set()) { + args.rval().set(result_value); + } + return !exception_state.is_exception_set(); +} + +bool set_disabledProperty( + JSContext* context, unsigned argc, JS::Value* vp) { + + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + + const JSClass* proto_class = + MozjsDisabledInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<DisabledInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + DisabledInterface* impl = + wrapper_private->wrappable<DisabledInterface>().get(); + TypeTraits<int32_t >::ConversionType value; + if (args.length() != 1) { + NOTREACHED(); + return false; + } + FromJSValue(context, args[0], kNoConversionFlags, &exception_state, + &value); + if (exception_state.is_exception_set()) { + return false; + } + + impl->set_disabled_property(value); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + +bool fcn_disabledFunction( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + const JSClass* proto_class = + MozjsDisabledInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<DisabledInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + DisabledInterface* impl = + wrapper_private->wrappable<DisabledInterface>().get(); + + impl->DisabledFunction(); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + + + +const JSPropertySpec prototype_properties[] = { + { // Read/Write property + "disabledProperty", + JSPROP_SHARED | JSPROP_ENUMERATE, + { { &get_disabledProperty, NULL } }, + { { &set_disabledProperty, NULL } }, + }, + JS_PS_END +}; + +const JSFunctionSpec prototype_functions[] = { + JS_FNSPEC( + "disabledFunction", fcn_disabledFunction, NULL, + 0, JSPROP_ENUMERATE, NULL), + JS_FS_END +}; + +const JSPropertySpec interface_object_properties[] = { + JS_PS_END +}; + +const JSFunctionSpec interface_object_functions[] = { + JS_FS_END +}; + +const JSPropertySpec own_properties[] = { + JS_PS_END +}; + +void InitializePrototypeAndInterfaceObject( + InterfaceData* interface_data, JSContext* context, + JS::HandleObject global_object) { + DCHECK(!interface_data->prototype); + DCHECK(!interface_data->interface_object); + DCHECK(JS_IsGlobalObject(global_object)); + + JS::RootedObject parent_prototype( + context, JS_GetObjectPrototype(context, global_object)); + DCHECK(parent_prototype); + + interface_data->prototype = JS_NewObjectWithGivenProto( + context, &prototype_class_definition, parent_prototype + ); + + JS::RootedObject rooted_prototype(context, interface_data->prototype); + bool success = JS_DefineProperties( + context, + rooted_prototype, + prototype_properties); + + DCHECK(success); + success = JS_DefineFunctions( + context, rooted_prototype, prototype_functions); + DCHECK(success); + + JS::RootedObject function_prototype( + context, JS_GetFunctionPrototype(context, global_object)); + DCHECK(function_prototype); + // Create the Interface object. + interface_data->interface_object = JS_NewObjectWithGivenProto( + context, &interface_object_class_definition, + function_prototype); + + // Add the InterfaceObject.name property. + JS::RootedObject rooted_interface_object( + context, interface_data->interface_object); + JS::RootedValue name_value(context); + const char name[] = + "DisabledInterface"; + name_value.setString(JS_NewStringCopyZ(context, name)); + success = JS_DefineProperty( + context, rooted_interface_object, "name", name_value, JSPROP_READONLY, + NULL, NULL); + DCHECK(success); + + // Define interface object properties (including constants). + success = JS_DefineProperties(context, rooted_interface_object, + interface_object_properties); + DCHECK(success); + // Define interface object functions (static). + success = JS_DefineFunctions(context, rooted_interface_object, + interface_object_functions); + DCHECK(success); + + // Set the Prototype.constructor and Constructor.prototype properties. + DCHECK(interface_data->interface_object); + DCHECK(interface_data->prototype); + success = JS_LinkConstructorAndPrototype( + context, + rooted_interface_object, + rooted_prototype); + DCHECK(success); +} + +InterfaceData* GetInterfaceData(JSContext* context) { + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + // Use the address of the properties definition for this interface as a + // unique key for looking up the InterfaceData for this interface. + intptr_t key = reinterpret_cast<intptr_t>(&own_properties); + InterfaceData* interface_data = global_environment->GetInterfaceData(key); + if (!interface_data) { + interface_data = new InterfaceData(); + DCHECK(interface_data); + global_environment->CacheInterfaceData(key, interface_data); + DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key)); + } + return interface_data; +} + +} // namespace + +// static +JSObject* MozjsDisabledInterface::CreateProxy( + JSContext* context, const scoped_refptr<Wrappable>& wrappable) { + DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); + JS::RootedObject global_object( + context, + MozjsGlobalEnvironment::GetFromContext(context)->global_object()); + DCHECK(global_object); + + InterfaceData* interface_data = GetInterfaceData(context); + JS::RootedObject prototype(context, GetPrototype(context, global_object)); + DCHECK(prototype); + JS::RootedObject new_object( + context, + JS_NewObjectWithGivenProto( + context, &instance_class_definition, prototype)); + DCHECK(new_object); + JS::RootedObject proxy(context, + ProxyHandler::NewProxy( + context, proxy_handler.Pointer(), new_object, prototype)); + WrapperPrivate::AddPrivateData(context, proxy, wrappable); + return proxy; +} + +// static +const JSClass* MozjsDisabledInterface::PrototypeClass( + JSContext* context) { + DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); + JS::RootedObject global_object( + context, + MozjsGlobalEnvironment::GetFromContext(context)->global_object()); + DCHECK(global_object); + + JS::RootedObject prototype(context, GetPrototype(context, global_object)); + const JSClass* proto_class = JS_GetClass(prototype); + return proto_class; +} + +// static +JSObject* MozjsDisabledInterface::GetPrototype( + JSContext* context, JS::HandleObject global_object) { + DCHECK(JS_IsGlobalObject(global_object)); + + InterfaceData* interface_data = GetInterfaceData(context); + if (!interface_data->prototype) { + // Create new prototype that has all the props and methods + InitializePrototypeAndInterfaceObject( + interface_data, context, global_object); + } + DCHECK(interface_data->prototype); + return interface_data->prototype; +} + +// static +JSObject* MozjsDisabledInterface::GetInterfaceObject( + JSContext* context, JS::HandleObject global_object) { + DCHECK(JS_IsGlobalObject(global_object)); + + InterfaceData* interface_data = GetInterfaceData(context); + if (!interface_data->interface_object) { + InitializePrototypeAndInterfaceObject( + interface_data, context, global_object); + } + DCHECK(interface_data->interface_object); + return interface_data->interface_object; +} + + +namespace { +} // namespace + + +} // namespace testing +} // namespace bindings +} // namespace cobalt +#endif // defined(NO_ENABLE_CONDITIONAL_INTERFACE)
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_disabled_interface.h b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_disabled_interface.h new file mode 100644 index 0000000..d002588 --- /dev/null +++ b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_disabled_interface.h
@@ -0,0 +1,56 @@ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// clang-format off + +// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! +// Auto-generated from template: bindings/mozjs-45/templates/interface.h.template + +#ifndef MozjsDisabledInterface_h +#define MozjsDisabledInterface_h + +#if defined(NO_ENABLE_CONDITIONAL_INTERFACE) + +#include "base/hash_tables.h" +#include "base/lazy_instance.h" +#include "base/memory/ref_counted.h" +#include "base/threading/thread_checker.h" +#include "cobalt/base/polymorphic_downcast.h" +#include "cobalt/script/wrappable.h" +#include "cobalt/bindings/testing/disabled_interface.h" + +#include "third_party/mozjs-45/js/src/jsapi.h" + +namespace cobalt { +namespace bindings { +namespace testing { + +class MozjsDisabledInterface { + public: + static JSObject* CreateProxy(JSContext* context, + const scoped_refptr<script::Wrappable>& wrappable); + static const JSClass* PrototypeClass(JSContext* context); + static JSObject* GetPrototype(JSContext* context, + JS::HandleObject global_object); + static JSObject* GetInterfaceObject(JSContext* context, + JS::HandleObject global_object); +}; + +} // namespace testing +} // namespace bindings +} // namespace cobalt + +#endif // defined(NO_ENABLE_CONDITIONAL_INTERFACE) + +#endif // MozjsDisabledInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_dom_string_test_interface.cc b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_dom_string_test_interface.cc new file mode 100644 index 0000000..5f0d7b5 --- /dev/null +++ b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_dom_string_test_interface.cc
@@ -0,0 +1,835 @@ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// clang-format off + +// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! +// Auto-generated from template: bindings/mozjs-45/templates/interface.cc.template + +#include "cobalt/bindings/testing/mozjs_dom_string_test_interface.h" + +#include "base/debug/trace_event.h" +#include "cobalt/base/polymorphic_downcast.h" +#include "cobalt/script/global_environment.h" +#include "cobalt/script/opaque_handle.h" +#include "cobalt/script/script_value.h" + +#include "base/lazy_instance.h" +#include "cobalt/script/exception_state.h" +#include "cobalt/script/mozjs-45/callback_function_conversion.h" +#include "cobalt/script/mozjs-45/conversion_helpers.h" +#include "cobalt/script/mozjs-45/mozjs_callback_function.h" +#include "cobalt/script/mozjs-45/mozjs_exception_state.h" +#include "cobalt/script/mozjs-45/mozjs_global_environment.h" +#include "cobalt/script/mozjs-45/mozjs_object_handle.h" +#include "cobalt/script/mozjs-45/mozjs_property_enumerator.h" +#include "cobalt/script/mozjs-45/mozjs_user_object_holder.h" +#include "cobalt/script/mozjs-45/proxy_handler.h" +#include "cobalt/script/mozjs-45/type_traits.h" +#include "cobalt/script/mozjs-45/wrapper_factory.h" +#include "cobalt/script/mozjs-45/wrapper_private.h" +#include "cobalt/script/property_enumerator.h" +#include "cobalt/script/sequence.h" +#include "third_party/mozjs-45/js/src/jsapi.h" +#include "third_party/mozjs-45/js/src/jsfriendapi.h" + +namespace { +using cobalt::bindings::testing::DOMStringTestInterface; +using cobalt::bindings::testing::MozjsDOMStringTestInterface; +using cobalt::script::CallbackInterfaceTraits; +using cobalt::script::GlobalEnvironment; +using cobalt::script::OpaqueHandle; +using cobalt::script::OpaqueHandleHolder; +using cobalt::script::ScriptValue; +using cobalt::script::Wrappable; + +using cobalt::script::CallbackFunction; +using cobalt::script::CallbackInterfaceTraits; +using cobalt::script::ExceptionState; +using cobalt::script::Wrappable; +using cobalt::script::mozjs::FromJSValue; +using cobalt::script::mozjs::InterfaceData; +using cobalt::script::mozjs::MozjsCallbackFunction; +using cobalt::script::mozjs::MozjsExceptionState; +using cobalt::script::mozjs::MozjsGlobalEnvironment; +using cobalt::script::mozjs::MozjsPropertyEnumerator; +using cobalt::script::mozjs::MozjsUserObjectHolder; +using cobalt::script::mozjs::ProxyHandler; +using cobalt::script::mozjs::ToJSValue; +using cobalt::script::mozjs::TypeTraits; +using cobalt::script::mozjs::WrapperFactory; +using cobalt::script::mozjs::WrapperPrivate; +using cobalt::script::mozjs::kConversionFlagNullable; +using cobalt::script::mozjs::kConversionFlagRestricted; +using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString; +using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString; +using cobalt::script::mozjs::kNoConversionFlags; +} // namespace + +namespace cobalt { +namespace bindings { +namespace testing { + +namespace { + +class MozjsDOMStringTestInterfaceHandler : public ProxyHandler { + public: + MozjsDOMStringTestInterfaceHandler() + : ProxyHandler(indexed_property_hooks, named_property_hooks) {} + + private: + static NamedPropertyHooks named_property_hooks; + static IndexedPropertyHooks indexed_property_hooks; +}; + +ProxyHandler::NamedPropertyHooks +MozjsDOMStringTestInterfaceHandler::named_property_hooks = { + NULL, + NULL, + NULL, + NULL, + NULL, +}; +ProxyHandler::IndexedPropertyHooks +MozjsDOMStringTestInterfaceHandler::indexed_property_hooks = { + NULL, + NULL, + NULL, + NULL, + NULL, +}; + +static base::LazyInstance<MozjsDOMStringTestInterfaceHandler> + proxy_handler; + +bool HasInstance(JSContext *context, JS::HandleObject type, + JS::MutableHandleValue vp, bool *success) { + JS::RootedObject global_object( + context, JS_GetGlobalForObject(context, type)); + DCHECK(global_object); + + JS::RootedObject prototype( + context, MozjsDOMStringTestInterface::GetPrototype(context, global_object)); + + // |IsDelegate| walks the prototype chain of an object returning true if + // .prototype is found. + bool is_delegate; + if (!IsDelegate(context, prototype, vp, &is_delegate)) { + *success = false; + return false; + } + + *success = is_delegate; + return true; +} + +const JSClass instance_class_definition = { + "DOMStringTestInterface", + 0 | JSCLASS_HAS_PRIVATE, + NULL, // addProperty + NULL, // delProperty + NULL, // getProperty + NULL, // setProperty + NULL, // enumerate + NULL, // resolve + NULL, // mayResolve + &WrapperPrivate::Finalizer, // finalize + NULL, // call + NULL, // hasInstance + NULL, // construct + &WrapperPrivate::Trace, // trace +}; + +const JSClass prototype_class_definition = { + "DOMStringTestInterfacePrototype", +}; + +const JSClass interface_object_class_definition = { + "DOMStringTestInterfaceConstructor", + 0, + NULL, // addProperty + NULL, // delProperty + NULL, // getProperty + NULL, // setProperty + NULL, // enumerate + NULL, // resolve + NULL, // mayResolve + NULL, // finalize + NULL, // call + &HasInstance, + NULL, +}; + +bool get_property( + JSContext* context, unsigned argc, JS::Value* vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + const JSClass* proto_class = + MozjsDOMStringTestInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<DOMStringTestInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + DOMStringTestInterface* impl = + wrapper_private->wrappable<DOMStringTestInterface>().get(); + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->property(), + &result_value); + } + if (!exception_state.is_exception_set()) { + args.rval().set(result_value); + } + return !exception_state.is_exception_set(); +} + +bool set_property( + JSContext* context, unsigned argc, JS::Value* vp) { + + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + + const JSClass* proto_class = + MozjsDOMStringTestInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<DOMStringTestInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + DOMStringTestInterface* impl = + wrapper_private->wrappable<DOMStringTestInterface>().get(); + TypeTraits<std::string >::ConversionType value; + if (args.length() != 1) { + NOTREACHED(); + return false; + } + FromJSValue(context, args[0], kNoConversionFlags, &exception_state, + &value); + if (exception_state.is_exception_set()) { + return false; + } + + impl->set_property(value); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + +bool get_readOnlyProperty( + JSContext* context, unsigned argc, JS::Value* vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + const JSClass* proto_class = + MozjsDOMStringTestInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<DOMStringTestInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + DOMStringTestInterface* impl = + wrapper_private->wrappable<DOMStringTestInterface>().get(); + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->read_only_property(), + &result_value); + } + if (!exception_state.is_exception_set()) { + args.rval().set(result_value); + } + return !exception_state.is_exception_set(); +} + + +bool get_readOnlyTokenProperty( + JSContext* context, unsigned argc, JS::Value* vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + const JSClass* proto_class = + MozjsDOMStringTestInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<DOMStringTestInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + DOMStringTestInterface* impl = + wrapper_private->wrappable<DOMStringTestInterface>().get(); + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->read_only_token_property(), + &result_value); + } + if (!exception_state.is_exception_set()) { + args.rval().set(result_value); + } + return !exception_state.is_exception_set(); +} + + +bool get_nullIsEmptyProperty( + JSContext* context, unsigned argc, JS::Value* vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + const JSClass* proto_class = + MozjsDOMStringTestInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<DOMStringTestInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + DOMStringTestInterface* impl = + wrapper_private->wrappable<DOMStringTestInterface>().get(); + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->null_is_empty_property(), + &result_value); + } + if (!exception_state.is_exception_set()) { + args.rval().set(result_value); + } + return !exception_state.is_exception_set(); +} + +bool set_nullIsEmptyProperty( + JSContext* context, unsigned argc, JS::Value* vp) { + + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + + const JSClass* proto_class = + MozjsDOMStringTestInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<DOMStringTestInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + DOMStringTestInterface* impl = + wrapper_private->wrappable<DOMStringTestInterface>().get(); + TypeTraits<std::string >::ConversionType value; + if (args.length() != 1) { + NOTREACHED(); + return false; + } + FromJSValue(context, args[0], (kConversionFlagTreatNullAsEmptyString), &exception_state, + &value); + if (exception_state.is_exception_set()) { + return false; + } + + impl->set_null_is_empty_property(value); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + +bool get_undefinedIsEmptyProperty( + JSContext* context, unsigned argc, JS::Value* vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + const JSClass* proto_class = + MozjsDOMStringTestInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<DOMStringTestInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + DOMStringTestInterface* impl = + wrapper_private->wrappable<DOMStringTestInterface>().get(); + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->undefined_is_empty_property(), + &result_value); + } + if (!exception_state.is_exception_set()) { + args.rval().set(result_value); + } + return !exception_state.is_exception_set(); +} + +bool set_undefinedIsEmptyProperty( + JSContext* context, unsigned argc, JS::Value* vp) { + + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + + const JSClass* proto_class = + MozjsDOMStringTestInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<DOMStringTestInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + DOMStringTestInterface* impl = + wrapper_private->wrappable<DOMStringTestInterface>().get(); + TypeTraits<std::string >::ConversionType value; + if (args.length() != 1) { + NOTREACHED(); + return false; + } + FromJSValue(context, args[0], (kConversionFlagTreatUndefinedAsEmptyString), &exception_state, + &value); + if (exception_state.is_exception_set()) { + return false; + } + + impl->set_undefined_is_empty_property(value); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + +bool get_nullableUndefinedIsEmptyProperty( + JSContext* context, unsigned argc, JS::Value* vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + const JSClass* proto_class = + MozjsDOMStringTestInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<DOMStringTestInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + DOMStringTestInterface* impl = + wrapper_private->wrappable<DOMStringTestInterface>().get(); + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->nullable_undefined_is_empty_property(), + &result_value); + } + if (!exception_state.is_exception_set()) { + args.rval().set(result_value); + } + return !exception_state.is_exception_set(); +} + +bool set_nullableUndefinedIsEmptyProperty( + JSContext* context, unsigned argc, JS::Value* vp) { + + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + + const JSClass* proto_class = + MozjsDOMStringTestInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<DOMStringTestInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + DOMStringTestInterface* impl = + wrapper_private->wrappable<DOMStringTestInterface>().get(); + TypeTraits<base::optional<std::string > >::ConversionType value; + if (args.length() != 1) { + NOTREACHED(); + return false; + } + FromJSValue(context, args[0], (kConversionFlagNullable | kConversionFlagTreatUndefinedAsEmptyString), &exception_state, + &value); + if (exception_state.is_exception_set()) { + return false; + } + + impl->set_nullable_undefined_is_empty_property(value); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + + + +const JSPropertySpec prototype_properties[] = { + { // Read/Write property + "property", + JSPROP_SHARED | JSPROP_ENUMERATE, + { { &get_property, NULL } }, + { { &set_property, NULL } }, + }, + { // Readonly attribute + "readOnlyProperty", + JSPROP_SHARED | JSPROP_ENUMERATE, + { { &get_readOnlyProperty, NULL } }, + JSNATIVE_WRAPPER(NULL), + }, + { // Readonly attribute + "readOnlyTokenProperty", + JSPROP_SHARED | JSPROP_ENUMERATE, + { { &get_readOnlyTokenProperty, NULL } }, + JSNATIVE_WRAPPER(NULL), + }, + { // Read/Write property + "nullIsEmptyProperty", + JSPROP_SHARED | JSPROP_ENUMERATE, + { { &get_nullIsEmptyProperty, NULL } }, + { { &set_nullIsEmptyProperty, NULL } }, + }, + { // Read/Write property + "undefinedIsEmptyProperty", + JSPROP_SHARED | JSPROP_ENUMERATE, + { { &get_undefinedIsEmptyProperty, NULL } }, + { { &set_undefinedIsEmptyProperty, NULL } }, + }, + { // Read/Write property + "nullableUndefinedIsEmptyProperty", + JSPROP_SHARED | JSPROP_ENUMERATE, + { { &get_nullableUndefinedIsEmptyProperty, NULL } }, + { { &set_nullableUndefinedIsEmptyProperty, NULL } }, + }, + JS_PS_END +}; + +const JSFunctionSpec prototype_functions[] = { + JS_FS_END +}; + +const JSPropertySpec interface_object_properties[] = { + JS_PS_END +}; + +const JSFunctionSpec interface_object_functions[] = { + JS_FS_END +}; + +const JSPropertySpec own_properties[] = { + JS_PS_END +}; + +void InitializePrototypeAndInterfaceObject( + InterfaceData* interface_data, JSContext* context, + JS::HandleObject global_object) { + DCHECK(!interface_data->prototype); + DCHECK(!interface_data->interface_object); + DCHECK(JS_IsGlobalObject(global_object)); + + JS::RootedObject parent_prototype( + context, JS_GetObjectPrototype(context, global_object)); + DCHECK(parent_prototype); + + interface_data->prototype = JS_NewObjectWithGivenProto( + context, &prototype_class_definition, parent_prototype + ); + + JS::RootedObject rooted_prototype(context, interface_data->prototype); + bool success = JS_DefineProperties( + context, + rooted_prototype, + prototype_properties); + + DCHECK(success); + success = JS_DefineFunctions( + context, rooted_prototype, prototype_functions); + DCHECK(success); + + JS::RootedObject function_prototype( + context, JS_GetFunctionPrototype(context, global_object)); + DCHECK(function_prototype); + // Create the Interface object. + interface_data->interface_object = JS_NewObjectWithGivenProto( + context, &interface_object_class_definition, + function_prototype); + + // Add the InterfaceObject.name property. + JS::RootedObject rooted_interface_object( + context, interface_data->interface_object); + JS::RootedValue name_value(context); + const char name[] = + "DOMStringTestInterface"; + name_value.setString(JS_NewStringCopyZ(context, name)); + success = JS_DefineProperty( + context, rooted_interface_object, "name", name_value, JSPROP_READONLY, + NULL, NULL); + DCHECK(success); + + // Define interface object properties (including constants). + success = JS_DefineProperties(context, rooted_interface_object, + interface_object_properties); + DCHECK(success); + // Define interface object functions (static). + success = JS_DefineFunctions(context, rooted_interface_object, + interface_object_functions); + DCHECK(success); + + // Set the Prototype.constructor and Constructor.prototype properties. + DCHECK(interface_data->interface_object); + DCHECK(interface_data->prototype); + success = JS_LinkConstructorAndPrototype( + context, + rooted_interface_object, + rooted_prototype); + DCHECK(success); +} + +InterfaceData* GetInterfaceData(JSContext* context) { + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + // Use the address of the properties definition for this interface as a + // unique key for looking up the InterfaceData for this interface. + intptr_t key = reinterpret_cast<intptr_t>(&own_properties); + InterfaceData* interface_data = global_environment->GetInterfaceData(key); + if (!interface_data) { + interface_data = new InterfaceData(); + DCHECK(interface_data); + global_environment->CacheInterfaceData(key, interface_data); + DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key)); + } + return interface_data; +} + +} // namespace + +// static +JSObject* MozjsDOMStringTestInterface::CreateProxy( + JSContext* context, const scoped_refptr<Wrappable>& wrappable) { + DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); + JS::RootedObject global_object( + context, + MozjsGlobalEnvironment::GetFromContext(context)->global_object()); + DCHECK(global_object); + + InterfaceData* interface_data = GetInterfaceData(context); + JS::RootedObject prototype(context, GetPrototype(context, global_object)); + DCHECK(prototype); + JS::RootedObject new_object( + context, + JS_NewObjectWithGivenProto( + context, &instance_class_definition, prototype)); + DCHECK(new_object); + JS::RootedObject proxy(context, + ProxyHandler::NewProxy( + context, proxy_handler.Pointer(), new_object, prototype)); + WrapperPrivate::AddPrivateData(context, proxy, wrappable); + return proxy; +} + +// static +const JSClass* MozjsDOMStringTestInterface::PrototypeClass( + JSContext* context) { + DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); + JS::RootedObject global_object( + context, + MozjsGlobalEnvironment::GetFromContext(context)->global_object()); + DCHECK(global_object); + + JS::RootedObject prototype(context, GetPrototype(context, global_object)); + const JSClass* proto_class = JS_GetClass(prototype); + return proto_class; +} + +// static +JSObject* MozjsDOMStringTestInterface::GetPrototype( + JSContext* context, JS::HandleObject global_object) { + DCHECK(JS_IsGlobalObject(global_object)); + + InterfaceData* interface_data = GetInterfaceData(context); + if (!interface_data->prototype) { + // Create new prototype that has all the props and methods + InitializePrototypeAndInterfaceObject( + interface_data, context, global_object); + } + DCHECK(interface_data->prototype); + return interface_data->prototype; +} + +// static +JSObject* MozjsDOMStringTestInterface::GetInterfaceObject( + JSContext* context, JS::HandleObject global_object) { + DCHECK(JS_IsGlobalObject(global_object)); + + InterfaceData* interface_data = GetInterfaceData(context); + if (!interface_data->interface_object) { + InitializePrototypeAndInterfaceObject( + interface_data, context, global_object); + } + DCHECK(interface_data->interface_object); + return interface_data->interface_object; +} + + +namespace { +} // namespace + + +} // namespace testing +} // namespace bindings +} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_dom_string_test_interface.h b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_dom_string_test_interface.h new file mode 100644 index 0000000..3c92b55 --- /dev/null +++ b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_dom_string_test_interface.h
@@ -0,0 +1,52 @@ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// clang-format off + +// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! +// Auto-generated from template: bindings/mozjs-45/templates/interface.h.template + +#ifndef MozjsDOMStringTestInterface_h +#define MozjsDOMStringTestInterface_h + +#include "base/hash_tables.h" +#include "base/lazy_instance.h" +#include "base/memory/ref_counted.h" +#include "base/threading/thread_checker.h" +#include "cobalt/base/polymorphic_downcast.h" +#include "cobalt/script/wrappable.h" +#include "cobalt/bindings/testing/dom_string_test_interface.h" + +#include "third_party/mozjs-45/js/src/jsapi.h" + +namespace cobalt { +namespace bindings { +namespace testing { + +class MozjsDOMStringTestInterface { + public: + static JSObject* CreateProxy(JSContext* context, + const scoped_refptr<script::Wrappable>& wrappable); + static const JSClass* PrototypeClass(JSContext* context); + static JSObject* GetPrototype(JSContext* context, + JS::HandleObject global_object); + static JSObject* GetInterfaceObject(JSContext* context, + JS::HandleObject global_object); +}; + +} // namespace testing +} // namespace bindings +} // namespace cobalt + +#endif // MozjsDOMStringTestInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_enumeration_interface.cc b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_enumeration_interface.cc new file mode 100644 index 0000000..a2ff077 --- /dev/null +++ b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_enumeration_interface.cc
@@ -0,0 +1,534 @@ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// clang-format off + +// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! +// Auto-generated from template: bindings/mozjs-45/templates/interface.cc.template + +#include "cobalt/bindings/testing/mozjs_enumeration_interface.h" + +#include "base/debug/trace_event.h" +#include "cobalt/base/polymorphic_downcast.h" +#include "cobalt/script/global_environment.h" +#include "cobalt/script/opaque_handle.h" +#include "cobalt/script/script_value.h" + +#include "base/lazy_instance.h" +#include "cobalt/script/exception_state.h" +#include "cobalt/script/mozjs-45/callback_function_conversion.h" +#include "cobalt/script/mozjs-45/conversion_helpers.h" +#include "cobalt/script/mozjs-45/mozjs_callback_function.h" +#include "cobalt/script/mozjs-45/mozjs_exception_state.h" +#include "cobalt/script/mozjs-45/mozjs_global_environment.h" +#include "cobalt/script/mozjs-45/mozjs_object_handle.h" +#include "cobalt/script/mozjs-45/mozjs_property_enumerator.h" +#include "cobalt/script/mozjs-45/mozjs_user_object_holder.h" +#include "cobalt/script/mozjs-45/proxy_handler.h" +#include "cobalt/script/mozjs-45/type_traits.h" +#include "cobalt/script/mozjs-45/wrapper_factory.h" +#include "cobalt/script/mozjs-45/wrapper_private.h" +#include "cobalt/script/property_enumerator.h" +#include "cobalt/script/sequence.h" +#include "third_party/mozjs-45/js/src/jsapi.h" +#include "third_party/mozjs-45/js/src/jsfriendapi.h" + +namespace { +using cobalt::bindings::testing::EnumerationInterface; +using cobalt::bindings::testing::MozjsEnumerationInterface; +using cobalt::script::CallbackInterfaceTraits; +using cobalt::script::GlobalEnvironment; +using cobalt::script::OpaqueHandle; +using cobalt::script::OpaqueHandleHolder; +using cobalt::script::ScriptValue; +using cobalt::script::Wrappable; + +using cobalt::script::CallbackFunction; +using cobalt::script::CallbackInterfaceTraits; +using cobalt::script::ExceptionState; +using cobalt::script::Wrappable; +using cobalt::script::mozjs::FromJSValue; +using cobalt::script::mozjs::InterfaceData; +using cobalt::script::mozjs::MozjsCallbackFunction; +using cobalt::script::mozjs::MozjsExceptionState; +using cobalt::script::mozjs::MozjsGlobalEnvironment; +using cobalt::script::mozjs::MozjsPropertyEnumerator; +using cobalt::script::mozjs::MozjsUserObjectHolder; +using cobalt::script::mozjs::ProxyHandler; +using cobalt::script::mozjs::ToJSValue; +using cobalt::script::mozjs::TypeTraits; +using cobalt::script::mozjs::WrapperFactory; +using cobalt::script::mozjs::WrapperPrivate; +using cobalt::script::mozjs::kConversionFlagNullable; +using cobalt::script::mozjs::kConversionFlagRestricted; +using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString; +using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString; +using cobalt::script::mozjs::kNoConversionFlags; +// Declare and define these in the same namespace that the other overloads +// were brought into with the using declaration. +void ToJSValue( + JSContext* context, + EnumerationInterface::TestEnum in_enum, + JS::MutableHandleValue out_value); +void FromJSValue(JSContext* context, JS::HandleValue value, + int conversion_flags, ExceptionState* exception_state, + EnumerationInterface::TestEnum* out_enum); +} // namespace + +namespace cobalt { +namespace bindings { +namespace testing { + +namespace { + +class MozjsEnumerationInterfaceHandler : public ProxyHandler { + public: + MozjsEnumerationInterfaceHandler() + : ProxyHandler(indexed_property_hooks, named_property_hooks) {} + + private: + static NamedPropertyHooks named_property_hooks; + static IndexedPropertyHooks indexed_property_hooks; +}; + +ProxyHandler::NamedPropertyHooks +MozjsEnumerationInterfaceHandler::named_property_hooks = { + NULL, + NULL, + NULL, + NULL, + NULL, +}; +ProxyHandler::IndexedPropertyHooks +MozjsEnumerationInterfaceHandler::indexed_property_hooks = { + NULL, + NULL, + NULL, + NULL, + NULL, +}; + +static base::LazyInstance<MozjsEnumerationInterfaceHandler> + proxy_handler; + +bool Constructor(JSContext* context, unsigned int argc, JS::Value* vp); +bool HasInstance(JSContext *context, JS::HandleObject type, + JS::MutableHandleValue vp, bool *success) { + JS::RootedObject global_object( + context, JS_GetGlobalForObject(context, type)); + DCHECK(global_object); + + JS::RootedObject prototype( + context, MozjsEnumerationInterface::GetPrototype(context, global_object)); + + // |IsDelegate| walks the prototype chain of an object returning true if + // .prototype is found. + bool is_delegate; + if (!IsDelegate(context, prototype, vp, &is_delegate)) { + *success = false; + return false; + } + + *success = is_delegate; + return true; +} + +const JSClass instance_class_definition = { + "EnumerationInterface", + 0 | JSCLASS_HAS_PRIVATE, + NULL, // addProperty + NULL, // delProperty + NULL, // getProperty + NULL, // setProperty + NULL, // enumerate + NULL, // resolve + NULL, // mayResolve + &WrapperPrivate::Finalizer, // finalize + NULL, // call + NULL, // hasInstance + NULL, // construct + &WrapperPrivate::Trace, // trace +}; + +const JSClass prototype_class_definition = { + "EnumerationInterfacePrototype", +}; + +const JSClass interface_object_class_definition = { + "EnumerationInterfaceConstructor", + 0, + NULL, // addProperty + NULL, // delProperty + NULL, // getProperty + NULL, // setProperty + NULL, // enumerate + NULL, // resolve + NULL, // mayResolve + NULL, // finalize + NULL, // call + &HasInstance, + Constructor, +}; + +bool get_enumProperty( + JSContext* context, unsigned argc, JS::Value* vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + const JSClass* proto_class = + MozjsEnumerationInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<EnumerationInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + EnumerationInterface* impl = + wrapper_private->wrappable<EnumerationInterface>().get(); + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->enum_property(), + &result_value); + } + if (!exception_state.is_exception_set()) { + args.rval().set(result_value); + } + return !exception_state.is_exception_set(); +} + +bool set_enumProperty( + JSContext* context, unsigned argc, JS::Value* vp) { + + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + + const JSClass* proto_class = + MozjsEnumerationInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<EnumerationInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + EnumerationInterface* impl = + wrapper_private->wrappable<EnumerationInterface>().get(); + TypeTraits<EnumerationInterface::TestEnum >::ConversionType value; + if (args.length() != 1) { + NOTREACHED(); + return false; + } + FromJSValue(context, args[0], kNoConversionFlags, &exception_state, + &value); + if (exception_state.is_exception_set()) { + return false; + } + + impl->set_enum_property(value); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + + + +const JSPropertySpec prototype_properties[] = { + { // Read/Write property + "enumProperty", + JSPROP_SHARED | JSPROP_ENUMERATE, + { { &get_enumProperty, NULL } }, + { { &set_enumProperty, NULL } }, + }, + JS_PS_END +}; + +const JSFunctionSpec prototype_functions[] = { + JS_FS_END +}; + +const JSPropertySpec interface_object_properties[] = { + JS_PS_END +}; + +const JSFunctionSpec interface_object_functions[] = { + JS_FS_END +}; + +const JSPropertySpec own_properties[] = { + JS_PS_END +}; + +void InitializePrototypeAndInterfaceObject( + InterfaceData* interface_data, JSContext* context, + JS::HandleObject global_object) { + DCHECK(!interface_data->prototype); + DCHECK(!interface_data->interface_object); + DCHECK(JS_IsGlobalObject(global_object)); + + JS::RootedObject parent_prototype( + context, JS_GetObjectPrototype(context, global_object)); + DCHECK(parent_prototype); + + interface_data->prototype = JS_NewObjectWithGivenProto( + context, &prototype_class_definition, parent_prototype + ); + + JS::RootedObject rooted_prototype(context, interface_data->prototype); + bool success = JS_DefineProperties( + context, + rooted_prototype, + prototype_properties); + + DCHECK(success); + success = JS_DefineFunctions( + context, rooted_prototype, prototype_functions); + DCHECK(success); + + JS::RootedObject function_prototype( + context, JS_GetFunctionPrototype(context, global_object)); + DCHECK(function_prototype); + // Create the Interface object. + interface_data->interface_object = JS_NewObjectWithGivenProto( + context, &interface_object_class_definition, + function_prototype); + + // Add the InterfaceObject.name property. + JS::RootedObject rooted_interface_object( + context, interface_data->interface_object); + JS::RootedValue name_value(context); + const char name[] = + "EnumerationInterface"; + name_value.setString(JS_NewStringCopyZ(context, name)); + success = JS_DefineProperty( + context, rooted_interface_object, "name", name_value, JSPROP_READONLY, + NULL, NULL); + DCHECK(success); + + // Add the InterfaceObject.length property. It is set to the length of the + // shortest argument list of all overload constructors. + JS::RootedValue length_value(context); + length_value.setInt32(0); + success = JS_DefineProperty( + context, rooted_interface_object, "length", length_value, + JSPROP_READONLY, NULL, NULL); + DCHECK(success); + + // Define interface object properties (including constants). + success = JS_DefineProperties(context, rooted_interface_object, + interface_object_properties); + DCHECK(success); + // Define interface object functions (static). + success = JS_DefineFunctions(context, rooted_interface_object, + interface_object_functions); + DCHECK(success); + + // Set the Prototype.constructor and Constructor.prototype properties. + DCHECK(interface_data->interface_object); + DCHECK(interface_data->prototype); + success = JS_LinkConstructorAndPrototype( + context, + rooted_interface_object, + rooted_prototype); + DCHECK(success); +} + +InterfaceData* GetInterfaceData(JSContext* context) { + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + // Use the address of the properties definition for this interface as a + // unique key for looking up the InterfaceData for this interface. + intptr_t key = reinterpret_cast<intptr_t>(&own_properties); + InterfaceData* interface_data = global_environment->GetInterfaceData(key); + if (!interface_data) { + interface_data = new InterfaceData(); + DCHECK(interface_data); + global_environment->CacheInterfaceData(key, interface_data); + DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key)); + } + return interface_data; +} + +} // namespace + +// static +JSObject* MozjsEnumerationInterface::CreateProxy( + JSContext* context, const scoped_refptr<Wrappable>& wrappable) { + DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); + JS::RootedObject global_object( + context, + MozjsGlobalEnvironment::GetFromContext(context)->global_object()); + DCHECK(global_object); + + InterfaceData* interface_data = GetInterfaceData(context); + JS::RootedObject prototype(context, GetPrototype(context, global_object)); + DCHECK(prototype); + JS::RootedObject new_object( + context, + JS_NewObjectWithGivenProto( + context, &instance_class_definition, prototype)); + DCHECK(new_object); + JS::RootedObject proxy(context, + ProxyHandler::NewProxy( + context, proxy_handler.Pointer(), new_object, prototype)); + WrapperPrivate::AddPrivateData(context, proxy, wrappable); + return proxy; +} + +// static +const JSClass* MozjsEnumerationInterface::PrototypeClass( + JSContext* context) { + DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); + JS::RootedObject global_object( + context, + MozjsGlobalEnvironment::GetFromContext(context)->global_object()); + DCHECK(global_object); + + JS::RootedObject prototype(context, GetPrototype(context, global_object)); + const JSClass* proto_class = JS_GetClass(prototype); + return proto_class; +} + +// static +JSObject* MozjsEnumerationInterface::GetPrototype( + JSContext* context, JS::HandleObject global_object) { + DCHECK(JS_IsGlobalObject(global_object)); + + InterfaceData* interface_data = GetInterfaceData(context); + if (!interface_data->prototype) { + // Create new prototype that has all the props and methods + InitializePrototypeAndInterfaceObject( + interface_data, context, global_object); + } + DCHECK(interface_data->prototype); + return interface_data->prototype; +} + +// static +JSObject* MozjsEnumerationInterface::GetInterfaceObject( + JSContext* context, JS::HandleObject global_object) { + DCHECK(JS_IsGlobalObject(global_object)); + + InterfaceData* interface_data = GetInterfaceData(context); + if (!interface_data->interface_object) { + InitializePrototypeAndInterfaceObject( + interface_data, context, global_object); + } + DCHECK(interface_data->interface_object); + return interface_data->interface_object; +} + + +namespace { +bool Constructor(JSContext* context, unsigned int argc, JS::Value* vp) { + MozjsExceptionState exception_state(context); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + + scoped_refptr<EnumerationInterface> new_object = + new EnumerationInterface(); + JS::RootedValue result_value(context); + ToJSValue(context, new_object, &result_value); + DCHECK(result_value.isObject()); + args.rval().setObject(result_value.toObject()); + return true; +} +} // namespace + + +} // namespace testing +} // namespace bindings +} // namespace cobalt + +namespace { + +inline void ToJSValue( + JSContext* context, + EnumerationInterface::TestEnum in_enum, + JS::MutableHandleValue out_value) { + + switch (in_enum) { + case EnumerationInterface::kAlpha: + ToJSValue(context, std::string("alpha"), out_value); + return; + case EnumerationInterface::kBeta: + ToJSValue(context, std::string("beta"), out_value); + return; + case EnumerationInterface::kGamma: + ToJSValue(context, std::string("gamma"), out_value); + return; + default: + NOTREACHED(); + out_value.set(JS::UndefinedValue()); + } +} + +inline void FromJSValue(JSContext* context, JS::HandleValue value, + int conversion_flags, ExceptionState* exception_state, + EnumerationInterface::TestEnum* out_enum) { + DCHECK_EQ(0, conversion_flags) << "Unexpected conversion flags."; + // JSValue -> IDL enum algorithm described here: + // http://heycam.github.io/webidl/#es-enumeration + // 1. Let S be the result of calling ToString(V). + JS::RootedString rooted_string(context, JS::ToString(context, value)); + + bool match = false; +// 3. Return the enumeration value of type E that is equal to S. +if (JS_StringEqualsAscii( + context, rooted_string, "alpha", &match) + && match) { + *out_enum = EnumerationInterface::kAlpha; + } else if (JS_StringEqualsAscii( + context, rooted_string, "beta", &match) + && match) { + *out_enum = EnumerationInterface::kBeta; + } else if (JS_StringEqualsAscii( + context, rooted_string, "gamma", &match) + && match) { + *out_enum = EnumerationInterface::kGamma; + } else { + // 2. If S is not one of E's enumeration values, then throw a TypeError. + exception_state->SetSimpleException(cobalt::script::kConvertToEnumFailed); + return; + } +} +} // namespace
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_enumeration_interface.h b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_enumeration_interface.h new file mode 100644 index 0000000..270fdf1 --- /dev/null +++ b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_enumeration_interface.h
@@ -0,0 +1,52 @@ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// clang-format off + +// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! +// Auto-generated from template: bindings/mozjs-45/templates/interface.h.template + +#ifndef MozjsEnumerationInterface_h +#define MozjsEnumerationInterface_h + +#include "base/hash_tables.h" +#include "base/lazy_instance.h" +#include "base/memory/ref_counted.h" +#include "base/threading/thread_checker.h" +#include "cobalt/base/polymorphic_downcast.h" +#include "cobalt/script/wrappable.h" +#include "cobalt/bindings/testing/enumeration_interface.h" + +#include "third_party/mozjs-45/js/src/jsapi.h" + +namespace cobalt { +namespace bindings { +namespace testing { + +class MozjsEnumerationInterface { + public: + static JSObject* CreateProxy(JSContext* context, + const scoped_refptr<script::Wrappable>& wrappable); + static const JSClass* PrototypeClass(JSContext* context); + static JSObject* GetPrototype(JSContext* context, + JS::HandleObject global_object); + static JSObject* GetInterfaceObject(JSContext* context, + JS::HandleObject global_object); +}; + +} // namespace testing +} // namespace bindings +} // namespace cobalt + +#endif // MozjsEnumerationInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_exception_object_interface.cc b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_exception_object_interface.cc new file mode 100644 index 0000000..c949639 --- /dev/null +++ b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_exception_object_interface.cc
@@ -0,0 +1,455 @@ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// clang-format off + +// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! +// Auto-generated from template: bindings/mozjs-45/templates/interface.cc.template + +#include "cobalt/bindings/testing/mozjs_exception_object_interface.h" + +#include "base/debug/trace_event.h" +#include "cobalt/base/polymorphic_downcast.h" +#include "cobalt/script/global_environment.h" +#include "cobalt/script/opaque_handle.h" +#include "cobalt/script/script_value.h" + +#include "base/lazy_instance.h" +#include "cobalt/script/exception_state.h" +#include "cobalt/script/mozjs-45/callback_function_conversion.h" +#include "cobalt/script/mozjs-45/conversion_helpers.h" +#include "cobalt/script/mozjs-45/mozjs_callback_function.h" +#include "cobalt/script/mozjs-45/mozjs_exception_state.h" +#include "cobalt/script/mozjs-45/mozjs_global_environment.h" +#include "cobalt/script/mozjs-45/mozjs_object_handle.h" +#include "cobalt/script/mozjs-45/mozjs_property_enumerator.h" +#include "cobalt/script/mozjs-45/mozjs_user_object_holder.h" +#include "cobalt/script/mozjs-45/proxy_handler.h" +#include "cobalt/script/mozjs-45/type_traits.h" +#include "cobalt/script/mozjs-45/wrapper_factory.h" +#include "cobalt/script/mozjs-45/wrapper_private.h" +#include "cobalt/script/property_enumerator.h" +#include "cobalt/script/sequence.h" +#include "third_party/mozjs-45/js/src/jsapi.h" +#include "third_party/mozjs-45/js/src/jsexn.h" +#include "third_party/mozjs-45/js/src/jsfriendapi.h" + +namespace { +using cobalt::bindings::testing::ExceptionObjectInterface; +using cobalt::bindings::testing::MozjsExceptionObjectInterface; +using cobalt::script::CallbackInterfaceTraits; +using cobalt::script::GlobalEnvironment; +using cobalt::script::OpaqueHandle; +using cobalt::script::OpaqueHandleHolder; +using cobalt::script::ScriptValue; +using cobalt::script::Wrappable; + +using cobalt::script::CallbackFunction; +using cobalt::script::CallbackInterfaceTraits; +using cobalt::script::ExceptionState; +using cobalt::script::Wrappable; +using cobalt::script::mozjs::FromJSValue; +using cobalt::script::mozjs::InterfaceData; +using cobalt::script::mozjs::MozjsCallbackFunction; +using cobalt::script::mozjs::MozjsExceptionState; +using cobalt::script::mozjs::MozjsGlobalEnvironment; +using cobalt::script::mozjs::MozjsPropertyEnumerator; +using cobalt::script::mozjs::MozjsUserObjectHolder; +using cobalt::script::mozjs::ProxyHandler; +using cobalt::script::mozjs::ToJSValue; +using cobalt::script::mozjs::TypeTraits; +using cobalt::script::mozjs::WrapperFactory; +using cobalt::script::mozjs::WrapperPrivate; +using cobalt::script::mozjs::kConversionFlagNullable; +using cobalt::script::mozjs::kConversionFlagRestricted; +using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString; +using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString; +using cobalt::script::mozjs::kNoConversionFlags; +} // namespace + +namespace cobalt { +namespace bindings { +namespace testing { + +namespace { + +class MozjsExceptionObjectInterfaceHandler : public ProxyHandler { + public: + MozjsExceptionObjectInterfaceHandler() + : ProxyHandler(indexed_property_hooks, named_property_hooks) {} + + private: + static NamedPropertyHooks named_property_hooks; + static IndexedPropertyHooks indexed_property_hooks; +}; + +ProxyHandler::NamedPropertyHooks +MozjsExceptionObjectInterfaceHandler::named_property_hooks = { + NULL, + NULL, + NULL, + NULL, + NULL, +}; +ProxyHandler::IndexedPropertyHooks +MozjsExceptionObjectInterfaceHandler::indexed_property_hooks = { + NULL, + NULL, + NULL, + NULL, + NULL, +}; + +static base::LazyInstance<MozjsExceptionObjectInterfaceHandler> + proxy_handler; + +bool HasInstance(JSContext *context, JS::HandleObject type, + JS::MutableHandleValue vp, bool *success) { + JS::RootedObject global_object( + context, JS_GetGlobalForObject(context, type)); + DCHECK(global_object); + + JS::RootedObject prototype( + context, MozjsExceptionObjectInterface::GetPrototype(context, global_object)); + + // |IsDelegate| walks the prototype chain of an object returning true if + // .prototype is found. + bool is_delegate; + if (!IsDelegate(context, prototype, vp, &is_delegate)) { + *success = false; + return false; + } + + *success = is_delegate; + return true; +} + +const JSClass instance_class_definition = { + "ExceptionObjectInterface", + 0 | JSCLASS_HAS_PRIVATE, + NULL, // addProperty + NULL, // delProperty + NULL, // getProperty + NULL, // setProperty + NULL, // enumerate + NULL, // resolve + NULL, // mayResolve + &WrapperPrivate::Finalizer, // finalize + NULL, // call + NULL, // hasInstance + NULL, // construct + &WrapperPrivate::Trace, // trace +}; + +const JSClass prototype_class_definition = { + "ExceptionObjectInterfacePrototype", +}; + +const JSClass interface_object_class_definition = { + "ExceptionObjectInterfaceConstructor", + 0, + NULL, // addProperty + NULL, // delProperty + NULL, // getProperty + NULL, // setProperty + NULL, // enumerate + NULL, // resolve + NULL, // mayResolve + NULL, // finalize + NULL, // call + &HasInstance, + NULL, +}; + +bool get_error( + JSContext* context, unsigned argc, JS::Value* vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + const JSClass* proto_class = + MozjsExceptionObjectInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<ExceptionObjectInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + ExceptionObjectInterface* impl = + wrapper_private->wrappable<ExceptionObjectInterface>().get(); + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->error(), + &result_value); + } + if (!exception_state.is_exception_set()) { + args.rval().set(result_value); + } + return !exception_state.is_exception_set(); +} + + +bool get_message( + JSContext* context, unsigned argc, JS::Value* vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + const JSClass* proto_class = + MozjsExceptionObjectInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<ExceptionObjectInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + ExceptionObjectInterface* impl = + wrapper_private->wrappable<ExceptionObjectInterface>().get(); + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->message(), + &result_value); + } + if (!exception_state.is_exception_set()) { + args.rval().set(result_value); + } + return !exception_state.is_exception_set(); +} + + + + +const JSPropertySpec prototype_properties[] = { + { // Readonly attribute + "error", + JSPROP_SHARED | JSPROP_ENUMERATE, + { { &get_error, NULL } }, + JSNATIVE_WRAPPER(NULL), + }, + { // Readonly attribute + "message", + JSPROP_SHARED | JSPROP_ENUMERATE, + { { &get_message, NULL } }, + JSNATIVE_WRAPPER(NULL), + }, + JS_PS_END +}; + +const JSFunctionSpec prototype_functions[] = { + JS_FS_END +}; + +const JSPropertySpec interface_object_properties[] = { + JS_PS_END +}; + +const JSFunctionSpec interface_object_functions[] = { + JS_FS_END +}; + +const JSPropertySpec own_properties[] = { + JS_PS_END +}; + +void InitializePrototypeAndInterfaceObject( + InterfaceData* interface_data, JSContext* context, + JS::HandleObject global_object) { + DCHECK(!interface_data->prototype); + DCHECK(!interface_data->interface_object); + DCHECK(JS_IsGlobalObject(global_object)); + + // Get Error prototype. + JS::RootedObject parent_prototype(context); + bool success_check = JS_GetClassPrototype( + context, js::GetExceptionProtoKey(JSEXN_ERR), &parent_prototype); + DCHECK(success_check); + DCHECK(parent_prototype); + + interface_data->prototype = JS_NewObjectWithGivenProto( + context, &prototype_class_definition, parent_prototype + ); + + JS::RootedObject rooted_prototype(context, interface_data->prototype); + bool success = JS_DefineProperties( + context, + rooted_prototype, + prototype_properties); + + DCHECK(success); + success = JS_DefineFunctions( + context, rooted_prototype, prototype_functions); + DCHECK(success); + + JS::RootedObject function_prototype( + context, JS_GetFunctionPrototype(context, global_object)); + DCHECK(function_prototype); + // Create the Interface object. + interface_data->interface_object = JS_NewObjectWithGivenProto( + context, &interface_object_class_definition, + function_prototype); + + // Add the InterfaceObject.name property. + JS::RootedObject rooted_interface_object( + context, interface_data->interface_object); + JS::RootedValue name_value(context); + const char name[] = + "ExceptionObjectInterface"; + name_value.setString(JS_NewStringCopyZ(context, name)); + success = JS_DefineProperty( + context, rooted_interface_object, "name", name_value, JSPROP_READONLY, + NULL, NULL); + DCHECK(success); + + // Define interface object properties (including constants). + success = JS_DefineProperties(context, rooted_interface_object, + interface_object_properties); + DCHECK(success); + // Define interface object functions (static). + success = JS_DefineFunctions(context, rooted_interface_object, + interface_object_functions); + DCHECK(success); + + // Set the Prototype.constructor and Constructor.prototype properties. + DCHECK(interface_data->interface_object); + DCHECK(interface_data->prototype); + success = JS_LinkConstructorAndPrototype( + context, + rooted_interface_object, + rooted_prototype); + DCHECK(success); +} + +InterfaceData* GetInterfaceData(JSContext* context) { + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + // Use the address of the properties definition for this interface as a + // unique key for looking up the InterfaceData for this interface. + intptr_t key = reinterpret_cast<intptr_t>(&own_properties); + InterfaceData* interface_data = global_environment->GetInterfaceData(key); + if (!interface_data) { + interface_data = new InterfaceData(); + DCHECK(interface_data); + global_environment->CacheInterfaceData(key, interface_data); + DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key)); + } + return interface_data; +} + +} // namespace + +// static +JSObject* MozjsExceptionObjectInterface::CreateProxy( + JSContext* context, const scoped_refptr<Wrappable>& wrappable) { + DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); + JS::RootedObject global_object( + context, + MozjsGlobalEnvironment::GetFromContext(context)->global_object()); + DCHECK(global_object); + + InterfaceData* interface_data = GetInterfaceData(context); + JS::RootedObject prototype(context, GetPrototype(context, global_object)); + DCHECK(prototype); + JS::RootedObject new_object( + context, + JS_NewObjectWithGivenProto( + context, &instance_class_definition, prototype)); + DCHECK(new_object); + JS::RootedObject proxy(context, + ProxyHandler::NewProxy( + context, proxy_handler.Pointer(), new_object, prototype)); + WrapperPrivate::AddPrivateData(context, proxy, wrappable); + return proxy; +} + +// static +const JSClass* MozjsExceptionObjectInterface::PrototypeClass( + JSContext* context) { + DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); + JS::RootedObject global_object( + context, + MozjsGlobalEnvironment::GetFromContext(context)->global_object()); + DCHECK(global_object); + + JS::RootedObject prototype(context, GetPrototype(context, global_object)); + const JSClass* proto_class = JS_GetClass(prototype); + return proto_class; +} + +// static +JSObject* MozjsExceptionObjectInterface::GetPrototype( + JSContext* context, JS::HandleObject global_object) { + DCHECK(JS_IsGlobalObject(global_object)); + + InterfaceData* interface_data = GetInterfaceData(context); + if (!interface_data->prototype) { + // Create new prototype that has all the props and methods + InitializePrototypeAndInterfaceObject( + interface_data, context, global_object); + } + DCHECK(interface_data->prototype); + return interface_data->prototype; +} + +// static +JSObject* MozjsExceptionObjectInterface::GetInterfaceObject( + JSContext* context, JS::HandleObject global_object) { + DCHECK(JS_IsGlobalObject(global_object)); + + InterfaceData* interface_data = GetInterfaceData(context); + if (!interface_data->interface_object) { + InitializePrototypeAndInterfaceObject( + interface_data, context, global_object); + } + DCHECK(interface_data->interface_object); + return interface_data->interface_object; +} + + +namespace { +} // namespace + + +} // namespace testing +} // namespace bindings +} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_exception_object_interface.h b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_exception_object_interface.h new file mode 100644 index 0000000..7a6847a --- /dev/null +++ b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_exception_object_interface.h
@@ -0,0 +1,52 @@ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// clang-format off + +// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! +// Auto-generated from template: bindings/mozjs-45/templates/interface.h.template + +#ifndef MozjsExceptionObjectInterface_h +#define MozjsExceptionObjectInterface_h + +#include "base/hash_tables.h" +#include "base/lazy_instance.h" +#include "base/memory/ref_counted.h" +#include "base/threading/thread_checker.h" +#include "cobalt/base/polymorphic_downcast.h" +#include "cobalt/script/wrappable.h" +#include "cobalt/bindings/testing/exception_object_interface.h" + +#include "third_party/mozjs-45/js/src/jsapi.h" + +namespace cobalt { +namespace bindings { +namespace testing { + +class MozjsExceptionObjectInterface { + public: + static JSObject* CreateProxy(JSContext* context, + const scoped_refptr<script::Wrappable>& wrappable); + static const JSClass* PrototypeClass(JSContext* context); + static JSObject* GetPrototype(JSContext* context, + JS::HandleObject global_object); + static JSObject* GetInterfaceObject(JSContext* context, + JS::HandleObject global_object); +}; + +} // namespace testing +} // namespace bindings +} // namespace cobalt + +#endif // MozjsExceptionObjectInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_exceptions_interface.cc b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_exceptions_interface.cc new file mode 100644 index 0000000..f48b647 --- /dev/null +++ b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_exceptions_interface.cc
@@ -0,0 +1,525 @@ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// clang-format off + +// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! +// Auto-generated from template: bindings/mozjs-45/templates/interface.cc.template + +#include "cobalt/bindings/testing/mozjs_exceptions_interface.h" + +#include "base/debug/trace_event.h" +#include "cobalt/base/polymorphic_downcast.h" +#include "cobalt/script/global_environment.h" +#include "cobalt/script/opaque_handle.h" +#include "cobalt/script/script_value.h" + +#include "base/lazy_instance.h" +#include "cobalt/script/exception_state.h" +#include "cobalt/script/mozjs-45/callback_function_conversion.h" +#include "cobalt/script/mozjs-45/conversion_helpers.h" +#include "cobalt/script/mozjs-45/mozjs_callback_function.h" +#include "cobalt/script/mozjs-45/mozjs_exception_state.h" +#include "cobalt/script/mozjs-45/mozjs_global_environment.h" +#include "cobalt/script/mozjs-45/mozjs_object_handle.h" +#include "cobalt/script/mozjs-45/mozjs_property_enumerator.h" +#include "cobalt/script/mozjs-45/mozjs_user_object_holder.h" +#include "cobalt/script/mozjs-45/proxy_handler.h" +#include "cobalt/script/mozjs-45/type_traits.h" +#include "cobalt/script/mozjs-45/wrapper_factory.h" +#include "cobalt/script/mozjs-45/wrapper_private.h" +#include "cobalt/script/property_enumerator.h" +#include "cobalt/script/sequence.h" +#include "third_party/mozjs-45/js/src/jsapi.h" +#include "third_party/mozjs-45/js/src/jsfriendapi.h" + +namespace { +using cobalt::bindings::testing::ExceptionsInterface; +using cobalt::bindings::testing::MozjsExceptionsInterface; +using cobalt::script::CallbackInterfaceTraits; +using cobalt::script::GlobalEnvironment; +using cobalt::script::OpaqueHandle; +using cobalt::script::OpaqueHandleHolder; +using cobalt::script::ScriptValue; +using cobalt::script::Wrappable; + +using cobalt::script::CallbackFunction; +using cobalt::script::CallbackInterfaceTraits; +using cobalt::script::ExceptionState; +using cobalt::script::Wrappable; +using cobalt::script::mozjs::FromJSValue; +using cobalt::script::mozjs::InterfaceData; +using cobalt::script::mozjs::MozjsCallbackFunction; +using cobalt::script::mozjs::MozjsExceptionState; +using cobalt::script::mozjs::MozjsGlobalEnvironment; +using cobalt::script::mozjs::MozjsPropertyEnumerator; +using cobalt::script::mozjs::MozjsUserObjectHolder; +using cobalt::script::mozjs::ProxyHandler; +using cobalt::script::mozjs::ToJSValue; +using cobalt::script::mozjs::TypeTraits; +using cobalt::script::mozjs::WrapperFactory; +using cobalt::script::mozjs::WrapperPrivate; +using cobalt::script::mozjs::kConversionFlagNullable; +using cobalt::script::mozjs::kConversionFlagRestricted; +using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString; +using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString; +using cobalt::script::mozjs::kNoConversionFlags; +} // namespace + +namespace cobalt { +namespace bindings { +namespace testing { + +namespace { + +class MozjsExceptionsInterfaceHandler : public ProxyHandler { + public: + MozjsExceptionsInterfaceHandler() + : ProxyHandler(indexed_property_hooks, named_property_hooks) {} + + private: + static NamedPropertyHooks named_property_hooks; + static IndexedPropertyHooks indexed_property_hooks; +}; + +ProxyHandler::NamedPropertyHooks +MozjsExceptionsInterfaceHandler::named_property_hooks = { + NULL, + NULL, + NULL, + NULL, + NULL, +}; +ProxyHandler::IndexedPropertyHooks +MozjsExceptionsInterfaceHandler::indexed_property_hooks = { + NULL, + NULL, + NULL, + NULL, + NULL, +}; + +static base::LazyInstance<MozjsExceptionsInterfaceHandler> + proxy_handler; + +bool Constructor(JSContext* context, unsigned int argc, JS::Value* vp); +bool HasInstance(JSContext *context, JS::HandleObject type, + JS::MutableHandleValue vp, bool *success) { + JS::RootedObject global_object( + context, JS_GetGlobalForObject(context, type)); + DCHECK(global_object); + + JS::RootedObject prototype( + context, MozjsExceptionsInterface::GetPrototype(context, global_object)); + + // |IsDelegate| walks the prototype chain of an object returning true if + // .prototype is found. + bool is_delegate; + if (!IsDelegate(context, prototype, vp, &is_delegate)) { + *success = false; + return false; + } + + *success = is_delegate; + return true; +} + +const JSClass instance_class_definition = { + "ExceptionsInterface", + 0 | JSCLASS_HAS_PRIVATE, + NULL, // addProperty + NULL, // delProperty + NULL, // getProperty + NULL, // setProperty + NULL, // enumerate + NULL, // resolve + NULL, // mayResolve + &WrapperPrivate::Finalizer, // finalize + NULL, // call + NULL, // hasInstance + NULL, // construct + &WrapperPrivate::Trace, // trace +}; + +const JSClass prototype_class_definition = { + "ExceptionsInterfacePrototype", +}; + +const JSClass interface_object_class_definition = { + "ExceptionsInterfaceConstructor", + 0, + NULL, // addProperty + NULL, // delProperty + NULL, // getProperty + NULL, // setProperty + NULL, // enumerate + NULL, // resolve + NULL, // mayResolve + NULL, // finalize + NULL, // call + &HasInstance, + Constructor, +}; + +bool get_attributeThrowsException( + JSContext* context, unsigned argc, JS::Value* vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + const JSClass* proto_class = + MozjsExceptionsInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<ExceptionsInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + ExceptionsInterface* impl = + wrapper_private->wrappable<ExceptionsInterface>().get(); + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->attribute_throws_exception(&exception_state), + &result_value); + } + if (!exception_state.is_exception_set()) { + args.rval().set(result_value); + } + return !exception_state.is_exception_set(); +} + +bool set_attributeThrowsException( + JSContext* context, unsigned argc, JS::Value* vp) { + + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + + const JSClass* proto_class = + MozjsExceptionsInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<ExceptionsInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + ExceptionsInterface* impl = + wrapper_private->wrappable<ExceptionsInterface>().get(); + TypeTraits<bool >::ConversionType value; + if (args.length() != 1) { + NOTREACHED(); + return false; + } + FromJSValue(context, args[0], kNoConversionFlags, &exception_state, + &value); + if (exception_state.is_exception_set()) { + return false; + } + + impl->set_attribute_throws_exception(value, &exception_state); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + +bool fcn_functionThrowsException( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + const JSClass* proto_class = + MozjsExceptionsInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<ExceptionsInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + ExceptionsInterface* impl = + wrapper_private->wrappable<ExceptionsInterface>().get(); + + impl->FunctionThrowsException(&exception_state); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + + + +const JSPropertySpec prototype_properties[] = { + { // Read/Write property + "attributeThrowsException", + JSPROP_SHARED | JSPROP_ENUMERATE, + { { &get_attributeThrowsException, NULL } }, + { { &set_attributeThrowsException, NULL } }, + }, + JS_PS_END +}; + +const JSFunctionSpec prototype_functions[] = { + JS_FNSPEC( + "functionThrowsException", fcn_functionThrowsException, NULL, + 0, JSPROP_ENUMERATE, NULL), + JS_FS_END +}; + +const JSPropertySpec interface_object_properties[] = { + JS_PS_END +}; + +const JSFunctionSpec interface_object_functions[] = { + JS_FS_END +}; + +const JSPropertySpec own_properties[] = { + JS_PS_END +}; + +void InitializePrototypeAndInterfaceObject( + InterfaceData* interface_data, JSContext* context, + JS::HandleObject global_object) { + DCHECK(!interface_data->prototype); + DCHECK(!interface_data->interface_object); + DCHECK(JS_IsGlobalObject(global_object)); + + JS::RootedObject parent_prototype( + context, JS_GetObjectPrototype(context, global_object)); + DCHECK(parent_prototype); + + interface_data->prototype = JS_NewObjectWithGivenProto( + context, &prototype_class_definition, parent_prototype + ); + + JS::RootedObject rooted_prototype(context, interface_data->prototype); + bool success = JS_DefineProperties( + context, + rooted_prototype, + prototype_properties); + + DCHECK(success); + success = JS_DefineFunctions( + context, rooted_prototype, prototype_functions); + DCHECK(success); + + JS::RootedObject function_prototype( + context, JS_GetFunctionPrototype(context, global_object)); + DCHECK(function_prototype); + // Create the Interface object. + interface_data->interface_object = JS_NewObjectWithGivenProto( + context, &interface_object_class_definition, + function_prototype); + + // Add the InterfaceObject.name property. + JS::RootedObject rooted_interface_object( + context, interface_data->interface_object); + JS::RootedValue name_value(context); + const char name[] = + "ExceptionsInterface"; + name_value.setString(JS_NewStringCopyZ(context, name)); + success = JS_DefineProperty( + context, rooted_interface_object, "name", name_value, JSPROP_READONLY, + NULL, NULL); + DCHECK(success); + + // Add the InterfaceObject.length property. It is set to the length of the + // shortest argument list of all overload constructors. + JS::RootedValue length_value(context); + length_value.setInt32(0); + success = JS_DefineProperty( + context, rooted_interface_object, "length", length_value, + JSPROP_READONLY, NULL, NULL); + DCHECK(success); + + // Define interface object properties (including constants). + success = JS_DefineProperties(context, rooted_interface_object, + interface_object_properties); + DCHECK(success); + // Define interface object functions (static). + success = JS_DefineFunctions(context, rooted_interface_object, + interface_object_functions); + DCHECK(success); + + // Set the Prototype.constructor and Constructor.prototype properties. + DCHECK(interface_data->interface_object); + DCHECK(interface_data->prototype); + success = JS_LinkConstructorAndPrototype( + context, + rooted_interface_object, + rooted_prototype); + DCHECK(success); +} + +InterfaceData* GetInterfaceData(JSContext* context) { + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + // Use the address of the properties definition for this interface as a + // unique key for looking up the InterfaceData for this interface. + intptr_t key = reinterpret_cast<intptr_t>(&own_properties); + InterfaceData* interface_data = global_environment->GetInterfaceData(key); + if (!interface_data) { + interface_data = new InterfaceData(); + DCHECK(interface_data); + global_environment->CacheInterfaceData(key, interface_data); + DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key)); + } + return interface_data; +} + +} // namespace + +// static +JSObject* MozjsExceptionsInterface::CreateProxy( + JSContext* context, const scoped_refptr<Wrappable>& wrappable) { + DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); + JS::RootedObject global_object( + context, + MozjsGlobalEnvironment::GetFromContext(context)->global_object()); + DCHECK(global_object); + + InterfaceData* interface_data = GetInterfaceData(context); + JS::RootedObject prototype(context, GetPrototype(context, global_object)); + DCHECK(prototype); + JS::RootedObject new_object( + context, + JS_NewObjectWithGivenProto( + context, &instance_class_definition, prototype)); + DCHECK(new_object); + JS::RootedObject proxy(context, + ProxyHandler::NewProxy( + context, proxy_handler.Pointer(), new_object, prototype)); + WrapperPrivate::AddPrivateData(context, proxy, wrappable); + return proxy; +} + +// static +const JSClass* MozjsExceptionsInterface::PrototypeClass( + JSContext* context) { + DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); + JS::RootedObject global_object( + context, + MozjsGlobalEnvironment::GetFromContext(context)->global_object()); + DCHECK(global_object); + + JS::RootedObject prototype(context, GetPrototype(context, global_object)); + const JSClass* proto_class = JS_GetClass(prototype); + return proto_class; +} + +// static +JSObject* MozjsExceptionsInterface::GetPrototype( + JSContext* context, JS::HandleObject global_object) { + DCHECK(JS_IsGlobalObject(global_object)); + + InterfaceData* interface_data = GetInterfaceData(context); + if (!interface_data->prototype) { + // Create new prototype that has all the props and methods + InitializePrototypeAndInterfaceObject( + interface_data, context, global_object); + } + DCHECK(interface_data->prototype); + return interface_data->prototype; +} + +// static +JSObject* MozjsExceptionsInterface::GetInterfaceObject( + JSContext* context, JS::HandleObject global_object) { + DCHECK(JS_IsGlobalObject(global_object)); + + InterfaceData* interface_data = GetInterfaceData(context); + if (!interface_data->interface_object) { + InitializePrototypeAndInterfaceObject( + interface_data, context, global_object); + } + DCHECK(interface_data->interface_object); + return interface_data->interface_object; +} + + +namespace { +bool Constructor(JSContext* context, unsigned int argc, JS::Value* vp) { + MozjsExceptionState exception_state(context); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + + scoped_refptr<ExceptionsInterface> new_object = + new ExceptionsInterface(&exception_state); + // In case that an exception is thrown from constructor. + if (exception_state.is_exception_set()) { + return false; + } + JS::RootedValue result_value(context); + ToJSValue(context, new_object, &result_value); + DCHECK(result_value.isObject()); + args.rval().setObject(result_value.toObject()); + return true; +} +} // namespace + + +} // namespace testing +} // namespace bindings +} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_exceptions_interface.h b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_exceptions_interface.h new file mode 100644 index 0000000..0b9e1b5 --- /dev/null +++ b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_exceptions_interface.h
@@ -0,0 +1,52 @@ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// clang-format off + +// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! +// Auto-generated from template: bindings/mozjs-45/templates/interface.h.template + +#ifndef MozjsExceptionsInterface_h +#define MozjsExceptionsInterface_h + +#include "base/hash_tables.h" +#include "base/lazy_instance.h" +#include "base/memory/ref_counted.h" +#include "base/threading/thread_checker.h" +#include "cobalt/base/polymorphic_downcast.h" +#include "cobalt/script/wrappable.h" +#include "cobalt/bindings/testing/exceptions_interface.h" + +#include "third_party/mozjs-45/js/src/jsapi.h" + +namespace cobalt { +namespace bindings { +namespace testing { + +class MozjsExceptionsInterface { + public: + static JSObject* CreateProxy(JSContext* context, + const scoped_refptr<script::Wrappable>& wrappable); + static const JSClass* PrototypeClass(JSContext* context); + static JSObject* GetPrototype(JSContext* context, + JS::HandleObject global_object); + static JSObject* GetInterfaceObject(JSContext* context, + JS::HandleObject global_object); +}; + +} // namespace testing +} // namespace bindings +} // namespace cobalt + +#endif // MozjsExceptionsInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_extended_idl_attributes_interface.cc b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_extended_idl_attributes_interface.cc new file mode 100644 index 0000000..654ef33 --- /dev/null +++ b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_extended_idl_attributes_interface.cc
@@ -0,0 +1,405 @@ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// clang-format off + +// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! +// Auto-generated from template: bindings/mozjs-45/templates/interface.cc.template + +#include "cobalt/bindings/testing/mozjs_extended_idl_attributes_interface.h" + +#include "base/debug/trace_event.h" +#include "cobalt/base/polymorphic_downcast.h" +#include "cobalt/script/global_environment.h" +#include "cobalt/script/opaque_handle.h" +#include "cobalt/script/script_value.h" + +#include "base/lazy_instance.h" +#include "cobalt/script/exception_state.h" +#include "cobalt/script/mozjs-45/callback_function_conversion.h" +#include "cobalt/script/mozjs-45/conversion_helpers.h" +#include "cobalt/script/mozjs-45/mozjs_callback_function.h" +#include "cobalt/script/mozjs-45/mozjs_exception_state.h" +#include "cobalt/script/mozjs-45/mozjs_global_environment.h" +#include "cobalt/script/mozjs-45/mozjs_object_handle.h" +#include "cobalt/script/mozjs-45/mozjs_property_enumerator.h" +#include "cobalt/script/mozjs-45/mozjs_user_object_holder.h" +#include "cobalt/script/mozjs-45/proxy_handler.h" +#include "cobalt/script/mozjs-45/type_traits.h" +#include "cobalt/script/mozjs-45/wrapper_factory.h" +#include "cobalt/script/mozjs-45/wrapper_private.h" +#include "cobalt/script/property_enumerator.h" +#include "cobalt/script/sequence.h" +#include "third_party/mozjs-45/js/src/jsapi.h" +#include "third_party/mozjs-45/js/src/jsfriendapi.h" + +namespace { +using cobalt::bindings::testing::ExtendedIDLAttributesInterface; +using cobalt::bindings::testing::MozjsExtendedIDLAttributesInterface; +using cobalt::script::CallbackInterfaceTraits; +using cobalt::script::GlobalEnvironment; +using cobalt::script::OpaqueHandle; +using cobalt::script::OpaqueHandleHolder; +using cobalt::script::ScriptValue; +using cobalt::script::Wrappable; + +using cobalt::script::CallbackFunction; +using cobalt::script::CallbackInterfaceTraits; +using cobalt::script::ExceptionState; +using cobalt::script::Wrappable; +using cobalt::script::mozjs::FromJSValue; +using cobalt::script::mozjs::InterfaceData; +using cobalt::script::mozjs::MozjsCallbackFunction; +using cobalt::script::mozjs::MozjsExceptionState; +using cobalt::script::mozjs::MozjsGlobalEnvironment; +using cobalt::script::mozjs::MozjsPropertyEnumerator; +using cobalt::script::mozjs::MozjsUserObjectHolder; +using cobalt::script::mozjs::ProxyHandler; +using cobalt::script::mozjs::ToJSValue; +using cobalt::script::mozjs::TypeTraits; +using cobalt::script::mozjs::WrapperFactory; +using cobalt::script::mozjs::WrapperPrivate; +using cobalt::script::mozjs::kConversionFlagNullable; +using cobalt::script::mozjs::kConversionFlagRestricted; +using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString; +using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString; +using cobalt::script::mozjs::kNoConversionFlags; +} // namespace + +namespace cobalt { +namespace bindings { +namespace testing { + +namespace { + +class MozjsExtendedIDLAttributesInterfaceHandler : public ProxyHandler { + public: + MozjsExtendedIDLAttributesInterfaceHandler() + : ProxyHandler(indexed_property_hooks, named_property_hooks) {} + + private: + static NamedPropertyHooks named_property_hooks; + static IndexedPropertyHooks indexed_property_hooks; +}; + +ProxyHandler::NamedPropertyHooks +MozjsExtendedIDLAttributesInterfaceHandler::named_property_hooks = { + NULL, + NULL, + NULL, + NULL, + NULL, +}; +ProxyHandler::IndexedPropertyHooks +MozjsExtendedIDLAttributesInterfaceHandler::indexed_property_hooks = { + NULL, + NULL, + NULL, + NULL, + NULL, +}; + +static base::LazyInstance<MozjsExtendedIDLAttributesInterfaceHandler> + proxy_handler; + +bool HasInstance(JSContext *context, JS::HandleObject type, + JS::MutableHandleValue vp, bool *success) { + JS::RootedObject global_object( + context, JS_GetGlobalForObject(context, type)); + DCHECK(global_object); + + JS::RootedObject prototype( + context, MozjsExtendedIDLAttributesInterface::GetPrototype(context, global_object)); + + // |IsDelegate| walks the prototype chain of an object returning true if + // .prototype is found. + bool is_delegate; + if (!IsDelegate(context, prototype, vp, &is_delegate)) { + *success = false; + return false; + } + + *success = is_delegate; + return true; +} + +const JSClass instance_class_definition = { + "ExtendedIDLAttributesInterface", + 0 | JSCLASS_HAS_PRIVATE, + NULL, // addProperty + NULL, // delProperty + NULL, // getProperty + NULL, // setProperty + NULL, // enumerate + NULL, // resolve + NULL, // mayResolve + &WrapperPrivate::Finalizer, // finalize + NULL, // call + NULL, // hasInstance + NULL, // construct + &WrapperPrivate::Trace, // trace +}; + +const JSClass prototype_class_definition = { + "ExtendedIDLAttributesInterfacePrototype", +}; + +const JSClass interface_object_class_definition = { + "ExtendedIDLAttributesInterfaceConstructor", + 0, + NULL, // addProperty + NULL, // delProperty + NULL, // getProperty + NULL, // setProperty + NULL, // enumerate + NULL, // resolve + NULL, // mayResolve + NULL, // finalize + NULL, // call + &HasInstance, + NULL, +}; + +bool fcn_callWithSettings( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + const JSClass* proto_class = + MozjsExtendedIDLAttributesInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<ExtendedIDLAttributesInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + ExtendedIDLAttributesInterface* impl = + wrapper_private->wrappable<ExtendedIDLAttributesInterface>().get(); + MozjsGlobalEnvironment* callwith_global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + + impl->CallWithSettings(callwith_global_environment->GetEnvironmentSettings()); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + + + +const JSPropertySpec prototype_properties[] = { + JS_PS_END +}; + +const JSFunctionSpec prototype_functions[] = { + JS_FNSPEC( + "callWithSettings", fcn_callWithSettings, NULL, + 0, JSPROP_ENUMERATE, NULL), + JS_FS_END +}; + +const JSPropertySpec interface_object_properties[] = { + JS_PS_END +}; + +const JSFunctionSpec interface_object_functions[] = { + JS_FS_END +}; + +const JSPropertySpec own_properties[] = { + JS_PS_END +}; + +void InitializePrototypeAndInterfaceObject( + InterfaceData* interface_data, JSContext* context, + JS::HandleObject global_object) { + DCHECK(!interface_data->prototype); + DCHECK(!interface_data->interface_object); + DCHECK(JS_IsGlobalObject(global_object)); + + JS::RootedObject parent_prototype( + context, JS_GetObjectPrototype(context, global_object)); + DCHECK(parent_prototype); + + interface_data->prototype = JS_NewObjectWithGivenProto( + context, &prototype_class_definition, parent_prototype + ); + + JS::RootedObject rooted_prototype(context, interface_data->prototype); + bool success = JS_DefineProperties( + context, + rooted_prototype, + prototype_properties); + + DCHECK(success); + success = JS_DefineFunctions( + context, rooted_prototype, prototype_functions); + DCHECK(success); + + JS::RootedObject function_prototype( + context, JS_GetFunctionPrototype(context, global_object)); + DCHECK(function_prototype); + // Create the Interface object. + interface_data->interface_object = JS_NewObjectWithGivenProto( + context, &interface_object_class_definition, + function_prototype); + + // Add the InterfaceObject.name property. + JS::RootedObject rooted_interface_object( + context, interface_data->interface_object); + JS::RootedValue name_value(context); + const char name[] = + "ExtendedIDLAttributesInterface"; + name_value.setString(JS_NewStringCopyZ(context, name)); + success = JS_DefineProperty( + context, rooted_interface_object, "name", name_value, JSPROP_READONLY, + NULL, NULL); + DCHECK(success); + + // Define interface object properties (including constants). + success = JS_DefineProperties(context, rooted_interface_object, + interface_object_properties); + DCHECK(success); + // Define interface object functions (static). + success = JS_DefineFunctions(context, rooted_interface_object, + interface_object_functions); + DCHECK(success); + + // Set the Prototype.constructor and Constructor.prototype properties. + DCHECK(interface_data->interface_object); + DCHECK(interface_data->prototype); + success = JS_LinkConstructorAndPrototype( + context, + rooted_interface_object, + rooted_prototype); + DCHECK(success); +} + +InterfaceData* GetInterfaceData(JSContext* context) { + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + // Use the address of the properties definition for this interface as a + // unique key for looking up the InterfaceData for this interface. + intptr_t key = reinterpret_cast<intptr_t>(&own_properties); + InterfaceData* interface_data = global_environment->GetInterfaceData(key); + if (!interface_data) { + interface_data = new InterfaceData(); + DCHECK(interface_data); + global_environment->CacheInterfaceData(key, interface_data); + DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key)); + } + return interface_data; +} + +} // namespace + +// static +JSObject* MozjsExtendedIDLAttributesInterface::CreateProxy( + JSContext* context, const scoped_refptr<Wrappable>& wrappable) { + DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); + JS::RootedObject global_object( + context, + MozjsGlobalEnvironment::GetFromContext(context)->global_object()); + DCHECK(global_object); + + InterfaceData* interface_data = GetInterfaceData(context); + JS::RootedObject prototype(context, GetPrototype(context, global_object)); + DCHECK(prototype); + JS::RootedObject new_object( + context, + JS_NewObjectWithGivenProto( + context, &instance_class_definition, prototype)); + DCHECK(new_object); + JS::RootedObject proxy(context, + ProxyHandler::NewProxy( + context, proxy_handler.Pointer(), new_object, prototype)); + WrapperPrivate::AddPrivateData(context, proxy, wrappable); + return proxy; +} + +// static +const JSClass* MozjsExtendedIDLAttributesInterface::PrototypeClass( + JSContext* context) { + DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); + JS::RootedObject global_object( + context, + MozjsGlobalEnvironment::GetFromContext(context)->global_object()); + DCHECK(global_object); + + JS::RootedObject prototype(context, GetPrototype(context, global_object)); + const JSClass* proto_class = JS_GetClass(prototype); + return proto_class; +} + +// static +JSObject* MozjsExtendedIDLAttributesInterface::GetPrototype( + JSContext* context, JS::HandleObject global_object) { + DCHECK(JS_IsGlobalObject(global_object)); + + InterfaceData* interface_data = GetInterfaceData(context); + if (!interface_data->prototype) { + // Create new prototype that has all the props and methods + InitializePrototypeAndInterfaceObject( + interface_data, context, global_object); + } + DCHECK(interface_data->prototype); + return interface_data->prototype; +} + +// static +JSObject* MozjsExtendedIDLAttributesInterface::GetInterfaceObject( + JSContext* context, JS::HandleObject global_object) { + DCHECK(JS_IsGlobalObject(global_object)); + + InterfaceData* interface_data = GetInterfaceData(context); + if (!interface_data->interface_object) { + InitializePrototypeAndInterfaceObject( + interface_data, context, global_object); + } + DCHECK(interface_data->interface_object); + return interface_data->interface_object; +} + + +namespace { +} // namespace + + +} // namespace testing +} // namespace bindings +} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_extended_idl_attributes_interface.h b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_extended_idl_attributes_interface.h new file mode 100644 index 0000000..f36605a --- /dev/null +++ b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_extended_idl_attributes_interface.h
@@ -0,0 +1,52 @@ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// clang-format off + +// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! +// Auto-generated from template: bindings/mozjs-45/templates/interface.h.template + +#ifndef MozjsExtendedIDLAttributesInterface_h +#define MozjsExtendedIDLAttributesInterface_h + +#include "base/hash_tables.h" +#include "base/lazy_instance.h" +#include "base/memory/ref_counted.h" +#include "base/threading/thread_checker.h" +#include "cobalt/base/polymorphic_downcast.h" +#include "cobalt/script/wrappable.h" +#include "cobalt/bindings/testing/extended_idl_attributes_interface.h" + +#include "third_party/mozjs-45/js/src/jsapi.h" + +namespace cobalt { +namespace bindings { +namespace testing { + +class MozjsExtendedIDLAttributesInterface { + public: + static JSObject* CreateProxy(JSContext* context, + const scoped_refptr<script::Wrappable>& wrappable); + static const JSClass* PrototypeClass(JSContext* context); + static JSObject* GetPrototype(JSContext* context, + JS::HandleObject global_object); + static JSObject* GetInterfaceObject(JSContext* context, + JS::HandleObject global_object); +}; + +} // namespace testing +} // namespace bindings +} // namespace cobalt + +#endif // MozjsExtendedIDLAttributesInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_garbage_collection_test_interface.cc b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_garbage_collection_test_interface.cc new file mode 100644 index 0000000..b0362c8 --- /dev/null +++ b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_garbage_collection_test_interface.cc
@@ -0,0 +1,582 @@ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// clang-format off + +// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! +// Auto-generated from template: bindings/mozjs-45/templates/interface.cc.template + +#include "cobalt/bindings/testing/mozjs_garbage_collection_test_interface.h" + +#include "base/debug/trace_event.h" +#include "cobalt/base/polymorphic_downcast.h" +#include "cobalt/script/global_environment.h" +#include "cobalt/script/opaque_handle.h" +#include "cobalt/script/script_value.h" +#include "cobalt/bindings/testing/garbage_collection_test_interface.h" +#include "cobalt/bindings/testing/mozjs_garbage_collection_test_interface.h" + +#include "base/lazy_instance.h" +#include "cobalt/script/exception_state.h" +#include "cobalt/script/mozjs-45/callback_function_conversion.h" +#include "cobalt/script/mozjs-45/conversion_helpers.h" +#include "cobalt/script/mozjs-45/mozjs_callback_function.h" +#include "cobalt/script/mozjs-45/mozjs_exception_state.h" +#include "cobalt/script/mozjs-45/mozjs_global_environment.h" +#include "cobalt/script/mozjs-45/mozjs_object_handle.h" +#include "cobalt/script/mozjs-45/mozjs_property_enumerator.h" +#include "cobalt/script/mozjs-45/mozjs_user_object_holder.h" +#include "cobalt/script/mozjs-45/proxy_handler.h" +#include "cobalt/script/mozjs-45/type_traits.h" +#include "cobalt/script/mozjs-45/wrapper_factory.h" +#include "cobalt/script/mozjs-45/wrapper_private.h" +#include "cobalt/script/property_enumerator.h" +#include "cobalt/script/sequence.h" +#include "third_party/mozjs-45/js/src/jsapi.h" +#include "third_party/mozjs-45/js/src/jsfriendapi.h" + +namespace { +using cobalt::bindings::testing::GarbageCollectionTestInterface; +using cobalt::bindings::testing::MozjsGarbageCollectionTestInterface; +using cobalt::bindings::testing::GarbageCollectionTestInterface; +using cobalt::bindings::testing::MozjsGarbageCollectionTestInterface; +using cobalt::script::CallbackInterfaceTraits; +using cobalt::script::GlobalEnvironment; +using cobalt::script::OpaqueHandle; +using cobalt::script::OpaqueHandleHolder; +using cobalt::script::ScriptValue; +using cobalt::script::Wrappable; + +using cobalt::script::CallbackFunction; +using cobalt::script::CallbackInterfaceTraits; +using cobalt::script::ExceptionState; +using cobalt::script::Wrappable; +using cobalt::script::mozjs::FromJSValue; +using cobalt::script::mozjs::InterfaceData; +using cobalt::script::mozjs::MozjsCallbackFunction; +using cobalt::script::mozjs::MozjsExceptionState; +using cobalt::script::mozjs::MozjsGlobalEnvironment; +using cobalt::script::mozjs::MozjsPropertyEnumerator; +using cobalt::script::mozjs::MozjsUserObjectHolder; +using cobalt::script::mozjs::ProxyHandler; +using cobalt::script::mozjs::ToJSValue; +using cobalt::script::mozjs::TypeTraits; +using cobalt::script::mozjs::WrapperFactory; +using cobalt::script::mozjs::WrapperPrivate; +using cobalt::script::mozjs::kConversionFlagNullable; +using cobalt::script::mozjs::kConversionFlagRestricted; +using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString; +using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString; +using cobalt::script::mozjs::kNoConversionFlags; +} // namespace + +namespace cobalt { +namespace bindings { +namespace testing { + +namespace { + +Wrappable* GetOpaqueRootFromWrappable( + const scoped_refptr<Wrappable>& wrappable) { + GarbageCollectionTestInterface* impl = + base::polymorphic_downcast<GarbageCollectionTestInterface*>(wrappable.get()); + return impl->GetHead(); +} + +class MozjsGarbageCollectionTestInterfaceHandler : public ProxyHandler { + public: + MozjsGarbageCollectionTestInterfaceHandler() + : ProxyHandler(indexed_property_hooks, named_property_hooks) {} + + private: + static NamedPropertyHooks named_property_hooks; + static IndexedPropertyHooks indexed_property_hooks; +}; + +ProxyHandler::NamedPropertyHooks +MozjsGarbageCollectionTestInterfaceHandler::named_property_hooks = { + NULL, + NULL, + NULL, + NULL, + NULL, +}; +ProxyHandler::IndexedPropertyHooks +MozjsGarbageCollectionTestInterfaceHandler::indexed_property_hooks = { + NULL, + NULL, + NULL, + NULL, + NULL, +}; + +static base::LazyInstance<MozjsGarbageCollectionTestInterfaceHandler> + proxy_handler; + +bool Constructor(JSContext* context, unsigned int argc, JS::Value* vp); +bool HasInstance(JSContext *context, JS::HandleObject type, + JS::MutableHandleValue vp, bool *success) { + JS::RootedObject global_object( + context, JS_GetGlobalForObject(context, type)); + DCHECK(global_object); + + JS::RootedObject prototype( + context, MozjsGarbageCollectionTestInterface::GetPrototype(context, global_object)); + + // |IsDelegate| walks the prototype chain of an object returning true if + // .prototype is found. + bool is_delegate; + if (!IsDelegate(context, prototype, vp, &is_delegate)) { + *success = false; + return false; + } + + *success = is_delegate; + return true; +} + +const JSClass instance_class_definition = { + "GarbageCollectionTestInterface", + 0 | JSCLASS_HAS_PRIVATE, + NULL, // addProperty + NULL, // delProperty + NULL, // getProperty + NULL, // setProperty + NULL, // enumerate + NULL, // resolve + NULL, // mayResolve + &WrapperPrivate::Finalizer, // finalize + NULL, // call + NULL, // hasInstance + NULL, // construct + &WrapperPrivate::Trace, // trace +}; + +const JSClass prototype_class_definition = { + "GarbageCollectionTestInterfacePrototype", +}; + +const JSClass interface_object_class_definition = { + "GarbageCollectionTestInterfaceConstructor", + 0, + NULL, // addProperty + NULL, // delProperty + NULL, // getProperty + NULL, // setProperty + NULL, // enumerate + NULL, // resolve + NULL, // mayResolve + NULL, // finalize + NULL, // call + &HasInstance, + Constructor, +}; + +bool get_previous( + JSContext* context, unsigned argc, JS::Value* vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + const JSClass* proto_class = + MozjsGarbageCollectionTestInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<GarbageCollectionTestInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + GarbageCollectionTestInterface* impl = + wrapper_private->wrappable<GarbageCollectionTestInterface>().get(); + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->previous(), + &result_value); + } + if (!exception_state.is_exception_set()) { + args.rval().set(result_value); + } + return !exception_state.is_exception_set(); +} + +bool set_previous( + JSContext* context, unsigned argc, JS::Value* vp) { + + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + + const JSClass* proto_class = + MozjsGarbageCollectionTestInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<GarbageCollectionTestInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + GarbageCollectionTestInterface* impl = + wrapper_private->wrappable<GarbageCollectionTestInterface>().get(); + TypeTraits<scoped_refptr<GarbageCollectionTestInterface> >::ConversionType value; + if (args.length() != 1) { + NOTREACHED(); + return false; + } + FromJSValue(context, args[0], (kConversionFlagNullable), &exception_state, + &value); + if (exception_state.is_exception_set()) { + return false; + } + + impl->set_previous(value); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + +bool get_next( + JSContext* context, unsigned argc, JS::Value* vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + const JSClass* proto_class = + MozjsGarbageCollectionTestInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<GarbageCollectionTestInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + GarbageCollectionTestInterface* impl = + wrapper_private->wrappable<GarbageCollectionTestInterface>().get(); + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->next(), + &result_value); + } + if (!exception_state.is_exception_set()) { + args.rval().set(result_value); + } + return !exception_state.is_exception_set(); +} + +bool set_next( + JSContext* context, unsigned argc, JS::Value* vp) { + + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + + const JSClass* proto_class = + MozjsGarbageCollectionTestInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<GarbageCollectionTestInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + GarbageCollectionTestInterface* impl = + wrapper_private->wrappable<GarbageCollectionTestInterface>().get(); + TypeTraits<scoped_refptr<GarbageCollectionTestInterface> >::ConversionType value; + if (args.length() != 1) { + NOTREACHED(); + return false; + } + FromJSValue(context, args[0], (kConversionFlagNullable), &exception_state, + &value); + if (exception_state.is_exception_set()) { + return false; + } + + impl->set_next(value); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + + + +const JSPropertySpec prototype_properties[] = { + { // Read/Write property + "previous", + JSPROP_SHARED | JSPROP_ENUMERATE, + { { &get_previous, NULL } }, + { { &set_previous, NULL } }, + }, + { // Read/Write property + "next", + JSPROP_SHARED | JSPROP_ENUMERATE, + { { &get_next, NULL } }, + { { &set_next, NULL } }, + }, + JS_PS_END +}; + +const JSFunctionSpec prototype_functions[] = { + JS_FS_END +}; + +const JSPropertySpec interface_object_properties[] = { + JS_PS_END +}; + +const JSFunctionSpec interface_object_functions[] = { + JS_FS_END +}; + +const JSPropertySpec own_properties[] = { + JS_PS_END +}; + +void InitializePrototypeAndInterfaceObject( + InterfaceData* interface_data, JSContext* context, + JS::HandleObject global_object) { + DCHECK(!interface_data->prototype); + DCHECK(!interface_data->interface_object); + DCHECK(JS_IsGlobalObject(global_object)); + + JS::RootedObject parent_prototype( + context, JS_GetObjectPrototype(context, global_object)); + DCHECK(parent_prototype); + + interface_data->prototype = JS_NewObjectWithGivenProto( + context, &prototype_class_definition, parent_prototype + ); + + JS::RootedObject rooted_prototype(context, interface_data->prototype); + bool success = JS_DefineProperties( + context, + rooted_prototype, + prototype_properties); + + DCHECK(success); + success = JS_DefineFunctions( + context, rooted_prototype, prototype_functions); + DCHECK(success); + + JS::RootedObject function_prototype( + context, JS_GetFunctionPrototype(context, global_object)); + DCHECK(function_prototype); + // Create the Interface object. + interface_data->interface_object = JS_NewObjectWithGivenProto( + context, &interface_object_class_definition, + function_prototype); + + // Add the InterfaceObject.name property. + JS::RootedObject rooted_interface_object( + context, interface_data->interface_object); + JS::RootedValue name_value(context); + const char name[] = + "GarbageCollectionTestInterface"; + name_value.setString(JS_NewStringCopyZ(context, name)); + success = JS_DefineProperty( + context, rooted_interface_object, "name", name_value, JSPROP_READONLY, + NULL, NULL); + DCHECK(success); + + // Add the InterfaceObject.length property. It is set to the length of the + // shortest argument list of all overload constructors. + JS::RootedValue length_value(context); + length_value.setInt32(0); + success = JS_DefineProperty( + context, rooted_interface_object, "length", length_value, + JSPROP_READONLY, NULL, NULL); + DCHECK(success); + + // Define interface object properties (including constants). + success = JS_DefineProperties(context, rooted_interface_object, + interface_object_properties); + DCHECK(success); + // Define interface object functions (static). + success = JS_DefineFunctions(context, rooted_interface_object, + interface_object_functions); + DCHECK(success); + + // Set the Prototype.constructor and Constructor.prototype properties. + DCHECK(interface_data->interface_object); + DCHECK(interface_data->prototype); + success = JS_LinkConstructorAndPrototype( + context, + rooted_interface_object, + rooted_prototype); + DCHECK(success); +} + +InterfaceData* GetInterfaceData(JSContext* context) { + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + // Use the address of the properties definition for this interface as a + // unique key for looking up the InterfaceData for this interface. + intptr_t key = reinterpret_cast<intptr_t>(&own_properties); + InterfaceData* interface_data = global_environment->GetInterfaceData(key); + if (!interface_data) { + interface_data = new InterfaceData(); + DCHECK(interface_data); + global_environment->CacheInterfaceData(key, interface_data); + DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key)); + } + return interface_data; +} + +} // namespace + +// static +JSObject* MozjsGarbageCollectionTestInterface::CreateProxy( + JSContext* context, const scoped_refptr<Wrappable>& wrappable) { + DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); + JS::RootedObject global_object( + context, + MozjsGlobalEnvironment::GetFromContext(context)->global_object()); + DCHECK(global_object); + + InterfaceData* interface_data = GetInterfaceData(context); + JS::RootedObject prototype(context, GetPrototype(context, global_object)); + DCHECK(prototype); + JS::RootedObject new_object( + context, + JS_NewObjectWithGivenProto( + context, &instance_class_definition, prototype)); + DCHECK(new_object); + JS::RootedObject proxy(context, + ProxyHandler::NewProxy( + context, proxy_handler.Pointer(), new_object, prototype)); + WrapperPrivate::GetOpaqueRootFunction get_root; + WrapperPrivate::GetReachableWrappablesFunction get_reachable_wrappables; + get_root = base::Bind(&GetOpaqueRootFromWrappable); + WrapperPrivate::AddPrivateData( + context, proxy, wrappable, get_root, get_reachable_wrappables); + return proxy; +} + +// static +const JSClass* MozjsGarbageCollectionTestInterface::PrototypeClass( + JSContext* context) { + DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); + JS::RootedObject global_object( + context, + MozjsGlobalEnvironment::GetFromContext(context)->global_object()); + DCHECK(global_object); + + JS::RootedObject prototype(context, GetPrototype(context, global_object)); + const JSClass* proto_class = JS_GetClass(prototype); + return proto_class; +} + +// static +JSObject* MozjsGarbageCollectionTestInterface::GetPrototype( + JSContext* context, JS::HandleObject global_object) { + DCHECK(JS_IsGlobalObject(global_object)); + + InterfaceData* interface_data = GetInterfaceData(context); + if (!interface_data->prototype) { + // Create new prototype that has all the props and methods + InitializePrototypeAndInterfaceObject( + interface_data, context, global_object); + } + DCHECK(interface_data->prototype); + return interface_data->prototype; +} + +// static +JSObject* MozjsGarbageCollectionTestInterface::GetInterfaceObject( + JSContext* context, JS::HandleObject global_object) { + DCHECK(JS_IsGlobalObject(global_object)); + + InterfaceData* interface_data = GetInterfaceData(context); + if (!interface_data->interface_object) { + InitializePrototypeAndInterfaceObject( + interface_data, context, global_object); + } + DCHECK(interface_data->interface_object); + return interface_data->interface_object; +} + + +namespace { +bool Constructor(JSContext* context, unsigned int argc, JS::Value* vp) { + MozjsExceptionState exception_state(context); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + + scoped_refptr<GarbageCollectionTestInterface> new_object = + new GarbageCollectionTestInterface(); + JS::RootedValue result_value(context); + ToJSValue(context, new_object, &result_value); + DCHECK(result_value.isObject()); + args.rval().setObject(result_value.toObject()); + return true; +} +} // namespace + + +} // namespace testing +} // namespace bindings +} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_garbage_collection_test_interface.h b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_garbage_collection_test_interface.h new file mode 100644 index 0000000..f6a0a82 --- /dev/null +++ b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_garbage_collection_test_interface.h
@@ -0,0 +1,52 @@ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// clang-format off + +// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! +// Auto-generated from template: bindings/mozjs-45/templates/interface.h.template + +#ifndef MozjsGarbageCollectionTestInterface_h +#define MozjsGarbageCollectionTestInterface_h + +#include "base/hash_tables.h" +#include "base/lazy_instance.h" +#include "base/memory/ref_counted.h" +#include "base/threading/thread_checker.h" +#include "cobalt/base/polymorphic_downcast.h" +#include "cobalt/script/wrappable.h" +#include "cobalt/bindings/testing/garbage_collection_test_interface.h" + +#include "third_party/mozjs-45/js/src/jsapi.h" + +namespace cobalt { +namespace bindings { +namespace testing { + +class MozjsGarbageCollectionTestInterface { + public: + static JSObject* CreateProxy(JSContext* context, + const scoped_refptr<script::Wrappable>& wrappable); + static const JSClass* PrototypeClass(JSContext* context); + static JSObject* GetPrototype(JSContext* context, + JS::HandleObject global_object); + static JSObject* GetInterfaceObject(JSContext* context, + JS::HandleObject global_object); +}; + +} // namespace testing +} // namespace bindings +} // namespace cobalt + +#endif // MozjsGarbageCollectionTestInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_get_opaque_root_interface.cc b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_get_opaque_root_interface.cc new file mode 100644 index 0000000..9199783 --- /dev/null +++ b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_get_opaque_root_interface.cc
@@ -0,0 +1,398 @@ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// clang-format off + +// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! +// Auto-generated from template: bindings/mozjs-45/templates/interface.cc.template + +#include "cobalt/bindings/testing/mozjs_get_opaque_root_interface.h" + +#include "base/debug/trace_event.h" +#include "cobalt/base/polymorphic_downcast.h" +#include "cobalt/script/global_environment.h" +#include "cobalt/script/opaque_handle.h" +#include "cobalt/script/script_value.h" + +#include "base/lazy_instance.h" +#include "cobalt/script/exception_state.h" +#include "cobalt/script/mozjs-45/callback_function_conversion.h" +#include "cobalt/script/mozjs-45/conversion_helpers.h" +#include "cobalt/script/mozjs-45/mozjs_callback_function.h" +#include "cobalt/script/mozjs-45/mozjs_exception_state.h" +#include "cobalt/script/mozjs-45/mozjs_global_environment.h" +#include "cobalt/script/mozjs-45/mozjs_object_handle.h" +#include "cobalt/script/mozjs-45/mozjs_property_enumerator.h" +#include "cobalt/script/mozjs-45/mozjs_user_object_holder.h" +#include "cobalt/script/mozjs-45/proxy_handler.h" +#include "cobalt/script/mozjs-45/type_traits.h" +#include "cobalt/script/mozjs-45/wrapper_factory.h" +#include "cobalt/script/mozjs-45/wrapper_private.h" +#include "cobalt/script/property_enumerator.h" +#include "cobalt/script/sequence.h" +#include "third_party/mozjs-45/js/src/jsapi.h" +#include "third_party/mozjs-45/js/src/jsfriendapi.h" + +namespace { +using cobalt::bindings::testing::GetOpaqueRootInterface; +using cobalt::bindings::testing::MozjsGetOpaqueRootInterface; +using cobalt::script::CallbackInterfaceTraits; +using cobalt::script::GlobalEnvironment; +using cobalt::script::OpaqueHandle; +using cobalt::script::OpaqueHandleHolder; +using cobalt::script::ScriptValue; +using cobalt::script::Wrappable; + +using cobalt::script::CallbackFunction; +using cobalt::script::CallbackInterfaceTraits; +using cobalt::script::ExceptionState; +using cobalt::script::Wrappable; +using cobalt::script::mozjs::FromJSValue; +using cobalt::script::mozjs::InterfaceData; +using cobalt::script::mozjs::MozjsCallbackFunction; +using cobalt::script::mozjs::MozjsExceptionState; +using cobalt::script::mozjs::MozjsGlobalEnvironment; +using cobalt::script::mozjs::MozjsPropertyEnumerator; +using cobalt::script::mozjs::MozjsUserObjectHolder; +using cobalt::script::mozjs::ProxyHandler; +using cobalt::script::mozjs::ToJSValue; +using cobalt::script::mozjs::TypeTraits; +using cobalt::script::mozjs::WrapperFactory; +using cobalt::script::mozjs::WrapperPrivate; +using cobalt::script::mozjs::kConversionFlagNullable; +using cobalt::script::mozjs::kConversionFlagRestricted; +using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString; +using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString; +using cobalt::script::mozjs::kNoConversionFlags; +} // namespace + +namespace cobalt { +namespace bindings { +namespace testing { + +namespace { + +Wrappable* GetOpaqueRootFromWrappable( + const scoped_refptr<Wrappable>& wrappable) { + GetOpaqueRootInterface* impl = + base::polymorphic_downcast<GetOpaqueRootInterface*>(wrappable.get()); + return impl->get_opaque_root_function_name(); +} + +void GetReachableWrappables(const scoped_refptr<Wrappable>& wrappable, + WrapperPrivate::WrappableVector* reachable) { + DCHECK(reachable); + GetOpaqueRootInterface* impl = + base::polymorphic_downcast<GetOpaqueRootInterface*>(wrappable.get()); + Wrappable* reachable_0 = impl->add_opaque_root_function_name(); + if (reachable_0) { + reachable->push_back(reachable_0); + } +} + +class MozjsGetOpaqueRootInterfaceHandler : public ProxyHandler { + public: + MozjsGetOpaqueRootInterfaceHandler() + : ProxyHandler(indexed_property_hooks, named_property_hooks) {} + + private: + static NamedPropertyHooks named_property_hooks; + static IndexedPropertyHooks indexed_property_hooks; +}; + +ProxyHandler::NamedPropertyHooks +MozjsGetOpaqueRootInterfaceHandler::named_property_hooks = { + NULL, + NULL, + NULL, + NULL, + NULL, +}; +ProxyHandler::IndexedPropertyHooks +MozjsGetOpaqueRootInterfaceHandler::indexed_property_hooks = { + NULL, + NULL, + NULL, + NULL, + NULL, +}; + +static base::LazyInstance<MozjsGetOpaqueRootInterfaceHandler> + proxy_handler; + +bool Constructor(JSContext* context, unsigned int argc, JS::Value* vp); +bool HasInstance(JSContext *context, JS::HandleObject type, + JS::MutableHandleValue vp, bool *success) { + JS::RootedObject global_object( + context, JS_GetGlobalForObject(context, type)); + DCHECK(global_object); + + JS::RootedObject prototype( + context, MozjsGetOpaqueRootInterface::GetPrototype(context, global_object)); + + // |IsDelegate| walks the prototype chain of an object returning true if + // .prototype is found. + bool is_delegate; + if (!IsDelegate(context, prototype, vp, &is_delegate)) { + *success = false; + return false; + } + + *success = is_delegate; + return true; +} + +const JSClass instance_class_definition = { + "GetOpaqueRootInterface", + 0 | JSCLASS_HAS_PRIVATE, + NULL, // addProperty + NULL, // delProperty + NULL, // getProperty + NULL, // setProperty + NULL, // enumerate + NULL, // resolve + NULL, // mayResolve + &WrapperPrivate::Finalizer, // finalize + NULL, // call + NULL, // hasInstance + NULL, // construct + &WrapperPrivate::Trace, // trace +}; + +const JSClass prototype_class_definition = { + "GetOpaqueRootInterfacePrototype", +}; + +const JSClass interface_object_class_definition = { + "GetOpaqueRootInterfaceConstructor", + 0, + NULL, // addProperty + NULL, // delProperty + NULL, // getProperty + NULL, // setProperty + NULL, // enumerate + NULL, // resolve + NULL, // mayResolve + NULL, // finalize + NULL, // call + &HasInstance, + Constructor, +}; + + + +const JSPropertySpec prototype_properties[] = { + JS_PS_END +}; + +const JSFunctionSpec prototype_functions[] = { + JS_FS_END +}; + +const JSPropertySpec interface_object_properties[] = { + JS_PS_END +}; + +const JSFunctionSpec interface_object_functions[] = { + JS_FS_END +}; + +const JSPropertySpec own_properties[] = { + JS_PS_END +}; + +void InitializePrototypeAndInterfaceObject( + InterfaceData* interface_data, JSContext* context, + JS::HandleObject global_object) { + DCHECK(!interface_data->prototype); + DCHECK(!interface_data->interface_object); + DCHECK(JS_IsGlobalObject(global_object)); + + JS::RootedObject parent_prototype( + context, JS_GetObjectPrototype(context, global_object)); + DCHECK(parent_prototype); + + interface_data->prototype = JS_NewObjectWithGivenProto( + context, &prototype_class_definition, parent_prototype + ); + + JS::RootedObject rooted_prototype(context, interface_data->prototype); + bool success = JS_DefineProperties( + context, + rooted_prototype, + prototype_properties); + + DCHECK(success); + success = JS_DefineFunctions( + context, rooted_prototype, prototype_functions); + DCHECK(success); + + JS::RootedObject function_prototype( + context, JS_GetFunctionPrototype(context, global_object)); + DCHECK(function_prototype); + // Create the Interface object. + interface_data->interface_object = JS_NewObjectWithGivenProto( + context, &interface_object_class_definition, + function_prototype); + + // Add the InterfaceObject.name property. + JS::RootedObject rooted_interface_object( + context, interface_data->interface_object); + JS::RootedValue name_value(context); + const char name[] = + "GetOpaqueRootInterface"; + name_value.setString(JS_NewStringCopyZ(context, name)); + success = JS_DefineProperty( + context, rooted_interface_object, "name", name_value, JSPROP_READONLY, + NULL, NULL); + DCHECK(success); + + // Add the InterfaceObject.length property. It is set to the length of the + // shortest argument list of all overload constructors. + JS::RootedValue length_value(context); + length_value.setInt32(0); + success = JS_DefineProperty( + context, rooted_interface_object, "length", length_value, + JSPROP_READONLY, NULL, NULL); + DCHECK(success); + + // Define interface object properties (including constants). + success = JS_DefineProperties(context, rooted_interface_object, + interface_object_properties); + DCHECK(success); + // Define interface object functions (static). + success = JS_DefineFunctions(context, rooted_interface_object, + interface_object_functions); + DCHECK(success); + + // Set the Prototype.constructor and Constructor.prototype properties. + DCHECK(interface_data->interface_object); + DCHECK(interface_data->prototype); + success = JS_LinkConstructorAndPrototype( + context, + rooted_interface_object, + rooted_prototype); + DCHECK(success); +} + +InterfaceData* GetInterfaceData(JSContext* context) { + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + // Use the address of the properties definition for this interface as a + // unique key for looking up the InterfaceData for this interface. + intptr_t key = reinterpret_cast<intptr_t>(&own_properties); + InterfaceData* interface_data = global_environment->GetInterfaceData(key); + if (!interface_data) { + interface_data = new InterfaceData(); + DCHECK(interface_data); + global_environment->CacheInterfaceData(key, interface_data); + DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key)); + } + return interface_data; +} + +} // namespace + +// static +JSObject* MozjsGetOpaqueRootInterface::CreateProxy( + JSContext* context, const scoped_refptr<Wrappable>& wrappable) { + DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); + JS::RootedObject global_object( + context, + MozjsGlobalEnvironment::GetFromContext(context)->global_object()); + DCHECK(global_object); + + InterfaceData* interface_data = GetInterfaceData(context); + JS::RootedObject prototype(context, GetPrototype(context, global_object)); + DCHECK(prototype); + JS::RootedObject new_object( + context, + JS_NewObjectWithGivenProto( + context, &instance_class_definition, prototype)); + DCHECK(new_object); + JS::RootedObject proxy(context, + ProxyHandler::NewProxy( + context, proxy_handler.Pointer(), new_object, prototype)); + WrapperPrivate::GetOpaqueRootFunction get_root; + WrapperPrivate::GetReachableWrappablesFunction get_reachable_wrappables; + get_root = base::Bind(&GetOpaqueRootFromWrappable); + get_reachable_wrappables = base::Bind(&GetReachableWrappables); + WrapperPrivate::AddPrivateData( + context, proxy, wrappable, get_root, get_reachable_wrappables); + return proxy; +} + +// static +const JSClass* MozjsGetOpaqueRootInterface::PrototypeClass( + JSContext* context) { + DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); + JS::RootedObject global_object( + context, + MozjsGlobalEnvironment::GetFromContext(context)->global_object()); + DCHECK(global_object); + + JS::RootedObject prototype(context, GetPrototype(context, global_object)); + const JSClass* proto_class = JS_GetClass(prototype); + return proto_class; +} + +// static +JSObject* MozjsGetOpaqueRootInterface::GetPrototype( + JSContext* context, JS::HandleObject global_object) { + DCHECK(JS_IsGlobalObject(global_object)); + + InterfaceData* interface_data = GetInterfaceData(context); + if (!interface_data->prototype) { + // Create new prototype that has all the props and methods + InitializePrototypeAndInterfaceObject( + interface_data, context, global_object); + } + DCHECK(interface_data->prototype); + return interface_data->prototype; +} + +// static +JSObject* MozjsGetOpaqueRootInterface::GetInterfaceObject( + JSContext* context, JS::HandleObject global_object) { + DCHECK(JS_IsGlobalObject(global_object)); + + InterfaceData* interface_data = GetInterfaceData(context); + if (!interface_data->interface_object) { + InitializePrototypeAndInterfaceObject( + interface_data, context, global_object); + } + DCHECK(interface_data->interface_object); + return interface_data->interface_object; +} + + +namespace { +bool Constructor(JSContext* context, unsigned int argc, JS::Value* vp) { + MozjsExceptionState exception_state(context); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + + scoped_refptr<GetOpaqueRootInterface> new_object = + new GetOpaqueRootInterface(); + JS::RootedValue result_value(context); + ToJSValue(context, new_object, &result_value); + DCHECK(result_value.isObject()); + args.rval().setObject(result_value.toObject()); + return true; +} +} // namespace + + +} // namespace testing +} // namespace bindings +} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_get_opaque_root_interface.h b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_get_opaque_root_interface.h new file mode 100644 index 0000000..962b8a1 --- /dev/null +++ b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_get_opaque_root_interface.h
@@ -0,0 +1,52 @@ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// clang-format off + +// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! +// Auto-generated from template: bindings/mozjs-45/templates/interface.h.template + +#ifndef MozjsGetOpaqueRootInterface_h +#define MozjsGetOpaqueRootInterface_h + +#include "base/hash_tables.h" +#include "base/lazy_instance.h" +#include "base/memory/ref_counted.h" +#include "base/threading/thread_checker.h" +#include "cobalt/base/polymorphic_downcast.h" +#include "cobalt/script/wrappable.h" +#include "cobalt/bindings/testing/get_opaque_root_interface.h" + +#include "third_party/mozjs-45/js/src/jsapi.h" + +namespace cobalt { +namespace bindings { +namespace testing { + +class MozjsGetOpaqueRootInterface { + public: + static JSObject* CreateProxy(JSContext* context, + const scoped_refptr<script::Wrappable>& wrappable); + static const JSClass* PrototypeClass(JSContext* context); + static JSObject* GetPrototype(JSContext* context, + JS::HandleObject global_object); + static JSObject* GetInterfaceObject(JSContext* context, + JS::HandleObject global_object); +}; + +} // namespace testing +} // namespace bindings +} // namespace cobalt + +#endif // MozjsGetOpaqueRootInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_global_interface_parent.cc b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_global_interface_parent.cc new file mode 100644 index 0000000..0c6e2ec --- /dev/null +++ b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_global_interface_parent.cc
@@ -0,0 +1,403 @@ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// clang-format off + +// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! +// Auto-generated from template: bindings/mozjs-45/templates/interface.cc.template + +#include "cobalt/bindings/testing/mozjs_global_interface_parent.h" + +#include "base/debug/trace_event.h" +#include "cobalt/base/polymorphic_downcast.h" +#include "cobalt/script/global_environment.h" +#include "cobalt/script/opaque_handle.h" +#include "cobalt/script/script_value.h" + +#include "base/lazy_instance.h" +#include "cobalt/script/exception_state.h" +#include "cobalt/script/mozjs-45/callback_function_conversion.h" +#include "cobalt/script/mozjs-45/conversion_helpers.h" +#include "cobalt/script/mozjs-45/mozjs_callback_function.h" +#include "cobalt/script/mozjs-45/mozjs_exception_state.h" +#include "cobalt/script/mozjs-45/mozjs_global_environment.h" +#include "cobalt/script/mozjs-45/mozjs_object_handle.h" +#include "cobalt/script/mozjs-45/mozjs_property_enumerator.h" +#include "cobalt/script/mozjs-45/mozjs_user_object_holder.h" +#include "cobalt/script/mozjs-45/proxy_handler.h" +#include "cobalt/script/mozjs-45/type_traits.h" +#include "cobalt/script/mozjs-45/wrapper_factory.h" +#include "cobalt/script/mozjs-45/wrapper_private.h" +#include "cobalt/script/property_enumerator.h" +#include "cobalt/script/sequence.h" +#include "third_party/mozjs-45/js/src/jsapi.h" +#include "third_party/mozjs-45/js/src/jsfriendapi.h" + +namespace { +using cobalt::bindings::testing::GlobalInterfaceParent; +using cobalt::bindings::testing::MozjsGlobalInterfaceParent; +using cobalt::script::CallbackInterfaceTraits; +using cobalt::script::GlobalEnvironment; +using cobalt::script::OpaqueHandle; +using cobalt::script::OpaqueHandleHolder; +using cobalt::script::ScriptValue; +using cobalt::script::Wrappable; + +using cobalt::script::CallbackFunction; +using cobalt::script::CallbackInterfaceTraits; +using cobalt::script::ExceptionState; +using cobalt::script::Wrappable; +using cobalt::script::mozjs::FromJSValue; +using cobalt::script::mozjs::InterfaceData; +using cobalt::script::mozjs::MozjsCallbackFunction; +using cobalt::script::mozjs::MozjsExceptionState; +using cobalt::script::mozjs::MozjsGlobalEnvironment; +using cobalt::script::mozjs::MozjsPropertyEnumerator; +using cobalt::script::mozjs::MozjsUserObjectHolder; +using cobalt::script::mozjs::ProxyHandler; +using cobalt::script::mozjs::ToJSValue; +using cobalt::script::mozjs::TypeTraits; +using cobalt::script::mozjs::WrapperFactory; +using cobalt::script::mozjs::WrapperPrivate; +using cobalt::script::mozjs::kConversionFlagNullable; +using cobalt::script::mozjs::kConversionFlagRestricted; +using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString; +using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString; +using cobalt::script::mozjs::kNoConversionFlags; +} // namespace + +namespace cobalt { +namespace bindings { +namespace testing { + +namespace { + +class MozjsGlobalInterfaceParentHandler : public ProxyHandler { + public: + MozjsGlobalInterfaceParentHandler() + : ProxyHandler(indexed_property_hooks, named_property_hooks) {} + + private: + static NamedPropertyHooks named_property_hooks; + static IndexedPropertyHooks indexed_property_hooks; +}; + +ProxyHandler::NamedPropertyHooks +MozjsGlobalInterfaceParentHandler::named_property_hooks = { + NULL, + NULL, + NULL, + NULL, + NULL, +}; +ProxyHandler::IndexedPropertyHooks +MozjsGlobalInterfaceParentHandler::indexed_property_hooks = { + NULL, + NULL, + NULL, + NULL, + NULL, +}; + +static base::LazyInstance<MozjsGlobalInterfaceParentHandler> + proxy_handler; + +bool HasInstance(JSContext *context, JS::HandleObject type, + JS::MutableHandleValue vp, bool *success) { + JS::RootedObject global_object( + context, JS_GetGlobalForObject(context, type)); + DCHECK(global_object); + + JS::RootedObject prototype( + context, MozjsGlobalInterfaceParent::GetPrototype(context, global_object)); + + // |IsDelegate| walks the prototype chain of an object returning true if + // .prototype is found. + bool is_delegate; + if (!IsDelegate(context, prototype, vp, &is_delegate)) { + *success = false; + return false; + } + + *success = is_delegate; + return true; +} + +const JSClass instance_class_definition = { + "GlobalInterfaceParent", + 0 | JSCLASS_HAS_PRIVATE, + NULL, // addProperty + NULL, // delProperty + NULL, // getProperty + NULL, // setProperty + NULL, // enumerate + NULL, // resolve + NULL, // mayResolve + &WrapperPrivate::Finalizer, // finalize + NULL, // call + NULL, // hasInstance + NULL, // construct + &WrapperPrivate::Trace, // trace +}; + +const JSClass prototype_class_definition = { + "GlobalInterfaceParentPrototype", +}; + +const JSClass interface_object_class_definition = { + "GlobalInterfaceParentConstructor", + 0, + NULL, // addProperty + NULL, // delProperty + NULL, // getProperty + NULL, // setProperty + NULL, // enumerate + NULL, // resolve + NULL, // mayResolve + NULL, // finalize + NULL, // call + &HasInstance, + NULL, +}; + +bool fcn_parentOperation( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + const JSClass* proto_class = + MozjsGlobalInterfaceParent::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<GlobalInterfaceParent>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + GlobalInterfaceParent* impl = + wrapper_private->wrappable<GlobalInterfaceParent>().get(); + + impl->ParentOperation(); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + + + +const JSPropertySpec prototype_properties[] = { + JS_PS_END +}; + +const JSFunctionSpec prototype_functions[] = { + JS_FNSPEC( + "parentOperation", fcn_parentOperation, NULL, + 0, JSPROP_ENUMERATE, NULL), + JS_FS_END +}; + +const JSPropertySpec interface_object_properties[] = { + JS_PS_END +}; + +const JSFunctionSpec interface_object_functions[] = { + JS_FS_END +}; + +const JSPropertySpec own_properties[] = { + JS_PS_END +}; + +void InitializePrototypeAndInterfaceObject( + InterfaceData* interface_data, JSContext* context, + JS::HandleObject global_object) { + DCHECK(!interface_data->prototype); + DCHECK(!interface_data->interface_object); + DCHECK(JS_IsGlobalObject(global_object)); + + JS::RootedObject parent_prototype( + context, JS_GetObjectPrototype(context, global_object)); + DCHECK(parent_prototype); + + interface_data->prototype = JS_NewObjectWithGivenProto( + context, &prototype_class_definition, parent_prototype + ); + + JS::RootedObject rooted_prototype(context, interface_data->prototype); + bool success = JS_DefineProperties( + context, + rooted_prototype, + prototype_properties); + + DCHECK(success); + success = JS_DefineFunctions( + context, rooted_prototype, prototype_functions); + DCHECK(success); + + JS::RootedObject function_prototype( + context, JS_GetFunctionPrototype(context, global_object)); + DCHECK(function_prototype); + // Create the Interface object. + interface_data->interface_object = JS_NewObjectWithGivenProto( + context, &interface_object_class_definition, + function_prototype); + + // Add the InterfaceObject.name property. + JS::RootedObject rooted_interface_object( + context, interface_data->interface_object); + JS::RootedValue name_value(context); + const char name[] = + "GlobalInterfaceParent"; + name_value.setString(JS_NewStringCopyZ(context, name)); + success = JS_DefineProperty( + context, rooted_interface_object, "name", name_value, JSPROP_READONLY, + NULL, NULL); + DCHECK(success); + + // Define interface object properties (including constants). + success = JS_DefineProperties(context, rooted_interface_object, + interface_object_properties); + DCHECK(success); + // Define interface object functions (static). + success = JS_DefineFunctions(context, rooted_interface_object, + interface_object_functions); + DCHECK(success); + + // Set the Prototype.constructor and Constructor.prototype properties. + DCHECK(interface_data->interface_object); + DCHECK(interface_data->prototype); + success = JS_LinkConstructorAndPrototype( + context, + rooted_interface_object, + rooted_prototype); + DCHECK(success); +} + +InterfaceData* GetInterfaceData(JSContext* context) { + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + // Use the address of the properties definition for this interface as a + // unique key for looking up the InterfaceData for this interface. + intptr_t key = reinterpret_cast<intptr_t>(&own_properties); + InterfaceData* interface_data = global_environment->GetInterfaceData(key); + if (!interface_data) { + interface_data = new InterfaceData(); + DCHECK(interface_data); + global_environment->CacheInterfaceData(key, interface_data); + DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key)); + } + return interface_data; +} + +} // namespace + +// static +JSObject* MozjsGlobalInterfaceParent::CreateProxy( + JSContext* context, const scoped_refptr<Wrappable>& wrappable) { + DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); + JS::RootedObject global_object( + context, + MozjsGlobalEnvironment::GetFromContext(context)->global_object()); + DCHECK(global_object); + + InterfaceData* interface_data = GetInterfaceData(context); + JS::RootedObject prototype(context, GetPrototype(context, global_object)); + DCHECK(prototype); + JS::RootedObject new_object( + context, + JS_NewObjectWithGivenProto( + context, &instance_class_definition, prototype)); + DCHECK(new_object); + JS::RootedObject proxy(context, + ProxyHandler::NewProxy( + context, proxy_handler.Pointer(), new_object, prototype)); + WrapperPrivate::AddPrivateData(context, proxy, wrappable); + return proxy; +} + +// static +const JSClass* MozjsGlobalInterfaceParent::PrototypeClass( + JSContext* context) { + DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); + JS::RootedObject global_object( + context, + MozjsGlobalEnvironment::GetFromContext(context)->global_object()); + DCHECK(global_object); + + JS::RootedObject prototype(context, GetPrototype(context, global_object)); + const JSClass* proto_class = JS_GetClass(prototype); + return proto_class; +} + +// static +JSObject* MozjsGlobalInterfaceParent::GetPrototype( + JSContext* context, JS::HandleObject global_object) { + DCHECK(JS_IsGlobalObject(global_object)); + + InterfaceData* interface_data = GetInterfaceData(context); + if (!interface_data->prototype) { + // Create new prototype that has all the props and methods + InitializePrototypeAndInterfaceObject( + interface_data, context, global_object); + } + DCHECK(interface_data->prototype); + return interface_data->prototype; +} + +// static +JSObject* MozjsGlobalInterfaceParent::GetInterfaceObject( + JSContext* context, JS::HandleObject global_object) { + DCHECK(JS_IsGlobalObject(global_object)); + + InterfaceData* interface_data = GetInterfaceData(context); + if (!interface_data->interface_object) { + InitializePrototypeAndInterfaceObject( + interface_data, context, global_object); + } + DCHECK(interface_data->interface_object); + return interface_data->interface_object; +} + + +namespace { +} // namespace + + +} // namespace testing +} // namespace bindings +} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_global_interface_parent.h b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_global_interface_parent.h new file mode 100644 index 0000000..6bb067c --- /dev/null +++ b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_global_interface_parent.h
@@ -0,0 +1,52 @@ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// clang-format off + +// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! +// Auto-generated from template: bindings/mozjs-45/templates/interface.h.template + +#ifndef MozjsGlobalInterfaceParent_h +#define MozjsGlobalInterfaceParent_h + +#include "base/hash_tables.h" +#include "base/lazy_instance.h" +#include "base/memory/ref_counted.h" +#include "base/threading/thread_checker.h" +#include "cobalt/base/polymorphic_downcast.h" +#include "cobalt/script/wrappable.h" +#include "cobalt/bindings/testing/global_interface_parent.h" + +#include "third_party/mozjs-45/js/src/jsapi.h" + +namespace cobalt { +namespace bindings { +namespace testing { + +class MozjsGlobalInterfaceParent { + public: + static JSObject* CreateProxy(JSContext* context, + const scoped_refptr<script::Wrappable>& wrappable); + static const JSClass* PrototypeClass(JSContext* context); + static JSObject* GetPrototype(JSContext* context, + JS::HandleObject global_object); + static JSObject* GetInterfaceObject(JSContext* context, + JS::HandleObject global_object); +}; + +} // namespace testing +} // namespace bindings +} // namespace cobalt + +#endif // MozjsGlobalInterfaceParent_h
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_indexed_getter_interface.cc b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_indexed_getter_interface.cc new file mode 100644 index 0000000..619e1cf --- /dev/null +++ b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_indexed_getter_interface.cc
@@ -0,0 +1,734 @@ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// clang-format off + +// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! +// Auto-generated from template: bindings/mozjs-45/templates/interface.cc.template + +#include "cobalt/bindings/testing/mozjs_indexed_getter_interface.h" + +#include "base/debug/trace_event.h" +#include "cobalt/base/polymorphic_downcast.h" +#include "cobalt/script/global_environment.h" +#include "cobalt/script/opaque_handle.h" +#include "cobalt/script/script_value.h" + +#include "base/lazy_instance.h" +#include "cobalt/script/exception_state.h" +#include "cobalt/script/mozjs-45/callback_function_conversion.h" +#include "cobalt/script/mozjs-45/conversion_helpers.h" +#include "cobalt/script/mozjs-45/mozjs_callback_function.h" +#include "cobalt/script/mozjs-45/mozjs_exception_state.h" +#include "cobalt/script/mozjs-45/mozjs_global_environment.h" +#include "cobalt/script/mozjs-45/mozjs_object_handle.h" +#include "cobalt/script/mozjs-45/mozjs_property_enumerator.h" +#include "cobalt/script/mozjs-45/mozjs_user_object_holder.h" +#include "cobalt/script/mozjs-45/proxy_handler.h" +#include "cobalt/script/mozjs-45/type_traits.h" +#include "cobalt/script/mozjs-45/wrapper_factory.h" +#include "cobalt/script/mozjs-45/wrapper_private.h" +#include "cobalt/script/property_enumerator.h" +#include "cobalt/script/sequence.h" +#include "third_party/mozjs-45/js/src/jsapi.h" +#include "third_party/mozjs-45/js/src/jsfriendapi.h" + +namespace { +using cobalt::bindings::testing::IndexedGetterInterface; +using cobalt::bindings::testing::MozjsIndexedGetterInterface; +using cobalt::script::CallbackInterfaceTraits; +using cobalt::script::GlobalEnvironment; +using cobalt::script::OpaqueHandle; +using cobalt::script::OpaqueHandleHolder; +using cobalt::script::ScriptValue; +using cobalt::script::Wrappable; + +using cobalt::script::CallbackFunction; +using cobalt::script::CallbackInterfaceTraits; +using cobalt::script::ExceptionState; +using cobalt::script::Wrappable; +using cobalt::script::mozjs::FromJSValue; +using cobalt::script::mozjs::InterfaceData; +using cobalt::script::mozjs::MozjsCallbackFunction; +using cobalt::script::mozjs::MozjsExceptionState; +using cobalt::script::mozjs::MozjsGlobalEnvironment; +using cobalt::script::mozjs::MozjsPropertyEnumerator; +using cobalt::script::mozjs::MozjsUserObjectHolder; +using cobalt::script::mozjs::ProxyHandler; +using cobalt::script::mozjs::ToJSValue; +using cobalt::script::mozjs::TypeTraits; +using cobalt::script::mozjs::WrapperFactory; +using cobalt::script::mozjs::WrapperPrivate; +using cobalt::script::mozjs::kConversionFlagNullable; +using cobalt::script::mozjs::kConversionFlagRestricted; +using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString; +using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString; +using cobalt::script::mozjs::kNoConversionFlags; +} // namespace + +namespace cobalt { +namespace bindings { +namespace testing { + +namespace { + +bool IsSupportedIndexProperty(JSContext* context, JS::HandleObject object, + uint32_t index) { + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + IndexedGetterInterface* impl = + wrapper_private->wrappable<IndexedGetterInterface>().get(); + return index < impl->length(); +} + +void EnumerateSupportedIndexes(JSContext* context, JS::HandleObject object, + JS::AutoIdVector* properties) { + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + IndexedGetterInterface* impl = + wrapper_private->wrappable<IndexedGetterInterface>().get(); + const uint32_t kNumIndexedProperties = impl->length(); + for (uint32_t i = 0; i < kNumIndexedProperties; ++i) { + properties->append(INT_TO_JSID(i)); + } +} + +bool GetIndexedProperty( + JSContext* context, JS::HandleObject object, JS::HandleId id, + JS::MutableHandleValue vp) { + JS::RootedValue id_value(context); + if (!JS_IdToValue(context, id, &id_value)) { + NOTREACHED(); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + IndexedGetterInterface* impl = + wrapper_private->wrappable<IndexedGetterInterface>().get(); + uint32_t index; + FromJSValue(context, id_value, kNoConversionFlags, &exception_state, &index); + if (exception_state.is_exception_set()) { + // The ID should be an integer or a string, so we shouldn't have any + // exceptions converting to string. + NOTREACHED(); + return false; + } + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->IndexedGetter(index), + &result_value); + } + if (!exception_state.is_exception_set()) { + vp.set(result_value); + } + return !exception_state.is_exception_set(); +} + +bool SetIndexedProperty( + JSContext* context, JS::HandleObject object, JS::HandleId id, + JS::MutableHandleValue vp, JS::ObjectOpResult& object_op_result) { + JS::RootedValue id_value(context); + if (!JS_IdToValue(context, id, &id_value)) { + NOTREACHED(); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + IndexedGetterInterface* impl = + wrapper_private->wrappable<IndexedGetterInterface>().get(); + uint32_t index; + FromJSValue(context, id_value, kNoConversionFlags, &exception_state, &index); + if (exception_state.is_exception_set()) { + // The ID should be an integer or a string, so we shouldn't have any + // exceptions converting to string. + NOTREACHED(); + return false; + } + TypeTraits<uint32_t >::ConversionType value; + FromJSValue(context, vp, kNoConversionFlags, + &exception_state, &value); + if (exception_state.is_exception_set()) { + return false; + } + + impl->IndexedSetter(index, value); + result_value.set(JS::UndefinedHandleValue); + if (!exception_state.is_exception_set()) { + return object_op_result.succeed(); + } else { + return false; + } +} + +bool DeleteIndexedProperty( + JSContext* context, JS::HandleObject object, uint32_t index) { + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + IndexedGetterInterface* impl = + wrapper_private->wrappable<IndexedGetterInterface>().get(); + + impl->IndexedDeleter(index); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + +class MozjsIndexedGetterInterfaceHandler : public ProxyHandler { + public: + MozjsIndexedGetterInterfaceHandler() + : ProxyHandler(indexed_property_hooks, named_property_hooks) {} + + private: + static NamedPropertyHooks named_property_hooks; + static IndexedPropertyHooks indexed_property_hooks; +}; + +ProxyHandler::NamedPropertyHooks +MozjsIndexedGetterInterfaceHandler::named_property_hooks = { + NULL, + NULL, + NULL, + NULL, + NULL, +}; +ProxyHandler::IndexedPropertyHooks +MozjsIndexedGetterInterfaceHandler::indexed_property_hooks = { + IsSupportedIndexProperty, + EnumerateSupportedIndexes, + GetIndexedProperty, + SetIndexedProperty, + DeleteIndexedProperty, +}; + +static base::LazyInstance<MozjsIndexedGetterInterfaceHandler> + proxy_handler; + +bool HasInstance(JSContext *context, JS::HandleObject type, + JS::MutableHandleValue vp, bool *success) { + JS::RootedObject global_object( + context, JS_GetGlobalForObject(context, type)); + DCHECK(global_object); + + JS::RootedObject prototype( + context, MozjsIndexedGetterInterface::GetPrototype(context, global_object)); + + // |IsDelegate| walks the prototype chain of an object returning true if + // .prototype is found. + bool is_delegate; + if (!IsDelegate(context, prototype, vp, &is_delegate)) { + *success = false; + return false; + } + + *success = is_delegate; + return true; +} + +const JSClass instance_class_definition = { + "IndexedGetterInterface", + 0 | JSCLASS_HAS_PRIVATE, + NULL, // addProperty + NULL, // delProperty + NULL, // getProperty + NULL, // setProperty + NULL, // enumerate + NULL, // resolve + NULL, // mayResolve + &WrapperPrivate::Finalizer, // finalize + NULL, // call + NULL, // hasInstance + NULL, // construct + &WrapperPrivate::Trace, // trace +}; + +const JSClass prototype_class_definition = { + "IndexedGetterInterfacePrototype", +}; + +const JSClass interface_object_class_definition = { + "IndexedGetterInterfaceConstructor", + 0, + NULL, // addProperty + NULL, // delProperty + NULL, // getProperty + NULL, // setProperty + NULL, // enumerate + NULL, // resolve + NULL, // mayResolve + NULL, // finalize + NULL, // call + &HasInstance, + NULL, +}; + +bool get_length( + JSContext* context, unsigned argc, JS::Value* vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + const JSClass* proto_class = + MozjsIndexedGetterInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<IndexedGetterInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + IndexedGetterInterface* impl = + wrapper_private->wrappable<IndexedGetterInterface>().get(); + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->length(), + &result_value); + } + if (!exception_state.is_exception_set()) { + args.rval().set(result_value); + } + return !exception_state.is_exception_set(); +} + + +bool fcn_indexedDeleter( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + const JSClass* proto_class = + MozjsIndexedGetterInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<IndexedGetterInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + IndexedGetterInterface* impl = + wrapper_private->wrappable<IndexedGetterInterface>().get(); + const size_t kMinArguments = 1; + if (args.length() < kMinArguments) { + exception_state.SetSimpleException(script::kInvalidNumberOfArguments); + return false; + } + // Non-optional arguments + TypeTraits<uint32_t >::ConversionType index; + + DCHECK_LT(0, args.length()); + JS::RootedValue non_optional_value0( + context, args[0]); + FromJSValue(context, + non_optional_value0, + kNoConversionFlags, + &exception_state, &index); + if (exception_state.is_exception_set()) { + return false; + } + + impl->IndexedDeleter(index); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + +bool fcn_indexedGetter( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + const JSClass* proto_class = + MozjsIndexedGetterInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<IndexedGetterInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + IndexedGetterInterface* impl = + wrapper_private->wrappable<IndexedGetterInterface>().get(); + const size_t kMinArguments = 1; + if (args.length() < kMinArguments) { + exception_state.SetSimpleException(script::kInvalidNumberOfArguments); + return false; + } + // Non-optional arguments + TypeTraits<uint32_t >::ConversionType index; + + DCHECK_LT(0, args.length()); + JS::RootedValue non_optional_value0( + context, args[0]); + FromJSValue(context, + non_optional_value0, + kNoConversionFlags, + &exception_state, &index); + if (exception_state.is_exception_set()) { + return false; + } + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->IndexedGetter(index), + &result_value); + } + if (!exception_state.is_exception_set()) { + args.rval().set(result_value); + } + return !exception_state.is_exception_set(); +} + +bool fcn_indexedSetter( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + const JSClass* proto_class = + MozjsIndexedGetterInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<IndexedGetterInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + IndexedGetterInterface* impl = + wrapper_private->wrappable<IndexedGetterInterface>().get(); + const size_t kMinArguments = 2; + if (args.length() < kMinArguments) { + exception_state.SetSimpleException(script::kInvalidNumberOfArguments); + return false; + } + // Non-optional arguments + TypeTraits<uint32_t >::ConversionType index; + TypeTraits<uint32_t >::ConversionType value; + + DCHECK_LT(0, args.length()); + JS::RootedValue non_optional_value0( + context, args[0]); + FromJSValue(context, + non_optional_value0, + kNoConversionFlags, + &exception_state, &index); + if (exception_state.is_exception_set()) { + return false; + } + + DCHECK_LT(1, args.length()); + JS::RootedValue non_optional_value1( + context, args[1]); + FromJSValue(context, + non_optional_value1, + kNoConversionFlags, + &exception_state, &value); + if (exception_state.is_exception_set()) { + return false; + } + + impl->IndexedSetter(index, value); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + + + +const JSPropertySpec prototype_properties[] = { + { // Readonly attribute + "length", + JSPROP_SHARED | JSPROP_ENUMERATE, + { { &get_length, NULL } }, + JSNATIVE_WRAPPER(NULL), + }, + JS_PS_END +}; + +const JSFunctionSpec prototype_functions[] = { + JS_FNSPEC( + "indexedDeleter", fcn_indexedDeleter, NULL, + 1, JSPROP_ENUMERATE, NULL), + JS_FNSPEC( + "indexedGetter", fcn_indexedGetter, NULL, + 1, JSPROP_ENUMERATE, NULL), + JS_FNSPEC( + "indexedSetter", fcn_indexedSetter, NULL, + 2, JSPROP_ENUMERATE, NULL), + JS_FS_END +}; + +const JSPropertySpec interface_object_properties[] = { + JS_PS_END +}; + +const JSFunctionSpec interface_object_functions[] = { + JS_FS_END +}; + +const JSPropertySpec own_properties[] = { + JS_PS_END +}; + +void InitializePrototypeAndInterfaceObject( + InterfaceData* interface_data, JSContext* context, + JS::HandleObject global_object) { + DCHECK(!interface_data->prototype); + DCHECK(!interface_data->interface_object); + DCHECK(JS_IsGlobalObject(global_object)); + + JS::RootedObject parent_prototype( + context, JS_GetObjectPrototype(context, global_object)); + DCHECK(parent_prototype); + + interface_data->prototype = JS_NewObjectWithGivenProto( + context, &prototype_class_definition, parent_prototype + ); + + JS::RootedObject rooted_prototype(context, interface_data->prototype); + bool success = JS_DefineProperties( + context, + rooted_prototype, + prototype_properties); + + DCHECK(success); + success = JS_DefineFunctions( + context, rooted_prototype, prototype_functions); + DCHECK(success); + + JS::RootedObject function_prototype( + context, JS_GetFunctionPrototype(context, global_object)); + DCHECK(function_prototype); + // Create the Interface object. + interface_data->interface_object = JS_NewObjectWithGivenProto( + context, &interface_object_class_definition, + function_prototype); + + // Add the InterfaceObject.name property. + JS::RootedObject rooted_interface_object( + context, interface_data->interface_object); + JS::RootedValue name_value(context); + const char name[] = + "IndexedGetterInterface"; + name_value.setString(JS_NewStringCopyZ(context, name)); + success = JS_DefineProperty( + context, rooted_interface_object, "name", name_value, JSPROP_READONLY, + NULL, NULL); + DCHECK(success); + + // Define interface object properties (including constants). + success = JS_DefineProperties(context, rooted_interface_object, + interface_object_properties); + DCHECK(success); + // Define interface object functions (static). + success = JS_DefineFunctions(context, rooted_interface_object, + interface_object_functions); + DCHECK(success); + + // Set the Prototype.constructor and Constructor.prototype properties. + DCHECK(interface_data->interface_object); + DCHECK(interface_data->prototype); + success = JS_LinkConstructorAndPrototype( + context, + rooted_interface_object, + rooted_prototype); + DCHECK(success); +} + +InterfaceData* GetInterfaceData(JSContext* context) { + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + // Use the address of the properties definition for this interface as a + // unique key for looking up the InterfaceData for this interface. + intptr_t key = reinterpret_cast<intptr_t>(&own_properties); + InterfaceData* interface_data = global_environment->GetInterfaceData(key); + if (!interface_data) { + interface_data = new InterfaceData(); + DCHECK(interface_data); + global_environment->CacheInterfaceData(key, interface_data); + DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key)); + } + return interface_data; +} + +} // namespace + +// static +JSObject* MozjsIndexedGetterInterface::CreateProxy( + JSContext* context, const scoped_refptr<Wrappable>& wrappable) { + DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); + JS::RootedObject global_object( + context, + MozjsGlobalEnvironment::GetFromContext(context)->global_object()); + DCHECK(global_object); + + InterfaceData* interface_data = GetInterfaceData(context); + JS::RootedObject prototype(context, GetPrototype(context, global_object)); + DCHECK(prototype); + JS::RootedObject new_object( + context, + JS_NewObjectWithGivenProto( + context, &instance_class_definition, prototype)); + DCHECK(new_object); + JS::RootedObject proxy(context, + ProxyHandler::NewProxy( + context, proxy_handler.Pointer(), new_object, prototype)); + WrapperPrivate::AddPrivateData(context, proxy, wrappable); + return proxy; +} + +// static +const JSClass* MozjsIndexedGetterInterface::PrototypeClass( + JSContext* context) { + DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); + JS::RootedObject global_object( + context, + MozjsGlobalEnvironment::GetFromContext(context)->global_object()); + DCHECK(global_object); + + JS::RootedObject prototype(context, GetPrototype(context, global_object)); + const JSClass* proto_class = JS_GetClass(prototype); + return proto_class; +} + +// static +JSObject* MozjsIndexedGetterInterface::GetPrototype( + JSContext* context, JS::HandleObject global_object) { + DCHECK(JS_IsGlobalObject(global_object)); + + InterfaceData* interface_data = GetInterfaceData(context); + if (!interface_data->prototype) { + // Create new prototype that has all the props and methods + InitializePrototypeAndInterfaceObject( + interface_data, context, global_object); + } + DCHECK(interface_data->prototype); + return interface_data->prototype; +} + +// static +JSObject* MozjsIndexedGetterInterface::GetInterfaceObject( + JSContext* context, JS::HandleObject global_object) { + DCHECK(JS_IsGlobalObject(global_object)); + + InterfaceData* interface_data = GetInterfaceData(context); + if (!interface_data->interface_object) { + InitializePrototypeAndInterfaceObject( + interface_data, context, global_object); + } + DCHECK(interface_data->interface_object); + return interface_data->interface_object; +} + + +namespace { +} // namespace + + +} // namespace testing +} // namespace bindings +} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_indexed_getter_interface.h b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_indexed_getter_interface.h new file mode 100644 index 0000000..f84682e --- /dev/null +++ b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_indexed_getter_interface.h
@@ -0,0 +1,52 @@ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// clang-format off + +// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! +// Auto-generated from template: bindings/mozjs-45/templates/interface.h.template + +#ifndef MozjsIndexedGetterInterface_h +#define MozjsIndexedGetterInterface_h + +#include "base/hash_tables.h" +#include "base/lazy_instance.h" +#include "base/memory/ref_counted.h" +#include "base/threading/thread_checker.h" +#include "cobalt/base/polymorphic_downcast.h" +#include "cobalt/script/wrappable.h" +#include "cobalt/bindings/testing/indexed_getter_interface.h" + +#include "third_party/mozjs-45/js/src/jsapi.h" + +namespace cobalt { +namespace bindings { +namespace testing { + +class MozjsIndexedGetterInterface { + public: + static JSObject* CreateProxy(JSContext* context, + const scoped_refptr<script::Wrappable>& wrappable); + static const JSClass* PrototypeClass(JSContext* context); + static JSObject* GetPrototype(JSContext* context, + JS::HandleObject global_object); + static JSObject* GetInterfaceObject(JSContext* context, + JS::HandleObject global_object); +}; + +} // namespace testing +} // namespace bindings +} // namespace cobalt + +#endif // MozjsIndexedGetterInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_interface_with_unsupported_properties.cc b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_interface_with_unsupported_properties.cc new file mode 100644 index 0000000..4f22190 --- /dev/null +++ b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_interface_with_unsupported_properties.cc
@@ -0,0 +1,402 @@ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// clang-format off + +// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! +// Auto-generated from template: bindings/mozjs-45/templates/interface.cc.template + +#include "cobalt/bindings/testing/mozjs_interface_with_unsupported_properties.h" + +#include "base/debug/trace_event.h" +#include "cobalt/base/polymorphic_downcast.h" +#include "cobalt/script/global_environment.h" +#include "cobalt/script/opaque_handle.h" +#include "cobalt/script/script_value.h" + +#include "base/lazy_instance.h" +#include "cobalt/script/exception_state.h" +#include "cobalt/script/mozjs-45/callback_function_conversion.h" +#include "cobalt/script/mozjs-45/conversion_helpers.h" +#include "cobalt/script/mozjs-45/mozjs_callback_function.h" +#include "cobalt/script/mozjs-45/mozjs_exception_state.h" +#include "cobalt/script/mozjs-45/mozjs_global_environment.h" +#include "cobalt/script/mozjs-45/mozjs_object_handle.h" +#include "cobalt/script/mozjs-45/mozjs_property_enumerator.h" +#include "cobalt/script/mozjs-45/mozjs_user_object_holder.h" +#include "cobalt/script/mozjs-45/proxy_handler.h" +#include "cobalt/script/mozjs-45/type_traits.h" +#include "cobalt/script/mozjs-45/wrapper_factory.h" +#include "cobalt/script/mozjs-45/wrapper_private.h" +#include "cobalt/script/property_enumerator.h" +#include "cobalt/script/sequence.h" +#include "third_party/mozjs-45/js/src/jsapi.h" +#include "third_party/mozjs-45/js/src/jsfriendapi.h" + +namespace { +using cobalt::bindings::testing::InterfaceWithUnsupportedProperties; +using cobalt::bindings::testing::MozjsInterfaceWithUnsupportedProperties; +using cobalt::script::CallbackInterfaceTraits; +using cobalt::script::GlobalEnvironment; +using cobalt::script::OpaqueHandle; +using cobalt::script::OpaqueHandleHolder; +using cobalt::script::ScriptValue; +using cobalt::script::Wrappable; + +using cobalt::script::CallbackFunction; +using cobalt::script::CallbackInterfaceTraits; +using cobalt::script::ExceptionState; +using cobalt::script::Wrappable; +using cobalt::script::mozjs::FromJSValue; +using cobalt::script::mozjs::InterfaceData; +using cobalt::script::mozjs::MozjsCallbackFunction; +using cobalt::script::mozjs::MozjsExceptionState; +using cobalt::script::mozjs::MozjsGlobalEnvironment; +using cobalt::script::mozjs::MozjsPropertyEnumerator; +using cobalt::script::mozjs::MozjsUserObjectHolder; +using cobalt::script::mozjs::ProxyHandler; +using cobalt::script::mozjs::ToJSValue; +using cobalt::script::mozjs::TypeTraits; +using cobalt::script::mozjs::WrapperFactory; +using cobalt::script::mozjs::WrapperPrivate; +using cobalt::script::mozjs::kConversionFlagNullable; +using cobalt::script::mozjs::kConversionFlagRestricted; +using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString; +using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString; +using cobalt::script::mozjs::kNoConversionFlags; +} // namespace + +namespace cobalt { +namespace bindings { +namespace testing { + +namespace { + +class MozjsInterfaceWithUnsupportedPropertiesHandler : public ProxyHandler { + public: + MozjsInterfaceWithUnsupportedPropertiesHandler() + : ProxyHandler(indexed_property_hooks, named_property_hooks) {} + + private: + static NamedPropertyHooks named_property_hooks; + static IndexedPropertyHooks indexed_property_hooks; +}; + +ProxyHandler::NamedPropertyHooks +MozjsInterfaceWithUnsupportedPropertiesHandler::named_property_hooks = { + NULL, + NULL, + NULL, + NULL, + NULL, +}; +ProxyHandler::IndexedPropertyHooks +MozjsInterfaceWithUnsupportedPropertiesHandler::indexed_property_hooks = { + NULL, + NULL, + NULL, + NULL, + NULL, +}; + +static base::LazyInstance<MozjsInterfaceWithUnsupportedPropertiesHandler> + proxy_handler; + +bool HasInstance(JSContext *context, JS::HandleObject type, + JS::MutableHandleValue vp, bool *success) { + JS::RootedObject global_object( + context, JS_GetGlobalForObject(context, type)); + DCHECK(global_object); + + JS::RootedObject prototype( + context, MozjsInterfaceWithUnsupportedProperties::GetPrototype(context, global_object)); + + // |IsDelegate| walks the prototype chain of an object returning true if + // .prototype is found. + bool is_delegate; + if (!IsDelegate(context, prototype, vp, &is_delegate)) { + *success = false; + return false; + } + + *success = is_delegate; + return true; +} + +const JSClass instance_class_definition = { + "InterfaceWithUnsupportedProperties", + 0 | JSCLASS_HAS_PRIVATE, + NULL, // addProperty + NULL, // delProperty + NULL, // getProperty + NULL, // setProperty + NULL, // enumerate + NULL, // resolve + NULL, // mayResolve + &WrapperPrivate::Finalizer, // finalize + NULL, // call + NULL, // hasInstance + NULL, // construct + &WrapperPrivate::Trace, // trace +}; + +const JSClass prototype_class_definition = { + "InterfaceWithUnsupportedPropertiesPrototype", +}; + +const JSClass interface_object_class_definition = { + "InterfaceWithUnsupportedPropertiesConstructor", + 0, + NULL, // addProperty + NULL, // delProperty + NULL, // getProperty + NULL, // setProperty + NULL, // enumerate + NULL, // resolve + NULL, // mayResolve + NULL, // finalize + NULL, // call + &HasInstance, + NULL, +}; + +bool get_supportedAttribute( + JSContext* context, unsigned argc, JS::Value* vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + const JSClass* proto_class = + MozjsInterfaceWithUnsupportedProperties::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<InterfaceWithUnsupportedProperties>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + InterfaceWithUnsupportedProperties* impl = + wrapper_private->wrappable<InterfaceWithUnsupportedProperties>().get(); + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->supported_attribute(), + &result_value); + } + if (!exception_state.is_exception_set()) { + args.rval().set(result_value); + } + return !exception_state.is_exception_set(); +} + + + + +const JSPropertySpec prototype_properties[] = { + { // Readonly attribute + "supportedAttribute", + JSPROP_SHARED | JSPROP_ENUMERATE, + { { &get_supportedAttribute, NULL } }, + JSNATIVE_WRAPPER(NULL), + }, + JS_PS_END +}; + +const JSFunctionSpec prototype_functions[] = { + JS_FS_END +}; + +const JSPropertySpec interface_object_properties[] = { + JS_PS_END +}; + +const JSFunctionSpec interface_object_functions[] = { + JS_FS_END +}; + +const JSPropertySpec own_properties[] = { + JS_PS_END +}; + +void InitializePrototypeAndInterfaceObject( + InterfaceData* interface_data, JSContext* context, + JS::HandleObject global_object) { + DCHECK(!interface_data->prototype); + DCHECK(!interface_data->interface_object); + DCHECK(JS_IsGlobalObject(global_object)); + + JS::RootedObject parent_prototype( + context, JS_GetObjectPrototype(context, global_object)); + DCHECK(parent_prototype); + + interface_data->prototype = JS_NewObjectWithGivenProto( + context, &prototype_class_definition, parent_prototype + ); + + JS::RootedObject rooted_prototype(context, interface_data->prototype); + bool success = JS_DefineProperties( + context, + rooted_prototype, + prototype_properties); + + DCHECK(success); + success = JS_DefineFunctions( + context, rooted_prototype, prototype_functions); + DCHECK(success); + + JS::RootedObject function_prototype( + context, JS_GetFunctionPrototype(context, global_object)); + DCHECK(function_prototype); + // Create the Interface object. + interface_data->interface_object = JS_NewObjectWithGivenProto( + context, &interface_object_class_definition, + function_prototype); + + // Add the InterfaceObject.name property. + JS::RootedObject rooted_interface_object( + context, interface_data->interface_object); + JS::RootedValue name_value(context); + const char name[] = + "InterfaceWithUnsupportedProperties"; + name_value.setString(JS_NewStringCopyZ(context, name)); + success = JS_DefineProperty( + context, rooted_interface_object, "name", name_value, JSPROP_READONLY, + NULL, NULL); + DCHECK(success); + + // Define interface object properties (including constants). + success = JS_DefineProperties(context, rooted_interface_object, + interface_object_properties); + DCHECK(success); + // Define interface object functions (static). + success = JS_DefineFunctions(context, rooted_interface_object, + interface_object_functions); + DCHECK(success); + + // Set the Prototype.constructor and Constructor.prototype properties. + DCHECK(interface_data->interface_object); + DCHECK(interface_data->prototype); + success = JS_LinkConstructorAndPrototype( + context, + rooted_interface_object, + rooted_prototype); + DCHECK(success); +} + +InterfaceData* GetInterfaceData(JSContext* context) { + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + // Use the address of the properties definition for this interface as a + // unique key for looking up the InterfaceData for this interface. + intptr_t key = reinterpret_cast<intptr_t>(&own_properties); + InterfaceData* interface_data = global_environment->GetInterfaceData(key); + if (!interface_data) { + interface_data = new InterfaceData(); + DCHECK(interface_data); + global_environment->CacheInterfaceData(key, interface_data); + DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key)); + } + return interface_data; +} + +} // namespace + +// static +JSObject* MozjsInterfaceWithUnsupportedProperties::CreateProxy( + JSContext* context, const scoped_refptr<Wrappable>& wrappable) { + DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); + JS::RootedObject global_object( + context, + MozjsGlobalEnvironment::GetFromContext(context)->global_object()); + DCHECK(global_object); + + InterfaceData* interface_data = GetInterfaceData(context); + JS::RootedObject prototype(context, GetPrototype(context, global_object)); + DCHECK(prototype); + JS::RootedObject new_object( + context, + JS_NewObjectWithGivenProto( + context, &instance_class_definition, prototype)); + DCHECK(new_object); + JS::RootedObject proxy(context, + ProxyHandler::NewProxy( + context, proxy_handler.Pointer(), new_object, prototype)); + WrapperPrivate::AddPrivateData(context, proxy, wrappable); + return proxy; +} + +// static +const JSClass* MozjsInterfaceWithUnsupportedProperties::PrototypeClass( + JSContext* context) { + DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); + JS::RootedObject global_object( + context, + MozjsGlobalEnvironment::GetFromContext(context)->global_object()); + DCHECK(global_object); + + JS::RootedObject prototype(context, GetPrototype(context, global_object)); + const JSClass* proto_class = JS_GetClass(prototype); + return proto_class; +} + +// static +JSObject* MozjsInterfaceWithUnsupportedProperties::GetPrototype( + JSContext* context, JS::HandleObject global_object) { + DCHECK(JS_IsGlobalObject(global_object)); + + InterfaceData* interface_data = GetInterfaceData(context); + if (!interface_data->prototype) { + // Create new prototype that has all the props and methods + InitializePrototypeAndInterfaceObject( + interface_data, context, global_object); + } + DCHECK(interface_data->prototype); + return interface_data->prototype; +} + +// static +JSObject* MozjsInterfaceWithUnsupportedProperties::GetInterfaceObject( + JSContext* context, JS::HandleObject global_object) { + DCHECK(JS_IsGlobalObject(global_object)); + + InterfaceData* interface_data = GetInterfaceData(context); + if (!interface_data->interface_object) { + InitializePrototypeAndInterfaceObject( + interface_data, context, global_object); + } + DCHECK(interface_data->interface_object); + return interface_data->interface_object; +} + + +namespace { +} // namespace + + +} // namespace testing +} // namespace bindings +} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_interface_with_unsupported_properties.h b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_interface_with_unsupported_properties.h new file mode 100644 index 0000000..934c59f --- /dev/null +++ b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_interface_with_unsupported_properties.h
@@ -0,0 +1,52 @@ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// clang-format off + +// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! +// Auto-generated from template: bindings/mozjs-45/templates/interface.h.template + +#ifndef MozjsInterfaceWithUnsupportedProperties_h +#define MozjsInterfaceWithUnsupportedProperties_h + +#include "base/hash_tables.h" +#include "base/lazy_instance.h" +#include "base/memory/ref_counted.h" +#include "base/threading/thread_checker.h" +#include "cobalt/base/polymorphic_downcast.h" +#include "cobalt/script/wrappable.h" +#include "cobalt/bindings/testing/interface_with_unsupported_properties.h" + +#include "third_party/mozjs-45/js/src/jsapi.h" + +namespace cobalt { +namespace bindings { +namespace testing { + +class MozjsInterfaceWithUnsupportedProperties { + public: + static JSObject* CreateProxy(JSContext* context, + const scoped_refptr<script::Wrappable>& wrappable); + static const JSClass* PrototypeClass(JSContext* context); + static JSObject* GetPrototype(JSContext* context, + JS::HandleObject global_object); + static JSObject* GetInterfaceObject(JSContext* context, + JS::HandleObject global_object); +}; + +} // namespace testing +} // namespace bindings +} // namespace cobalt + +#endif // MozjsInterfaceWithUnsupportedProperties_h
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_named_constructor_interface.cc b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_named_constructor_interface.cc new file mode 100644 index 0000000..8e3736c --- /dev/null +++ b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_named_constructor_interface.cc
@@ -0,0 +1,375 @@ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// clang-format off + +// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! +// Auto-generated from template: bindings/mozjs-45/templates/interface.cc.template + +#include "cobalt/bindings/testing/mozjs_named_constructor_interface.h" + +#include "base/debug/trace_event.h" +#include "cobalt/base/polymorphic_downcast.h" +#include "cobalt/script/global_environment.h" +#include "cobalt/script/opaque_handle.h" +#include "cobalt/script/script_value.h" + +#include "base/lazy_instance.h" +#include "cobalt/script/exception_state.h" +#include "cobalt/script/mozjs-45/callback_function_conversion.h" +#include "cobalt/script/mozjs-45/conversion_helpers.h" +#include "cobalt/script/mozjs-45/mozjs_callback_function.h" +#include "cobalt/script/mozjs-45/mozjs_exception_state.h" +#include "cobalt/script/mozjs-45/mozjs_global_environment.h" +#include "cobalt/script/mozjs-45/mozjs_object_handle.h" +#include "cobalt/script/mozjs-45/mozjs_property_enumerator.h" +#include "cobalt/script/mozjs-45/mozjs_user_object_holder.h" +#include "cobalt/script/mozjs-45/proxy_handler.h" +#include "cobalt/script/mozjs-45/type_traits.h" +#include "cobalt/script/mozjs-45/wrapper_factory.h" +#include "cobalt/script/mozjs-45/wrapper_private.h" +#include "cobalt/script/property_enumerator.h" +#include "cobalt/script/sequence.h" +#include "third_party/mozjs-45/js/src/jsapi.h" +#include "third_party/mozjs-45/js/src/jsfriendapi.h" + +namespace { +using cobalt::bindings::testing::NamedConstructorInterface; +using cobalt::bindings::testing::MozjsNamedConstructorInterface; +using cobalt::script::CallbackInterfaceTraits; +using cobalt::script::GlobalEnvironment; +using cobalt::script::OpaqueHandle; +using cobalt::script::OpaqueHandleHolder; +using cobalt::script::ScriptValue; +using cobalt::script::Wrappable; + +using cobalt::script::CallbackFunction; +using cobalt::script::CallbackInterfaceTraits; +using cobalt::script::ExceptionState; +using cobalt::script::Wrappable; +using cobalt::script::mozjs::FromJSValue; +using cobalt::script::mozjs::InterfaceData; +using cobalt::script::mozjs::MozjsCallbackFunction; +using cobalt::script::mozjs::MozjsExceptionState; +using cobalt::script::mozjs::MozjsGlobalEnvironment; +using cobalt::script::mozjs::MozjsPropertyEnumerator; +using cobalt::script::mozjs::MozjsUserObjectHolder; +using cobalt::script::mozjs::ProxyHandler; +using cobalt::script::mozjs::ToJSValue; +using cobalt::script::mozjs::TypeTraits; +using cobalt::script::mozjs::WrapperFactory; +using cobalt::script::mozjs::WrapperPrivate; +using cobalt::script::mozjs::kConversionFlagNullable; +using cobalt::script::mozjs::kConversionFlagRestricted; +using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString; +using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString; +using cobalt::script::mozjs::kNoConversionFlags; +} // namespace + +namespace cobalt { +namespace bindings { +namespace testing { + +namespace { + +class MozjsNamedConstructorInterfaceHandler : public ProxyHandler { + public: + MozjsNamedConstructorInterfaceHandler() + : ProxyHandler(indexed_property_hooks, named_property_hooks) {} + + private: + static NamedPropertyHooks named_property_hooks; + static IndexedPropertyHooks indexed_property_hooks; +}; + +ProxyHandler::NamedPropertyHooks +MozjsNamedConstructorInterfaceHandler::named_property_hooks = { + NULL, + NULL, + NULL, + NULL, + NULL, +}; +ProxyHandler::IndexedPropertyHooks +MozjsNamedConstructorInterfaceHandler::indexed_property_hooks = { + NULL, + NULL, + NULL, + NULL, + NULL, +}; + +static base::LazyInstance<MozjsNamedConstructorInterfaceHandler> + proxy_handler; + +bool Constructor(JSContext* context, unsigned int argc, JS::Value* vp); +bool HasInstance(JSContext *context, JS::HandleObject type, + JS::MutableHandleValue vp, bool *success) { + JS::RootedObject global_object( + context, JS_GetGlobalForObject(context, type)); + DCHECK(global_object); + + JS::RootedObject prototype( + context, MozjsNamedConstructorInterface::GetPrototype(context, global_object)); + + // |IsDelegate| walks the prototype chain of an object returning true if + // .prototype is found. + bool is_delegate; + if (!IsDelegate(context, prototype, vp, &is_delegate)) { + *success = false; + return false; + } + + *success = is_delegate; + return true; +} + +const JSClass instance_class_definition = { + "NamedConstructorInterface", + 0 | JSCLASS_HAS_PRIVATE, + NULL, // addProperty + NULL, // delProperty + NULL, // getProperty + NULL, // setProperty + NULL, // enumerate + NULL, // resolve + NULL, // mayResolve + &WrapperPrivate::Finalizer, // finalize + NULL, // call + NULL, // hasInstance + NULL, // construct + &WrapperPrivate::Trace, // trace +}; + +const JSClass prototype_class_definition = { + "NamedConstructorInterfacePrototype", +}; + +const JSClass interface_object_class_definition = { + "NamedConstructorInterfaceConstructor", + 0, + NULL, // addProperty + NULL, // delProperty + NULL, // getProperty + NULL, // setProperty + NULL, // enumerate + NULL, // resolve + NULL, // mayResolve + NULL, // finalize + NULL, // call + &HasInstance, + Constructor, +}; + + + +const JSPropertySpec prototype_properties[] = { + JS_PS_END +}; + +const JSFunctionSpec prototype_functions[] = { + JS_FS_END +}; + +const JSPropertySpec interface_object_properties[] = { + JS_PS_END +}; + +const JSFunctionSpec interface_object_functions[] = { + JS_FS_END +}; + +const JSPropertySpec own_properties[] = { + JS_PS_END +}; + +void InitializePrototypeAndInterfaceObject( + InterfaceData* interface_data, JSContext* context, + JS::HandleObject global_object) { + DCHECK(!interface_data->prototype); + DCHECK(!interface_data->interface_object); + DCHECK(JS_IsGlobalObject(global_object)); + + JS::RootedObject parent_prototype( + context, JS_GetObjectPrototype(context, global_object)); + DCHECK(parent_prototype); + + interface_data->prototype = JS_NewObjectWithGivenProto( + context, &prototype_class_definition, parent_prototype + ); + + JS::RootedObject rooted_prototype(context, interface_data->prototype); + bool success = JS_DefineProperties( + context, + rooted_prototype, + prototype_properties); + + DCHECK(success); + success = JS_DefineFunctions( + context, rooted_prototype, prototype_functions); + DCHECK(success); + + JS::RootedObject function_prototype( + context, JS_GetFunctionPrototype(context, global_object)); + DCHECK(function_prototype); + // Create the Interface object. + interface_data->interface_object = JS_NewObjectWithGivenProto( + context, &interface_object_class_definition, + function_prototype); + + // Add the InterfaceObject.name property. + JS::RootedObject rooted_interface_object( + context, interface_data->interface_object); + JS::RootedValue name_value(context); + const char name[] = + "SomeNamedConstructor"; + name_value.setString(JS_NewStringCopyZ(context, name)); + success = JS_DefineProperty( + context, rooted_interface_object, "name", name_value, JSPROP_READONLY, + NULL, NULL); + DCHECK(success); + + // Add the InterfaceObject.length property. It is set to the length of the + // shortest argument list of all overload constructors. + JS::RootedValue length_value(context); + length_value.setInt32(0); + success = JS_DefineProperty( + context, rooted_interface_object, "length", length_value, + JSPROP_READONLY, NULL, NULL); + DCHECK(success); + + // Define interface object properties (including constants). + success = JS_DefineProperties(context, rooted_interface_object, + interface_object_properties); + DCHECK(success); + // Define interface object functions (static). + success = JS_DefineFunctions(context, rooted_interface_object, + interface_object_functions); + DCHECK(success); + + // Set the Prototype.constructor and Constructor.prototype properties. + DCHECK(interface_data->interface_object); + DCHECK(interface_data->prototype); + success = JS_LinkConstructorAndPrototype( + context, + rooted_interface_object, + rooted_prototype); + DCHECK(success); +} + +InterfaceData* GetInterfaceData(JSContext* context) { + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + // Use the address of the properties definition for this interface as a + // unique key for looking up the InterfaceData for this interface. + intptr_t key = reinterpret_cast<intptr_t>(&own_properties); + InterfaceData* interface_data = global_environment->GetInterfaceData(key); + if (!interface_data) { + interface_data = new InterfaceData(); + DCHECK(interface_data); + global_environment->CacheInterfaceData(key, interface_data); + DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key)); + } + return interface_data; +} + +} // namespace + +// static +JSObject* MozjsNamedConstructorInterface::CreateProxy( + JSContext* context, const scoped_refptr<Wrappable>& wrappable) { + DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); + JS::RootedObject global_object( + context, + MozjsGlobalEnvironment::GetFromContext(context)->global_object()); + DCHECK(global_object); + + InterfaceData* interface_data = GetInterfaceData(context); + JS::RootedObject prototype(context, GetPrototype(context, global_object)); + DCHECK(prototype); + JS::RootedObject new_object( + context, + JS_NewObjectWithGivenProto( + context, &instance_class_definition, prototype)); + DCHECK(new_object); + JS::RootedObject proxy(context, + ProxyHandler::NewProxy( + context, proxy_handler.Pointer(), new_object, prototype)); + WrapperPrivate::AddPrivateData(context, proxy, wrappable); + return proxy; +} + +// static +const JSClass* MozjsNamedConstructorInterface::PrototypeClass( + JSContext* context) { + DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); + JS::RootedObject global_object( + context, + MozjsGlobalEnvironment::GetFromContext(context)->global_object()); + DCHECK(global_object); + + JS::RootedObject prototype(context, GetPrototype(context, global_object)); + const JSClass* proto_class = JS_GetClass(prototype); + return proto_class; +} + +// static +JSObject* MozjsNamedConstructorInterface::GetPrototype( + JSContext* context, JS::HandleObject global_object) { + DCHECK(JS_IsGlobalObject(global_object)); + + InterfaceData* interface_data = GetInterfaceData(context); + if (!interface_data->prototype) { + // Create new prototype that has all the props and methods + InitializePrototypeAndInterfaceObject( + interface_data, context, global_object); + } + DCHECK(interface_data->prototype); + return interface_data->prototype; +} + +// static +JSObject* MozjsNamedConstructorInterface::GetInterfaceObject( + JSContext* context, JS::HandleObject global_object) { + DCHECK(JS_IsGlobalObject(global_object)); + + InterfaceData* interface_data = GetInterfaceData(context); + if (!interface_data->interface_object) { + InitializePrototypeAndInterfaceObject( + interface_data, context, global_object); + } + DCHECK(interface_data->interface_object); + return interface_data->interface_object; +} + + +namespace { +bool Constructor(JSContext* context, unsigned int argc, JS::Value* vp) { + MozjsExceptionState exception_state(context); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + + scoped_refptr<NamedConstructorInterface> new_object = + new NamedConstructorInterface(); + JS::RootedValue result_value(context); + ToJSValue(context, new_object, &result_value); + DCHECK(result_value.isObject()); + args.rval().setObject(result_value.toObject()); + return true; +} +} // namespace + + +} // namespace testing +} // namespace bindings +} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_named_constructor_interface.h b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_named_constructor_interface.h new file mode 100644 index 0000000..fa8c30e --- /dev/null +++ b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_named_constructor_interface.h
@@ -0,0 +1,52 @@ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// clang-format off + +// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! +// Auto-generated from template: bindings/mozjs-45/templates/interface.h.template + +#ifndef MozjsNamedConstructorInterface_h +#define MozjsNamedConstructorInterface_h + +#include "base/hash_tables.h" +#include "base/lazy_instance.h" +#include "base/memory/ref_counted.h" +#include "base/threading/thread_checker.h" +#include "cobalt/base/polymorphic_downcast.h" +#include "cobalt/script/wrappable.h" +#include "cobalt/bindings/testing/named_constructor_interface.h" + +#include "third_party/mozjs-45/js/src/jsapi.h" + +namespace cobalt { +namespace bindings { +namespace testing { + +class MozjsNamedConstructorInterface { + public: + static JSObject* CreateProxy(JSContext* context, + const scoped_refptr<script::Wrappable>& wrappable); + static const JSClass* PrototypeClass(JSContext* context); + static JSObject* GetPrototype(JSContext* context, + JS::HandleObject global_object); + static JSObject* GetInterfaceObject(JSContext* context, + JS::HandleObject global_object); +}; + +} // namespace testing +} // namespace bindings +} // namespace cobalt + +#endif // MozjsNamedConstructorInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_named_getter_interface.cc b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_named_getter_interface.cc new file mode 100644 index 0000000..2bebf98 --- /dev/null +++ b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_named_getter_interface.cc
@@ -0,0 +1,687 @@ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// clang-format off + +// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! +// Auto-generated from template: bindings/mozjs-45/templates/interface.cc.template + +#include "cobalt/bindings/testing/mozjs_named_getter_interface.h" + +#include "base/debug/trace_event.h" +#include "cobalt/base/polymorphic_downcast.h" +#include "cobalt/script/global_environment.h" +#include "cobalt/script/opaque_handle.h" +#include "cobalt/script/script_value.h" + +#include "base/lazy_instance.h" +#include "cobalt/script/exception_state.h" +#include "cobalt/script/mozjs-45/callback_function_conversion.h" +#include "cobalt/script/mozjs-45/conversion_helpers.h" +#include "cobalt/script/mozjs-45/mozjs_callback_function.h" +#include "cobalt/script/mozjs-45/mozjs_exception_state.h" +#include "cobalt/script/mozjs-45/mozjs_global_environment.h" +#include "cobalt/script/mozjs-45/mozjs_object_handle.h" +#include "cobalt/script/mozjs-45/mozjs_property_enumerator.h" +#include "cobalt/script/mozjs-45/mozjs_user_object_holder.h" +#include "cobalt/script/mozjs-45/proxy_handler.h" +#include "cobalt/script/mozjs-45/type_traits.h" +#include "cobalt/script/mozjs-45/wrapper_factory.h" +#include "cobalt/script/mozjs-45/wrapper_private.h" +#include "cobalt/script/property_enumerator.h" +#include "cobalt/script/sequence.h" +#include "third_party/mozjs-45/js/src/jsapi.h" +#include "third_party/mozjs-45/js/src/jsfriendapi.h" + +namespace { +using cobalt::bindings::testing::NamedGetterInterface; +using cobalt::bindings::testing::MozjsNamedGetterInterface; +using cobalt::script::CallbackInterfaceTraits; +using cobalt::script::GlobalEnvironment; +using cobalt::script::OpaqueHandle; +using cobalt::script::OpaqueHandleHolder; +using cobalt::script::ScriptValue; +using cobalt::script::Wrappable; + +using cobalt::script::CallbackFunction; +using cobalt::script::CallbackInterfaceTraits; +using cobalt::script::ExceptionState; +using cobalt::script::Wrappable; +using cobalt::script::mozjs::FromJSValue; +using cobalt::script::mozjs::InterfaceData; +using cobalt::script::mozjs::MozjsCallbackFunction; +using cobalt::script::mozjs::MozjsExceptionState; +using cobalt::script::mozjs::MozjsGlobalEnvironment; +using cobalt::script::mozjs::MozjsPropertyEnumerator; +using cobalt::script::mozjs::MozjsUserObjectHolder; +using cobalt::script::mozjs::ProxyHandler; +using cobalt::script::mozjs::ToJSValue; +using cobalt::script::mozjs::TypeTraits; +using cobalt::script::mozjs::WrapperFactory; +using cobalt::script::mozjs::WrapperPrivate; +using cobalt::script::mozjs::kConversionFlagNullable; +using cobalt::script::mozjs::kConversionFlagRestricted; +using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString; +using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString; +using cobalt::script::mozjs::kNoConversionFlags; +} // namespace + +namespace cobalt { +namespace bindings { +namespace testing { + +namespace { + +bool IsSupportedNamedProperty(JSContext* context, JS::HandleObject object, + const std::string& property_name) { + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + NamedGetterInterface* impl = + wrapper_private->wrappable<NamedGetterInterface>().get(); + return impl->CanQueryNamedProperty(property_name); +} + +void EnumerateSupportedNames(JSContext* context, JS::HandleObject object, + JS::AutoIdVector* properties) { + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + NamedGetterInterface* impl = + wrapper_private->wrappable<NamedGetterInterface>().get(); + MozjsPropertyEnumerator enumerator(context, properties); + impl->EnumerateNamedProperties(&enumerator); +} + +bool GetNamedProperty( + JSContext* context, JS::HandleObject object, JS::HandleId id, + JS::MutableHandleValue vp) { + JS::RootedValue id_value(context); + if (!JS_IdToValue(context, id, &id_value)) { + NOTREACHED(); + return false; + } + + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + NamedGetterInterface* impl = + wrapper_private->wrappable<NamedGetterInterface>().get(); + std::string property_name; + FromJSValue(context, id_value, kNoConversionFlags, &exception_state, + &property_name); + if (exception_state.is_exception_set()) { + // The ID should be an integer or a string, so we shouldn't have any + // exceptions converting to string. + NOTREACHED(); + return false; + } + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->NamedGetter(property_name), + &result_value); + } + if (!exception_state.is_exception_set()) { + vp.set(result_value); + } + return !exception_state.is_exception_set(); +} + +bool SetNamedProperty( + JSContext* context, JS::HandleObject object, JS::HandleId id, + JS::MutableHandleValue vp, JS::ObjectOpResult& object_op_result) { + JS::RootedValue id_value(context); + if (!JS_IdToValue(context, id, &id_value)) { + NOTREACHED(); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + NamedGetterInterface* impl = + wrapper_private->wrappable<NamedGetterInterface>().get(); + std::string property_name; + FromJSValue(context, id_value, kNoConversionFlags, &exception_state, + &property_name); + if (exception_state.is_exception_set()) { + // The ID should be an integer or a string, so we shouldn't have any + // exceptions converting to string. + NOTREACHED(); + return false; + } + TypeTraits<std::string >::ConversionType value; + FromJSValue(context, vp, kNoConversionFlags, + &exception_state, &value); + if (exception_state.is_exception_set()) { + return false; + } + + impl->NamedSetter(property_name, value); + result_value.set(JS::UndefinedHandleValue); + + if (!exception_state.is_exception_set()) { + return object_op_result.succeed(); + } else { + return false; + } +} + +bool DeleteNamedProperty(JSContext* context, JS::HandleObject object, + const std::string& property_name) { + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + NamedGetterInterface* impl = + wrapper_private->wrappable<NamedGetterInterface>().get(); + + impl->NamedDeleter(property_name); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + +class MozjsNamedGetterInterfaceHandler : public ProxyHandler { + public: + MozjsNamedGetterInterfaceHandler() + : ProxyHandler(indexed_property_hooks, named_property_hooks) {} + + private: + static NamedPropertyHooks named_property_hooks; + static IndexedPropertyHooks indexed_property_hooks; +}; + +ProxyHandler::NamedPropertyHooks +MozjsNamedGetterInterfaceHandler::named_property_hooks = { + IsSupportedNamedProperty, + EnumerateSupportedNames, + GetNamedProperty, + SetNamedProperty, + DeleteNamedProperty, +}; +ProxyHandler::IndexedPropertyHooks +MozjsNamedGetterInterfaceHandler::indexed_property_hooks = { + NULL, + NULL, + NULL, + NULL, + NULL, +}; + +static base::LazyInstance<MozjsNamedGetterInterfaceHandler> + proxy_handler; + +bool HasInstance(JSContext *context, JS::HandleObject type, + JS::MutableHandleValue vp, bool *success) { + JS::RootedObject global_object( + context, JS_GetGlobalForObject(context, type)); + DCHECK(global_object); + + JS::RootedObject prototype( + context, MozjsNamedGetterInterface::GetPrototype(context, global_object)); + + // |IsDelegate| walks the prototype chain of an object returning true if + // .prototype is found. + bool is_delegate; + if (!IsDelegate(context, prototype, vp, &is_delegate)) { + *success = false; + return false; + } + + *success = is_delegate; + return true; +} + +const JSClass instance_class_definition = { + "NamedGetterInterface", + 0 | JSCLASS_HAS_PRIVATE, + NULL, // addProperty + NULL, // delProperty + NULL, // getProperty + NULL, // setProperty + NULL, // enumerate + NULL, // resolve + NULL, // mayResolve + &WrapperPrivate::Finalizer, // finalize + NULL, // call + NULL, // hasInstance + NULL, // construct + &WrapperPrivate::Trace, // trace +}; + +const JSClass prototype_class_definition = { + "NamedGetterInterfacePrototype", +}; + +const JSClass interface_object_class_definition = { + "NamedGetterInterfaceConstructor", + 0, + NULL, // addProperty + NULL, // delProperty + NULL, // getProperty + NULL, // setProperty + NULL, // enumerate + NULL, // resolve + NULL, // mayResolve + NULL, // finalize + NULL, // call + &HasInstance, + NULL, +}; + +bool fcn_namedDeleter( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + const JSClass* proto_class = + MozjsNamedGetterInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<NamedGetterInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + NamedGetterInterface* impl = + wrapper_private->wrappable<NamedGetterInterface>().get(); + const size_t kMinArguments = 1; + if (args.length() < kMinArguments) { + exception_state.SetSimpleException(script::kInvalidNumberOfArguments); + return false; + } + // Non-optional arguments + TypeTraits<std::string >::ConversionType name; + + DCHECK_LT(0, args.length()); + JS::RootedValue non_optional_value0( + context, args[0]); + FromJSValue(context, + non_optional_value0, + kNoConversionFlags, + &exception_state, &name); + if (exception_state.is_exception_set()) { + return false; + } + + impl->NamedDeleter(name); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + +bool fcn_namedGetter( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + const JSClass* proto_class = + MozjsNamedGetterInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<NamedGetterInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + NamedGetterInterface* impl = + wrapper_private->wrappable<NamedGetterInterface>().get(); + const size_t kMinArguments = 1; + if (args.length() < kMinArguments) { + exception_state.SetSimpleException(script::kInvalidNumberOfArguments); + return false; + } + // Non-optional arguments + TypeTraits<std::string >::ConversionType name; + + DCHECK_LT(0, args.length()); + JS::RootedValue non_optional_value0( + context, args[0]); + FromJSValue(context, + non_optional_value0, + kNoConversionFlags, + &exception_state, &name); + if (exception_state.is_exception_set()) { + return false; + } + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->NamedGetter(name), + &result_value); + } + if (!exception_state.is_exception_set()) { + args.rval().set(result_value); + } + return !exception_state.is_exception_set(); +} + +bool fcn_namedSetter( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + const JSClass* proto_class = + MozjsNamedGetterInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<NamedGetterInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + NamedGetterInterface* impl = + wrapper_private->wrappable<NamedGetterInterface>().get(); + const size_t kMinArguments = 2; + if (args.length() < kMinArguments) { + exception_state.SetSimpleException(script::kInvalidNumberOfArguments); + return false; + } + // Non-optional arguments + TypeTraits<std::string >::ConversionType name; + TypeTraits<std::string >::ConversionType value; + + DCHECK_LT(0, args.length()); + JS::RootedValue non_optional_value0( + context, args[0]); + FromJSValue(context, + non_optional_value0, + kNoConversionFlags, + &exception_state, &name); + if (exception_state.is_exception_set()) { + return false; + } + + DCHECK_LT(1, args.length()); + JS::RootedValue non_optional_value1( + context, args[1]); + FromJSValue(context, + non_optional_value1, + kNoConversionFlags, + &exception_state, &value); + if (exception_state.is_exception_set()) { + return false; + } + + impl->NamedSetter(name, value); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + + + +const JSPropertySpec prototype_properties[] = { + JS_PS_END +}; + +const JSFunctionSpec prototype_functions[] = { + JS_FNSPEC( + "namedDeleter", fcn_namedDeleter, NULL, + 1, JSPROP_ENUMERATE, NULL), + JS_FNSPEC( + "namedGetter", fcn_namedGetter, NULL, + 1, JSPROP_ENUMERATE, NULL), + JS_FNSPEC( + "namedSetter", fcn_namedSetter, NULL, + 2, JSPROP_ENUMERATE, NULL), + JS_FS_END +}; + +const JSPropertySpec interface_object_properties[] = { + JS_PS_END +}; + +const JSFunctionSpec interface_object_functions[] = { + JS_FS_END +}; + +const JSPropertySpec own_properties[] = { + JS_PS_END +}; + +void InitializePrototypeAndInterfaceObject( + InterfaceData* interface_data, JSContext* context, + JS::HandleObject global_object) { + DCHECK(!interface_data->prototype); + DCHECK(!interface_data->interface_object); + DCHECK(JS_IsGlobalObject(global_object)); + + JS::RootedObject parent_prototype( + context, JS_GetObjectPrototype(context, global_object)); + DCHECK(parent_prototype); + + interface_data->prototype = JS_NewObjectWithGivenProto( + context, &prototype_class_definition, parent_prototype + ); + + JS::RootedObject rooted_prototype(context, interface_data->prototype); + bool success = JS_DefineProperties( + context, + rooted_prototype, + prototype_properties); + + DCHECK(success); + success = JS_DefineFunctions( + context, rooted_prototype, prototype_functions); + DCHECK(success); + + JS::RootedObject function_prototype( + context, JS_GetFunctionPrototype(context, global_object)); + DCHECK(function_prototype); + // Create the Interface object. + interface_data->interface_object = JS_NewObjectWithGivenProto( + context, &interface_object_class_definition, + function_prototype); + + // Add the InterfaceObject.name property. + JS::RootedObject rooted_interface_object( + context, interface_data->interface_object); + JS::RootedValue name_value(context); + const char name[] = + "NamedGetterInterface"; + name_value.setString(JS_NewStringCopyZ(context, name)); + success = JS_DefineProperty( + context, rooted_interface_object, "name", name_value, JSPROP_READONLY, + NULL, NULL); + DCHECK(success); + + // Define interface object properties (including constants). + success = JS_DefineProperties(context, rooted_interface_object, + interface_object_properties); + DCHECK(success); + // Define interface object functions (static). + success = JS_DefineFunctions(context, rooted_interface_object, + interface_object_functions); + DCHECK(success); + + // Set the Prototype.constructor and Constructor.prototype properties. + DCHECK(interface_data->interface_object); + DCHECK(interface_data->prototype); + success = JS_LinkConstructorAndPrototype( + context, + rooted_interface_object, + rooted_prototype); + DCHECK(success); +} + +InterfaceData* GetInterfaceData(JSContext* context) { + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + // Use the address of the properties definition for this interface as a + // unique key for looking up the InterfaceData for this interface. + intptr_t key = reinterpret_cast<intptr_t>(&own_properties); + InterfaceData* interface_data = global_environment->GetInterfaceData(key); + if (!interface_data) { + interface_data = new InterfaceData(); + DCHECK(interface_data); + global_environment->CacheInterfaceData(key, interface_data); + DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key)); + } + return interface_data; +} + +} // namespace + +// static +JSObject* MozjsNamedGetterInterface::CreateProxy( + JSContext* context, const scoped_refptr<Wrappable>& wrappable) { + DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); + JS::RootedObject global_object( + context, + MozjsGlobalEnvironment::GetFromContext(context)->global_object()); + DCHECK(global_object); + + InterfaceData* interface_data = GetInterfaceData(context); + JS::RootedObject prototype(context, GetPrototype(context, global_object)); + DCHECK(prototype); + JS::RootedObject new_object( + context, + JS_NewObjectWithGivenProto( + context, &instance_class_definition, prototype)); + DCHECK(new_object); + JS::RootedObject proxy(context, + ProxyHandler::NewProxy( + context, proxy_handler.Pointer(), new_object, prototype)); + WrapperPrivate::AddPrivateData(context, proxy, wrappable); + return proxy; +} + +// static +const JSClass* MozjsNamedGetterInterface::PrototypeClass( + JSContext* context) { + DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); + JS::RootedObject global_object( + context, + MozjsGlobalEnvironment::GetFromContext(context)->global_object()); + DCHECK(global_object); + + JS::RootedObject prototype(context, GetPrototype(context, global_object)); + const JSClass* proto_class = JS_GetClass(prototype); + return proto_class; +} + +// static +JSObject* MozjsNamedGetterInterface::GetPrototype( + JSContext* context, JS::HandleObject global_object) { + DCHECK(JS_IsGlobalObject(global_object)); + + InterfaceData* interface_data = GetInterfaceData(context); + if (!interface_data->prototype) { + // Create new prototype that has all the props and methods + InitializePrototypeAndInterfaceObject( + interface_data, context, global_object); + } + DCHECK(interface_data->prototype); + return interface_data->prototype; +} + +// static +JSObject* MozjsNamedGetterInterface::GetInterfaceObject( + JSContext* context, JS::HandleObject global_object) { + DCHECK(JS_IsGlobalObject(global_object)); + + InterfaceData* interface_data = GetInterfaceData(context); + if (!interface_data->interface_object) { + InitializePrototypeAndInterfaceObject( + interface_data, context, global_object); + } + DCHECK(interface_data->interface_object); + return interface_data->interface_object; +} + + +namespace { +} // namespace + + +} // namespace testing +} // namespace bindings +} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_named_getter_interface.h b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_named_getter_interface.h new file mode 100644 index 0000000..fb2591c --- /dev/null +++ b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_named_getter_interface.h
@@ -0,0 +1,52 @@ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// clang-format off + +// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! +// Auto-generated from template: bindings/mozjs-45/templates/interface.h.template + +#ifndef MozjsNamedGetterInterface_h +#define MozjsNamedGetterInterface_h + +#include "base/hash_tables.h" +#include "base/lazy_instance.h" +#include "base/memory/ref_counted.h" +#include "base/threading/thread_checker.h" +#include "cobalt/base/polymorphic_downcast.h" +#include "cobalt/script/wrappable.h" +#include "cobalt/bindings/testing/named_getter_interface.h" + +#include "third_party/mozjs-45/js/src/jsapi.h" + +namespace cobalt { +namespace bindings { +namespace testing { + +class MozjsNamedGetterInterface { + public: + static JSObject* CreateProxy(JSContext* context, + const scoped_refptr<script::Wrappable>& wrappable); + static const JSClass* PrototypeClass(JSContext* context); + static JSObject* GetPrototype(JSContext* context, + JS::HandleObject global_object); + static JSObject* GetInterfaceObject(JSContext* context, + JS::HandleObject global_object); +}; + +} // namespace testing +} // namespace bindings +} // namespace cobalt + +#endif // MozjsNamedGetterInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_named_indexed_getter_interface.cc b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_named_indexed_getter_interface.cc new file mode 100644 index 0000000..758af1c --- /dev/null +++ b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_named_indexed_getter_interface.cc
@@ -0,0 +1,1048 @@ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// clang-format off + +// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! +// Auto-generated from template: bindings/mozjs-45/templates/interface.cc.template + +#include "cobalt/bindings/testing/mozjs_named_indexed_getter_interface.h" + +#include "base/debug/trace_event.h" +#include "cobalt/base/polymorphic_downcast.h" +#include "cobalt/script/global_environment.h" +#include "cobalt/script/opaque_handle.h" +#include "cobalt/script/script_value.h" + +#include "base/lazy_instance.h" +#include "cobalt/script/exception_state.h" +#include "cobalt/script/mozjs-45/callback_function_conversion.h" +#include "cobalt/script/mozjs-45/conversion_helpers.h" +#include "cobalt/script/mozjs-45/mozjs_callback_function.h" +#include "cobalt/script/mozjs-45/mozjs_exception_state.h" +#include "cobalt/script/mozjs-45/mozjs_global_environment.h" +#include "cobalt/script/mozjs-45/mozjs_object_handle.h" +#include "cobalt/script/mozjs-45/mozjs_property_enumerator.h" +#include "cobalt/script/mozjs-45/mozjs_user_object_holder.h" +#include "cobalt/script/mozjs-45/proxy_handler.h" +#include "cobalt/script/mozjs-45/type_traits.h" +#include "cobalt/script/mozjs-45/wrapper_factory.h" +#include "cobalt/script/mozjs-45/wrapper_private.h" +#include "cobalt/script/property_enumerator.h" +#include "cobalt/script/sequence.h" +#include "third_party/mozjs-45/js/src/jsapi.h" +#include "third_party/mozjs-45/js/src/jsfriendapi.h" + +namespace { +using cobalt::bindings::testing::NamedIndexedGetterInterface; +using cobalt::bindings::testing::MozjsNamedIndexedGetterInterface; +using cobalt::script::CallbackInterfaceTraits; +using cobalt::script::GlobalEnvironment; +using cobalt::script::OpaqueHandle; +using cobalt::script::OpaqueHandleHolder; +using cobalt::script::ScriptValue; +using cobalt::script::Wrappable; + +using cobalt::script::CallbackFunction; +using cobalt::script::CallbackInterfaceTraits; +using cobalt::script::ExceptionState; +using cobalt::script::Wrappable; +using cobalt::script::mozjs::FromJSValue; +using cobalt::script::mozjs::InterfaceData; +using cobalt::script::mozjs::MozjsCallbackFunction; +using cobalt::script::mozjs::MozjsExceptionState; +using cobalt::script::mozjs::MozjsGlobalEnvironment; +using cobalt::script::mozjs::MozjsPropertyEnumerator; +using cobalt::script::mozjs::MozjsUserObjectHolder; +using cobalt::script::mozjs::ProxyHandler; +using cobalt::script::mozjs::ToJSValue; +using cobalt::script::mozjs::TypeTraits; +using cobalt::script::mozjs::WrapperFactory; +using cobalt::script::mozjs::WrapperPrivate; +using cobalt::script::mozjs::kConversionFlagNullable; +using cobalt::script::mozjs::kConversionFlagRestricted; +using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString; +using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString; +using cobalt::script::mozjs::kNoConversionFlags; +} // namespace + +namespace cobalt { +namespace bindings { +namespace testing { + +namespace { + +bool IsSupportedNamedProperty(JSContext* context, JS::HandleObject object, + const std::string& property_name) { + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + NamedIndexedGetterInterface* impl = + wrapper_private->wrappable<NamedIndexedGetterInterface>().get(); + return impl->CanQueryNamedProperty(property_name); +} + +void EnumerateSupportedNames(JSContext* context, JS::HandleObject object, + JS::AutoIdVector* properties) { + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + NamedIndexedGetterInterface* impl = + wrapper_private->wrappable<NamedIndexedGetterInterface>().get(); + MozjsPropertyEnumerator enumerator(context, properties); + impl->EnumerateNamedProperties(&enumerator); +} + +bool GetNamedProperty( + JSContext* context, JS::HandleObject object, JS::HandleId id, + JS::MutableHandleValue vp) { + JS::RootedValue id_value(context); + if (!JS_IdToValue(context, id, &id_value)) { + NOTREACHED(); + return false; + } + + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + NamedIndexedGetterInterface* impl = + wrapper_private->wrappable<NamedIndexedGetterInterface>().get(); + std::string property_name; + FromJSValue(context, id_value, kNoConversionFlags, &exception_state, + &property_name); + if (exception_state.is_exception_set()) { + // The ID should be an integer or a string, so we shouldn't have any + // exceptions converting to string. + NOTREACHED(); + return false; + } + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->NamedGetter(property_name), + &result_value); + } + if (!exception_state.is_exception_set()) { + vp.set(result_value); + } + return !exception_state.is_exception_set(); +} + +bool SetNamedProperty( + JSContext* context, JS::HandleObject object, JS::HandleId id, + JS::MutableHandleValue vp, JS::ObjectOpResult& object_op_result) { + JS::RootedValue id_value(context); + if (!JS_IdToValue(context, id, &id_value)) { + NOTREACHED(); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + NamedIndexedGetterInterface* impl = + wrapper_private->wrappable<NamedIndexedGetterInterface>().get(); + std::string property_name; + FromJSValue(context, id_value, kNoConversionFlags, &exception_state, + &property_name); + if (exception_state.is_exception_set()) { + // The ID should be an integer or a string, so we shouldn't have any + // exceptions converting to string. + NOTREACHED(); + return false; + } + TypeTraits<std::string >::ConversionType value; + FromJSValue(context, vp, kNoConversionFlags, + &exception_state, &value); + if (exception_state.is_exception_set()) { + return false; + } + + impl->NamedSetter(property_name, value); + result_value.set(JS::UndefinedHandleValue); + + if (!exception_state.is_exception_set()) { + return object_op_result.succeed(); + } else { + return false; + } +} + +bool IsSupportedIndexProperty(JSContext* context, JS::HandleObject object, + uint32_t index) { + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + NamedIndexedGetterInterface* impl = + wrapper_private->wrappable<NamedIndexedGetterInterface>().get(); + return index < impl->length(); +} + +void EnumerateSupportedIndexes(JSContext* context, JS::HandleObject object, + JS::AutoIdVector* properties) { + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + NamedIndexedGetterInterface* impl = + wrapper_private->wrappable<NamedIndexedGetterInterface>().get(); + const uint32_t kNumIndexedProperties = impl->length(); + for (uint32_t i = 0; i < kNumIndexedProperties; ++i) { + properties->append(INT_TO_JSID(i)); + } +} + +bool GetIndexedProperty( + JSContext* context, JS::HandleObject object, JS::HandleId id, + JS::MutableHandleValue vp) { + JS::RootedValue id_value(context); + if (!JS_IdToValue(context, id, &id_value)) { + NOTREACHED(); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + NamedIndexedGetterInterface* impl = + wrapper_private->wrappable<NamedIndexedGetterInterface>().get(); + uint32_t index; + FromJSValue(context, id_value, kNoConversionFlags, &exception_state, &index); + if (exception_state.is_exception_set()) { + // The ID should be an integer or a string, so we shouldn't have any + // exceptions converting to string. + NOTREACHED(); + return false; + } + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->IndexedGetter(index), + &result_value); + } + if (!exception_state.is_exception_set()) { + vp.set(result_value); + } + return !exception_state.is_exception_set(); +} + +bool SetIndexedProperty( + JSContext* context, JS::HandleObject object, JS::HandleId id, + JS::MutableHandleValue vp, JS::ObjectOpResult& object_op_result) { + JS::RootedValue id_value(context); + if (!JS_IdToValue(context, id, &id_value)) { + NOTREACHED(); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + NamedIndexedGetterInterface* impl = + wrapper_private->wrappable<NamedIndexedGetterInterface>().get(); + uint32_t index; + FromJSValue(context, id_value, kNoConversionFlags, &exception_state, &index); + if (exception_state.is_exception_set()) { + // The ID should be an integer or a string, so we shouldn't have any + // exceptions converting to string. + NOTREACHED(); + return false; + } + TypeTraits<uint32_t >::ConversionType value; + FromJSValue(context, vp, kNoConversionFlags, + &exception_state, &value); + if (exception_state.is_exception_set()) { + return false; + } + + impl->IndexedSetter(index, value); + result_value.set(JS::UndefinedHandleValue); + if (!exception_state.is_exception_set()) { + return object_op_result.succeed(); + } else { + return false; + } +} + +class MozjsNamedIndexedGetterInterfaceHandler : public ProxyHandler { + public: + MozjsNamedIndexedGetterInterfaceHandler() + : ProxyHandler(indexed_property_hooks, named_property_hooks) {} + + private: + static NamedPropertyHooks named_property_hooks; + static IndexedPropertyHooks indexed_property_hooks; +}; + +ProxyHandler::NamedPropertyHooks +MozjsNamedIndexedGetterInterfaceHandler::named_property_hooks = { + IsSupportedNamedProperty, + EnumerateSupportedNames, + GetNamedProperty, + SetNamedProperty, + NULL, +}; +ProxyHandler::IndexedPropertyHooks +MozjsNamedIndexedGetterInterfaceHandler::indexed_property_hooks = { + IsSupportedIndexProperty, + EnumerateSupportedIndexes, + GetIndexedProperty, + SetIndexedProperty, + NULL, +}; + +static base::LazyInstance<MozjsNamedIndexedGetterInterfaceHandler> + proxy_handler; + +bool HasInstance(JSContext *context, JS::HandleObject type, + JS::MutableHandleValue vp, bool *success) { + JS::RootedObject global_object( + context, JS_GetGlobalForObject(context, type)); + DCHECK(global_object); + + JS::RootedObject prototype( + context, MozjsNamedIndexedGetterInterface::GetPrototype(context, global_object)); + + // |IsDelegate| walks the prototype chain of an object returning true if + // .prototype is found. + bool is_delegate; + if (!IsDelegate(context, prototype, vp, &is_delegate)) { + *success = false; + return false; + } + + *success = is_delegate; + return true; +} + +const JSClass instance_class_definition = { + "NamedIndexedGetterInterface", + 0 | JSCLASS_HAS_PRIVATE, + NULL, // addProperty + NULL, // delProperty + NULL, // getProperty + NULL, // setProperty + NULL, // enumerate + NULL, // resolve + NULL, // mayResolve + &WrapperPrivate::Finalizer, // finalize + NULL, // call + NULL, // hasInstance + NULL, // construct + &WrapperPrivate::Trace, // trace +}; + +const JSClass prototype_class_definition = { + "NamedIndexedGetterInterfacePrototype", +}; + +const JSClass interface_object_class_definition = { + "NamedIndexedGetterInterfaceConstructor", + 0, + NULL, // addProperty + NULL, // delProperty + NULL, // getProperty + NULL, // setProperty + NULL, // enumerate + NULL, // resolve + NULL, // mayResolve + NULL, // finalize + NULL, // call + &HasInstance, + NULL, +}; + +bool get_length( + JSContext* context, unsigned argc, JS::Value* vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + const JSClass* proto_class = + MozjsNamedIndexedGetterInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<NamedIndexedGetterInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + NamedIndexedGetterInterface* impl = + wrapper_private->wrappable<NamedIndexedGetterInterface>().get(); + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->length(), + &result_value); + } + if (!exception_state.is_exception_set()) { + args.rval().set(result_value); + } + return !exception_state.is_exception_set(); +} + + +bool get_propertyOnBaseClass( + JSContext* context, unsigned argc, JS::Value* vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + const JSClass* proto_class = + MozjsNamedIndexedGetterInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<NamedIndexedGetterInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + NamedIndexedGetterInterface* impl = + wrapper_private->wrappable<NamedIndexedGetterInterface>().get(); + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->property_on_base_class(), + &result_value); + } + if (!exception_state.is_exception_set()) { + args.rval().set(result_value); + } + return !exception_state.is_exception_set(); +} + +bool set_propertyOnBaseClass( + JSContext* context, unsigned argc, JS::Value* vp) { + + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + + const JSClass* proto_class = + MozjsNamedIndexedGetterInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<NamedIndexedGetterInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + NamedIndexedGetterInterface* impl = + wrapper_private->wrappable<NamedIndexedGetterInterface>().get(); + TypeTraits<bool >::ConversionType value; + if (args.length() != 1) { + NOTREACHED(); + return false; + } + FromJSValue(context, args[0], kNoConversionFlags, &exception_state, + &value); + if (exception_state.is_exception_set()) { + return false; + } + + impl->set_property_on_base_class(value); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + +bool fcn_indexedGetter( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + const JSClass* proto_class = + MozjsNamedIndexedGetterInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<NamedIndexedGetterInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + NamedIndexedGetterInterface* impl = + wrapper_private->wrappable<NamedIndexedGetterInterface>().get(); + const size_t kMinArguments = 1; + if (args.length() < kMinArguments) { + exception_state.SetSimpleException(script::kInvalidNumberOfArguments); + return false; + } + // Non-optional arguments + TypeTraits<uint32_t >::ConversionType index; + + DCHECK_LT(0, args.length()); + JS::RootedValue non_optional_value0( + context, args[0]); + FromJSValue(context, + non_optional_value0, + kNoConversionFlags, + &exception_state, &index); + if (exception_state.is_exception_set()) { + return false; + } + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->IndexedGetter(index), + &result_value); + } + if (!exception_state.is_exception_set()) { + args.rval().set(result_value); + } + return !exception_state.is_exception_set(); +} + +bool fcn_indexedSetter( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + const JSClass* proto_class = + MozjsNamedIndexedGetterInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<NamedIndexedGetterInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + NamedIndexedGetterInterface* impl = + wrapper_private->wrappable<NamedIndexedGetterInterface>().get(); + const size_t kMinArguments = 2; + if (args.length() < kMinArguments) { + exception_state.SetSimpleException(script::kInvalidNumberOfArguments); + return false; + } + // Non-optional arguments + TypeTraits<uint32_t >::ConversionType index; + TypeTraits<uint32_t >::ConversionType value; + + DCHECK_LT(0, args.length()); + JS::RootedValue non_optional_value0( + context, args[0]); + FromJSValue(context, + non_optional_value0, + kNoConversionFlags, + &exception_state, &index); + if (exception_state.is_exception_set()) { + return false; + } + + DCHECK_LT(1, args.length()); + JS::RootedValue non_optional_value1( + context, args[1]); + FromJSValue(context, + non_optional_value1, + kNoConversionFlags, + &exception_state, &value); + if (exception_state.is_exception_set()) { + return false; + } + + impl->IndexedSetter(index, value); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + +bool fcn_namedGetter( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + const JSClass* proto_class = + MozjsNamedIndexedGetterInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<NamedIndexedGetterInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + NamedIndexedGetterInterface* impl = + wrapper_private->wrappable<NamedIndexedGetterInterface>().get(); + const size_t kMinArguments = 1; + if (args.length() < kMinArguments) { + exception_state.SetSimpleException(script::kInvalidNumberOfArguments); + return false; + } + // Non-optional arguments + TypeTraits<std::string >::ConversionType name; + + DCHECK_LT(0, args.length()); + JS::RootedValue non_optional_value0( + context, args[0]); + FromJSValue(context, + non_optional_value0, + kNoConversionFlags, + &exception_state, &name); + if (exception_state.is_exception_set()) { + return false; + } + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->NamedGetter(name), + &result_value); + } + if (!exception_state.is_exception_set()) { + args.rval().set(result_value); + } + return !exception_state.is_exception_set(); +} + +bool fcn_namedSetter( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + const JSClass* proto_class = + MozjsNamedIndexedGetterInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<NamedIndexedGetterInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + NamedIndexedGetterInterface* impl = + wrapper_private->wrappable<NamedIndexedGetterInterface>().get(); + const size_t kMinArguments = 2; + if (args.length() < kMinArguments) { + exception_state.SetSimpleException(script::kInvalidNumberOfArguments); + return false; + } + // Non-optional arguments + TypeTraits<std::string >::ConversionType name; + TypeTraits<std::string >::ConversionType value; + + DCHECK_LT(0, args.length()); + JS::RootedValue non_optional_value0( + context, args[0]); + FromJSValue(context, + non_optional_value0, + kNoConversionFlags, + &exception_state, &name); + if (exception_state.is_exception_set()) { + return false; + } + + DCHECK_LT(1, args.length()); + JS::RootedValue non_optional_value1( + context, args[1]); + FromJSValue(context, + non_optional_value1, + kNoConversionFlags, + &exception_state, &value); + if (exception_state.is_exception_set()) { + return false; + } + + impl->NamedSetter(name, value); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + +bool fcn_operationOnBaseClass( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + const JSClass* proto_class = + MozjsNamedIndexedGetterInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<NamedIndexedGetterInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + NamedIndexedGetterInterface* impl = + wrapper_private->wrappable<NamedIndexedGetterInterface>().get(); + + impl->OperationOnBaseClass(); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + + + +const JSPropertySpec prototype_properties[] = { + { // Readonly attribute + "length", + JSPROP_SHARED | JSPROP_ENUMERATE, + { { &get_length, NULL } }, + JSNATIVE_WRAPPER(NULL), + }, + { // Read/Write property + "propertyOnBaseClass", + JSPROP_SHARED | JSPROP_ENUMERATE, + { { &get_propertyOnBaseClass, NULL } }, + { { &set_propertyOnBaseClass, NULL } }, + }, + JS_PS_END +}; + +const JSFunctionSpec prototype_functions[] = { + JS_FNSPEC( + "indexedGetter", fcn_indexedGetter, NULL, + 1, JSPROP_ENUMERATE, NULL), + JS_FNSPEC( + "indexedSetter", fcn_indexedSetter, NULL, + 2, JSPROP_ENUMERATE, NULL), + JS_FNSPEC( + "namedGetter", fcn_namedGetter, NULL, + 1, JSPROP_ENUMERATE, NULL), + JS_FNSPEC( + "namedSetter", fcn_namedSetter, NULL, + 2, JSPROP_ENUMERATE, NULL), + JS_FNSPEC( + "operationOnBaseClass", fcn_operationOnBaseClass, NULL, + 0, JSPROP_ENUMERATE, NULL), + JS_FS_END +}; + +const JSPropertySpec interface_object_properties[] = { + JS_PS_END +}; + +const JSFunctionSpec interface_object_functions[] = { + JS_FS_END +}; + +const JSPropertySpec own_properties[] = { + JS_PS_END +}; + +void InitializePrototypeAndInterfaceObject( + InterfaceData* interface_data, JSContext* context, + JS::HandleObject global_object) { + DCHECK(!interface_data->prototype); + DCHECK(!interface_data->interface_object); + DCHECK(JS_IsGlobalObject(global_object)); + + JS::RootedObject parent_prototype( + context, JS_GetObjectPrototype(context, global_object)); + DCHECK(parent_prototype); + + interface_data->prototype = JS_NewObjectWithGivenProto( + context, &prototype_class_definition, parent_prototype + ); + + JS::RootedObject rooted_prototype(context, interface_data->prototype); + bool success = JS_DefineProperties( + context, + rooted_prototype, + prototype_properties); + + DCHECK(success); + success = JS_DefineFunctions( + context, rooted_prototype, prototype_functions); + DCHECK(success); + + JS::RootedObject function_prototype( + context, JS_GetFunctionPrototype(context, global_object)); + DCHECK(function_prototype); + // Create the Interface object. + interface_data->interface_object = JS_NewObjectWithGivenProto( + context, &interface_object_class_definition, + function_prototype); + + // Add the InterfaceObject.name property. + JS::RootedObject rooted_interface_object( + context, interface_data->interface_object); + JS::RootedValue name_value(context); + const char name[] = + "NamedIndexedGetterInterface"; + name_value.setString(JS_NewStringCopyZ(context, name)); + success = JS_DefineProperty( + context, rooted_interface_object, "name", name_value, JSPROP_READONLY, + NULL, NULL); + DCHECK(success); + + // Define interface object properties (including constants). + success = JS_DefineProperties(context, rooted_interface_object, + interface_object_properties); + DCHECK(success); + // Define interface object functions (static). + success = JS_DefineFunctions(context, rooted_interface_object, + interface_object_functions); + DCHECK(success); + + // Set the Prototype.constructor and Constructor.prototype properties. + DCHECK(interface_data->interface_object); + DCHECK(interface_data->prototype); + success = JS_LinkConstructorAndPrototype( + context, + rooted_interface_object, + rooted_prototype); + DCHECK(success); +} + +InterfaceData* GetInterfaceData(JSContext* context) { + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + // Use the address of the properties definition for this interface as a + // unique key for looking up the InterfaceData for this interface. + intptr_t key = reinterpret_cast<intptr_t>(&own_properties); + InterfaceData* interface_data = global_environment->GetInterfaceData(key); + if (!interface_data) { + interface_data = new InterfaceData(); + DCHECK(interface_data); + global_environment->CacheInterfaceData(key, interface_data); + DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key)); + } + return interface_data; +} + +} // namespace + +// static +JSObject* MozjsNamedIndexedGetterInterface::CreateProxy( + JSContext* context, const scoped_refptr<Wrappable>& wrappable) { + DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); + JS::RootedObject global_object( + context, + MozjsGlobalEnvironment::GetFromContext(context)->global_object()); + DCHECK(global_object); + + InterfaceData* interface_data = GetInterfaceData(context); + JS::RootedObject prototype(context, GetPrototype(context, global_object)); + DCHECK(prototype); + JS::RootedObject new_object( + context, + JS_NewObjectWithGivenProto( + context, &instance_class_definition, prototype)); + DCHECK(new_object); + JS::RootedObject proxy(context, + ProxyHandler::NewProxy( + context, proxy_handler.Pointer(), new_object, prototype)); + WrapperPrivate::AddPrivateData(context, proxy, wrappable); + return proxy; +} + +// static +const JSClass* MozjsNamedIndexedGetterInterface::PrototypeClass( + JSContext* context) { + DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); + JS::RootedObject global_object( + context, + MozjsGlobalEnvironment::GetFromContext(context)->global_object()); + DCHECK(global_object); + + JS::RootedObject prototype(context, GetPrototype(context, global_object)); + const JSClass* proto_class = JS_GetClass(prototype); + return proto_class; +} + +// static +JSObject* MozjsNamedIndexedGetterInterface::GetPrototype( + JSContext* context, JS::HandleObject global_object) { + DCHECK(JS_IsGlobalObject(global_object)); + + InterfaceData* interface_data = GetInterfaceData(context); + if (!interface_data->prototype) { + // Create new prototype that has all the props and methods + InitializePrototypeAndInterfaceObject( + interface_data, context, global_object); + } + DCHECK(interface_data->prototype); + return interface_data->prototype; +} + +// static +JSObject* MozjsNamedIndexedGetterInterface::GetInterfaceObject( + JSContext* context, JS::HandleObject global_object) { + DCHECK(JS_IsGlobalObject(global_object)); + + InterfaceData* interface_data = GetInterfaceData(context); + if (!interface_data->interface_object) { + InitializePrototypeAndInterfaceObject( + interface_data, context, global_object); + } + DCHECK(interface_data->interface_object); + return interface_data->interface_object; +} + + +namespace { +} // namespace + + +} // namespace testing +} // namespace bindings +} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_named_indexed_getter_interface.h b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_named_indexed_getter_interface.h new file mode 100644 index 0000000..0a861a1 --- /dev/null +++ b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_named_indexed_getter_interface.h
@@ -0,0 +1,52 @@ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// clang-format off + +// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! +// Auto-generated from template: bindings/mozjs-45/templates/interface.h.template + +#ifndef MozjsNamedIndexedGetterInterface_h +#define MozjsNamedIndexedGetterInterface_h + +#include "base/hash_tables.h" +#include "base/lazy_instance.h" +#include "base/memory/ref_counted.h" +#include "base/threading/thread_checker.h" +#include "cobalt/base/polymorphic_downcast.h" +#include "cobalt/script/wrappable.h" +#include "cobalt/bindings/testing/named_indexed_getter_interface.h" + +#include "third_party/mozjs-45/js/src/jsapi.h" + +namespace cobalt { +namespace bindings { +namespace testing { + +class MozjsNamedIndexedGetterInterface { + public: + static JSObject* CreateProxy(JSContext* context, + const scoped_refptr<script::Wrappable>& wrappable); + static const JSClass* PrototypeClass(JSContext* context); + static JSObject* GetPrototype(JSContext* context, + JS::HandleObject global_object); + static JSObject* GetInterfaceObject(JSContext* context, + JS::HandleObject global_object); +}; + +} // namespace testing +} // namespace bindings +} // namespace cobalt + +#endif // MozjsNamedIndexedGetterInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_nested_put_forwards_interface.cc b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_nested_put_forwards_interface.cc new file mode 100644 index 0000000..a7d26f6 --- /dev/null +++ b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_nested_put_forwards_interface.cc
@@ -0,0 +1,475 @@ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// clang-format off + +// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! +// Auto-generated from template: bindings/mozjs-45/templates/interface.cc.template + +#include "cobalt/bindings/testing/mozjs_nested_put_forwards_interface.h" + +#include "base/debug/trace_event.h" +#include "cobalt/base/polymorphic_downcast.h" +#include "cobalt/script/global_environment.h" +#include "cobalt/script/opaque_handle.h" +#include "cobalt/script/script_value.h" +#include "cobalt/bindings/testing/mozjs_put_forwards_interface.h" +#include "cobalt/bindings/testing/put_forwards_interface.h" + +#include "base/lazy_instance.h" +#include "cobalt/script/exception_state.h" +#include "cobalt/script/mozjs-45/callback_function_conversion.h" +#include "cobalt/script/mozjs-45/conversion_helpers.h" +#include "cobalt/script/mozjs-45/mozjs_callback_function.h" +#include "cobalt/script/mozjs-45/mozjs_exception_state.h" +#include "cobalt/script/mozjs-45/mozjs_global_environment.h" +#include "cobalt/script/mozjs-45/mozjs_object_handle.h" +#include "cobalt/script/mozjs-45/mozjs_property_enumerator.h" +#include "cobalt/script/mozjs-45/mozjs_user_object_holder.h" +#include "cobalt/script/mozjs-45/proxy_handler.h" +#include "cobalt/script/mozjs-45/type_traits.h" +#include "cobalt/script/mozjs-45/wrapper_factory.h" +#include "cobalt/script/mozjs-45/wrapper_private.h" +#include "cobalt/script/property_enumerator.h" +#include "cobalt/script/sequence.h" +#include "third_party/mozjs-45/js/src/jsapi.h" +#include "third_party/mozjs-45/js/src/jsfriendapi.h" + +namespace { +using cobalt::bindings::testing::NestedPutForwardsInterface; +using cobalt::bindings::testing::MozjsNestedPutForwardsInterface; +using cobalt::bindings::testing::MozjsPutForwardsInterface; +using cobalt::bindings::testing::PutForwardsInterface; +using cobalt::script::CallbackInterfaceTraits; +using cobalt::script::GlobalEnvironment; +using cobalt::script::OpaqueHandle; +using cobalt::script::OpaqueHandleHolder; +using cobalt::script::ScriptValue; +using cobalt::script::Wrappable; + +using cobalt::script::CallbackFunction; +using cobalt::script::CallbackInterfaceTraits; +using cobalt::script::ExceptionState; +using cobalt::script::Wrappable; +using cobalt::script::mozjs::FromJSValue; +using cobalt::script::mozjs::InterfaceData; +using cobalt::script::mozjs::MozjsCallbackFunction; +using cobalt::script::mozjs::MozjsExceptionState; +using cobalt::script::mozjs::MozjsGlobalEnvironment; +using cobalt::script::mozjs::MozjsPropertyEnumerator; +using cobalt::script::mozjs::MozjsUserObjectHolder; +using cobalt::script::mozjs::ProxyHandler; +using cobalt::script::mozjs::ToJSValue; +using cobalt::script::mozjs::TypeTraits; +using cobalt::script::mozjs::WrapperFactory; +using cobalt::script::mozjs::WrapperPrivate; +using cobalt::script::mozjs::kConversionFlagNullable; +using cobalt::script::mozjs::kConversionFlagRestricted; +using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString; +using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString; +using cobalt::script::mozjs::kNoConversionFlags; +} // namespace + +namespace cobalt { +namespace bindings { +namespace testing { + +namespace { + +class MozjsNestedPutForwardsInterfaceHandler : public ProxyHandler { + public: + MozjsNestedPutForwardsInterfaceHandler() + : ProxyHandler(indexed_property_hooks, named_property_hooks) {} + + private: + static NamedPropertyHooks named_property_hooks; + static IndexedPropertyHooks indexed_property_hooks; +}; + +ProxyHandler::NamedPropertyHooks +MozjsNestedPutForwardsInterfaceHandler::named_property_hooks = { + NULL, + NULL, + NULL, + NULL, + NULL, +}; +ProxyHandler::IndexedPropertyHooks +MozjsNestedPutForwardsInterfaceHandler::indexed_property_hooks = { + NULL, + NULL, + NULL, + NULL, + NULL, +}; + +static base::LazyInstance<MozjsNestedPutForwardsInterfaceHandler> + proxy_handler; + +bool HasInstance(JSContext *context, JS::HandleObject type, + JS::MutableHandleValue vp, bool *success) { + JS::RootedObject global_object( + context, JS_GetGlobalForObject(context, type)); + DCHECK(global_object); + + JS::RootedObject prototype( + context, MozjsNestedPutForwardsInterface::GetPrototype(context, global_object)); + + // |IsDelegate| walks the prototype chain of an object returning true if + // .prototype is found. + bool is_delegate; + if (!IsDelegate(context, prototype, vp, &is_delegate)) { + *success = false; + return false; + } + + *success = is_delegate; + return true; +} + +const JSClass instance_class_definition = { + "NestedPutForwardsInterface", + 0 | JSCLASS_HAS_PRIVATE, + NULL, // addProperty + NULL, // delProperty + NULL, // getProperty + NULL, // setProperty + NULL, // enumerate + NULL, // resolve + NULL, // mayResolve + &WrapperPrivate::Finalizer, // finalize + NULL, // call + NULL, // hasInstance + NULL, // construct + &WrapperPrivate::Trace, // trace +}; + +const JSClass prototype_class_definition = { + "NestedPutForwardsInterfacePrototype", +}; + +const JSClass interface_object_class_definition = { + "NestedPutForwardsInterfaceConstructor", + 0, + NULL, // addProperty + NULL, // delProperty + NULL, // getProperty + NULL, // setProperty + NULL, // enumerate + NULL, // resolve + NULL, // mayResolve + NULL, // finalize + NULL, // call + &HasInstance, + NULL, +}; + +bool get_nestedForwardingAttribute( + JSContext* context, unsigned argc, JS::Value* vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + const JSClass* proto_class = + MozjsNestedPutForwardsInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<NestedPutForwardsInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + NestedPutForwardsInterface* impl = + wrapper_private->wrappable<NestedPutForwardsInterface>().get(); + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->nested_forwarding_attribute(), + &result_value); + } + if (!exception_state.is_exception_set()) { + args.rval().set(result_value); + } + return !exception_state.is_exception_set(); +} + +bool set_nestedForwardingAttribute( + JSContext* context, unsigned argc, JS::Value* vp) { + + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + + const JSClass* proto_class = + MozjsNestedPutForwardsInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<NestedPutForwardsInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + NestedPutForwardsInterface* impl = + wrapper_private->wrappable<NestedPutForwardsInterface>().get(); + { // Begin scope of scoped_refptr<PutForwardsInterface> forwarded_impl. + scoped_refptr<PutForwardsInterface> forwarded_impl = + impl->nested_forwarding_attribute(); + if (!forwarded_impl) { + NOTREACHED(); + return false; + } + if (!exception_state.is_exception_set()) { + { // Begin scope of scoped_refptr<ArbitraryInterface> forwarded_forwarded_impl. + scoped_refptr<ArbitraryInterface> forwarded_forwarded_impl = + forwarded_impl->forwarding_attribute(); + if (!forwarded_forwarded_impl) { + NOTREACHED(); + return false; + } + if (!exception_state.is_exception_set()) { + TypeTraits<std::string >::ConversionType value; + if (args.length() != 1) { + NOTREACHED(); + return false; + } + FromJSValue(context, args[0], kNoConversionFlags, &exception_state, + &value); + if (exception_state.is_exception_set()) { + return false; + } + + forwarded_forwarded_impl->set_arbitrary_property(value); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + return !exception_state.is_exception_set(); + } // End scope of scoped_refptr<ArbitraryInterface> forwarded_forwarded_impl. +} + return !exception_state.is_exception_set(); + } // End scope of scoped_refptr<PutForwardsInterface> forwarded_impl. +} + + + +const JSPropertySpec prototype_properties[] = { + { // Read/Write property + "nestedForwardingAttribute", + JSPROP_SHARED | JSPROP_ENUMERATE, + { { &get_nestedForwardingAttribute, NULL } }, + { { &set_nestedForwardingAttribute, NULL } }, + }, + JS_PS_END +}; + +const JSFunctionSpec prototype_functions[] = { + JS_FS_END +}; + +const JSPropertySpec interface_object_properties[] = { + JS_PS_END +}; + +const JSFunctionSpec interface_object_functions[] = { + JS_FS_END +}; + +const JSPropertySpec own_properties[] = { + JS_PS_END +}; + +void InitializePrototypeAndInterfaceObject( + InterfaceData* interface_data, JSContext* context, + JS::HandleObject global_object) { + DCHECK(!interface_data->prototype); + DCHECK(!interface_data->interface_object); + DCHECK(JS_IsGlobalObject(global_object)); + + JS::RootedObject parent_prototype( + context, JS_GetObjectPrototype(context, global_object)); + DCHECK(parent_prototype); + + interface_data->prototype = JS_NewObjectWithGivenProto( + context, &prototype_class_definition, parent_prototype + ); + + JS::RootedObject rooted_prototype(context, interface_data->prototype); + bool success = JS_DefineProperties( + context, + rooted_prototype, + prototype_properties); + + DCHECK(success); + success = JS_DefineFunctions( + context, rooted_prototype, prototype_functions); + DCHECK(success); + + JS::RootedObject function_prototype( + context, JS_GetFunctionPrototype(context, global_object)); + DCHECK(function_prototype); + // Create the Interface object. + interface_data->interface_object = JS_NewObjectWithGivenProto( + context, &interface_object_class_definition, + function_prototype); + + // Add the InterfaceObject.name property. + JS::RootedObject rooted_interface_object( + context, interface_data->interface_object); + JS::RootedValue name_value(context); + const char name[] = + "NestedPutForwardsInterface"; + name_value.setString(JS_NewStringCopyZ(context, name)); + success = JS_DefineProperty( + context, rooted_interface_object, "name", name_value, JSPROP_READONLY, + NULL, NULL); + DCHECK(success); + + // Define interface object properties (including constants). + success = JS_DefineProperties(context, rooted_interface_object, + interface_object_properties); + DCHECK(success); + // Define interface object functions (static). + success = JS_DefineFunctions(context, rooted_interface_object, + interface_object_functions); + DCHECK(success); + + // Set the Prototype.constructor and Constructor.prototype properties. + DCHECK(interface_data->interface_object); + DCHECK(interface_data->prototype); + success = JS_LinkConstructorAndPrototype( + context, + rooted_interface_object, + rooted_prototype); + DCHECK(success); +} + +InterfaceData* GetInterfaceData(JSContext* context) { + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + // Use the address of the properties definition for this interface as a + // unique key for looking up the InterfaceData for this interface. + intptr_t key = reinterpret_cast<intptr_t>(&own_properties); + InterfaceData* interface_data = global_environment->GetInterfaceData(key); + if (!interface_data) { + interface_data = new InterfaceData(); + DCHECK(interface_data); + global_environment->CacheInterfaceData(key, interface_data); + DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key)); + } + return interface_data; +} + +} // namespace + +// static +JSObject* MozjsNestedPutForwardsInterface::CreateProxy( + JSContext* context, const scoped_refptr<Wrappable>& wrappable) { + DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); + JS::RootedObject global_object( + context, + MozjsGlobalEnvironment::GetFromContext(context)->global_object()); + DCHECK(global_object); + + InterfaceData* interface_data = GetInterfaceData(context); + JS::RootedObject prototype(context, GetPrototype(context, global_object)); + DCHECK(prototype); + JS::RootedObject new_object( + context, + JS_NewObjectWithGivenProto( + context, &instance_class_definition, prototype)); + DCHECK(new_object); + JS::RootedObject proxy(context, + ProxyHandler::NewProxy( + context, proxy_handler.Pointer(), new_object, prototype)); + WrapperPrivate::AddPrivateData(context, proxy, wrappable); + return proxy; +} + +// static +const JSClass* MozjsNestedPutForwardsInterface::PrototypeClass( + JSContext* context) { + DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); + JS::RootedObject global_object( + context, + MozjsGlobalEnvironment::GetFromContext(context)->global_object()); + DCHECK(global_object); + + JS::RootedObject prototype(context, GetPrototype(context, global_object)); + const JSClass* proto_class = JS_GetClass(prototype); + return proto_class; +} + +// static +JSObject* MozjsNestedPutForwardsInterface::GetPrototype( + JSContext* context, JS::HandleObject global_object) { + DCHECK(JS_IsGlobalObject(global_object)); + + InterfaceData* interface_data = GetInterfaceData(context); + if (!interface_data->prototype) { + // Create new prototype that has all the props and methods + InitializePrototypeAndInterfaceObject( + interface_data, context, global_object); + } + DCHECK(interface_data->prototype); + return interface_data->prototype; +} + +// static +JSObject* MozjsNestedPutForwardsInterface::GetInterfaceObject( + JSContext* context, JS::HandleObject global_object) { + DCHECK(JS_IsGlobalObject(global_object)); + + InterfaceData* interface_data = GetInterfaceData(context); + if (!interface_data->interface_object) { + InitializePrototypeAndInterfaceObject( + interface_data, context, global_object); + } + DCHECK(interface_data->interface_object); + return interface_data->interface_object; +} + + +namespace { +} // namespace + + +} // namespace testing +} // namespace bindings +} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_nested_put_forwards_interface.h b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_nested_put_forwards_interface.h new file mode 100644 index 0000000..85d16c5 --- /dev/null +++ b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_nested_put_forwards_interface.h
@@ -0,0 +1,52 @@ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// clang-format off + +// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! +// Auto-generated from template: bindings/mozjs-45/templates/interface.h.template + +#ifndef MozjsNestedPutForwardsInterface_h +#define MozjsNestedPutForwardsInterface_h + +#include "base/hash_tables.h" +#include "base/lazy_instance.h" +#include "base/memory/ref_counted.h" +#include "base/threading/thread_checker.h" +#include "cobalt/base/polymorphic_downcast.h" +#include "cobalt/script/wrappable.h" +#include "cobalt/bindings/testing/nested_put_forwards_interface.h" + +#include "third_party/mozjs-45/js/src/jsapi.h" + +namespace cobalt { +namespace bindings { +namespace testing { + +class MozjsNestedPutForwardsInterface { + public: + static JSObject* CreateProxy(JSContext* context, + const scoped_refptr<script::Wrappable>& wrappable); + static const JSClass* PrototypeClass(JSContext* context); + static JSObject* GetPrototype(JSContext* context, + JS::HandleObject global_object); + static JSObject* GetInterfaceObject(JSContext* context, + JS::HandleObject global_object); +}; + +} // namespace testing +} // namespace bindings +} // namespace cobalt + +#endif // MozjsNestedPutForwardsInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_no_constructor_interface.cc b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_no_constructor_interface.cc new file mode 100644 index 0000000..f3de799 --- /dev/null +++ b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_no_constructor_interface.cc
@@ -0,0 +1,353 @@ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// clang-format off + +// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! +// Auto-generated from template: bindings/mozjs-45/templates/interface.cc.template + +#include "cobalt/bindings/testing/mozjs_no_constructor_interface.h" + +#include "base/debug/trace_event.h" +#include "cobalt/base/polymorphic_downcast.h" +#include "cobalt/script/global_environment.h" +#include "cobalt/script/opaque_handle.h" +#include "cobalt/script/script_value.h" + +#include "base/lazy_instance.h" +#include "cobalt/script/exception_state.h" +#include "cobalt/script/mozjs-45/callback_function_conversion.h" +#include "cobalt/script/mozjs-45/conversion_helpers.h" +#include "cobalt/script/mozjs-45/mozjs_callback_function.h" +#include "cobalt/script/mozjs-45/mozjs_exception_state.h" +#include "cobalt/script/mozjs-45/mozjs_global_environment.h" +#include "cobalt/script/mozjs-45/mozjs_object_handle.h" +#include "cobalt/script/mozjs-45/mozjs_property_enumerator.h" +#include "cobalt/script/mozjs-45/mozjs_user_object_holder.h" +#include "cobalt/script/mozjs-45/proxy_handler.h" +#include "cobalt/script/mozjs-45/type_traits.h" +#include "cobalt/script/mozjs-45/wrapper_factory.h" +#include "cobalt/script/mozjs-45/wrapper_private.h" +#include "cobalt/script/property_enumerator.h" +#include "cobalt/script/sequence.h" +#include "third_party/mozjs-45/js/src/jsapi.h" +#include "third_party/mozjs-45/js/src/jsfriendapi.h" + +namespace { +using cobalt::bindings::testing::NoConstructorInterface; +using cobalt::bindings::testing::MozjsNoConstructorInterface; +using cobalt::script::CallbackInterfaceTraits; +using cobalt::script::GlobalEnvironment; +using cobalt::script::OpaqueHandle; +using cobalt::script::OpaqueHandleHolder; +using cobalt::script::ScriptValue; +using cobalt::script::Wrappable; + +using cobalt::script::CallbackFunction; +using cobalt::script::CallbackInterfaceTraits; +using cobalt::script::ExceptionState; +using cobalt::script::Wrappable; +using cobalt::script::mozjs::FromJSValue; +using cobalt::script::mozjs::InterfaceData; +using cobalt::script::mozjs::MozjsCallbackFunction; +using cobalt::script::mozjs::MozjsExceptionState; +using cobalt::script::mozjs::MozjsGlobalEnvironment; +using cobalt::script::mozjs::MozjsPropertyEnumerator; +using cobalt::script::mozjs::MozjsUserObjectHolder; +using cobalt::script::mozjs::ProxyHandler; +using cobalt::script::mozjs::ToJSValue; +using cobalt::script::mozjs::TypeTraits; +using cobalt::script::mozjs::WrapperFactory; +using cobalt::script::mozjs::WrapperPrivate; +using cobalt::script::mozjs::kConversionFlagNullable; +using cobalt::script::mozjs::kConversionFlagRestricted; +using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString; +using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString; +using cobalt::script::mozjs::kNoConversionFlags; +} // namespace + +namespace cobalt { +namespace bindings { +namespace testing { + +namespace { + +class MozjsNoConstructorInterfaceHandler : public ProxyHandler { + public: + MozjsNoConstructorInterfaceHandler() + : ProxyHandler(indexed_property_hooks, named_property_hooks) {} + + private: + static NamedPropertyHooks named_property_hooks; + static IndexedPropertyHooks indexed_property_hooks; +}; + +ProxyHandler::NamedPropertyHooks +MozjsNoConstructorInterfaceHandler::named_property_hooks = { + NULL, + NULL, + NULL, + NULL, + NULL, +}; +ProxyHandler::IndexedPropertyHooks +MozjsNoConstructorInterfaceHandler::indexed_property_hooks = { + NULL, + NULL, + NULL, + NULL, + NULL, +}; + +static base::LazyInstance<MozjsNoConstructorInterfaceHandler> + proxy_handler; + +bool HasInstance(JSContext *context, JS::HandleObject type, + JS::MutableHandleValue vp, bool *success) { + JS::RootedObject global_object( + context, JS_GetGlobalForObject(context, type)); + DCHECK(global_object); + + JS::RootedObject prototype( + context, MozjsNoConstructorInterface::GetPrototype(context, global_object)); + + // |IsDelegate| walks the prototype chain of an object returning true if + // .prototype is found. + bool is_delegate; + if (!IsDelegate(context, prototype, vp, &is_delegate)) { + *success = false; + return false; + } + + *success = is_delegate; + return true; +} + +const JSClass instance_class_definition = { + "NoConstructorInterface", + 0 | JSCLASS_HAS_PRIVATE, + NULL, // addProperty + NULL, // delProperty + NULL, // getProperty + NULL, // setProperty + NULL, // enumerate + NULL, // resolve + NULL, // mayResolve + &WrapperPrivate::Finalizer, // finalize + NULL, // call + NULL, // hasInstance + NULL, // construct + &WrapperPrivate::Trace, // trace +}; + +const JSClass prototype_class_definition = { + "NoConstructorInterfacePrototype", +}; + +const JSClass interface_object_class_definition = { + "NoConstructorInterfaceConstructor", + 0, + NULL, // addProperty + NULL, // delProperty + NULL, // getProperty + NULL, // setProperty + NULL, // enumerate + NULL, // resolve + NULL, // mayResolve + NULL, // finalize + NULL, // call + &HasInstance, + NULL, +}; + + + +const JSPropertySpec prototype_properties[] = { + JS_PS_END +}; + +const JSFunctionSpec prototype_functions[] = { + JS_FS_END +}; + +const JSPropertySpec interface_object_properties[] = { + JS_PS_END +}; + +const JSFunctionSpec interface_object_functions[] = { + JS_FS_END +}; + +const JSPropertySpec own_properties[] = { + JS_PS_END +}; + +void InitializePrototypeAndInterfaceObject( + InterfaceData* interface_data, JSContext* context, + JS::HandleObject global_object) { + DCHECK(!interface_data->prototype); + DCHECK(!interface_data->interface_object); + DCHECK(JS_IsGlobalObject(global_object)); + + JS::RootedObject parent_prototype( + context, JS_GetObjectPrototype(context, global_object)); + DCHECK(parent_prototype); + + interface_data->prototype = JS_NewObjectWithGivenProto( + context, &prototype_class_definition, parent_prototype + ); + + JS::RootedObject rooted_prototype(context, interface_data->prototype); + bool success = JS_DefineProperties( + context, + rooted_prototype, + prototype_properties); + + DCHECK(success); + success = JS_DefineFunctions( + context, rooted_prototype, prototype_functions); + DCHECK(success); + + JS::RootedObject function_prototype( + context, JS_GetFunctionPrototype(context, global_object)); + DCHECK(function_prototype); + // Create the Interface object. + interface_data->interface_object = JS_NewObjectWithGivenProto( + context, &interface_object_class_definition, + function_prototype); + + // Add the InterfaceObject.name property. + JS::RootedObject rooted_interface_object( + context, interface_data->interface_object); + JS::RootedValue name_value(context); + const char name[] = + "NoConstructorInterface"; + name_value.setString(JS_NewStringCopyZ(context, name)); + success = JS_DefineProperty( + context, rooted_interface_object, "name", name_value, JSPROP_READONLY, + NULL, NULL); + DCHECK(success); + + // Define interface object properties (including constants). + success = JS_DefineProperties(context, rooted_interface_object, + interface_object_properties); + DCHECK(success); + // Define interface object functions (static). + success = JS_DefineFunctions(context, rooted_interface_object, + interface_object_functions); + DCHECK(success); + + // Set the Prototype.constructor and Constructor.prototype properties. + DCHECK(interface_data->interface_object); + DCHECK(interface_data->prototype); + success = JS_LinkConstructorAndPrototype( + context, + rooted_interface_object, + rooted_prototype); + DCHECK(success); +} + +InterfaceData* GetInterfaceData(JSContext* context) { + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + // Use the address of the properties definition for this interface as a + // unique key for looking up the InterfaceData for this interface. + intptr_t key = reinterpret_cast<intptr_t>(&own_properties); + InterfaceData* interface_data = global_environment->GetInterfaceData(key); + if (!interface_data) { + interface_data = new InterfaceData(); + DCHECK(interface_data); + global_environment->CacheInterfaceData(key, interface_data); + DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key)); + } + return interface_data; +} + +} // namespace + +// static +JSObject* MozjsNoConstructorInterface::CreateProxy( + JSContext* context, const scoped_refptr<Wrappable>& wrappable) { + DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); + JS::RootedObject global_object( + context, + MozjsGlobalEnvironment::GetFromContext(context)->global_object()); + DCHECK(global_object); + + InterfaceData* interface_data = GetInterfaceData(context); + JS::RootedObject prototype(context, GetPrototype(context, global_object)); + DCHECK(prototype); + JS::RootedObject new_object( + context, + JS_NewObjectWithGivenProto( + context, &instance_class_definition, prototype)); + DCHECK(new_object); + JS::RootedObject proxy(context, + ProxyHandler::NewProxy( + context, proxy_handler.Pointer(), new_object, prototype)); + WrapperPrivate::AddPrivateData(context, proxy, wrappable); + return proxy; +} + +// static +const JSClass* MozjsNoConstructorInterface::PrototypeClass( + JSContext* context) { + DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); + JS::RootedObject global_object( + context, + MozjsGlobalEnvironment::GetFromContext(context)->global_object()); + DCHECK(global_object); + + JS::RootedObject prototype(context, GetPrototype(context, global_object)); + const JSClass* proto_class = JS_GetClass(prototype); + return proto_class; +} + +// static +JSObject* MozjsNoConstructorInterface::GetPrototype( + JSContext* context, JS::HandleObject global_object) { + DCHECK(JS_IsGlobalObject(global_object)); + + InterfaceData* interface_data = GetInterfaceData(context); + if (!interface_data->prototype) { + // Create new prototype that has all the props and methods + InitializePrototypeAndInterfaceObject( + interface_data, context, global_object); + } + DCHECK(interface_data->prototype); + return interface_data->prototype; +} + +// static +JSObject* MozjsNoConstructorInterface::GetInterfaceObject( + JSContext* context, JS::HandleObject global_object) { + DCHECK(JS_IsGlobalObject(global_object)); + + InterfaceData* interface_data = GetInterfaceData(context); + if (!interface_data->interface_object) { + InitializePrototypeAndInterfaceObject( + interface_data, context, global_object); + } + DCHECK(interface_data->interface_object); + return interface_data->interface_object; +} + + +namespace { +} // namespace + + +} // namespace testing +} // namespace bindings +} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_no_constructor_interface.h b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_no_constructor_interface.h new file mode 100644 index 0000000..5446794 --- /dev/null +++ b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_no_constructor_interface.h
@@ -0,0 +1,52 @@ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// clang-format off + +// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! +// Auto-generated from template: bindings/mozjs-45/templates/interface.h.template + +#ifndef MozjsNoConstructorInterface_h +#define MozjsNoConstructorInterface_h + +#include "base/hash_tables.h" +#include "base/lazy_instance.h" +#include "base/memory/ref_counted.h" +#include "base/threading/thread_checker.h" +#include "cobalt/base/polymorphic_downcast.h" +#include "cobalt/script/wrappable.h" +#include "cobalt/bindings/testing/no_constructor_interface.h" + +#include "third_party/mozjs-45/js/src/jsapi.h" + +namespace cobalt { +namespace bindings { +namespace testing { + +class MozjsNoConstructorInterface { + public: + static JSObject* CreateProxy(JSContext* context, + const scoped_refptr<script::Wrappable>& wrappable); + static const JSClass* PrototypeClass(JSContext* context); + static JSObject* GetPrototype(JSContext* context, + JS::HandleObject global_object); + static JSObject* GetInterfaceObject(JSContext* context, + JS::HandleObject global_object); +}; + +} // namespace testing +} // namespace bindings +} // namespace cobalt + +#endif // MozjsNoConstructorInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_no_interface_object_interface.cc b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_no_interface_object_interface.cc new file mode 100644 index 0000000..ab3db4e --- /dev/null +++ b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_no_interface_object_interface.cc
@@ -0,0 +1,302 @@ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// clang-format off + +// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! +// Auto-generated from template: bindings/mozjs-45/templates/interface.cc.template + +#include "cobalt/bindings/testing/mozjs_no_interface_object_interface.h" + +#include "base/debug/trace_event.h" +#include "cobalt/base/polymorphic_downcast.h" +#include "cobalt/script/global_environment.h" +#include "cobalt/script/opaque_handle.h" +#include "cobalt/script/script_value.h" + +#include "base/lazy_instance.h" +#include "cobalt/script/exception_state.h" +#include "cobalt/script/mozjs-45/callback_function_conversion.h" +#include "cobalt/script/mozjs-45/conversion_helpers.h" +#include "cobalt/script/mozjs-45/mozjs_callback_function.h" +#include "cobalt/script/mozjs-45/mozjs_exception_state.h" +#include "cobalt/script/mozjs-45/mozjs_global_environment.h" +#include "cobalt/script/mozjs-45/mozjs_object_handle.h" +#include "cobalt/script/mozjs-45/mozjs_property_enumerator.h" +#include "cobalt/script/mozjs-45/mozjs_user_object_holder.h" +#include "cobalt/script/mozjs-45/proxy_handler.h" +#include "cobalt/script/mozjs-45/type_traits.h" +#include "cobalt/script/mozjs-45/wrapper_factory.h" +#include "cobalt/script/mozjs-45/wrapper_private.h" +#include "cobalt/script/property_enumerator.h" +#include "cobalt/script/sequence.h" +#include "third_party/mozjs-45/js/src/jsapi.h" +#include "third_party/mozjs-45/js/src/jsfriendapi.h" + +namespace { +using cobalt::bindings::testing::NoInterfaceObjectInterface; +using cobalt::bindings::testing::MozjsNoInterfaceObjectInterface; +using cobalt::script::CallbackInterfaceTraits; +using cobalt::script::GlobalEnvironment; +using cobalt::script::OpaqueHandle; +using cobalt::script::OpaqueHandleHolder; +using cobalt::script::ScriptValue; +using cobalt::script::Wrappable; + +using cobalt::script::CallbackFunction; +using cobalt::script::CallbackInterfaceTraits; +using cobalt::script::ExceptionState; +using cobalt::script::Wrappable; +using cobalt::script::mozjs::FromJSValue; +using cobalt::script::mozjs::InterfaceData; +using cobalt::script::mozjs::MozjsCallbackFunction; +using cobalt::script::mozjs::MozjsExceptionState; +using cobalt::script::mozjs::MozjsGlobalEnvironment; +using cobalt::script::mozjs::MozjsPropertyEnumerator; +using cobalt::script::mozjs::MozjsUserObjectHolder; +using cobalt::script::mozjs::ProxyHandler; +using cobalt::script::mozjs::ToJSValue; +using cobalt::script::mozjs::TypeTraits; +using cobalt::script::mozjs::WrapperFactory; +using cobalt::script::mozjs::WrapperPrivate; +using cobalt::script::mozjs::kConversionFlagNullable; +using cobalt::script::mozjs::kConversionFlagRestricted; +using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString; +using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString; +using cobalt::script::mozjs::kNoConversionFlags; +} // namespace + +namespace cobalt { +namespace bindings { +namespace testing { + +namespace { + +class MozjsNoInterfaceObjectInterfaceHandler : public ProxyHandler { + public: + MozjsNoInterfaceObjectInterfaceHandler() + : ProxyHandler(indexed_property_hooks, named_property_hooks) {} + + private: + static NamedPropertyHooks named_property_hooks; + static IndexedPropertyHooks indexed_property_hooks; +}; + +ProxyHandler::NamedPropertyHooks +MozjsNoInterfaceObjectInterfaceHandler::named_property_hooks = { + NULL, + NULL, + NULL, + NULL, + NULL, +}; +ProxyHandler::IndexedPropertyHooks +MozjsNoInterfaceObjectInterfaceHandler::indexed_property_hooks = { + NULL, + NULL, + NULL, + NULL, + NULL, +}; + +static base::LazyInstance<MozjsNoInterfaceObjectInterfaceHandler> + proxy_handler; + +bool HasInstance(JSContext *context, JS::HandleObject type, + JS::MutableHandleValue vp, bool *success) { + JS::RootedObject global_object( + context, JS_GetGlobalForObject(context, type)); + DCHECK(global_object); + + JS::RootedObject prototype( + context, MozjsNoInterfaceObjectInterface::GetPrototype(context, global_object)); + + // |IsDelegate| walks the prototype chain of an object returning true if + // .prototype is found. + bool is_delegate; + if (!IsDelegate(context, prototype, vp, &is_delegate)) { + *success = false; + return false; + } + + *success = is_delegate; + return true; +} + +const JSClass instance_class_definition = { + "NoInterfaceObjectInterface", + 0 | JSCLASS_HAS_PRIVATE, + NULL, // addProperty + NULL, // delProperty + NULL, // getProperty + NULL, // setProperty + NULL, // enumerate + NULL, // resolve + NULL, // mayResolve + &WrapperPrivate::Finalizer, // finalize + NULL, // call + NULL, // hasInstance + NULL, // construct + &WrapperPrivate::Trace, // trace +}; + +const JSClass prototype_class_definition = { + "NoInterfaceObjectInterfacePrototype", +}; + +const JSClass interface_object_class_definition = { + "NoInterfaceObjectInterfaceConstructor", + 0, + NULL, // addProperty + NULL, // delProperty + NULL, // getProperty + NULL, // setProperty + NULL, // enumerate + NULL, // resolve + NULL, // mayResolve + NULL, // finalize + NULL, // call + &HasInstance, + NULL, +}; + + + +const JSPropertySpec prototype_properties[] = { + JS_PS_END +}; + +const JSFunctionSpec prototype_functions[] = { + JS_FS_END +}; + +const JSPropertySpec interface_object_properties[] = { + JS_PS_END +}; + +const JSFunctionSpec interface_object_functions[] = { + JS_FS_END +}; + +const JSPropertySpec own_properties[] = { + JS_PS_END +}; + +void InitializePrototypeAndInterfaceObject( + InterfaceData* interface_data, JSContext* context, + JS::HandleObject global_object) { + DCHECK(!interface_data->prototype); + DCHECK(!interface_data->interface_object); + DCHECK(JS_IsGlobalObject(global_object)); + + JS::RootedObject parent_prototype( + context, JS_GetObjectPrototype(context, global_object)); + DCHECK(parent_prototype); + + interface_data->prototype = JS_NewObjectWithGivenProto( + context, &prototype_class_definition, parent_prototype + ); + + JS::RootedObject rooted_prototype(context, interface_data->prototype); + bool success = JS_DefineProperties( + context, + rooted_prototype, + prototype_properties); + + DCHECK(success); + success = JS_DefineFunctions( + context, rooted_prototype, prototype_functions); + DCHECK(success); + +} + +InterfaceData* GetInterfaceData(JSContext* context) { + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + // Use the address of the properties definition for this interface as a + // unique key for looking up the InterfaceData for this interface. + intptr_t key = reinterpret_cast<intptr_t>(&own_properties); + InterfaceData* interface_data = global_environment->GetInterfaceData(key); + if (!interface_data) { + interface_data = new InterfaceData(); + DCHECK(interface_data); + global_environment->CacheInterfaceData(key, interface_data); + DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key)); + } + return interface_data; +} + +} // namespace + +// static +JSObject* MozjsNoInterfaceObjectInterface::CreateProxy( + JSContext* context, const scoped_refptr<Wrappable>& wrappable) { + DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); + JS::RootedObject global_object( + context, + MozjsGlobalEnvironment::GetFromContext(context)->global_object()); + DCHECK(global_object); + + InterfaceData* interface_data = GetInterfaceData(context); + JS::RootedObject prototype(context, GetPrototype(context, global_object)); + DCHECK(prototype); + JS::RootedObject new_object( + context, + JS_NewObjectWithGivenProto( + context, &instance_class_definition, prototype)); + DCHECK(new_object); + JS::RootedObject proxy(context, + ProxyHandler::NewProxy( + context, proxy_handler.Pointer(), new_object, prototype)); + WrapperPrivate::AddPrivateData(context, proxy, wrappable); + return proxy; +} + +// static +const JSClass* MozjsNoInterfaceObjectInterface::PrototypeClass( + JSContext* context) { + DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); + JS::RootedObject global_object( + context, + MozjsGlobalEnvironment::GetFromContext(context)->global_object()); + DCHECK(global_object); + + JS::RootedObject prototype(context, GetPrototype(context, global_object)); + const JSClass* proto_class = JS_GetClass(prototype); + return proto_class; +} + +// static +JSObject* MozjsNoInterfaceObjectInterface::GetPrototype( + JSContext* context, JS::HandleObject global_object) { + DCHECK(JS_IsGlobalObject(global_object)); + + InterfaceData* interface_data = GetInterfaceData(context); + if (!interface_data->prototype) { + // Create new prototype that has all the props and methods + InitializePrototypeAndInterfaceObject( + interface_data, context, global_object); + } + DCHECK(interface_data->prototype); + return interface_data->prototype; +} + + +namespace { +} // namespace + + +} // namespace testing +} // namespace bindings +} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_no_interface_object_interface.h b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_no_interface_object_interface.h new file mode 100644 index 0000000..64e78f5 --- /dev/null +++ b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_no_interface_object_interface.h
@@ -0,0 +1,50 @@ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// clang-format off + +// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! +// Auto-generated from template: bindings/mozjs-45/templates/interface.h.template + +#ifndef MozjsNoInterfaceObjectInterface_h +#define MozjsNoInterfaceObjectInterface_h + +#include "base/hash_tables.h" +#include "base/lazy_instance.h" +#include "base/memory/ref_counted.h" +#include "base/threading/thread_checker.h" +#include "cobalt/base/polymorphic_downcast.h" +#include "cobalt/script/wrappable.h" +#include "cobalt/bindings/testing/no_interface_object_interface.h" + +#include "third_party/mozjs-45/js/src/jsapi.h" + +namespace cobalt { +namespace bindings { +namespace testing { + +class MozjsNoInterfaceObjectInterface { + public: + static JSObject* CreateProxy(JSContext* context, + const scoped_refptr<script::Wrappable>& wrappable); + static const JSClass* PrototypeClass(JSContext* context); + static JSObject* GetPrototype(JSContext* context, + JS::HandleObject global_object); +}; + +} // namespace testing +} // namespace bindings +} // namespace cobalt + +#endif // MozjsNoInterfaceObjectInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_nullable_types_test_interface.cc b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_nullable_types_test_interface.cc new file mode 100644 index 0000000..163329f --- /dev/null +++ b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_nullable_types_test_interface.cc
@@ -0,0 +1,1237 @@ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// clang-format off + +// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! +// Auto-generated from template: bindings/mozjs-45/templates/interface.cc.template + +#include "cobalt/bindings/testing/mozjs_nullable_types_test_interface.h" + +#include "base/debug/trace_event.h" +#include "cobalt/base/polymorphic_downcast.h" +#include "cobalt/script/global_environment.h" +#include "cobalt/script/opaque_handle.h" +#include "cobalt/script/script_value.h" +#include "cobalt/bindings/testing/arbitrary_interface.h" +#include "cobalt/bindings/testing/mozjs_arbitrary_interface.h" + +#include "base/lazy_instance.h" +#include "cobalt/script/exception_state.h" +#include "cobalt/script/mozjs-45/callback_function_conversion.h" +#include "cobalt/script/mozjs-45/conversion_helpers.h" +#include "cobalt/script/mozjs-45/mozjs_callback_function.h" +#include "cobalt/script/mozjs-45/mozjs_exception_state.h" +#include "cobalt/script/mozjs-45/mozjs_global_environment.h" +#include "cobalt/script/mozjs-45/mozjs_object_handle.h" +#include "cobalt/script/mozjs-45/mozjs_property_enumerator.h" +#include "cobalt/script/mozjs-45/mozjs_user_object_holder.h" +#include "cobalt/script/mozjs-45/proxy_handler.h" +#include "cobalt/script/mozjs-45/type_traits.h" +#include "cobalt/script/mozjs-45/wrapper_factory.h" +#include "cobalt/script/mozjs-45/wrapper_private.h" +#include "cobalt/script/property_enumerator.h" +#include "cobalt/script/sequence.h" +#include "third_party/mozjs-45/js/src/jsapi.h" +#include "third_party/mozjs-45/js/src/jsfriendapi.h" + +namespace { +using cobalt::bindings::testing::NullableTypesTestInterface; +using cobalt::bindings::testing::MozjsNullableTypesTestInterface; +using cobalt::bindings::testing::ArbitraryInterface; +using cobalt::bindings::testing::MozjsArbitraryInterface; +using cobalt::script::CallbackInterfaceTraits; +using cobalt::script::GlobalEnvironment; +using cobalt::script::OpaqueHandle; +using cobalt::script::OpaqueHandleHolder; +using cobalt::script::ScriptValue; +using cobalt::script::Wrappable; + +using cobalt::script::CallbackFunction; +using cobalt::script::CallbackInterfaceTraits; +using cobalt::script::ExceptionState; +using cobalt::script::Wrappable; +using cobalt::script::mozjs::FromJSValue; +using cobalt::script::mozjs::InterfaceData; +using cobalt::script::mozjs::MozjsCallbackFunction; +using cobalt::script::mozjs::MozjsExceptionState; +using cobalt::script::mozjs::MozjsGlobalEnvironment; +using cobalt::script::mozjs::MozjsPropertyEnumerator; +using cobalt::script::mozjs::MozjsUserObjectHolder; +using cobalt::script::mozjs::ProxyHandler; +using cobalt::script::mozjs::ToJSValue; +using cobalt::script::mozjs::TypeTraits; +using cobalt::script::mozjs::WrapperFactory; +using cobalt::script::mozjs::WrapperPrivate; +using cobalt::script::mozjs::kConversionFlagNullable; +using cobalt::script::mozjs::kConversionFlagRestricted; +using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString; +using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString; +using cobalt::script::mozjs::kNoConversionFlags; +} // namespace + +namespace cobalt { +namespace bindings { +namespace testing { + +namespace { + +class MozjsNullableTypesTestInterfaceHandler : public ProxyHandler { + public: + MozjsNullableTypesTestInterfaceHandler() + : ProxyHandler(indexed_property_hooks, named_property_hooks) {} + + private: + static NamedPropertyHooks named_property_hooks; + static IndexedPropertyHooks indexed_property_hooks; +}; + +ProxyHandler::NamedPropertyHooks +MozjsNullableTypesTestInterfaceHandler::named_property_hooks = { + NULL, + NULL, + NULL, + NULL, + NULL, +}; +ProxyHandler::IndexedPropertyHooks +MozjsNullableTypesTestInterfaceHandler::indexed_property_hooks = { + NULL, + NULL, + NULL, + NULL, + NULL, +}; + +static base::LazyInstance<MozjsNullableTypesTestInterfaceHandler> + proxy_handler; + +bool HasInstance(JSContext *context, JS::HandleObject type, + JS::MutableHandleValue vp, bool *success) { + JS::RootedObject global_object( + context, JS_GetGlobalForObject(context, type)); + DCHECK(global_object); + + JS::RootedObject prototype( + context, MozjsNullableTypesTestInterface::GetPrototype(context, global_object)); + + // |IsDelegate| walks the prototype chain of an object returning true if + // .prototype is found. + bool is_delegate; + if (!IsDelegate(context, prototype, vp, &is_delegate)) { + *success = false; + return false; + } + + *success = is_delegate; + return true; +} + +const JSClass instance_class_definition = { + "NullableTypesTestInterface", + 0 | JSCLASS_HAS_PRIVATE, + NULL, // addProperty + NULL, // delProperty + NULL, // getProperty + NULL, // setProperty + NULL, // enumerate + NULL, // resolve + NULL, // mayResolve + &WrapperPrivate::Finalizer, // finalize + NULL, // call + NULL, // hasInstance + NULL, // construct + &WrapperPrivate::Trace, // trace +}; + +const JSClass prototype_class_definition = { + "NullableTypesTestInterfacePrototype", +}; + +const JSClass interface_object_class_definition = { + "NullableTypesTestInterfaceConstructor", + 0, + NULL, // addProperty + NULL, // delProperty + NULL, // getProperty + NULL, // setProperty + NULL, // enumerate + NULL, // resolve + NULL, // mayResolve + NULL, // finalize + NULL, // call + &HasInstance, + NULL, +}; + +bool get_nullableBooleanProperty( + JSContext* context, unsigned argc, JS::Value* vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + const JSClass* proto_class = + MozjsNullableTypesTestInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<NullableTypesTestInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + NullableTypesTestInterface* impl = + wrapper_private->wrappable<NullableTypesTestInterface>().get(); + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->nullable_boolean_property(), + &result_value); + } + if (!exception_state.is_exception_set()) { + args.rval().set(result_value); + } + return !exception_state.is_exception_set(); +} + +bool set_nullableBooleanProperty( + JSContext* context, unsigned argc, JS::Value* vp) { + + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + + const JSClass* proto_class = + MozjsNullableTypesTestInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<NullableTypesTestInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + NullableTypesTestInterface* impl = + wrapper_private->wrappable<NullableTypesTestInterface>().get(); + TypeTraits<base::optional<bool > >::ConversionType value; + if (args.length() != 1) { + NOTREACHED(); + return false; + } + FromJSValue(context, args[0], (kConversionFlagNullable), &exception_state, + &value); + if (exception_state.is_exception_set()) { + return false; + } + + impl->set_nullable_boolean_property(value); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + +bool get_nullableNumericProperty( + JSContext* context, unsigned argc, JS::Value* vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + const JSClass* proto_class = + MozjsNullableTypesTestInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<NullableTypesTestInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + NullableTypesTestInterface* impl = + wrapper_private->wrappable<NullableTypesTestInterface>().get(); + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->nullable_numeric_property(), + &result_value); + } + if (!exception_state.is_exception_set()) { + args.rval().set(result_value); + } + return !exception_state.is_exception_set(); +} + +bool set_nullableNumericProperty( + JSContext* context, unsigned argc, JS::Value* vp) { + + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + + const JSClass* proto_class = + MozjsNullableTypesTestInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<NullableTypesTestInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + NullableTypesTestInterface* impl = + wrapper_private->wrappable<NullableTypesTestInterface>().get(); + TypeTraits<base::optional<int32_t > >::ConversionType value; + if (args.length() != 1) { + NOTREACHED(); + return false; + } + FromJSValue(context, args[0], (kConversionFlagNullable), &exception_state, + &value); + if (exception_state.is_exception_set()) { + return false; + } + + impl->set_nullable_numeric_property(value); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + +bool get_nullableStringProperty( + JSContext* context, unsigned argc, JS::Value* vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + const JSClass* proto_class = + MozjsNullableTypesTestInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<NullableTypesTestInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + NullableTypesTestInterface* impl = + wrapper_private->wrappable<NullableTypesTestInterface>().get(); + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->nullable_string_property(), + &result_value); + } + if (!exception_state.is_exception_set()) { + args.rval().set(result_value); + } + return !exception_state.is_exception_set(); +} + +bool set_nullableStringProperty( + JSContext* context, unsigned argc, JS::Value* vp) { + + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + + const JSClass* proto_class = + MozjsNullableTypesTestInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<NullableTypesTestInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + NullableTypesTestInterface* impl = + wrapper_private->wrappable<NullableTypesTestInterface>().get(); + TypeTraits<base::optional<std::string > >::ConversionType value; + if (args.length() != 1) { + NOTREACHED(); + return false; + } + FromJSValue(context, args[0], (kConversionFlagNullable), &exception_state, + &value); + if (exception_state.is_exception_set()) { + return false; + } + + impl->set_nullable_string_property(value); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + +bool get_nullableObjectProperty( + JSContext* context, unsigned argc, JS::Value* vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + const JSClass* proto_class = + MozjsNullableTypesTestInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<NullableTypesTestInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + NullableTypesTestInterface* impl = + wrapper_private->wrappable<NullableTypesTestInterface>().get(); + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->nullable_object_property(), + &result_value); + } + if (!exception_state.is_exception_set()) { + args.rval().set(result_value); + } + return !exception_state.is_exception_set(); +} + +bool set_nullableObjectProperty( + JSContext* context, unsigned argc, JS::Value* vp) { + + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + + const JSClass* proto_class = + MozjsNullableTypesTestInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<NullableTypesTestInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + NullableTypesTestInterface* impl = + wrapper_private->wrappable<NullableTypesTestInterface>().get(); + TypeTraits<scoped_refptr<ArbitraryInterface> >::ConversionType value; + if (args.length() != 1) { + NOTREACHED(); + return false; + } + FromJSValue(context, args[0], (kConversionFlagNullable), &exception_state, + &value); + if (exception_state.is_exception_set()) { + return false; + } + + impl->set_nullable_object_property(value); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + +bool fcn_nullableBooleanArgument( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + const JSClass* proto_class = + MozjsNullableTypesTestInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<NullableTypesTestInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + NullableTypesTestInterface* impl = + wrapper_private->wrappable<NullableTypesTestInterface>().get(); + const size_t kMinArguments = 1; + if (args.length() < kMinArguments) { + exception_state.SetSimpleException(script::kInvalidNumberOfArguments); + return false; + } + // Non-optional arguments + TypeTraits<base::optional<bool > >::ConversionType arg; + + DCHECK_LT(0, args.length()); + JS::RootedValue non_optional_value0( + context, args[0]); + FromJSValue(context, + non_optional_value0, + (kConversionFlagNullable), + &exception_state, &arg); + if (exception_state.is_exception_set()) { + return false; + } + + impl->NullableBooleanArgument(arg); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + +bool fcn_nullableBooleanOperation( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + const JSClass* proto_class = + MozjsNullableTypesTestInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<NullableTypesTestInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + NullableTypesTestInterface* impl = + wrapper_private->wrappable<NullableTypesTestInterface>().get(); + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->NullableBooleanOperation(), + &result_value); + } + if (!exception_state.is_exception_set()) { + args.rval().set(result_value); + } + return !exception_state.is_exception_set(); +} + +bool fcn_nullableNumericArgument( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + const JSClass* proto_class = + MozjsNullableTypesTestInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<NullableTypesTestInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + NullableTypesTestInterface* impl = + wrapper_private->wrappable<NullableTypesTestInterface>().get(); + const size_t kMinArguments = 1; + if (args.length() < kMinArguments) { + exception_state.SetSimpleException(script::kInvalidNumberOfArguments); + return false; + } + // Non-optional arguments + TypeTraits<base::optional<int32_t > >::ConversionType arg; + + DCHECK_LT(0, args.length()); + JS::RootedValue non_optional_value0( + context, args[0]); + FromJSValue(context, + non_optional_value0, + (kConversionFlagNullable), + &exception_state, &arg); + if (exception_state.is_exception_set()) { + return false; + } + + impl->NullableNumericArgument(arg); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + +bool fcn_nullableNumericOperation( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + const JSClass* proto_class = + MozjsNullableTypesTestInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<NullableTypesTestInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + NullableTypesTestInterface* impl = + wrapper_private->wrappable<NullableTypesTestInterface>().get(); + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->NullableNumericOperation(), + &result_value); + } + if (!exception_state.is_exception_set()) { + args.rval().set(result_value); + } + return !exception_state.is_exception_set(); +} + +bool fcn_nullableObjectArgument( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + const JSClass* proto_class = + MozjsNullableTypesTestInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<NullableTypesTestInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + NullableTypesTestInterface* impl = + wrapper_private->wrappable<NullableTypesTestInterface>().get(); + const size_t kMinArguments = 1; + if (args.length() < kMinArguments) { + exception_state.SetSimpleException(script::kInvalidNumberOfArguments); + return false; + } + // Non-optional arguments + TypeTraits<scoped_refptr<ArbitraryInterface> >::ConversionType arg; + + DCHECK_LT(0, args.length()); + JS::RootedValue non_optional_value0( + context, args[0]); + FromJSValue(context, + non_optional_value0, + (kConversionFlagNullable), + &exception_state, &arg); + if (exception_state.is_exception_set()) { + return false; + } + + impl->NullableObjectArgument(arg); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + +bool fcn_nullableObjectOperation( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + const JSClass* proto_class = + MozjsNullableTypesTestInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<NullableTypesTestInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + NullableTypesTestInterface* impl = + wrapper_private->wrappable<NullableTypesTestInterface>().get(); + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->NullableObjectOperation(), + &result_value); + } + if (!exception_state.is_exception_set()) { + args.rval().set(result_value); + } + return !exception_state.is_exception_set(); +} + +bool fcn_nullableStringArgument( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + const JSClass* proto_class = + MozjsNullableTypesTestInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<NullableTypesTestInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + NullableTypesTestInterface* impl = + wrapper_private->wrappable<NullableTypesTestInterface>().get(); + const size_t kMinArguments = 1; + if (args.length() < kMinArguments) { + exception_state.SetSimpleException(script::kInvalidNumberOfArguments); + return false; + } + // Non-optional arguments + TypeTraits<base::optional<std::string > >::ConversionType arg; + + DCHECK_LT(0, args.length()); + JS::RootedValue non_optional_value0( + context, args[0]); + FromJSValue(context, + non_optional_value0, + (kConversionFlagNullable), + &exception_state, &arg); + if (exception_state.is_exception_set()) { + return false; + } + + impl->NullableStringArgument(arg); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + +bool fcn_nullableStringOperation( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + const JSClass* proto_class = + MozjsNullableTypesTestInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<NullableTypesTestInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + NullableTypesTestInterface* impl = + wrapper_private->wrappable<NullableTypesTestInterface>().get(); + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->NullableStringOperation(), + &result_value); + } + if (!exception_state.is_exception_set()) { + args.rval().set(result_value); + } + return !exception_state.is_exception_set(); +} + + + +const JSPropertySpec prototype_properties[] = { + { // Read/Write property + "nullableBooleanProperty", + JSPROP_SHARED | JSPROP_ENUMERATE, + { { &get_nullableBooleanProperty, NULL } }, + { { &set_nullableBooleanProperty, NULL } }, + }, + { // Read/Write property + "nullableNumericProperty", + JSPROP_SHARED | JSPROP_ENUMERATE, + { { &get_nullableNumericProperty, NULL } }, + { { &set_nullableNumericProperty, NULL } }, + }, + { // Read/Write property + "nullableStringProperty", + JSPROP_SHARED | JSPROP_ENUMERATE, + { { &get_nullableStringProperty, NULL } }, + { { &set_nullableStringProperty, NULL } }, + }, + { // Read/Write property + "nullableObjectProperty", + JSPROP_SHARED | JSPROP_ENUMERATE, + { { &get_nullableObjectProperty, NULL } }, + { { &set_nullableObjectProperty, NULL } }, + }, + JS_PS_END +}; + +const JSFunctionSpec prototype_functions[] = { + JS_FNSPEC( + "nullableBooleanArgument", fcn_nullableBooleanArgument, NULL, + 1, JSPROP_ENUMERATE, NULL), + JS_FNSPEC( + "nullableBooleanOperation", fcn_nullableBooleanOperation, NULL, + 0, JSPROP_ENUMERATE, NULL), + JS_FNSPEC( + "nullableNumericArgument", fcn_nullableNumericArgument, NULL, + 1, JSPROP_ENUMERATE, NULL), + JS_FNSPEC( + "nullableNumericOperation", fcn_nullableNumericOperation, NULL, + 0, JSPROP_ENUMERATE, NULL), + JS_FNSPEC( + "nullableObjectArgument", fcn_nullableObjectArgument, NULL, + 1, JSPROP_ENUMERATE, NULL), + JS_FNSPEC( + "nullableObjectOperation", fcn_nullableObjectOperation, NULL, + 0, JSPROP_ENUMERATE, NULL), + JS_FNSPEC( + "nullableStringArgument", fcn_nullableStringArgument, NULL, + 1, JSPROP_ENUMERATE, NULL), + JS_FNSPEC( + "nullableStringOperation", fcn_nullableStringOperation, NULL, + 0, JSPROP_ENUMERATE, NULL), + JS_FS_END +}; + +const JSPropertySpec interface_object_properties[] = { + JS_PS_END +}; + +const JSFunctionSpec interface_object_functions[] = { + JS_FS_END +}; + +const JSPropertySpec own_properties[] = { + JS_PS_END +}; + +void InitializePrototypeAndInterfaceObject( + InterfaceData* interface_data, JSContext* context, + JS::HandleObject global_object) { + DCHECK(!interface_data->prototype); + DCHECK(!interface_data->interface_object); + DCHECK(JS_IsGlobalObject(global_object)); + + JS::RootedObject parent_prototype( + context, JS_GetObjectPrototype(context, global_object)); + DCHECK(parent_prototype); + + interface_data->prototype = JS_NewObjectWithGivenProto( + context, &prototype_class_definition, parent_prototype + ); + + JS::RootedObject rooted_prototype(context, interface_data->prototype); + bool success = JS_DefineProperties( + context, + rooted_prototype, + prototype_properties); + + DCHECK(success); + success = JS_DefineFunctions( + context, rooted_prototype, prototype_functions); + DCHECK(success); + + JS::RootedObject function_prototype( + context, JS_GetFunctionPrototype(context, global_object)); + DCHECK(function_prototype); + // Create the Interface object. + interface_data->interface_object = JS_NewObjectWithGivenProto( + context, &interface_object_class_definition, + function_prototype); + + // Add the InterfaceObject.name property. + JS::RootedObject rooted_interface_object( + context, interface_data->interface_object); + JS::RootedValue name_value(context); + const char name[] = + "NullableTypesTestInterface"; + name_value.setString(JS_NewStringCopyZ(context, name)); + success = JS_DefineProperty( + context, rooted_interface_object, "name", name_value, JSPROP_READONLY, + NULL, NULL); + DCHECK(success); + + // Define interface object properties (including constants). + success = JS_DefineProperties(context, rooted_interface_object, + interface_object_properties); + DCHECK(success); + // Define interface object functions (static). + success = JS_DefineFunctions(context, rooted_interface_object, + interface_object_functions); + DCHECK(success); + + // Set the Prototype.constructor and Constructor.prototype properties. + DCHECK(interface_data->interface_object); + DCHECK(interface_data->prototype); + success = JS_LinkConstructorAndPrototype( + context, + rooted_interface_object, + rooted_prototype); + DCHECK(success); +} + +InterfaceData* GetInterfaceData(JSContext* context) { + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + // Use the address of the properties definition for this interface as a + // unique key for looking up the InterfaceData for this interface. + intptr_t key = reinterpret_cast<intptr_t>(&own_properties); + InterfaceData* interface_data = global_environment->GetInterfaceData(key); + if (!interface_data) { + interface_data = new InterfaceData(); + DCHECK(interface_data); + global_environment->CacheInterfaceData(key, interface_data); + DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key)); + } + return interface_data; +} + +} // namespace + +// static +JSObject* MozjsNullableTypesTestInterface::CreateProxy( + JSContext* context, const scoped_refptr<Wrappable>& wrappable) { + DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); + JS::RootedObject global_object( + context, + MozjsGlobalEnvironment::GetFromContext(context)->global_object()); + DCHECK(global_object); + + InterfaceData* interface_data = GetInterfaceData(context); + JS::RootedObject prototype(context, GetPrototype(context, global_object)); + DCHECK(prototype); + JS::RootedObject new_object( + context, + JS_NewObjectWithGivenProto( + context, &instance_class_definition, prototype)); + DCHECK(new_object); + JS::RootedObject proxy(context, + ProxyHandler::NewProxy( + context, proxy_handler.Pointer(), new_object, prototype)); + WrapperPrivate::AddPrivateData(context, proxy, wrappable); + return proxy; +} + +// static +const JSClass* MozjsNullableTypesTestInterface::PrototypeClass( + JSContext* context) { + DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); + JS::RootedObject global_object( + context, + MozjsGlobalEnvironment::GetFromContext(context)->global_object()); + DCHECK(global_object); + + JS::RootedObject prototype(context, GetPrototype(context, global_object)); + const JSClass* proto_class = JS_GetClass(prototype); + return proto_class; +} + +// static +JSObject* MozjsNullableTypesTestInterface::GetPrototype( + JSContext* context, JS::HandleObject global_object) { + DCHECK(JS_IsGlobalObject(global_object)); + + InterfaceData* interface_data = GetInterfaceData(context); + if (!interface_data->prototype) { + // Create new prototype that has all the props and methods + InitializePrototypeAndInterfaceObject( + interface_data, context, global_object); + } + DCHECK(interface_data->prototype); + return interface_data->prototype; +} + +// static +JSObject* MozjsNullableTypesTestInterface::GetInterfaceObject( + JSContext* context, JS::HandleObject global_object) { + DCHECK(JS_IsGlobalObject(global_object)); + + InterfaceData* interface_data = GetInterfaceData(context); + if (!interface_data->interface_object) { + InitializePrototypeAndInterfaceObject( + interface_data, context, global_object); + } + DCHECK(interface_data->interface_object); + return interface_data->interface_object; +} + + +namespace { +} // namespace + + +} // namespace testing +} // namespace bindings +} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_nullable_types_test_interface.h b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_nullable_types_test_interface.h new file mode 100644 index 0000000..2f1b48b --- /dev/null +++ b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_nullable_types_test_interface.h
@@ -0,0 +1,52 @@ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// clang-format off + +// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! +// Auto-generated from template: bindings/mozjs-45/templates/interface.h.template + +#ifndef MozjsNullableTypesTestInterface_h +#define MozjsNullableTypesTestInterface_h + +#include "base/hash_tables.h" +#include "base/lazy_instance.h" +#include "base/memory/ref_counted.h" +#include "base/threading/thread_checker.h" +#include "cobalt/base/polymorphic_downcast.h" +#include "cobalt/script/wrappable.h" +#include "cobalt/bindings/testing/nullable_types_test_interface.h" + +#include "third_party/mozjs-45/js/src/jsapi.h" + +namespace cobalt { +namespace bindings { +namespace testing { + +class MozjsNullableTypesTestInterface { + public: + static JSObject* CreateProxy(JSContext* context, + const scoped_refptr<script::Wrappable>& wrappable); + static const JSClass* PrototypeClass(JSContext* context); + static JSObject* GetPrototype(JSContext* context, + JS::HandleObject global_object); + static JSObject* GetInterfaceObject(JSContext* context, + JS::HandleObject global_object); +}; + +} // namespace testing +} // namespace bindings +} // namespace cobalt + +#endif // MozjsNullableTypesTestInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_numeric_types_test_interface.cc b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_numeric_types_test_interface.cc new file mode 100644 index 0000000..faaf01d --- /dev/null +++ b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_numeric_types_test_interface.cc
@@ -0,0 +1,2553 @@ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// clang-format off + +// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! +// Auto-generated from template: bindings/mozjs-45/templates/interface.cc.template + +#include "cobalt/bindings/testing/mozjs_numeric_types_test_interface.h" + +#include "base/debug/trace_event.h" +#include "cobalt/base/polymorphic_downcast.h" +#include "cobalt/script/global_environment.h" +#include "cobalt/script/opaque_handle.h" +#include "cobalt/script/script_value.h" + +#include "base/lazy_instance.h" +#include "cobalt/script/exception_state.h" +#include "cobalt/script/mozjs-45/callback_function_conversion.h" +#include "cobalt/script/mozjs-45/conversion_helpers.h" +#include "cobalt/script/mozjs-45/mozjs_callback_function.h" +#include "cobalt/script/mozjs-45/mozjs_exception_state.h" +#include "cobalt/script/mozjs-45/mozjs_global_environment.h" +#include "cobalt/script/mozjs-45/mozjs_object_handle.h" +#include "cobalt/script/mozjs-45/mozjs_property_enumerator.h" +#include "cobalt/script/mozjs-45/mozjs_user_object_holder.h" +#include "cobalt/script/mozjs-45/proxy_handler.h" +#include "cobalt/script/mozjs-45/type_traits.h" +#include "cobalt/script/mozjs-45/wrapper_factory.h" +#include "cobalt/script/mozjs-45/wrapper_private.h" +#include "cobalt/script/property_enumerator.h" +#include "cobalt/script/sequence.h" +#include "third_party/mozjs-45/js/src/jsapi.h" +#include "third_party/mozjs-45/js/src/jsfriendapi.h" + +namespace { +using cobalt::bindings::testing::NumericTypesTestInterface; +using cobalt::bindings::testing::MozjsNumericTypesTestInterface; +using cobalt::script::CallbackInterfaceTraits; +using cobalt::script::GlobalEnvironment; +using cobalt::script::OpaqueHandle; +using cobalt::script::OpaqueHandleHolder; +using cobalt::script::ScriptValue; +using cobalt::script::Wrappable; + +using cobalt::script::CallbackFunction; +using cobalt::script::CallbackInterfaceTraits; +using cobalt::script::ExceptionState; +using cobalt::script::Wrappable; +using cobalt::script::mozjs::FromJSValue; +using cobalt::script::mozjs::InterfaceData; +using cobalt::script::mozjs::MozjsCallbackFunction; +using cobalt::script::mozjs::MozjsExceptionState; +using cobalt::script::mozjs::MozjsGlobalEnvironment; +using cobalt::script::mozjs::MozjsPropertyEnumerator; +using cobalt::script::mozjs::MozjsUserObjectHolder; +using cobalt::script::mozjs::ProxyHandler; +using cobalt::script::mozjs::ToJSValue; +using cobalt::script::mozjs::TypeTraits; +using cobalt::script::mozjs::WrapperFactory; +using cobalt::script::mozjs::WrapperPrivate; +using cobalt::script::mozjs::kConversionFlagNullable; +using cobalt::script::mozjs::kConversionFlagRestricted; +using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString; +using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString; +using cobalt::script::mozjs::kNoConversionFlags; +} // namespace + +namespace cobalt { +namespace bindings { +namespace testing { + +namespace { + +class MozjsNumericTypesTestInterfaceHandler : public ProxyHandler { + public: + MozjsNumericTypesTestInterfaceHandler() + : ProxyHandler(indexed_property_hooks, named_property_hooks) {} + + private: + static NamedPropertyHooks named_property_hooks; + static IndexedPropertyHooks indexed_property_hooks; +}; + +ProxyHandler::NamedPropertyHooks +MozjsNumericTypesTestInterfaceHandler::named_property_hooks = { + NULL, + NULL, + NULL, + NULL, + NULL, +}; +ProxyHandler::IndexedPropertyHooks +MozjsNumericTypesTestInterfaceHandler::indexed_property_hooks = { + NULL, + NULL, + NULL, + NULL, + NULL, +}; + +static base::LazyInstance<MozjsNumericTypesTestInterfaceHandler> + proxy_handler; + +bool HasInstance(JSContext *context, JS::HandleObject type, + JS::MutableHandleValue vp, bool *success) { + JS::RootedObject global_object( + context, JS_GetGlobalForObject(context, type)); + DCHECK(global_object); + + JS::RootedObject prototype( + context, MozjsNumericTypesTestInterface::GetPrototype(context, global_object)); + + // |IsDelegate| walks the prototype chain of an object returning true if + // .prototype is found. + bool is_delegate; + if (!IsDelegate(context, prototype, vp, &is_delegate)) { + *success = false; + return false; + } + + *success = is_delegate; + return true; +} + +const JSClass instance_class_definition = { + "NumericTypesTestInterface", + 0 | JSCLASS_HAS_PRIVATE, + NULL, // addProperty + NULL, // delProperty + NULL, // getProperty + NULL, // setProperty + NULL, // enumerate + NULL, // resolve + NULL, // mayResolve + &WrapperPrivate::Finalizer, // finalize + NULL, // call + NULL, // hasInstance + NULL, // construct + &WrapperPrivate::Trace, // trace +}; + +const JSClass prototype_class_definition = { + "NumericTypesTestInterfacePrototype", +}; + +const JSClass interface_object_class_definition = { + "NumericTypesTestInterfaceConstructor", + 0, + NULL, // addProperty + NULL, // delProperty + NULL, // getProperty + NULL, // setProperty + NULL, // enumerate + NULL, // resolve + NULL, // mayResolve + NULL, // finalize + NULL, // call + &HasInstance, + NULL, +}; + +bool get_byteProperty( + JSContext* context, unsigned argc, JS::Value* vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + const JSClass* proto_class = + MozjsNumericTypesTestInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<NumericTypesTestInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + NumericTypesTestInterface* impl = + wrapper_private->wrappable<NumericTypesTestInterface>().get(); + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->byte_property(), + &result_value); + } + if (!exception_state.is_exception_set()) { + args.rval().set(result_value); + } + return !exception_state.is_exception_set(); +} + +bool set_byteProperty( + JSContext* context, unsigned argc, JS::Value* vp) { + + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + + const JSClass* proto_class = + MozjsNumericTypesTestInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<NumericTypesTestInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + NumericTypesTestInterface* impl = + wrapper_private->wrappable<NumericTypesTestInterface>().get(); + TypeTraits<int8_t >::ConversionType value; + if (args.length() != 1) { + NOTREACHED(); + return false; + } + FromJSValue(context, args[0], kNoConversionFlags, &exception_state, + &value); + if (exception_state.is_exception_set()) { + return false; + } + + impl->set_byte_property(value); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + +bool get_octetProperty( + JSContext* context, unsigned argc, JS::Value* vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + const JSClass* proto_class = + MozjsNumericTypesTestInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<NumericTypesTestInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + NumericTypesTestInterface* impl = + wrapper_private->wrappable<NumericTypesTestInterface>().get(); + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->octet_property(), + &result_value); + } + if (!exception_state.is_exception_set()) { + args.rval().set(result_value); + } + return !exception_state.is_exception_set(); +} + +bool set_octetProperty( + JSContext* context, unsigned argc, JS::Value* vp) { + + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + + const JSClass* proto_class = + MozjsNumericTypesTestInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<NumericTypesTestInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + NumericTypesTestInterface* impl = + wrapper_private->wrappable<NumericTypesTestInterface>().get(); + TypeTraits<uint8_t >::ConversionType value; + if (args.length() != 1) { + NOTREACHED(); + return false; + } + FromJSValue(context, args[0], kNoConversionFlags, &exception_state, + &value); + if (exception_state.is_exception_set()) { + return false; + } + + impl->set_octet_property(value); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + +bool get_shortProperty( + JSContext* context, unsigned argc, JS::Value* vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + const JSClass* proto_class = + MozjsNumericTypesTestInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<NumericTypesTestInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + NumericTypesTestInterface* impl = + wrapper_private->wrappable<NumericTypesTestInterface>().get(); + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->short_property(), + &result_value); + } + if (!exception_state.is_exception_set()) { + args.rval().set(result_value); + } + return !exception_state.is_exception_set(); +} + +bool set_shortProperty( + JSContext* context, unsigned argc, JS::Value* vp) { + + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + + const JSClass* proto_class = + MozjsNumericTypesTestInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<NumericTypesTestInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + NumericTypesTestInterface* impl = + wrapper_private->wrappable<NumericTypesTestInterface>().get(); + TypeTraits<int16_t >::ConversionType value; + if (args.length() != 1) { + NOTREACHED(); + return false; + } + FromJSValue(context, args[0], kNoConversionFlags, &exception_state, + &value); + if (exception_state.is_exception_set()) { + return false; + } + + impl->set_short_property(value); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + +bool get_unsignedShortProperty( + JSContext* context, unsigned argc, JS::Value* vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + const JSClass* proto_class = + MozjsNumericTypesTestInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<NumericTypesTestInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + NumericTypesTestInterface* impl = + wrapper_private->wrappable<NumericTypesTestInterface>().get(); + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->unsigned_short_property(), + &result_value); + } + if (!exception_state.is_exception_set()) { + args.rval().set(result_value); + } + return !exception_state.is_exception_set(); +} + +bool set_unsignedShortProperty( + JSContext* context, unsigned argc, JS::Value* vp) { + + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + + const JSClass* proto_class = + MozjsNumericTypesTestInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<NumericTypesTestInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + NumericTypesTestInterface* impl = + wrapper_private->wrappable<NumericTypesTestInterface>().get(); + TypeTraits<uint16_t >::ConversionType value; + if (args.length() != 1) { + NOTREACHED(); + return false; + } + FromJSValue(context, args[0], kNoConversionFlags, &exception_state, + &value); + if (exception_state.is_exception_set()) { + return false; + } + + impl->set_unsigned_short_property(value); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + +bool get_longProperty( + JSContext* context, unsigned argc, JS::Value* vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + const JSClass* proto_class = + MozjsNumericTypesTestInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<NumericTypesTestInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + NumericTypesTestInterface* impl = + wrapper_private->wrappable<NumericTypesTestInterface>().get(); + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->long_property(), + &result_value); + } + if (!exception_state.is_exception_set()) { + args.rval().set(result_value); + } + return !exception_state.is_exception_set(); +} + +bool set_longProperty( + JSContext* context, unsigned argc, JS::Value* vp) { + + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + + const JSClass* proto_class = + MozjsNumericTypesTestInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<NumericTypesTestInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + NumericTypesTestInterface* impl = + wrapper_private->wrappable<NumericTypesTestInterface>().get(); + TypeTraits<int32_t >::ConversionType value; + if (args.length() != 1) { + NOTREACHED(); + return false; + } + FromJSValue(context, args[0], kNoConversionFlags, &exception_state, + &value); + if (exception_state.is_exception_set()) { + return false; + } + + impl->set_long_property(value); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + +bool get_unsignedLongProperty( + JSContext* context, unsigned argc, JS::Value* vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + const JSClass* proto_class = + MozjsNumericTypesTestInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<NumericTypesTestInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + NumericTypesTestInterface* impl = + wrapper_private->wrappable<NumericTypesTestInterface>().get(); + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->unsigned_long_property(), + &result_value); + } + if (!exception_state.is_exception_set()) { + args.rval().set(result_value); + } + return !exception_state.is_exception_set(); +} + +bool set_unsignedLongProperty( + JSContext* context, unsigned argc, JS::Value* vp) { + + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + + const JSClass* proto_class = + MozjsNumericTypesTestInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<NumericTypesTestInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + NumericTypesTestInterface* impl = + wrapper_private->wrappable<NumericTypesTestInterface>().get(); + TypeTraits<uint32_t >::ConversionType value; + if (args.length() != 1) { + NOTREACHED(); + return false; + } + FromJSValue(context, args[0], kNoConversionFlags, &exception_state, + &value); + if (exception_state.is_exception_set()) { + return false; + } + + impl->set_unsigned_long_property(value); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + +bool get_longLongProperty( + JSContext* context, unsigned argc, JS::Value* vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + const JSClass* proto_class = + MozjsNumericTypesTestInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<NumericTypesTestInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + NumericTypesTestInterface* impl = + wrapper_private->wrappable<NumericTypesTestInterface>().get(); + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->long_long_property(), + &result_value); + } + if (!exception_state.is_exception_set()) { + args.rval().set(result_value); + } + return !exception_state.is_exception_set(); +} + +bool set_longLongProperty( + JSContext* context, unsigned argc, JS::Value* vp) { + + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + + const JSClass* proto_class = + MozjsNumericTypesTestInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<NumericTypesTestInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + NumericTypesTestInterface* impl = + wrapper_private->wrappable<NumericTypesTestInterface>().get(); + TypeTraits<int64_t >::ConversionType value; + if (args.length() != 1) { + NOTREACHED(); + return false; + } + FromJSValue(context, args[0], kNoConversionFlags, &exception_state, + &value); + if (exception_state.is_exception_set()) { + return false; + } + + impl->set_long_long_property(value); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + +bool get_unsignedLongLongProperty( + JSContext* context, unsigned argc, JS::Value* vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + const JSClass* proto_class = + MozjsNumericTypesTestInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<NumericTypesTestInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + NumericTypesTestInterface* impl = + wrapper_private->wrappable<NumericTypesTestInterface>().get(); + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->unsigned_long_long_property(), + &result_value); + } + if (!exception_state.is_exception_set()) { + args.rval().set(result_value); + } + return !exception_state.is_exception_set(); +} + +bool set_unsignedLongLongProperty( + JSContext* context, unsigned argc, JS::Value* vp) { + + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + + const JSClass* proto_class = + MozjsNumericTypesTestInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<NumericTypesTestInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + NumericTypesTestInterface* impl = + wrapper_private->wrappable<NumericTypesTestInterface>().get(); + TypeTraits<uint64_t >::ConversionType value; + if (args.length() != 1) { + NOTREACHED(); + return false; + } + FromJSValue(context, args[0], kNoConversionFlags, &exception_state, + &value); + if (exception_state.is_exception_set()) { + return false; + } + + impl->set_unsigned_long_long_property(value); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + +bool get_doubleProperty( + JSContext* context, unsigned argc, JS::Value* vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + const JSClass* proto_class = + MozjsNumericTypesTestInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<NumericTypesTestInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + NumericTypesTestInterface* impl = + wrapper_private->wrappable<NumericTypesTestInterface>().get(); + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->double_property(), + &result_value); + } + if (!exception_state.is_exception_set()) { + args.rval().set(result_value); + } + return !exception_state.is_exception_set(); +} + +bool set_doubleProperty( + JSContext* context, unsigned argc, JS::Value* vp) { + + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + + const JSClass* proto_class = + MozjsNumericTypesTestInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<NumericTypesTestInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + NumericTypesTestInterface* impl = + wrapper_private->wrappable<NumericTypesTestInterface>().get(); + TypeTraits<double >::ConversionType value; + if (args.length() != 1) { + NOTREACHED(); + return false; + } + FromJSValue(context, args[0], (kConversionFlagRestricted), &exception_state, + &value); + if (exception_state.is_exception_set()) { + return false; + } + + impl->set_double_property(value); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + +bool get_unrestrictedDoubleProperty( + JSContext* context, unsigned argc, JS::Value* vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + const JSClass* proto_class = + MozjsNumericTypesTestInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<NumericTypesTestInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + NumericTypesTestInterface* impl = + wrapper_private->wrappable<NumericTypesTestInterface>().get(); + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->unrestricted_double_property(), + &result_value); + } + if (!exception_state.is_exception_set()) { + args.rval().set(result_value); + } + return !exception_state.is_exception_set(); +} + +bool set_unrestrictedDoubleProperty( + JSContext* context, unsigned argc, JS::Value* vp) { + + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + + const JSClass* proto_class = + MozjsNumericTypesTestInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<NumericTypesTestInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + NumericTypesTestInterface* impl = + wrapper_private->wrappable<NumericTypesTestInterface>().get(); + TypeTraits<double >::ConversionType value; + if (args.length() != 1) { + NOTREACHED(); + return false; + } + FromJSValue(context, args[0], kNoConversionFlags, &exception_state, + &value); + if (exception_state.is_exception_set()) { + return false; + } + + impl->set_unrestricted_double_property(value); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + +bool fcn_byteArgumentOperation( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + const JSClass* proto_class = + MozjsNumericTypesTestInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<NumericTypesTestInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + NumericTypesTestInterface* impl = + wrapper_private->wrappable<NumericTypesTestInterface>().get(); + const size_t kMinArguments = 1; + if (args.length() < kMinArguments) { + exception_state.SetSimpleException(script::kInvalidNumberOfArguments); + return false; + } + // Non-optional arguments + TypeTraits<int8_t >::ConversionType arg1; + + DCHECK_LT(0, args.length()); + JS::RootedValue non_optional_value0( + context, args[0]); + FromJSValue(context, + non_optional_value0, + kNoConversionFlags, + &exception_state, &arg1); + if (exception_state.is_exception_set()) { + return false; + } + + impl->ByteArgumentOperation(arg1); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + +bool fcn_byteReturnOperation( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + const JSClass* proto_class = + MozjsNumericTypesTestInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<NumericTypesTestInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + NumericTypesTestInterface* impl = + wrapper_private->wrappable<NumericTypesTestInterface>().get(); + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->ByteReturnOperation(), + &result_value); + } + if (!exception_state.is_exception_set()) { + args.rval().set(result_value); + } + return !exception_state.is_exception_set(); +} + +bool fcn_doubleArgumentOperation( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + const JSClass* proto_class = + MozjsNumericTypesTestInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<NumericTypesTestInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + NumericTypesTestInterface* impl = + wrapper_private->wrappable<NumericTypesTestInterface>().get(); + const size_t kMinArguments = 1; + if (args.length() < kMinArguments) { + exception_state.SetSimpleException(script::kInvalidNumberOfArguments); + return false; + } + // Non-optional arguments + TypeTraits<double >::ConversionType arg1; + + DCHECK_LT(0, args.length()); + JS::RootedValue non_optional_value0( + context, args[0]); + FromJSValue(context, + non_optional_value0, + (kConversionFlagRestricted), + &exception_state, &arg1); + if (exception_state.is_exception_set()) { + return false; + } + + impl->DoubleArgumentOperation(arg1); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + +bool fcn_doubleReturnOperation( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + const JSClass* proto_class = + MozjsNumericTypesTestInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<NumericTypesTestInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + NumericTypesTestInterface* impl = + wrapper_private->wrappable<NumericTypesTestInterface>().get(); + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->DoubleReturnOperation(), + &result_value); + } + if (!exception_state.is_exception_set()) { + args.rval().set(result_value); + } + return !exception_state.is_exception_set(); +} + +bool fcn_longArgumentOperation( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + const JSClass* proto_class = + MozjsNumericTypesTestInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<NumericTypesTestInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + NumericTypesTestInterface* impl = + wrapper_private->wrappable<NumericTypesTestInterface>().get(); + const size_t kMinArguments = 1; + if (args.length() < kMinArguments) { + exception_state.SetSimpleException(script::kInvalidNumberOfArguments); + return false; + } + // Non-optional arguments + TypeTraits<int32_t >::ConversionType arg1; + + DCHECK_LT(0, args.length()); + JS::RootedValue non_optional_value0( + context, args[0]); + FromJSValue(context, + non_optional_value0, + kNoConversionFlags, + &exception_state, &arg1); + if (exception_state.is_exception_set()) { + return false; + } + + impl->LongArgumentOperation(arg1); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + +bool fcn_longLongArgumentOperation( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + const JSClass* proto_class = + MozjsNumericTypesTestInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<NumericTypesTestInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + NumericTypesTestInterface* impl = + wrapper_private->wrappable<NumericTypesTestInterface>().get(); + const size_t kMinArguments = 1; + if (args.length() < kMinArguments) { + exception_state.SetSimpleException(script::kInvalidNumberOfArguments); + return false; + } + // Non-optional arguments + TypeTraits<int64_t >::ConversionType arg1; + + DCHECK_LT(0, args.length()); + JS::RootedValue non_optional_value0( + context, args[0]); + FromJSValue(context, + non_optional_value0, + kNoConversionFlags, + &exception_state, &arg1); + if (exception_state.is_exception_set()) { + return false; + } + + impl->LongLongArgumentOperation(arg1); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + +bool fcn_longLongReturnOperation( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + const JSClass* proto_class = + MozjsNumericTypesTestInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<NumericTypesTestInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + NumericTypesTestInterface* impl = + wrapper_private->wrappable<NumericTypesTestInterface>().get(); + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->LongLongReturnOperation(), + &result_value); + } + if (!exception_state.is_exception_set()) { + args.rval().set(result_value); + } + return !exception_state.is_exception_set(); +} + +bool fcn_longReturnOperation( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + const JSClass* proto_class = + MozjsNumericTypesTestInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<NumericTypesTestInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + NumericTypesTestInterface* impl = + wrapper_private->wrappable<NumericTypesTestInterface>().get(); + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->LongReturnOperation(), + &result_value); + } + if (!exception_state.is_exception_set()) { + args.rval().set(result_value); + } + return !exception_state.is_exception_set(); +} + +bool fcn_octetArgumentOperation( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + const JSClass* proto_class = + MozjsNumericTypesTestInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<NumericTypesTestInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + NumericTypesTestInterface* impl = + wrapper_private->wrappable<NumericTypesTestInterface>().get(); + const size_t kMinArguments = 1; + if (args.length() < kMinArguments) { + exception_state.SetSimpleException(script::kInvalidNumberOfArguments); + return false; + } + // Non-optional arguments + TypeTraits<uint8_t >::ConversionType arg1; + + DCHECK_LT(0, args.length()); + JS::RootedValue non_optional_value0( + context, args[0]); + FromJSValue(context, + non_optional_value0, + kNoConversionFlags, + &exception_state, &arg1); + if (exception_state.is_exception_set()) { + return false; + } + + impl->OctetArgumentOperation(arg1); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + +bool fcn_octetReturnOperation( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + const JSClass* proto_class = + MozjsNumericTypesTestInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<NumericTypesTestInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + NumericTypesTestInterface* impl = + wrapper_private->wrappable<NumericTypesTestInterface>().get(); + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->OctetReturnOperation(), + &result_value); + } + if (!exception_state.is_exception_set()) { + args.rval().set(result_value); + } + return !exception_state.is_exception_set(); +} + +bool fcn_shortArgumentOperation( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + const JSClass* proto_class = + MozjsNumericTypesTestInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<NumericTypesTestInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + NumericTypesTestInterface* impl = + wrapper_private->wrappable<NumericTypesTestInterface>().get(); + const size_t kMinArguments = 1; + if (args.length() < kMinArguments) { + exception_state.SetSimpleException(script::kInvalidNumberOfArguments); + return false; + } + // Non-optional arguments + TypeTraits<int16_t >::ConversionType arg1; + + DCHECK_LT(0, args.length()); + JS::RootedValue non_optional_value0( + context, args[0]); + FromJSValue(context, + non_optional_value0, + kNoConversionFlags, + &exception_state, &arg1); + if (exception_state.is_exception_set()) { + return false; + } + + impl->ShortArgumentOperation(arg1); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + +bool fcn_shortReturnOperation( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + const JSClass* proto_class = + MozjsNumericTypesTestInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<NumericTypesTestInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + NumericTypesTestInterface* impl = + wrapper_private->wrappable<NumericTypesTestInterface>().get(); + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->ShortReturnOperation(), + &result_value); + } + if (!exception_state.is_exception_set()) { + args.rval().set(result_value); + } + return !exception_state.is_exception_set(); +} + +bool fcn_unrestrictedDoubleArgumentOperation( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + const JSClass* proto_class = + MozjsNumericTypesTestInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<NumericTypesTestInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + NumericTypesTestInterface* impl = + wrapper_private->wrappable<NumericTypesTestInterface>().get(); + const size_t kMinArguments = 1; + if (args.length() < kMinArguments) { + exception_state.SetSimpleException(script::kInvalidNumberOfArguments); + return false; + } + // Non-optional arguments + TypeTraits<double >::ConversionType arg1; + + DCHECK_LT(0, args.length()); + JS::RootedValue non_optional_value0( + context, args[0]); + FromJSValue(context, + non_optional_value0, + kNoConversionFlags, + &exception_state, &arg1); + if (exception_state.is_exception_set()) { + return false; + } + + impl->UnrestrictedDoubleArgumentOperation(arg1); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + +bool fcn_unrestrictedDoubleReturnOperation( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + const JSClass* proto_class = + MozjsNumericTypesTestInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<NumericTypesTestInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + NumericTypesTestInterface* impl = + wrapper_private->wrappable<NumericTypesTestInterface>().get(); + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->UnrestrictedDoubleReturnOperation(), + &result_value); + } + if (!exception_state.is_exception_set()) { + args.rval().set(result_value); + } + return !exception_state.is_exception_set(); +} + +bool fcn_unsignedLongArgumentOperation( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + const JSClass* proto_class = + MozjsNumericTypesTestInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<NumericTypesTestInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + NumericTypesTestInterface* impl = + wrapper_private->wrappable<NumericTypesTestInterface>().get(); + const size_t kMinArguments = 1; + if (args.length() < kMinArguments) { + exception_state.SetSimpleException(script::kInvalidNumberOfArguments); + return false; + } + // Non-optional arguments + TypeTraits<uint32_t >::ConversionType arg1; + + DCHECK_LT(0, args.length()); + JS::RootedValue non_optional_value0( + context, args[0]); + FromJSValue(context, + non_optional_value0, + kNoConversionFlags, + &exception_state, &arg1); + if (exception_state.is_exception_set()) { + return false; + } + + impl->UnsignedLongArgumentOperation(arg1); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + +bool fcn_unsignedLongLongArgumentOperation( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + const JSClass* proto_class = + MozjsNumericTypesTestInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<NumericTypesTestInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + NumericTypesTestInterface* impl = + wrapper_private->wrappable<NumericTypesTestInterface>().get(); + const size_t kMinArguments = 1; + if (args.length() < kMinArguments) { + exception_state.SetSimpleException(script::kInvalidNumberOfArguments); + return false; + } + // Non-optional arguments + TypeTraits<uint64_t >::ConversionType arg1; + + DCHECK_LT(0, args.length()); + JS::RootedValue non_optional_value0( + context, args[0]); + FromJSValue(context, + non_optional_value0, + kNoConversionFlags, + &exception_state, &arg1); + if (exception_state.is_exception_set()) { + return false; + } + + impl->UnsignedLongLongArgumentOperation(arg1); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + +bool fcn_unsignedLongLongReturnOperation( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + const JSClass* proto_class = + MozjsNumericTypesTestInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<NumericTypesTestInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + NumericTypesTestInterface* impl = + wrapper_private->wrappable<NumericTypesTestInterface>().get(); + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->UnsignedLongLongReturnOperation(), + &result_value); + } + if (!exception_state.is_exception_set()) { + args.rval().set(result_value); + } + return !exception_state.is_exception_set(); +} + +bool fcn_unsignedLongReturnOperation( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + const JSClass* proto_class = + MozjsNumericTypesTestInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<NumericTypesTestInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + NumericTypesTestInterface* impl = + wrapper_private->wrappable<NumericTypesTestInterface>().get(); + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->UnsignedLongReturnOperation(), + &result_value); + } + if (!exception_state.is_exception_set()) { + args.rval().set(result_value); + } + return !exception_state.is_exception_set(); +} + +bool fcn_unsignedShortArgumentOperation( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + const JSClass* proto_class = + MozjsNumericTypesTestInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<NumericTypesTestInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + NumericTypesTestInterface* impl = + wrapper_private->wrappable<NumericTypesTestInterface>().get(); + const size_t kMinArguments = 1; + if (args.length() < kMinArguments) { + exception_state.SetSimpleException(script::kInvalidNumberOfArguments); + return false; + } + // Non-optional arguments + TypeTraits<uint16_t >::ConversionType arg1; + + DCHECK_LT(0, args.length()); + JS::RootedValue non_optional_value0( + context, args[0]); + FromJSValue(context, + non_optional_value0, + kNoConversionFlags, + &exception_state, &arg1); + if (exception_state.is_exception_set()) { + return false; + } + + impl->UnsignedShortArgumentOperation(arg1); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + +bool fcn_unsignedShortReturnOperation( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + const JSClass* proto_class = + MozjsNumericTypesTestInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<NumericTypesTestInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + NumericTypesTestInterface* impl = + wrapper_private->wrappable<NumericTypesTestInterface>().get(); + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->UnsignedShortReturnOperation(), + &result_value); + } + if (!exception_state.is_exception_set()) { + args.rval().set(result_value); + } + return !exception_state.is_exception_set(); +} + + + +const JSPropertySpec prototype_properties[] = { + { // Read/Write property + "byteProperty", + JSPROP_SHARED | JSPROP_ENUMERATE, + { { &get_byteProperty, NULL } }, + { { &set_byteProperty, NULL } }, + }, + { // Read/Write property + "octetProperty", + JSPROP_SHARED | JSPROP_ENUMERATE, + { { &get_octetProperty, NULL } }, + { { &set_octetProperty, NULL } }, + }, + { // Read/Write property + "shortProperty", + JSPROP_SHARED | JSPROP_ENUMERATE, + { { &get_shortProperty, NULL } }, + { { &set_shortProperty, NULL } }, + }, + { // Read/Write property + "unsignedShortProperty", + JSPROP_SHARED | JSPROP_ENUMERATE, + { { &get_unsignedShortProperty, NULL } }, + { { &set_unsignedShortProperty, NULL } }, + }, + { // Read/Write property + "longProperty", + JSPROP_SHARED | JSPROP_ENUMERATE, + { { &get_longProperty, NULL } }, + { { &set_longProperty, NULL } }, + }, + { // Read/Write property + "unsignedLongProperty", + JSPROP_SHARED | JSPROP_ENUMERATE, + { { &get_unsignedLongProperty, NULL } }, + { { &set_unsignedLongProperty, NULL } }, + }, + { // Read/Write property + "longLongProperty", + JSPROP_SHARED | JSPROP_ENUMERATE, + { { &get_longLongProperty, NULL } }, + { { &set_longLongProperty, NULL } }, + }, + { // Read/Write property + "unsignedLongLongProperty", + JSPROP_SHARED | JSPROP_ENUMERATE, + { { &get_unsignedLongLongProperty, NULL } }, + { { &set_unsignedLongLongProperty, NULL } }, + }, + { // Read/Write property + "doubleProperty", + JSPROP_SHARED | JSPROP_ENUMERATE, + { { &get_doubleProperty, NULL } }, + { { &set_doubleProperty, NULL } }, + }, + { // Read/Write property + "unrestrictedDoubleProperty", + JSPROP_SHARED | JSPROP_ENUMERATE, + { { &get_unrestrictedDoubleProperty, NULL } }, + { { &set_unrestrictedDoubleProperty, NULL } }, + }, + JS_PS_END +}; + +const JSFunctionSpec prototype_functions[] = { + JS_FNSPEC( + "byteArgumentOperation", fcn_byteArgumentOperation, NULL, + 1, JSPROP_ENUMERATE, NULL), + JS_FNSPEC( + "byteReturnOperation", fcn_byteReturnOperation, NULL, + 0, JSPROP_ENUMERATE, NULL), + JS_FNSPEC( + "doubleArgumentOperation", fcn_doubleArgumentOperation, NULL, + 1, JSPROP_ENUMERATE, NULL), + JS_FNSPEC( + "doubleReturnOperation", fcn_doubleReturnOperation, NULL, + 0, JSPROP_ENUMERATE, NULL), + JS_FNSPEC( + "longArgumentOperation", fcn_longArgumentOperation, NULL, + 1, JSPROP_ENUMERATE, NULL), + JS_FNSPEC( + "longLongArgumentOperation", fcn_longLongArgumentOperation, NULL, + 1, JSPROP_ENUMERATE, NULL), + JS_FNSPEC( + "longLongReturnOperation", fcn_longLongReturnOperation, NULL, + 0, JSPROP_ENUMERATE, NULL), + JS_FNSPEC( + "longReturnOperation", fcn_longReturnOperation, NULL, + 0, JSPROP_ENUMERATE, NULL), + JS_FNSPEC( + "octetArgumentOperation", fcn_octetArgumentOperation, NULL, + 1, JSPROP_ENUMERATE, NULL), + JS_FNSPEC( + "octetReturnOperation", fcn_octetReturnOperation, NULL, + 0, JSPROP_ENUMERATE, NULL), + JS_FNSPEC( + "shortArgumentOperation", fcn_shortArgumentOperation, NULL, + 1, JSPROP_ENUMERATE, NULL), + JS_FNSPEC( + "shortReturnOperation", fcn_shortReturnOperation, NULL, + 0, JSPROP_ENUMERATE, NULL), + JS_FNSPEC( + "unrestrictedDoubleArgumentOperation", fcn_unrestrictedDoubleArgumentOperation, NULL, + 1, JSPROP_ENUMERATE, NULL), + JS_FNSPEC( + "unrestrictedDoubleReturnOperation", fcn_unrestrictedDoubleReturnOperation, NULL, + 0, JSPROP_ENUMERATE, NULL), + JS_FNSPEC( + "unsignedLongArgumentOperation", fcn_unsignedLongArgumentOperation, NULL, + 1, JSPROP_ENUMERATE, NULL), + JS_FNSPEC( + "unsignedLongLongArgumentOperation", fcn_unsignedLongLongArgumentOperation, NULL, + 1, JSPROP_ENUMERATE, NULL), + JS_FNSPEC( + "unsignedLongLongReturnOperation", fcn_unsignedLongLongReturnOperation, NULL, + 0, JSPROP_ENUMERATE, NULL), + JS_FNSPEC( + "unsignedLongReturnOperation", fcn_unsignedLongReturnOperation, NULL, + 0, JSPROP_ENUMERATE, NULL), + JS_FNSPEC( + "unsignedShortArgumentOperation", fcn_unsignedShortArgumentOperation, NULL, + 1, JSPROP_ENUMERATE, NULL), + JS_FNSPEC( + "unsignedShortReturnOperation", fcn_unsignedShortReturnOperation, NULL, + 0, JSPROP_ENUMERATE, NULL), + JS_FS_END +}; + +const JSPropertySpec interface_object_properties[] = { + JS_PS_END +}; + +const JSFunctionSpec interface_object_functions[] = { + JS_FS_END +}; + +const JSPropertySpec own_properties[] = { + JS_PS_END +}; + +void InitializePrototypeAndInterfaceObject( + InterfaceData* interface_data, JSContext* context, + JS::HandleObject global_object) { + DCHECK(!interface_data->prototype); + DCHECK(!interface_data->interface_object); + DCHECK(JS_IsGlobalObject(global_object)); + + JS::RootedObject parent_prototype( + context, JS_GetObjectPrototype(context, global_object)); + DCHECK(parent_prototype); + + interface_data->prototype = JS_NewObjectWithGivenProto( + context, &prototype_class_definition, parent_prototype + ); + + JS::RootedObject rooted_prototype(context, interface_data->prototype); + bool success = JS_DefineProperties( + context, + rooted_prototype, + prototype_properties); + + DCHECK(success); + success = JS_DefineFunctions( + context, rooted_prototype, prototype_functions); + DCHECK(success); + + JS::RootedObject function_prototype( + context, JS_GetFunctionPrototype(context, global_object)); + DCHECK(function_prototype); + // Create the Interface object. + interface_data->interface_object = JS_NewObjectWithGivenProto( + context, &interface_object_class_definition, + function_prototype); + + // Add the InterfaceObject.name property. + JS::RootedObject rooted_interface_object( + context, interface_data->interface_object); + JS::RootedValue name_value(context); + const char name[] = + "NumericTypesTestInterface"; + name_value.setString(JS_NewStringCopyZ(context, name)); + success = JS_DefineProperty( + context, rooted_interface_object, "name", name_value, JSPROP_READONLY, + NULL, NULL); + DCHECK(success); + + // Define interface object properties (including constants). + success = JS_DefineProperties(context, rooted_interface_object, + interface_object_properties); + DCHECK(success); + // Define interface object functions (static). + success = JS_DefineFunctions(context, rooted_interface_object, + interface_object_functions); + DCHECK(success); + + // Set the Prototype.constructor and Constructor.prototype properties. + DCHECK(interface_data->interface_object); + DCHECK(interface_data->prototype); + success = JS_LinkConstructorAndPrototype( + context, + rooted_interface_object, + rooted_prototype); + DCHECK(success); +} + +InterfaceData* GetInterfaceData(JSContext* context) { + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + // Use the address of the properties definition for this interface as a + // unique key for looking up the InterfaceData for this interface. + intptr_t key = reinterpret_cast<intptr_t>(&own_properties); + InterfaceData* interface_data = global_environment->GetInterfaceData(key); + if (!interface_data) { + interface_data = new InterfaceData(); + DCHECK(interface_data); + global_environment->CacheInterfaceData(key, interface_data); + DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key)); + } + return interface_data; +} + +} // namespace + +// static +JSObject* MozjsNumericTypesTestInterface::CreateProxy( + JSContext* context, const scoped_refptr<Wrappable>& wrappable) { + DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); + JS::RootedObject global_object( + context, + MozjsGlobalEnvironment::GetFromContext(context)->global_object()); + DCHECK(global_object); + + InterfaceData* interface_data = GetInterfaceData(context); + JS::RootedObject prototype(context, GetPrototype(context, global_object)); + DCHECK(prototype); + JS::RootedObject new_object( + context, + JS_NewObjectWithGivenProto( + context, &instance_class_definition, prototype)); + DCHECK(new_object); + JS::RootedObject proxy(context, + ProxyHandler::NewProxy( + context, proxy_handler.Pointer(), new_object, prototype)); + WrapperPrivate::AddPrivateData(context, proxy, wrappable); + return proxy; +} + +// static +const JSClass* MozjsNumericTypesTestInterface::PrototypeClass( + JSContext* context) { + DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); + JS::RootedObject global_object( + context, + MozjsGlobalEnvironment::GetFromContext(context)->global_object()); + DCHECK(global_object); + + JS::RootedObject prototype(context, GetPrototype(context, global_object)); + const JSClass* proto_class = JS_GetClass(prototype); + return proto_class; +} + +// static +JSObject* MozjsNumericTypesTestInterface::GetPrototype( + JSContext* context, JS::HandleObject global_object) { + DCHECK(JS_IsGlobalObject(global_object)); + + InterfaceData* interface_data = GetInterfaceData(context); + if (!interface_data->prototype) { + // Create new prototype that has all the props and methods + InitializePrototypeAndInterfaceObject( + interface_data, context, global_object); + } + DCHECK(interface_data->prototype); + return interface_data->prototype; +} + +// static +JSObject* MozjsNumericTypesTestInterface::GetInterfaceObject( + JSContext* context, JS::HandleObject global_object) { + DCHECK(JS_IsGlobalObject(global_object)); + + InterfaceData* interface_data = GetInterfaceData(context); + if (!interface_data->interface_object) { + InitializePrototypeAndInterfaceObject( + interface_data, context, global_object); + } + DCHECK(interface_data->interface_object); + return interface_data->interface_object; +} + + +namespace { +} // namespace + + +} // namespace testing +} // namespace bindings +} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_numeric_types_test_interface.h b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_numeric_types_test_interface.h new file mode 100644 index 0000000..bced5f0 --- /dev/null +++ b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_numeric_types_test_interface.h
@@ -0,0 +1,52 @@ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// clang-format off + +// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! +// Auto-generated from template: bindings/mozjs-45/templates/interface.h.template + +#ifndef MozjsNumericTypesTestInterface_h +#define MozjsNumericTypesTestInterface_h + +#include "base/hash_tables.h" +#include "base/lazy_instance.h" +#include "base/memory/ref_counted.h" +#include "base/threading/thread_checker.h" +#include "cobalt/base/polymorphic_downcast.h" +#include "cobalt/script/wrappable.h" +#include "cobalt/bindings/testing/numeric_types_test_interface.h" + +#include "third_party/mozjs-45/js/src/jsapi.h" + +namespace cobalt { +namespace bindings { +namespace testing { + +class MozjsNumericTypesTestInterface { + public: + static JSObject* CreateProxy(JSContext* context, + const scoped_refptr<script::Wrappable>& wrappable); + static const JSClass* PrototypeClass(JSContext* context); + static JSObject* GetPrototype(JSContext* context, + JS::HandleObject global_object); + static JSObject* GetInterfaceObject(JSContext* context, + JS::HandleObject global_object); +}; + +} // namespace testing +} // namespace bindings +} // namespace cobalt + +#endif // MozjsNumericTypesTestInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_object_type_bindings_interface.cc b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_object_type_bindings_interface.cc new file mode 100644 index 0000000..19677f8 --- /dev/null +++ b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_object_type_bindings_interface.cc
@@ -0,0 +1,702 @@ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// clang-format off + +// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! +// Auto-generated from template: bindings/mozjs-45/templates/interface.cc.template + +#include "cobalt/bindings/testing/mozjs_object_type_bindings_interface.h" + +#include "base/debug/trace_event.h" +#include "cobalt/base/polymorphic_downcast.h" +#include "cobalt/script/global_environment.h" +#include "cobalt/script/opaque_handle.h" +#include "cobalt/script/script_value.h" +#include "cobalt/bindings/testing/arbitrary_interface.h" +#include "cobalt/bindings/testing/base_interface.h" +#include "cobalt/bindings/testing/derived_interface.h" +#include "cobalt/bindings/testing/mozjs_arbitrary_interface.h" +#include "cobalt/bindings/testing/mozjs_base_interface.h" +#include "cobalt/bindings/testing/mozjs_derived_interface.h" + +#include "base/lazy_instance.h" +#include "cobalt/script/exception_state.h" +#include "cobalt/script/mozjs-45/callback_function_conversion.h" +#include "cobalt/script/mozjs-45/conversion_helpers.h" +#include "cobalt/script/mozjs-45/mozjs_callback_function.h" +#include "cobalt/script/mozjs-45/mozjs_exception_state.h" +#include "cobalt/script/mozjs-45/mozjs_global_environment.h" +#include "cobalt/script/mozjs-45/mozjs_object_handle.h" +#include "cobalt/script/mozjs-45/mozjs_property_enumerator.h" +#include "cobalt/script/mozjs-45/mozjs_user_object_holder.h" +#include "cobalt/script/mozjs-45/proxy_handler.h" +#include "cobalt/script/mozjs-45/type_traits.h" +#include "cobalt/script/mozjs-45/wrapper_factory.h" +#include "cobalt/script/mozjs-45/wrapper_private.h" +#include "cobalt/script/property_enumerator.h" +#include "cobalt/script/sequence.h" +#include "third_party/mozjs-45/js/src/jsapi.h" +#include "third_party/mozjs-45/js/src/jsfriendapi.h" + +namespace { +using cobalt::bindings::testing::ObjectTypeBindingsInterface; +using cobalt::bindings::testing::MozjsObjectTypeBindingsInterface; +using cobalt::bindings::testing::ArbitraryInterface; +using cobalt::bindings::testing::BaseInterface; +using cobalt::bindings::testing::DerivedInterface; +using cobalt::bindings::testing::MozjsArbitraryInterface; +using cobalt::bindings::testing::MozjsBaseInterface; +using cobalt::bindings::testing::MozjsDerivedInterface; +using cobalt::script::CallbackInterfaceTraits; +using cobalt::script::GlobalEnvironment; +using cobalt::script::OpaqueHandle; +using cobalt::script::OpaqueHandleHolder; +using cobalt::script::ScriptValue; +using cobalt::script::Wrappable; + +using cobalt::script::CallbackFunction; +using cobalt::script::CallbackInterfaceTraits; +using cobalt::script::ExceptionState; +using cobalt::script::Wrappable; +using cobalt::script::mozjs::FromJSValue; +using cobalt::script::mozjs::InterfaceData; +using cobalt::script::mozjs::MozjsCallbackFunction; +using cobalt::script::mozjs::MozjsExceptionState; +using cobalt::script::mozjs::MozjsGlobalEnvironment; +using cobalt::script::mozjs::MozjsPropertyEnumerator; +using cobalt::script::mozjs::MozjsUserObjectHolder; +using cobalt::script::mozjs::ProxyHandler; +using cobalt::script::mozjs::ToJSValue; +using cobalt::script::mozjs::TypeTraits; +using cobalt::script::mozjs::WrapperFactory; +using cobalt::script::mozjs::WrapperPrivate; +using cobalt::script::mozjs::kConversionFlagNullable; +using cobalt::script::mozjs::kConversionFlagRestricted; +using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString; +using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString; +using cobalt::script::mozjs::kNoConversionFlags; +} // namespace + +namespace cobalt { +namespace bindings { +namespace testing { + +namespace { + +class MozjsObjectTypeBindingsInterfaceHandler : public ProxyHandler { + public: + MozjsObjectTypeBindingsInterfaceHandler() + : ProxyHandler(indexed_property_hooks, named_property_hooks) {} + + private: + static NamedPropertyHooks named_property_hooks; + static IndexedPropertyHooks indexed_property_hooks; +}; + +ProxyHandler::NamedPropertyHooks +MozjsObjectTypeBindingsInterfaceHandler::named_property_hooks = { + NULL, + NULL, + NULL, + NULL, + NULL, +}; +ProxyHandler::IndexedPropertyHooks +MozjsObjectTypeBindingsInterfaceHandler::indexed_property_hooks = { + NULL, + NULL, + NULL, + NULL, + NULL, +}; + +static base::LazyInstance<MozjsObjectTypeBindingsInterfaceHandler> + proxy_handler; + +bool HasInstance(JSContext *context, JS::HandleObject type, + JS::MutableHandleValue vp, bool *success) { + JS::RootedObject global_object( + context, JS_GetGlobalForObject(context, type)); + DCHECK(global_object); + + JS::RootedObject prototype( + context, MozjsObjectTypeBindingsInterface::GetPrototype(context, global_object)); + + // |IsDelegate| walks the prototype chain of an object returning true if + // .prototype is found. + bool is_delegate; + if (!IsDelegate(context, prototype, vp, &is_delegate)) { + *success = false; + return false; + } + + *success = is_delegate; + return true; +} + +const JSClass instance_class_definition = { + "ObjectTypeBindingsInterface", + 0 | JSCLASS_HAS_PRIVATE, + NULL, // addProperty + NULL, // delProperty + NULL, // getProperty + NULL, // setProperty + NULL, // enumerate + NULL, // resolve + NULL, // mayResolve + &WrapperPrivate::Finalizer, // finalize + NULL, // call + NULL, // hasInstance + NULL, // construct + &WrapperPrivate::Trace, // trace +}; + +const JSClass prototype_class_definition = { + "ObjectTypeBindingsInterfacePrototype", +}; + +const JSClass interface_object_class_definition = { + "ObjectTypeBindingsInterfaceConstructor", + 0, + NULL, // addProperty + NULL, // delProperty + NULL, // getProperty + NULL, // setProperty + NULL, // enumerate + NULL, // resolve + NULL, // mayResolve + NULL, // finalize + NULL, // call + &HasInstance, + NULL, +}; + +bool get_arbitraryObject( + JSContext* context, unsigned argc, JS::Value* vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + const JSClass* proto_class = + MozjsObjectTypeBindingsInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<ObjectTypeBindingsInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + ObjectTypeBindingsInterface* impl = + wrapper_private->wrappable<ObjectTypeBindingsInterface>().get(); + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->arbitrary_object(), + &result_value); + } + if (!exception_state.is_exception_set()) { + args.rval().set(result_value); + } + return !exception_state.is_exception_set(); +} + +bool set_arbitraryObject( + JSContext* context, unsigned argc, JS::Value* vp) { + + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + + const JSClass* proto_class = + MozjsObjectTypeBindingsInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<ObjectTypeBindingsInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + ObjectTypeBindingsInterface* impl = + wrapper_private->wrappable<ObjectTypeBindingsInterface>().get(); + TypeTraits<scoped_refptr<ArbitraryInterface> >::ConversionType value; + if (args.length() != 1) { + NOTREACHED(); + return false; + } + FromJSValue(context, args[0], kNoConversionFlags, &exception_state, + &value); + if (exception_state.is_exception_set()) { + return false; + } + + impl->set_arbitrary_object(value); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + +bool get_baseInterface( + JSContext* context, unsigned argc, JS::Value* vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + const JSClass* proto_class = + MozjsObjectTypeBindingsInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<ObjectTypeBindingsInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + ObjectTypeBindingsInterface* impl = + wrapper_private->wrappable<ObjectTypeBindingsInterface>().get(); + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->base_interface(), + &result_value); + } + if (!exception_state.is_exception_set()) { + args.rval().set(result_value); + } + return !exception_state.is_exception_set(); +} + + +bool get_derivedInterface( + JSContext* context, unsigned argc, JS::Value* vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + const JSClass* proto_class = + MozjsObjectTypeBindingsInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<ObjectTypeBindingsInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + ObjectTypeBindingsInterface* impl = + wrapper_private->wrappable<ObjectTypeBindingsInterface>().get(); + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->derived_interface(), + &result_value); + } + if (!exception_state.is_exception_set()) { + args.rval().set(result_value); + } + return !exception_state.is_exception_set(); +} + +bool set_derivedInterface( + JSContext* context, unsigned argc, JS::Value* vp) { + + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + + const JSClass* proto_class = + MozjsObjectTypeBindingsInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<ObjectTypeBindingsInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + ObjectTypeBindingsInterface* impl = + wrapper_private->wrappable<ObjectTypeBindingsInterface>().get(); + TypeTraits<scoped_refptr<DerivedInterface> >::ConversionType value; + if (args.length() != 1) { + NOTREACHED(); + return false; + } + FromJSValue(context, args[0], kNoConversionFlags, &exception_state, + &value); + if (exception_state.is_exception_set()) { + return false; + } + + impl->set_derived_interface(value); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + +bool get_objectProperty( + JSContext* context, unsigned argc, JS::Value* vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + const JSClass* proto_class = + MozjsObjectTypeBindingsInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<ObjectTypeBindingsInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + ObjectTypeBindingsInterface* impl = + wrapper_private->wrappable<ObjectTypeBindingsInterface>().get(); + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->object_property(), + &result_value); + } + if (!exception_state.is_exception_set()) { + args.rval().set(result_value); + } + return !exception_state.is_exception_set(); +} + +bool set_objectProperty( + JSContext* context, unsigned argc, JS::Value* vp) { + + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + + const JSClass* proto_class = + MozjsObjectTypeBindingsInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<ObjectTypeBindingsInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + ObjectTypeBindingsInterface* impl = + wrapper_private->wrappable<ObjectTypeBindingsInterface>().get(); + TypeTraits<OpaqueHandle >::ConversionType value; + if (args.length() != 1) { + NOTREACHED(); + return false; + } + FromJSValue(context, args[0], (kConversionFlagNullable), &exception_state, + &value); + if (exception_state.is_exception_set()) { + return false; + } + + impl->set_object_property(value); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + + + +const JSPropertySpec prototype_properties[] = { + { // Read/Write property + "arbitraryObject", + JSPROP_SHARED | JSPROP_ENUMERATE, + { { &get_arbitraryObject, NULL } }, + { { &set_arbitraryObject, NULL } }, + }, + { // Readonly attribute + "baseInterface", + JSPROP_SHARED | JSPROP_ENUMERATE, + { { &get_baseInterface, NULL } }, + JSNATIVE_WRAPPER(NULL), + }, + { // Read/Write property + "derivedInterface", + JSPROP_SHARED | JSPROP_ENUMERATE, + { { &get_derivedInterface, NULL } }, + { { &set_derivedInterface, NULL } }, + }, + { // Read/Write property + "objectProperty", + JSPROP_SHARED | JSPROP_ENUMERATE, + { { &get_objectProperty, NULL } }, + { { &set_objectProperty, NULL } }, + }, + JS_PS_END +}; + +const JSFunctionSpec prototype_functions[] = { + JS_FS_END +}; + +const JSPropertySpec interface_object_properties[] = { + JS_PS_END +}; + +const JSFunctionSpec interface_object_functions[] = { + JS_FS_END +}; + +const JSPropertySpec own_properties[] = { + JS_PS_END +}; + +void InitializePrototypeAndInterfaceObject( + InterfaceData* interface_data, JSContext* context, + JS::HandleObject global_object) { + DCHECK(!interface_data->prototype); + DCHECK(!interface_data->interface_object); + DCHECK(JS_IsGlobalObject(global_object)); + + JS::RootedObject parent_prototype( + context, JS_GetObjectPrototype(context, global_object)); + DCHECK(parent_prototype); + + interface_data->prototype = JS_NewObjectWithGivenProto( + context, &prototype_class_definition, parent_prototype + ); + + JS::RootedObject rooted_prototype(context, interface_data->prototype); + bool success = JS_DefineProperties( + context, + rooted_prototype, + prototype_properties); + + DCHECK(success); + success = JS_DefineFunctions( + context, rooted_prototype, prototype_functions); + DCHECK(success); + + JS::RootedObject function_prototype( + context, JS_GetFunctionPrototype(context, global_object)); + DCHECK(function_prototype); + // Create the Interface object. + interface_data->interface_object = JS_NewObjectWithGivenProto( + context, &interface_object_class_definition, + function_prototype); + + // Add the InterfaceObject.name property. + JS::RootedObject rooted_interface_object( + context, interface_data->interface_object); + JS::RootedValue name_value(context); + const char name[] = + "ObjectTypeBindingsInterface"; + name_value.setString(JS_NewStringCopyZ(context, name)); + success = JS_DefineProperty( + context, rooted_interface_object, "name", name_value, JSPROP_READONLY, + NULL, NULL); + DCHECK(success); + + // Define interface object properties (including constants). + success = JS_DefineProperties(context, rooted_interface_object, + interface_object_properties); + DCHECK(success); + // Define interface object functions (static). + success = JS_DefineFunctions(context, rooted_interface_object, + interface_object_functions); + DCHECK(success); + + // Set the Prototype.constructor and Constructor.prototype properties. + DCHECK(interface_data->interface_object); + DCHECK(interface_data->prototype); + success = JS_LinkConstructorAndPrototype( + context, + rooted_interface_object, + rooted_prototype); + DCHECK(success); +} + +InterfaceData* GetInterfaceData(JSContext* context) { + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + // Use the address of the properties definition for this interface as a + // unique key for looking up the InterfaceData for this interface. + intptr_t key = reinterpret_cast<intptr_t>(&own_properties); + InterfaceData* interface_data = global_environment->GetInterfaceData(key); + if (!interface_data) { + interface_data = new InterfaceData(); + DCHECK(interface_data); + global_environment->CacheInterfaceData(key, interface_data); + DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key)); + } + return interface_data; +} + +} // namespace + +// static +JSObject* MozjsObjectTypeBindingsInterface::CreateProxy( + JSContext* context, const scoped_refptr<Wrappable>& wrappable) { + DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); + JS::RootedObject global_object( + context, + MozjsGlobalEnvironment::GetFromContext(context)->global_object()); + DCHECK(global_object); + + InterfaceData* interface_data = GetInterfaceData(context); + JS::RootedObject prototype(context, GetPrototype(context, global_object)); + DCHECK(prototype); + JS::RootedObject new_object( + context, + JS_NewObjectWithGivenProto( + context, &instance_class_definition, prototype)); + DCHECK(new_object); + JS::RootedObject proxy(context, + ProxyHandler::NewProxy( + context, proxy_handler.Pointer(), new_object, prototype)); + WrapperPrivate::AddPrivateData(context, proxy, wrappable); + return proxy; +} + +// static +const JSClass* MozjsObjectTypeBindingsInterface::PrototypeClass( + JSContext* context) { + DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); + JS::RootedObject global_object( + context, + MozjsGlobalEnvironment::GetFromContext(context)->global_object()); + DCHECK(global_object); + + JS::RootedObject prototype(context, GetPrototype(context, global_object)); + const JSClass* proto_class = JS_GetClass(prototype); + return proto_class; +} + +// static +JSObject* MozjsObjectTypeBindingsInterface::GetPrototype( + JSContext* context, JS::HandleObject global_object) { + DCHECK(JS_IsGlobalObject(global_object)); + + InterfaceData* interface_data = GetInterfaceData(context); + if (!interface_data->prototype) { + // Create new prototype that has all the props and methods + InitializePrototypeAndInterfaceObject( + interface_data, context, global_object); + } + DCHECK(interface_data->prototype); + return interface_data->prototype; +} + +// static +JSObject* MozjsObjectTypeBindingsInterface::GetInterfaceObject( + JSContext* context, JS::HandleObject global_object) { + DCHECK(JS_IsGlobalObject(global_object)); + + InterfaceData* interface_data = GetInterfaceData(context); + if (!interface_data->interface_object) { + InitializePrototypeAndInterfaceObject( + interface_data, context, global_object); + } + DCHECK(interface_data->interface_object); + return interface_data->interface_object; +} + + +namespace { +} // namespace + + +} // namespace testing +} // namespace bindings +} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_object_type_bindings_interface.h b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_object_type_bindings_interface.h new file mode 100644 index 0000000..c0f3c06 --- /dev/null +++ b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_object_type_bindings_interface.h
@@ -0,0 +1,52 @@ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// clang-format off + +// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! +// Auto-generated from template: bindings/mozjs-45/templates/interface.h.template + +#ifndef MozjsObjectTypeBindingsInterface_h +#define MozjsObjectTypeBindingsInterface_h + +#include "base/hash_tables.h" +#include "base/lazy_instance.h" +#include "base/memory/ref_counted.h" +#include "base/threading/thread_checker.h" +#include "cobalt/base/polymorphic_downcast.h" +#include "cobalt/script/wrappable.h" +#include "cobalt/bindings/testing/object_type_bindings_interface.h" + +#include "third_party/mozjs-45/js/src/jsapi.h" + +namespace cobalt { +namespace bindings { +namespace testing { + +class MozjsObjectTypeBindingsInterface { + public: + static JSObject* CreateProxy(JSContext* context, + const scoped_refptr<script::Wrappable>& wrappable); + static const JSClass* PrototypeClass(JSContext* context); + static JSObject* GetPrototype(JSContext* context, + JS::HandleObject global_object); + static JSObject* GetInterfaceObject(JSContext* context, + JS::HandleObject global_object); +}; + +} // namespace testing +} // namespace bindings +} // namespace cobalt + +#endif // MozjsObjectTypeBindingsInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_operations_test_interface.cc b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_operations_test_interface.cc new file mode 100644 index 0000000..7bc6ca2 --- /dev/null +++ b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_operations_test_interface.cc
@@ -0,0 +1,1924 @@ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// clang-format off + +// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! +// Auto-generated from template: bindings/mozjs-45/templates/interface.cc.template + +#include "cobalt/bindings/testing/mozjs_operations_test_interface.h" + +#include "base/debug/trace_event.h" +#include "cobalt/base/polymorphic_downcast.h" +#include "cobalt/script/global_environment.h" +#include "cobalt/script/opaque_handle.h" +#include "cobalt/script/script_value.h" +#include "cobalt/bindings/testing/arbitrary_interface.h" +#include "cobalt/bindings/testing/mozjs_arbitrary_interface.h" + +#include "base/lazy_instance.h" +#include "cobalt/script/exception_state.h" +#include "cobalt/script/mozjs-45/callback_function_conversion.h" +#include "cobalt/script/mozjs-45/conversion_helpers.h" +#include "cobalt/script/mozjs-45/mozjs_callback_function.h" +#include "cobalt/script/mozjs-45/mozjs_exception_state.h" +#include "cobalt/script/mozjs-45/mozjs_global_environment.h" +#include "cobalt/script/mozjs-45/mozjs_object_handle.h" +#include "cobalt/script/mozjs-45/mozjs_property_enumerator.h" +#include "cobalt/script/mozjs-45/mozjs_user_object_holder.h" +#include "cobalt/script/mozjs-45/proxy_handler.h" +#include "cobalt/script/mozjs-45/type_traits.h" +#include "cobalt/script/mozjs-45/wrapper_factory.h" +#include "cobalt/script/mozjs-45/wrapper_private.h" +#include "cobalt/script/property_enumerator.h" +#include "cobalt/script/sequence.h" +#include "third_party/mozjs-45/js/src/jsapi.h" +#include "third_party/mozjs-45/js/src/jsfriendapi.h" + +namespace { +using cobalt::bindings::testing::OperationsTestInterface; +using cobalt::bindings::testing::MozjsOperationsTestInterface; +using cobalt::bindings::testing::ArbitraryInterface; +using cobalt::bindings::testing::MozjsArbitraryInterface; +using cobalt::script::CallbackInterfaceTraits; +using cobalt::script::GlobalEnvironment; +using cobalt::script::OpaqueHandle; +using cobalt::script::OpaqueHandleHolder; +using cobalt::script::ScriptValue; +using cobalt::script::Wrappable; + +using cobalt::script::CallbackFunction; +using cobalt::script::CallbackInterfaceTraits; +using cobalt::script::ExceptionState; +using cobalt::script::Wrappable; +using cobalt::script::mozjs::FromJSValue; +using cobalt::script::mozjs::InterfaceData; +using cobalt::script::mozjs::MozjsCallbackFunction; +using cobalt::script::mozjs::MozjsExceptionState; +using cobalt::script::mozjs::MozjsGlobalEnvironment; +using cobalt::script::mozjs::MozjsPropertyEnumerator; +using cobalt::script::mozjs::MozjsUserObjectHolder; +using cobalt::script::mozjs::ProxyHandler; +using cobalt::script::mozjs::ToJSValue; +using cobalt::script::mozjs::TypeTraits; +using cobalt::script::mozjs::WrapperFactory; +using cobalt::script::mozjs::WrapperPrivate; +using cobalt::script::mozjs::kConversionFlagNullable; +using cobalt::script::mozjs::kConversionFlagRestricted; +using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString; +using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString; +using cobalt::script::mozjs::kNoConversionFlags; +} // namespace + +namespace cobalt { +namespace bindings { +namespace testing { + +namespace { + +class MozjsOperationsTestInterfaceHandler : public ProxyHandler { + public: + MozjsOperationsTestInterfaceHandler() + : ProxyHandler(indexed_property_hooks, named_property_hooks) {} + + private: + static NamedPropertyHooks named_property_hooks; + static IndexedPropertyHooks indexed_property_hooks; +}; + +ProxyHandler::NamedPropertyHooks +MozjsOperationsTestInterfaceHandler::named_property_hooks = { + NULL, + NULL, + NULL, + NULL, + NULL, +}; +ProxyHandler::IndexedPropertyHooks +MozjsOperationsTestInterfaceHandler::indexed_property_hooks = { + NULL, + NULL, + NULL, + NULL, + NULL, +}; + +static base::LazyInstance<MozjsOperationsTestInterfaceHandler> + proxy_handler; + +bool HasInstance(JSContext *context, JS::HandleObject type, + JS::MutableHandleValue vp, bool *success) { + JS::RootedObject global_object( + context, JS_GetGlobalForObject(context, type)); + DCHECK(global_object); + + JS::RootedObject prototype( + context, MozjsOperationsTestInterface::GetPrototype(context, global_object)); + + // |IsDelegate| walks the prototype chain of an object returning true if + // .prototype is found. + bool is_delegate; + if (!IsDelegate(context, prototype, vp, &is_delegate)) { + *success = false; + return false; + } + + *success = is_delegate; + return true; +} + +const JSClass instance_class_definition = { + "OperationsTestInterface", + 0 | JSCLASS_HAS_PRIVATE, + NULL, // addProperty + NULL, // delProperty + NULL, // getProperty + NULL, // setProperty + NULL, // enumerate + NULL, // resolve + NULL, // mayResolve + &WrapperPrivate::Finalizer, // finalize + NULL, // call + NULL, // hasInstance + NULL, // construct + &WrapperPrivate::Trace, // trace +}; + +const JSClass prototype_class_definition = { + "OperationsTestInterfacePrototype", +}; + +const JSClass interface_object_class_definition = { + "OperationsTestInterfaceConstructor", + 0, + NULL, // addProperty + NULL, // delProperty + NULL, // getProperty + NULL, // setProperty + NULL, // enumerate + NULL, // resolve + NULL, // mayResolve + NULL, // finalize + NULL, // call + &HasInstance, + NULL, +}; + +bool fcn_longFunctionNoArgs( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + const JSClass* proto_class = + MozjsOperationsTestInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<OperationsTestInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + OperationsTestInterface* impl = + wrapper_private->wrappable<OperationsTestInterface>().get(); + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->LongFunctionNoArgs(), + &result_value); + } + if (!exception_state.is_exception_set()) { + args.rval().set(result_value); + } + return !exception_state.is_exception_set(); +} + +bool fcn_objectFunctionNoArgs( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + const JSClass* proto_class = + MozjsOperationsTestInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<OperationsTestInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + OperationsTestInterface* impl = + wrapper_private->wrappable<OperationsTestInterface>().get(); + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->ObjectFunctionNoArgs(), + &result_value); + } + if (!exception_state.is_exception_set()) { + args.rval().set(result_value); + } + return !exception_state.is_exception_set(); +} + +bool fcn_optionalArgumentWithDefault( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + const JSClass* proto_class = + MozjsOperationsTestInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<OperationsTestInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + OperationsTestInterface* impl = + wrapper_private->wrappable<OperationsTestInterface>().get(); + // Optional arguments with default values + TypeTraits<double >::ConversionType arg1 = + 2.718; + size_t num_set_arguments = 1; + if (args.length() > 0) { + JS::RootedValue optional_value0( + context, args[0]); + FromJSValue(context, + optional_value0, + (kConversionFlagRestricted), + &exception_state, + &arg1); + if (exception_state.is_exception_set()) { + return false; + } + } + + impl->OptionalArgumentWithDefault(arg1); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + +bool fcn_optionalArguments( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + const JSClass* proto_class = + MozjsOperationsTestInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<OperationsTestInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + OperationsTestInterface* impl = + wrapper_private->wrappable<OperationsTestInterface>().get(); + const size_t kMinArguments = 1; + if (args.length() < kMinArguments) { + exception_state.SetSimpleException(script::kInvalidNumberOfArguments); + return false; + } + // Non-optional arguments + TypeTraits<int32_t >::ConversionType arg1; + // Optional arguments + TypeTraits<int32_t >::ConversionType arg2; + TypeTraits<int32_t >::ConversionType arg3; + + DCHECK_LT(0, args.length()); + JS::RootedValue non_optional_value0( + context, args[0]); + FromJSValue(context, + non_optional_value0, + kNoConversionFlags, + &exception_state, &arg1); + if (exception_state.is_exception_set()) { + return false; + } + size_t num_set_arguments = 1; + if (args.length() > 1) { + JS::RootedValue optional_value0( + context, args[1]); + FromJSValue(context, + optional_value0, + kNoConversionFlags, + &exception_state, + &arg2); + if (exception_state.is_exception_set()) { + return false; + } + ++num_set_arguments; + } + if (args.length() > 2) { + JS::RootedValue optional_value1( + context, args[2]); + FromJSValue(context, + optional_value1, + kNoConversionFlags, + &exception_state, + &arg3); + if (exception_state.is_exception_set()) { + return false; + } + ++num_set_arguments; + } + switch (num_set_arguments) { + case 1: + { + impl->OptionalArguments(arg1); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); + } + break; + case 2: + { + impl->OptionalArguments(arg1, arg2); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); + } + break; + case 3: + { + impl->OptionalArguments(arg1, arg2, arg3); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); + } + break; + default: + NOTREACHED(); + return false; + } +} + +bool fcn_optionalNullableArgumentsWithDefaults( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + const JSClass* proto_class = + MozjsOperationsTestInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<OperationsTestInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + OperationsTestInterface* impl = + wrapper_private->wrappable<OperationsTestInterface>().get(); + // Optional arguments with default values + TypeTraits<base::optional<bool > >::ConversionType arg1 = + base::nullopt; + TypeTraits<scoped_refptr<ArbitraryInterface> >::ConversionType arg2 = + NULL; + size_t num_set_arguments = 2; + if (args.length() > 0) { + JS::RootedValue optional_value0( + context, args[0]); + FromJSValue(context, + optional_value0, + (kConversionFlagNullable), + &exception_state, + &arg1); + if (exception_state.is_exception_set()) { + return false; + } + } + if (args.length() > 1) { + JS::RootedValue optional_value1( + context, args[1]); + FromJSValue(context, + optional_value1, + (kConversionFlagNullable), + &exception_state, + &arg2); + if (exception_state.is_exception_set()) { + return false; + } + } + + impl->OptionalNullableArgumentsWithDefaults(arg1, arg2); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + +bool fcn_overloadedFunction1( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + const JSClass* proto_class = + MozjsOperationsTestInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<OperationsTestInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + OperationsTestInterface* impl = + wrapper_private->wrappable<OperationsTestInterface>().get(); + + impl->OverloadedFunction(); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + +bool fcn_overloadedFunction2( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + const JSClass* proto_class = + MozjsOperationsTestInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<OperationsTestInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + OperationsTestInterface* impl = + wrapper_private->wrappable<OperationsTestInterface>().get(); + const size_t kMinArguments = 1; + if (args.length() < kMinArguments) { + exception_state.SetSimpleException(script::kInvalidNumberOfArguments); + return false; + } + // Non-optional arguments + TypeTraits<int32_t >::ConversionType arg; + + DCHECK_LT(0, args.length()); + JS::RootedValue non_optional_value0( + context, args[0]); + FromJSValue(context, + non_optional_value0, + kNoConversionFlags, + &exception_state, &arg); + if (exception_state.is_exception_set()) { + return false; + } + + impl->OverloadedFunction(arg); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + +bool fcn_overloadedFunction3( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + const JSClass* proto_class = + MozjsOperationsTestInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<OperationsTestInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + OperationsTestInterface* impl = + wrapper_private->wrappable<OperationsTestInterface>().get(); + const size_t kMinArguments = 1; + if (args.length() < kMinArguments) { + exception_state.SetSimpleException(script::kInvalidNumberOfArguments); + return false; + } + // Non-optional arguments + TypeTraits<std::string >::ConversionType arg; + + DCHECK_LT(0, args.length()); + JS::RootedValue non_optional_value0( + context, args[0]); + FromJSValue(context, + non_optional_value0, + kNoConversionFlags, + &exception_state, &arg); + if (exception_state.is_exception_set()) { + return false; + } + + impl->OverloadedFunction(arg); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + +bool fcn_overloadedFunction4( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + const JSClass* proto_class = + MozjsOperationsTestInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<OperationsTestInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + OperationsTestInterface* impl = + wrapper_private->wrappable<OperationsTestInterface>().get(); + const size_t kMinArguments = 3; + if (args.length() < kMinArguments) { + exception_state.SetSimpleException(script::kInvalidNumberOfArguments); + return false; + } + // Non-optional arguments + TypeTraits<int32_t >::ConversionType arg1; + TypeTraits<int32_t >::ConversionType arg2; + TypeTraits<int32_t >::ConversionType arg3; + + DCHECK_LT(0, args.length()); + JS::RootedValue non_optional_value0( + context, args[0]); + FromJSValue(context, + non_optional_value0, + kNoConversionFlags, + &exception_state, &arg1); + if (exception_state.is_exception_set()) { + return false; + } + + DCHECK_LT(1, args.length()); + JS::RootedValue non_optional_value1( + context, args[1]); + FromJSValue(context, + non_optional_value1, + kNoConversionFlags, + &exception_state, &arg2); + if (exception_state.is_exception_set()) { + return false; + } + + DCHECK_LT(2, args.length()); + JS::RootedValue non_optional_value2( + context, args[2]); + FromJSValue(context, + non_optional_value2, + kNoConversionFlags, + &exception_state, &arg3); + if (exception_state.is_exception_set()) { + return false; + } + + impl->OverloadedFunction(arg1, arg2, arg3); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + +bool fcn_overloadedFunction5( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + const JSClass* proto_class = + MozjsOperationsTestInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<OperationsTestInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + OperationsTestInterface* impl = + wrapper_private->wrappable<OperationsTestInterface>().get(); + const size_t kMinArguments = 3; + if (args.length() < kMinArguments) { + exception_state.SetSimpleException(script::kInvalidNumberOfArguments); + return false; + } + // Non-optional arguments + TypeTraits<int32_t >::ConversionType arg1; + TypeTraits<int32_t >::ConversionType arg2; + TypeTraits<scoped_refptr<ArbitraryInterface> >::ConversionType arg3; + + DCHECK_LT(0, args.length()); + JS::RootedValue non_optional_value0( + context, args[0]); + FromJSValue(context, + non_optional_value0, + kNoConversionFlags, + &exception_state, &arg1); + if (exception_state.is_exception_set()) { + return false; + } + + DCHECK_LT(1, args.length()); + JS::RootedValue non_optional_value1( + context, args[1]); + FromJSValue(context, + non_optional_value1, + kNoConversionFlags, + &exception_state, &arg2); + if (exception_state.is_exception_set()) { + return false; + } + + DCHECK_LT(2, args.length()); + JS::RootedValue non_optional_value2( + context, args[2]); + FromJSValue(context, + non_optional_value2, + kNoConversionFlags, + &exception_state, &arg3); + if (exception_state.is_exception_set()) { + return false; + } + + impl->OverloadedFunction(arg1, arg2, arg3); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + +bool fcn_overloadedFunction( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + switch(argc) { + case(0): { + // Overload resolution algorithm details found here: + // http://heycam.github.io/webidl/#dfn-overload-resolution-algorithm + if (true) { + return fcn_overloadedFunction1( + context, argc, vp); + } + break; + } + case(1): { + // Overload resolution algorithm details found here: + // http://heycam.github.io/webidl/#dfn-overload-resolution-algorithm + JS::RootedValue arg(context, args[0]); + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + JS::RootedObject object(context); + if (arg.isObject()) { + object = JS::RootedObject(context, &arg.toObject()); + } + if (arg.isNumber()) { + return fcn_overloadedFunction2( + context, argc, vp); + } + if (true) { + return fcn_overloadedFunction3( + context, argc, vp); + } + if (true) { + return fcn_overloadedFunction2( + context, argc, vp); + } + break; + } + case(3): { + // Overload resolution algorithm details found here: + // http://heycam.github.io/webidl/#dfn-overload-resolution-algorithm + JS::RootedValue arg(context, args[2]); + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + JS::RootedObject object(context); + if (arg.isObject()) { + object = JS::RootedObject(context, &arg.toObject()); + } + if (arg.isObject() ? wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<ArbitraryInterface>()) : + false) { + return fcn_overloadedFunction5( + context, argc, vp); + } + if (true) { + return fcn_overloadedFunction4( + context, argc, vp); + } + break; + } + } + // Invalid number of args + // http://heycam.github.io/webidl/#dfn-overload-resolution-algorithm + // 4. If S is empty, then throw a TypeError. + MozjsExceptionState exception_state(context); + exception_state.SetSimpleException(script::kInvalidNumberOfArguments); + return false; +} + +bool fcn_overloadedNullable1( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + const JSClass* proto_class = + MozjsOperationsTestInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<OperationsTestInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + OperationsTestInterface* impl = + wrapper_private->wrappable<OperationsTestInterface>().get(); + const size_t kMinArguments = 1; + if (args.length() < kMinArguments) { + exception_state.SetSimpleException(script::kInvalidNumberOfArguments); + return false; + } + // Non-optional arguments + TypeTraits<int32_t >::ConversionType arg; + + DCHECK_LT(0, args.length()); + JS::RootedValue non_optional_value0( + context, args[0]); + FromJSValue(context, + non_optional_value0, + kNoConversionFlags, + &exception_state, &arg); + if (exception_state.is_exception_set()) { + return false; + } + + impl->OverloadedNullable(arg); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + +bool fcn_overloadedNullable2( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + const JSClass* proto_class = + MozjsOperationsTestInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<OperationsTestInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + OperationsTestInterface* impl = + wrapper_private->wrappable<OperationsTestInterface>().get(); + const size_t kMinArguments = 1; + if (args.length() < kMinArguments) { + exception_state.SetSimpleException(script::kInvalidNumberOfArguments); + return false; + } + // Non-optional arguments + TypeTraits<base::optional<bool > >::ConversionType arg; + + DCHECK_LT(0, args.length()); + JS::RootedValue non_optional_value0( + context, args[0]); + FromJSValue(context, + non_optional_value0, + (kConversionFlagNullable), + &exception_state, &arg); + if (exception_state.is_exception_set()) { + return false; + } + + impl->OverloadedNullable(arg); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + +bool fcn_overloadedNullable( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + switch(argc) { + case(1): { + // Overload resolution algorithm details found here: + // http://heycam.github.io/webidl/#dfn-overload-resolution-algorithm + JS::RootedValue arg(context, args[0]); + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + JS::RootedObject object(context); + if (arg.isObject()) { + object = JS::RootedObject(context, &arg.toObject()); + } + if (arg.isNullOrUndefined()) { + return fcn_overloadedNullable2( + context, argc, vp); + } + if (true) { + return fcn_overloadedNullable1( + context, argc, vp); + } + break; + } + } + // Invalid number of args + // http://heycam.github.io/webidl/#dfn-overload-resolution-algorithm + // 4. If S is empty, then throw a TypeError. + MozjsExceptionState exception_state(context); + exception_state.SetSimpleException(script::kInvalidNumberOfArguments); + return false; +} + +bool fcn_stringFunctionNoArgs( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + const JSClass* proto_class = + MozjsOperationsTestInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<OperationsTestInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + OperationsTestInterface* impl = + wrapper_private->wrappable<OperationsTestInterface>().get(); + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->StringFunctionNoArgs(), + &result_value); + } + if (!exception_state.is_exception_set()) { + args.rval().set(result_value); + } + return !exception_state.is_exception_set(); +} + +bool fcn_variadicPrimitiveArguments( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + const JSClass* proto_class = + MozjsOperationsTestInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<OperationsTestInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + OperationsTestInterface* impl = + wrapper_private->wrappable<OperationsTestInterface>().get(); + // Variadic argument + TypeTraits<std::vector<int32_t> >::ConversionType bools; + + // Get variadic arguments. + const size_t kFirstVariadicArgIndex = 0; + if (args.length() > kFirstVariadicArgIndex) { + bools.resize(args.length() - kFirstVariadicArgIndex); + for (int i = 0; i + kFirstVariadicArgIndex < args.length(); ++i) { + JS::RootedValue variadic_argument_value( + context, args[i + kFirstVariadicArgIndex]); + FromJSValue(context, + variadic_argument_value, + kNoConversionFlags, + &exception_state, + &bools[i]); + if (exception_state.is_exception_set()) { + return false; + } + } + } + + impl->VariadicPrimitiveArguments(bools); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + +bool fcn_variadicStringArgumentsAfterOptionalArgument( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + const JSClass* proto_class = + MozjsOperationsTestInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<OperationsTestInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + OperationsTestInterface* impl = + wrapper_private->wrappable<OperationsTestInterface>().get(); + // Optional arguments + TypeTraits<bool >::ConversionType optional_arg; + // Variadic argument + TypeTraits<std::vector<std::string> >::ConversionType strings; + size_t num_set_arguments = 0; + if (args.length() > 0) { + JS::RootedValue optional_value0( + context, args[0]); + FromJSValue(context, + optional_value0, + kNoConversionFlags, + &exception_state, + &optional_arg); + if (exception_state.is_exception_set()) { + return false; + } + ++num_set_arguments; + } + + // Get variadic arguments. + const size_t kLastOptionalArgIndex = 1; + if (num_set_arguments == kLastOptionalArgIndex) { + // If the last optional argument has been set, we will call the overload + // that takes the variadic argument, possibly with an empty vector in the + // case that there are no more arguments left. + ++num_set_arguments; + } + const size_t kFirstVariadicArgIndex = 1; + if (args.length() > kFirstVariadicArgIndex) { + strings.resize(args.length() - kFirstVariadicArgIndex); + for (int i = 0; i + kFirstVariadicArgIndex < args.length(); ++i) { + JS::RootedValue variadic_argument_value( + context, args[i + kFirstVariadicArgIndex]); + FromJSValue(context, + variadic_argument_value, + kNoConversionFlags, + &exception_state, + &strings[i]); + if (exception_state.is_exception_set()) { + return false; + } + } + } + switch (num_set_arguments) { + case 0: + { + impl->VariadicStringArgumentsAfterOptionalArgument(); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); + } + break; + case 2: + { + impl->VariadicStringArgumentsAfterOptionalArgument(optional_arg, strings); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); + } + break; + default: + NOTREACHED(); + return false; + } +} + +bool fcn_voidFunctionLongArg( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + const JSClass* proto_class = + MozjsOperationsTestInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<OperationsTestInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + OperationsTestInterface* impl = + wrapper_private->wrappable<OperationsTestInterface>().get(); + const size_t kMinArguments = 1; + if (args.length() < kMinArguments) { + exception_state.SetSimpleException(script::kInvalidNumberOfArguments); + return false; + } + // Non-optional arguments + TypeTraits<int32_t >::ConversionType arg; + + DCHECK_LT(0, args.length()); + JS::RootedValue non_optional_value0( + context, args[0]); + FromJSValue(context, + non_optional_value0, + kNoConversionFlags, + &exception_state, &arg); + if (exception_state.is_exception_set()) { + return false; + } + + impl->VoidFunctionLongArg(arg); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + +bool fcn_voidFunctionNoArgs( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + const JSClass* proto_class = + MozjsOperationsTestInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<OperationsTestInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + OperationsTestInterface* impl = + wrapper_private->wrappable<OperationsTestInterface>().get(); + + impl->VoidFunctionNoArgs(); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + +bool fcn_voidFunctionObjectArg( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + const JSClass* proto_class = + MozjsOperationsTestInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<OperationsTestInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + OperationsTestInterface* impl = + wrapper_private->wrappable<OperationsTestInterface>().get(); + const size_t kMinArguments = 1; + if (args.length() < kMinArguments) { + exception_state.SetSimpleException(script::kInvalidNumberOfArguments); + return false; + } + // Non-optional arguments + TypeTraits<scoped_refptr<ArbitraryInterface> >::ConversionType arg; + + DCHECK_LT(0, args.length()); + JS::RootedValue non_optional_value0( + context, args[0]); + FromJSValue(context, + non_optional_value0, + kNoConversionFlags, + &exception_state, &arg); + if (exception_state.is_exception_set()) { + return false; + } + + impl->VoidFunctionObjectArg(arg); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + +bool fcn_voidFunctionStringArg( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + const JSClass* proto_class = + MozjsOperationsTestInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<OperationsTestInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + OperationsTestInterface* impl = + wrapper_private->wrappable<OperationsTestInterface>().get(); + const size_t kMinArguments = 1; + if (args.length() < kMinArguments) { + exception_state.SetSimpleException(script::kInvalidNumberOfArguments); + return false; + } + // Non-optional arguments + TypeTraits<std::string >::ConversionType arg; + + DCHECK_LT(0, args.length()); + JS::RootedValue non_optional_value0( + context, args[0]); + FromJSValue(context, + non_optional_value0, + kNoConversionFlags, + &exception_state, &arg); + if (exception_state.is_exception_set()) { + return false; + } + + impl->VoidFunctionStringArg(arg); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + +bool staticfcn_overloadedFunction1( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + const size_t kMinArguments = 1; + if (args.length() < kMinArguments) { + exception_state.SetSimpleException(script::kInvalidNumberOfArguments); + return false; + } + // Non-optional arguments + TypeTraits<double >::ConversionType arg; + + DCHECK_LT(0, args.length()); + JS::RootedValue non_optional_value0( + context, args[0]); + FromJSValue(context, + non_optional_value0, + (kConversionFlagRestricted), + &exception_state, &arg); + if (exception_state.is_exception_set()) { + return false; + } + + OperationsTestInterface::OverloadedFunction(arg); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + +bool staticfcn_overloadedFunction2( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + const size_t kMinArguments = 2; + if (args.length() < kMinArguments) { + exception_state.SetSimpleException(script::kInvalidNumberOfArguments); + return false; + } + // Non-optional arguments + TypeTraits<double >::ConversionType arg1; + TypeTraits<double >::ConversionType arg2; + + DCHECK_LT(0, args.length()); + JS::RootedValue non_optional_value0( + context, args[0]); + FromJSValue(context, + non_optional_value0, + (kConversionFlagRestricted), + &exception_state, &arg1); + if (exception_state.is_exception_set()) { + return false; + } + + DCHECK_LT(1, args.length()); + JS::RootedValue non_optional_value1( + context, args[1]); + FromJSValue(context, + non_optional_value1, + (kConversionFlagRestricted), + &exception_state, &arg2); + if (exception_state.is_exception_set()) { + return false; + } + + OperationsTestInterface::OverloadedFunction(arg1, arg2); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + +bool staticfcn_overloadedFunction( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + switch(argc) { + case(1): { + // Overload resolution algorithm details found here: + // http://heycam.github.io/webidl/#dfn-overload-resolution-algorithm + if (true) { + return staticfcn_overloadedFunction1( + context, argc, vp); + } + break; + } + case(2): { + // Overload resolution algorithm details found here: + // http://heycam.github.io/webidl/#dfn-overload-resolution-algorithm + if (true) { + return staticfcn_overloadedFunction2( + context, argc, vp); + } + break; + } + } + // Invalid number of args + // http://heycam.github.io/webidl/#dfn-overload-resolution-algorithm + // 4. If S is empty, then throw a TypeError. + MozjsExceptionState exception_state(context); + exception_state.SetSimpleException(script::kInvalidNumberOfArguments); + return false; +} + + + +const JSPropertySpec prototype_properties[] = { + JS_PS_END +}; + +const JSFunctionSpec prototype_functions[] = { + JS_FNSPEC( + "longFunctionNoArgs", fcn_longFunctionNoArgs, NULL, + 0, JSPROP_ENUMERATE, NULL), + JS_FNSPEC( + "objectFunctionNoArgs", fcn_objectFunctionNoArgs, NULL, + 0, JSPROP_ENUMERATE, NULL), + JS_FNSPEC( + "optionalArgumentWithDefault", fcn_optionalArgumentWithDefault, NULL, + 0, JSPROP_ENUMERATE, NULL), + JS_FNSPEC( + "optionalArguments", fcn_optionalArguments, NULL, + 1, JSPROP_ENUMERATE, NULL), + JS_FNSPEC( + "optionalNullableArgumentsWithDefaults", fcn_optionalNullableArgumentsWithDefaults, NULL, + 0, JSPROP_ENUMERATE, NULL), + JS_FNSPEC( + "overloadedFunction", fcn_overloadedFunction, NULL, + 0, JSPROP_ENUMERATE, NULL), + JS_FNSPEC( + "overloadedNullable", fcn_overloadedNullable, NULL, + 1, JSPROP_ENUMERATE, NULL), + JS_FNSPEC( + "stringFunctionNoArgs", fcn_stringFunctionNoArgs, NULL, + 0, JSPROP_ENUMERATE, NULL), + JS_FNSPEC( + "variadicPrimitiveArguments", fcn_variadicPrimitiveArguments, NULL, + 0, JSPROP_ENUMERATE, NULL), + JS_FNSPEC( + "variadicStringArgumentsAfterOptionalArgument", fcn_variadicStringArgumentsAfterOptionalArgument, NULL, + 0, JSPROP_ENUMERATE, NULL), + JS_FNSPEC( + "voidFunctionLongArg", fcn_voidFunctionLongArg, NULL, + 1, JSPROP_ENUMERATE, NULL), + JS_FNSPEC( + "voidFunctionNoArgs", fcn_voidFunctionNoArgs, NULL, + 0, JSPROP_ENUMERATE, NULL), + JS_FNSPEC( + "voidFunctionObjectArg", fcn_voidFunctionObjectArg, NULL, + 1, JSPROP_ENUMERATE, NULL), + JS_FNSPEC( + "voidFunctionStringArg", fcn_voidFunctionStringArg, NULL, + 1, JSPROP_ENUMERATE, NULL), + JS_FS_END +}; + +const JSPropertySpec interface_object_properties[] = { + JS_PS_END +}; + +const JSFunctionSpec interface_object_functions[] = { + JS_FNSPEC( + "overloadedFunction", staticfcn_overloadedFunction, NULL, + 1, JSPROP_ENUMERATE, NULL), + JS_FS_END +}; + +const JSPropertySpec own_properties[] = { + JS_PS_END +}; + +void InitializePrototypeAndInterfaceObject( + InterfaceData* interface_data, JSContext* context, + JS::HandleObject global_object) { + DCHECK(!interface_data->prototype); + DCHECK(!interface_data->interface_object); + DCHECK(JS_IsGlobalObject(global_object)); + + JS::RootedObject parent_prototype( + context, JS_GetObjectPrototype(context, global_object)); + DCHECK(parent_prototype); + + interface_data->prototype = JS_NewObjectWithGivenProto( + context, &prototype_class_definition, parent_prototype + ); + + JS::RootedObject rooted_prototype(context, interface_data->prototype); + bool success = JS_DefineProperties( + context, + rooted_prototype, + prototype_properties); + + DCHECK(success); + success = JS_DefineFunctions( + context, rooted_prototype, prototype_functions); + DCHECK(success); + + JS::RootedObject function_prototype( + context, JS_GetFunctionPrototype(context, global_object)); + DCHECK(function_prototype); + // Create the Interface object. + interface_data->interface_object = JS_NewObjectWithGivenProto( + context, &interface_object_class_definition, + function_prototype); + + // Add the InterfaceObject.name property. + JS::RootedObject rooted_interface_object( + context, interface_data->interface_object); + JS::RootedValue name_value(context); + const char name[] = + "OperationsTestInterface"; + name_value.setString(JS_NewStringCopyZ(context, name)); + success = JS_DefineProperty( + context, rooted_interface_object, "name", name_value, JSPROP_READONLY, + NULL, NULL); + DCHECK(success); + + // Define interface object properties (including constants). + success = JS_DefineProperties(context, rooted_interface_object, + interface_object_properties); + DCHECK(success); + // Define interface object functions (static). + success = JS_DefineFunctions(context, rooted_interface_object, + interface_object_functions); + DCHECK(success); + + // Set the Prototype.constructor and Constructor.prototype properties. + DCHECK(interface_data->interface_object); + DCHECK(interface_data->prototype); + success = JS_LinkConstructorAndPrototype( + context, + rooted_interface_object, + rooted_prototype); + DCHECK(success); +} + +InterfaceData* GetInterfaceData(JSContext* context) { + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + // Use the address of the properties definition for this interface as a + // unique key for looking up the InterfaceData for this interface. + intptr_t key = reinterpret_cast<intptr_t>(&own_properties); + InterfaceData* interface_data = global_environment->GetInterfaceData(key); + if (!interface_data) { + interface_data = new InterfaceData(); + DCHECK(interface_data); + global_environment->CacheInterfaceData(key, interface_data); + DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key)); + } + return interface_data; +} + +} // namespace + +// static +JSObject* MozjsOperationsTestInterface::CreateProxy( + JSContext* context, const scoped_refptr<Wrappable>& wrappable) { + DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); + JS::RootedObject global_object( + context, + MozjsGlobalEnvironment::GetFromContext(context)->global_object()); + DCHECK(global_object); + + InterfaceData* interface_data = GetInterfaceData(context); + JS::RootedObject prototype(context, GetPrototype(context, global_object)); + DCHECK(prototype); + JS::RootedObject new_object( + context, + JS_NewObjectWithGivenProto( + context, &instance_class_definition, prototype)); + DCHECK(new_object); + JS::RootedObject proxy(context, + ProxyHandler::NewProxy( + context, proxy_handler.Pointer(), new_object, prototype)); + WrapperPrivate::AddPrivateData(context, proxy, wrappable); + return proxy; +} + +// static +const JSClass* MozjsOperationsTestInterface::PrototypeClass( + JSContext* context) { + DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); + JS::RootedObject global_object( + context, + MozjsGlobalEnvironment::GetFromContext(context)->global_object()); + DCHECK(global_object); + + JS::RootedObject prototype(context, GetPrototype(context, global_object)); + const JSClass* proto_class = JS_GetClass(prototype); + return proto_class; +} + +// static +JSObject* MozjsOperationsTestInterface::GetPrototype( + JSContext* context, JS::HandleObject global_object) { + DCHECK(JS_IsGlobalObject(global_object)); + + InterfaceData* interface_data = GetInterfaceData(context); + if (!interface_data->prototype) { + // Create new prototype that has all the props and methods + InitializePrototypeAndInterfaceObject( + interface_data, context, global_object); + } + DCHECK(interface_data->prototype); + return interface_data->prototype; +} + +// static +JSObject* MozjsOperationsTestInterface::GetInterfaceObject( + JSContext* context, JS::HandleObject global_object) { + DCHECK(JS_IsGlobalObject(global_object)); + + InterfaceData* interface_data = GetInterfaceData(context); + if (!interface_data->interface_object) { + InitializePrototypeAndInterfaceObject( + interface_data, context, global_object); + } + DCHECK(interface_data->interface_object); + return interface_data->interface_object; +} + + +namespace { +} // namespace + + +} // namespace testing +} // namespace bindings +} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_operations_test_interface.h b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_operations_test_interface.h new file mode 100644 index 0000000..26cce5b --- /dev/null +++ b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_operations_test_interface.h
@@ -0,0 +1,52 @@ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// clang-format off + +// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! +// Auto-generated from template: bindings/mozjs-45/templates/interface.h.template + +#ifndef MozjsOperationsTestInterface_h +#define MozjsOperationsTestInterface_h + +#include "base/hash_tables.h" +#include "base/lazy_instance.h" +#include "base/memory/ref_counted.h" +#include "base/threading/thread_checker.h" +#include "cobalt/base/polymorphic_downcast.h" +#include "cobalt/script/wrappable.h" +#include "cobalt/bindings/testing/operations_test_interface.h" + +#include "third_party/mozjs-45/js/src/jsapi.h" + +namespace cobalt { +namespace bindings { +namespace testing { + +class MozjsOperationsTestInterface { + public: + static JSObject* CreateProxy(JSContext* context, + const scoped_refptr<script::Wrappable>& wrappable); + static const JSClass* PrototypeClass(JSContext* context); + static JSObject* GetPrototype(JSContext* context, + JS::HandleObject global_object); + static JSObject* GetInterfaceObject(JSContext* context, + JS::HandleObject global_object); +}; + +} // namespace testing +} // namespace bindings +} // namespace cobalt + +#endif // MozjsOperationsTestInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_put_forwards_interface.cc b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_put_forwards_interface.cc new file mode 100644 index 0000000..7e8b683 --- /dev/null +++ b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_put_forwards_interface.cc
@@ -0,0 +1,524 @@ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// clang-format off + +// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! +// Auto-generated from template: bindings/mozjs-45/templates/interface.cc.template + +#include "cobalt/bindings/testing/mozjs_put_forwards_interface.h" + +#include "base/debug/trace_event.h" +#include "cobalt/base/polymorphic_downcast.h" +#include "cobalt/script/global_environment.h" +#include "cobalt/script/opaque_handle.h" +#include "cobalt/script/script_value.h" +#include "cobalt/bindings/testing/arbitrary_interface.h" +#include "cobalt/bindings/testing/mozjs_arbitrary_interface.h" + +#include "base/lazy_instance.h" +#include "cobalt/script/exception_state.h" +#include "cobalt/script/mozjs-45/callback_function_conversion.h" +#include "cobalt/script/mozjs-45/conversion_helpers.h" +#include "cobalt/script/mozjs-45/mozjs_callback_function.h" +#include "cobalt/script/mozjs-45/mozjs_exception_state.h" +#include "cobalt/script/mozjs-45/mozjs_global_environment.h" +#include "cobalt/script/mozjs-45/mozjs_object_handle.h" +#include "cobalt/script/mozjs-45/mozjs_property_enumerator.h" +#include "cobalt/script/mozjs-45/mozjs_user_object_holder.h" +#include "cobalt/script/mozjs-45/proxy_handler.h" +#include "cobalt/script/mozjs-45/type_traits.h" +#include "cobalt/script/mozjs-45/wrapper_factory.h" +#include "cobalt/script/mozjs-45/wrapper_private.h" +#include "cobalt/script/property_enumerator.h" +#include "cobalt/script/sequence.h" +#include "third_party/mozjs-45/js/src/jsapi.h" +#include "third_party/mozjs-45/js/src/jsfriendapi.h" + +namespace { +using cobalt::bindings::testing::PutForwardsInterface; +using cobalt::bindings::testing::MozjsPutForwardsInterface; +using cobalt::bindings::testing::ArbitraryInterface; +using cobalt::bindings::testing::MozjsArbitraryInterface; +using cobalt::script::CallbackInterfaceTraits; +using cobalt::script::GlobalEnvironment; +using cobalt::script::OpaqueHandle; +using cobalt::script::OpaqueHandleHolder; +using cobalt::script::ScriptValue; +using cobalt::script::Wrappable; + +using cobalt::script::CallbackFunction; +using cobalt::script::CallbackInterfaceTraits; +using cobalt::script::ExceptionState; +using cobalt::script::Wrappable; +using cobalt::script::mozjs::FromJSValue; +using cobalt::script::mozjs::InterfaceData; +using cobalt::script::mozjs::MozjsCallbackFunction; +using cobalt::script::mozjs::MozjsExceptionState; +using cobalt::script::mozjs::MozjsGlobalEnvironment; +using cobalt::script::mozjs::MozjsPropertyEnumerator; +using cobalt::script::mozjs::MozjsUserObjectHolder; +using cobalt::script::mozjs::ProxyHandler; +using cobalt::script::mozjs::ToJSValue; +using cobalt::script::mozjs::TypeTraits; +using cobalt::script::mozjs::WrapperFactory; +using cobalt::script::mozjs::WrapperPrivate; +using cobalt::script::mozjs::kConversionFlagNullable; +using cobalt::script::mozjs::kConversionFlagRestricted; +using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString; +using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString; +using cobalt::script::mozjs::kNoConversionFlags; +} // namespace + +namespace cobalt { +namespace bindings { +namespace testing { + +namespace { + +class MozjsPutForwardsInterfaceHandler : public ProxyHandler { + public: + MozjsPutForwardsInterfaceHandler() + : ProxyHandler(indexed_property_hooks, named_property_hooks) {} + + private: + static NamedPropertyHooks named_property_hooks; + static IndexedPropertyHooks indexed_property_hooks; +}; + +ProxyHandler::NamedPropertyHooks +MozjsPutForwardsInterfaceHandler::named_property_hooks = { + NULL, + NULL, + NULL, + NULL, + NULL, +}; +ProxyHandler::IndexedPropertyHooks +MozjsPutForwardsInterfaceHandler::indexed_property_hooks = { + NULL, + NULL, + NULL, + NULL, + NULL, +}; + +static base::LazyInstance<MozjsPutForwardsInterfaceHandler> + proxy_handler; + +bool HasInstance(JSContext *context, JS::HandleObject type, + JS::MutableHandleValue vp, bool *success) { + JS::RootedObject global_object( + context, JS_GetGlobalForObject(context, type)); + DCHECK(global_object); + + JS::RootedObject prototype( + context, MozjsPutForwardsInterface::GetPrototype(context, global_object)); + + // |IsDelegate| walks the prototype chain of an object returning true if + // .prototype is found. + bool is_delegate; + if (!IsDelegate(context, prototype, vp, &is_delegate)) { + *success = false; + return false; + } + + *success = is_delegate; + return true; +} + +const JSClass instance_class_definition = { + "PutForwardsInterface", + 0 | JSCLASS_HAS_PRIVATE, + NULL, // addProperty + NULL, // delProperty + NULL, // getProperty + NULL, // setProperty + NULL, // enumerate + NULL, // resolve + NULL, // mayResolve + &WrapperPrivate::Finalizer, // finalize + NULL, // call + NULL, // hasInstance + NULL, // construct + &WrapperPrivate::Trace, // trace +}; + +const JSClass prototype_class_definition = { + "PutForwardsInterfacePrototype", +}; + +const JSClass interface_object_class_definition = { + "PutForwardsInterfaceConstructor", + 0, + NULL, // addProperty + NULL, // delProperty + NULL, // getProperty + NULL, // setProperty + NULL, // enumerate + NULL, // resolve + NULL, // mayResolve + NULL, // finalize + NULL, // call + &HasInstance, + NULL, +}; + +bool get_forwardingAttribute( + JSContext* context, unsigned argc, JS::Value* vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + const JSClass* proto_class = + MozjsPutForwardsInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<PutForwardsInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + PutForwardsInterface* impl = + wrapper_private->wrappable<PutForwardsInterface>().get(); + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->forwarding_attribute(), + &result_value); + } + if (!exception_state.is_exception_set()) { + args.rval().set(result_value); + } + return !exception_state.is_exception_set(); +} + +bool set_forwardingAttribute( + JSContext* context, unsigned argc, JS::Value* vp) { + + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + + const JSClass* proto_class = + MozjsPutForwardsInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<PutForwardsInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + PutForwardsInterface* impl = + wrapper_private->wrappable<PutForwardsInterface>().get(); + { // Begin scope of scoped_refptr<ArbitraryInterface> forwarded_impl. + scoped_refptr<ArbitraryInterface> forwarded_impl = + impl->forwarding_attribute(); + if (!forwarded_impl) { + NOTREACHED(); + return false; + } + if (!exception_state.is_exception_set()) { + TypeTraits<std::string >::ConversionType value; + if (args.length() != 1) { + NOTREACHED(); + return false; + } + FromJSValue(context, args[0], kNoConversionFlags, &exception_state, + &value); + if (exception_state.is_exception_set()) { + return false; + } + + forwarded_impl->set_arbitrary_property(value); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + return !exception_state.is_exception_set(); + } // End scope of scoped_refptr<ArbitraryInterface> forwarded_impl. +} + +bool staticget_staticForwardingAttribute( + JSContext* context, unsigned argc, JS::Value* vp) { + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + PutForwardsInterface::static_forwarding_attribute(), + &result_value); + } + if (!exception_state.is_exception_set()) { + args.rval().set(result_value); + } + return !exception_state.is_exception_set(); +} + +bool staticset_staticForwardingAttribute( + JSContext* context, unsigned argc, JS::Value* vp) { + + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + { // Begin scope of scoped_refptr<ArbitraryInterface> forwarded_impl. + scoped_refptr<ArbitraryInterface> forwarded_impl = + PutForwardsInterface::static_forwarding_attribute(); + if (!forwarded_impl) { + NOTREACHED(); + return false; + } + if (!exception_state.is_exception_set()) { + TypeTraits<std::string >::ConversionType value; + if (args.length() != 1) { + NOTREACHED(); + return false; + } + FromJSValue(context, args[0], kNoConversionFlags, &exception_state, + &value); + if (exception_state.is_exception_set()) { + return false; + } + + forwarded_impl->set_arbitrary_property(value); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + return !exception_state.is_exception_set(); + } // End scope of scoped_refptr<ArbitraryInterface> forwarded_impl. +} + + + +const JSPropertySpec prototype_properties[] = { + { // Read/Write property + "forwardingAttribute", + JSPROP_SHARED | JSPROP_ENUMERATE, + { { &get_forwardingAttribute, NULL } }, + { { &set_forwardingAttribute, NULL } }, + }, + JS_PS_END +}; + +const JSFunctionSpec prototype_functions[] = { + JS_FS_END +}; + +const JSPropertySpec interface_object_properties[] = { + { // Static read/write attribute. + "staticForwardingAttribute", + JSPROP_SHARED | JSPROP_ENUMERATE, + { { &staticget_staticForwardingAttribute, NULL } }, + { { &staticset_staticForwardingAttribute, NULL } }, + }, + JS_PS_END +}; + +const JSFunctionSpec interface_object_functions[] = { + JS_FS_END +}; + +const JSPropertySpec own_properties[] = { + JS_PS_END +}; + +void InitializePrototypeAndInterfaceObject( + InterfaceData* interface_data, JSContext* context, + JS::HandleObject global_object) { + DCHECK(!interface_data->prototype); + DCHECK(!interface_data->interface_object); + DCHECK(JS_IsGlobalObject(global_object)); + + JS::RootedObject parent_prototype( + context, JS_GetObjectPrototype(context, global_object)); + DCHECK(parent_prototype); + + interface_data->prototype = JS_NewObjectWithGivenProto( + context, &prototype_class_definition, parent_prototype + ); + + JS::RootedObject rooted_prototype(context, interface_data->prototype); + bool success = JS_DefineProperties( + context, + rooted_prototype, + prototype_properties); + + DCHECK(success); + success = JS_DefineFunctions( + context, rooted_prototype, prototype_functions); + DCHECK(success); + + JS::RootedObject function_prototype( + context, JS_GetFunctionPrototype(context, global_object)); + DCHECK(function_prototype); + // Create the Interface object. + interface_data->interface_object = JS_NewObjectWithGivenProto( + context, &interface_object_class_definition, + function_prototype); + + // Add the InterfaceObject.name property. + JS::RootedObject rooted_interface_object( + context, interface_data->interface_object); + JS::RootedValue name_value(context); + const char name[] = + "PutForwardsInterface"; + name_value.setString(JS_NewStringCopyZ(context, name)); + success = JS_DefineProperty( + context, rooted_interface_object, "name", name_value, JSPROP_READONLY, + NULL, NULL); + DCHECK(success); + + // Define interface object properties (including constants). + success = JS_DefineProperties(context, rooted_interface_object, + interface_object_properties); + DCHECK(success); + // Define interface object functions (static). + success = JS_DefineFunctions(context, rooted_interface_object, + interface_object_functions); + DCHECK(success); + + // Set the Prototype.constructor and Constructor.prototype properties. + DCHECK(interface_data->interface_object); + DCHECK(interface_data->prototype); + success = JS_LinkConstructorAndPrototype( + context, + rooted_interface_object, + rooted_prototype); + DCHECK(success); +} + +InterfaceData* GetInterfaceData(JSContext* context) { + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + // Use the address of the properties definition for this interface as a + // unique key for looking up the InterfaceData for this interface. + intptr_t key = reinterpret_cast<intptr_t>(&own_properties); + InterfaceData* interface_data = global_environment->GetInterfaceData(key); + if (!interface_data) { + interface_data = new InterfaceData(); + DCHECK(interface_data); + global_environment->CacheInterfaceData(key, interface_data); + DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key)); + } + return interface_data; +} + +} // namespace + +// static +JSObject* MozjsPutForwardsInterface::CreateProxy( + JSContext* context, const scoped_refptr<Wrappable>& wrappable) { + DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); + JS::RootedObject global_object( + context, + MozjsGlobalEnvironment::GetFromContext(context)->global_object()); + DCHECK(global_object); + + InterfaceData* interface_data = GetInterfaceData(context); + JS::RootedObject prototype(context, GetPrototype(context, global_object)); + DCHECK(prototype); + JS::RootedObject new_object( + context, + JS_NewObjectWithGivenProto( + context, &instance_class_definition, prototype)); + DCHECK(new_object); + JS::RootedObject proxy(context, + ProxyHandler::NewProxy( + context, proxy_handler.Pointer(), new_object, prototype)); + WrapperPrivate::AddPrivateData(context, proxy, wrappable); + return proxy; +} + +// static +const JSClass* MozjsPutForwardsInterface::PrototypeClass( + JSContext* context) { + DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); + JS::RootedObject global_object( + context, + MozjsGlobalEnvironment::GetFromContext(context)->global_object()); + DCHECK(global_object); + + JS::RootedObject prototype(context, GetPrototype(context, global_object)); + const JSClass* proto_class = JS_GetClass(prototype); + return proto_class; +} + +// static +JSObject* MozjsPutForwardsInterface::GetPrototype( + JSContext* context, JS::HandleObject global_object) { + DCHECK(JS_IsGlobalObject(global_object)); + + InterfaceData* interface_data = GetInterfaceData(context); + if (!interface_data->prototype) { + // Create new prototype that has all the props and methods + InitializePrototypeAndInterfaceObject( + interface_data, context, global_object); + } + DCHECK(interface_data->prototype); + return interface_data->prototype; +} + +// static +JSObject* MozjsPutForwardsInterface::GetInterfaceObject( + JSContext* context, JS::HandleObject global_object) { + DCHECK(JS_IsGlobalObject(global_object)); + + InterfaceData* interface_data = GetInterfaceData(context); + if (!interface_data->interface_object) { + InitializePrototypeAndInterfaceObject( + interface_data, context, global_object); + } + DCHECK(interface_data->interface_object); + return interface_data->interface_object; +} + + +namespace { +} // namespace + + +} // namespace testing +} // namespace bindings +} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_put_forwards_interface.h b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_put_forwards_interface.h new file mode 100644 index 0000000..66db793 --- /dev/null +++ b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_put_forwards_interface.h
@@ -0,0 +1,52 @@ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// clang-format off + +// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! +// Auto-generated from template: bindings/mozjs-45/templates/interface.h.template + +#ifndef MozjsPutForwardsInterface_h +#define MozjsPutForwardsInterface_h + +#include "base/hash_tables.h" +#include "base/lazy_instance.h" +#include "base/memory/ref_counted.h" +#include "base/threading/thread_checker.h" +#include "cobalt/base/polymorphic_downcast.h" +#include "cobalt/script/wrappable.h" +#include "cobalt/bindings/testing/put_forwards_interface.h" + +#include "third_party/mozjs-45/js/src/jsapi.h" + +namespace cobalt { +namespace bindings { +namespace testing { + +class MozjsPutForwardsInterface { + public: + static JSObject* CreateProxy(JSContext* context, + const scoped_refptr<script::Wrappable>& wrappable); + static const JSClass* PrototypeClass(JSContext* context); + static JSObject* GetPrototype(JSContext* context, + JS::HandleObject global_object); + static JSObject* GetInterfaceObject(JSContext* context, + JS::HandleObject global_object); +}; + +} // namespace testing +} // namespace bindings +} // namespace cobalt + +#endif // MozjsPutForwardsInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_sequence_user.cc b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_sequence_user.cc new file mode 100644 index 0000000..c55c849 --- /dev/null +++ b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_sequence_user.cc
@@ -0,0 +1,1243 @@ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// clang-format off + +// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! +// Auto-generated from template: bindings/mozjs-45/templates/interface.cc.template + +#include "cobalt/bindings/testing/mozjs_sequence_user.h" + +#include "base/debug/trace_event.h" +#include "cobalt/base/polymorphic_downcast.h" +#include "cobalt/script/global_environment.h" +#include "cobalt/script/opaque_handle.h" +#include "cobalt/script/script_value.h" + +#include "base/lazy_instance.h" +#include "cobalt/script/exception_state.h" +#include "cobalt/script/mozjs-45/callback_function_conversion.h" +#include "cobalt/script/mozjs-45/conversion_helpers.h" +#include "cobalt/script/mozjs-45/mozjs_callback_function.h" +#include "cobalt/script/mozjs-45/mozjs_exception_state.h" +#include "cobalt/script/mozjs-45/mozjs_global_environment.h" +#include "cobalt/script/mozjs-45/mozjs_object_handle.h" +#include "cobalt/script/mozjs-45/mozjs_property_enumerator.h" +#include "cobalt/script/mozjs-45/mozjs_user_object_holder.h" +#include "cobalt/script/mozjs-45/proxy_handler.h" +#include "cobalt/script/mozjs-45/type_traits.h" +#include "cobalt/script/mozjs-45/wrapper_factory.h" +#include "cobalt/script/mozjs-45/wrapper_private.h" +#include "cobalt/script/property_enumerator.h" +#include "cobalt/script/sequence.h" +#include "third_party/mozjs-45/js/src/jsapi.h" +#include "third_party/mozjs-45/js/src/jsfriendapi.h" + +namespace { +using cobalt::bindings::testing::SequenceUser; +using cobalt::bindings::testing::MozjsSequenceUser; +using cobalt::script::CallbackInterfaceTraits; +using cobalt::script::GlobalEnvironment; +using cobalt::script::OpaqueHandle; +using cobalt::script::OpaqueHandleHolder; +using cobalt::script::ScriptValue; +using cobalt::script::Wrappable; + +using cobalt::script::CallbackFunction; +using cobalt::script::CallbackInterfaceTraits; +using cobalt::script::ExceptionState; +using cobalt::script::Wrappable; +using cobalt::script::mozjs::FromJSValue; +using cobalt::script::mozjs::InterfaceData; +using cobalt::script::mozjs::MozjsCallbackFunction; +using cobalt::script::mozjs::MozjsExceptionState; +using cobalt::script::mozjs::MozjsGlobalEnvironment; +using cobalt::script::mozjs::MozjsPropertyEnumerator; +using cobalt::script::mozjs::MozjsUserObjectHolder; +using cobalt::script::mozjs::ProxyHandler; +using cobalt::script::mozjs::ToJSValue; +using cobalt::script::mozjs::TypeTraits; +using cobalt::script::mozjs::WrapperFactory; +using cobalt::script::mozjs::WrapperPrivate; +using cobalt::script::mozjs::kConversionFlagNullable; +using cobalt::script::mozjs::kConversionFlagRestricted; +using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString; +using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString; +using cobalt::script::mozjs::kNoConversionFlags; +} // namespace + +namespace cobalt { +namespace bindings { +namespace testing { + +namespace { + +class MozjsSequenceUserHandler : public ProxyHandler { + public: + MozjsSequenceUserHandler() + : ProxyHandler(indexed_property_hooks, named_property_hooks) {} + + private: + static NamedPropertyHooks named_property_hooks; + static IndexedPropertyHooks indexed_property_hooks; +}; + +ProxyHandler::NamedPropertyHooks +MozjsSequenceUserHandler::named_property_hooks = { + NULL, + NULL, + NULL, + NULL, + NULL, +}; +ProxyHandler::IndexedPropertyHooks +MozjsSequenceUserHandler::indexed_property_hooks = { + NULL, + NULL, + NULL, + NULL, + NULL, +}; + +static base::LazyInstance<MozjsSequenceUserHandler> + proxy_handler; + +bool Constructor(JSContext* context, unsigned int argc, JS::Value* vp); +bool HasInstance(JSContext *context, JS::HandleObject type, + JS::MutableHandleValue vp, bool *success) { + JS::RootedObject global_object( + context, JS_GetGlobalForObject(context, type)); + DCHECK(global_object); + + JS::RootedObject prototype( + context, MozjsSequenceUser::GetPrototype(context, global_object)); + + // |IsDelegate| walks the prototype chain of an object returning true if + // .prototype is found. + bool is_delegate; + if (!IsDelegate(context, prototype, vp, &is_delegate)) { + *success = false; + return false; + } + + *success = is_delegate; + return true; +} + +const JSClass instance_class_definition = { + "SequenceUser", + 0 | JSCLASS_HAS_PRIVATE, + NULL, // addProperty + NULL, // delProperty + NULL, // getProperty + NULL, // setProperty + NULL, // enumerate + NULL, // resolve + NULL, // mayResolve + &WrapperPrivate::Finalizer, // finalize + NULL, // call + NULL, // hasInstance + NULL, // construct + &WrapperPrivate::Trace, // trace +}; + +const JSClass prototype_class_definition = { + "SequenceUserPrototype", +}; + +const JSClass interface_object_class_definition = { + "SequenceUserConstructor", + 0, + NULL, // addProperty + NULL, // delProperty + NULL, // getProperty + NULL, // setProperty + NULL, // enumerate + NULL, // resolve + NULL, // mayResolve + NULL, // finalize + NULL, // call + &HasInstance, + Constructor, +}; + +bool fcn_getInterfaceSequence( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + const JSClass* proto_class = + MozjsSequenceUser::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<SequenceUser>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + SequenceUser* impl = + wrapper_private->wrappable<SequenceUser>().get(); + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->GetInterfaceSequence(), + &result_value); + } + if (!exception_state.is_exception_set()) { + args.rval().set(result_value); + } + return !exception_state.is_exception_set(); +} + +bool fcn_getInterfaceSequenceSequenceSequence( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + const JSClass* proto_class = + MozjsSequenceUser::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<SequenceUser>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + SequenceUser* impl = + wrapper_private->wrappable<SequenceUser>().get(); + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->GetInterfaceSequenceSequenceSequence(), + &result_value); + } + if (!exception_state.is_exception_set()) { + args.rval().set(result_value); + } + return !exception_state.is_exception_set(); +} + +bool fcn_getLongSequence( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + const JSClass* proto_class = + MozjsSequenceUser::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<SequenceUser>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + SequenceUser* impl = + wrapper_private->wrappable<SequenceUser>().get(); + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->GetLongSequence(), + &result_value); + } + if (!exception_state.is_exception_set()) { + args.rval().set(result_value); + } + return !exception_state.is_exception_set(); +} + +bool fcn_getStringSequence( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + const JSClass* proto_class = + MozjsSequenceUser::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<SequenceUser>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + SequenceUser* impl = + wrapper_private->wrappable<SequenceUser>().get(); + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->GetStringSequence(), + &result_value); + } + if (!exception_state.is_exception_set()) { + args.rval().set(result_value); + } + return !exception_state.is_exception_set(); +} + +bool fcn_getStringSequenceSequence( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + const JSClass* proto_class = + MozjsSequenceUser::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<SequenceUser>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + SequenceUser* impl = + wrapper_private->wrappable<SequenceUser>().get(); + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->GetStringSequenceSequence(), + &result_value); + } + if (!exception_state.is_exception_set()) { + args.rval().set(result_value); + } + return !exception_state.is_exception_set(); +} + +bool fcn_getUnionOfStringAndStringSequence( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + const JSClass* proto_class = + MozjsSequenceUser::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<SequenceUser>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + SequenceUser* impl = + wrapper_private->wrappable<SequenceUser>().get(); + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->GetUnionOfStringAndStringSequence(), + &result_value); + } + if (!exception_state.is_exception_set()) { + args.rval().set(result_value); + } + return !exception_state.is_exception_set(); +} + +bool fcn_getUnionSequence( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + const JSClass* proto_class = + MozjsSequenceUser::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<SequenceUser>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + SequenceUser* impl = + wrapper_private->wrappable<SequenceUser>().get(); + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->GetUnionSequence(), + &result_value); + } + if (!exception_state.is_exception_set()) { + args.rval().set(result_value); + } + return !exception_state.is_exception_set(); +} + +bool fcn_setInterfaceSequence( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + const JSClass* proto_class = + MozjsSequenceUser::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<SequenceUser>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + SequenceUser* impl = + wrapper_private->wrappable<SequenceUser>().get(); + const size_t kMinArguments = 1; + if (args.length() < kMinArguments) { + exception_state.SetSimpleException(script::kInvalidNumberOfArguments); + return false; + } + // Non-optional arguments + TypeTraits<script::Sequence< scoped_refptr<ArbitraryInterface> > >::ConversionType elements; + + DCHECK_LT(0, args.length()); + JS::RootedValue non_optional_value0( + context, args[0]); + FromJSValue(context, + non_optional_value0, + kNoConversionFlags, + &exception_state, &elements); + if (exception_state.is_exception_set()) { + return false; + } + + impl->SetInterfaceSequence(elements); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + +bool fcn_setInterfaceSequenceSequenceSequence( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + const JSClass* proto_class = + MozjsSequenceUser::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<SequenceUser>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + SequenceUser* impl = + wrapper_private->wrappable<SequenceUser>().get(); + const size_t kMinArguments = 1; + if (args.length() < kMinArguments) { + exception_state.SetSimpleException(script::kInvalidNumberOfArguments); + return false; + } + // Non-optional arguments + TypeTraits<script::Sequence< script::Sequence< script::Sequence< scoped_refptr<ArbitraryInterface> > > > >::ConversionType elements; + + DCHECK_LT(0, args.length()); + JS::RootedValue non_optional_value0( + context, args[0]); + FromJSValue(context, + non_optional_value0, + kNoConversionFlags, + &exception_state, &elements); + if (exception_state.is_exception_set()) { + return false; + } + + impl->SetInterfaceSequenceSequenceSequence(elements); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + +bool fcn_setLongSequence( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + const JSClass* proto_class = + MozjsSequenceUser::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<SequenceUser>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + SequenceUser* impl = + wrapper_private->wrappable<SequenceUser>().get(); + const size_t kMinArguments = 1; + if (args.length() < kMinArguments) { + exception_state.SetSimpleException(script::kInvalidNumberOfArguments); + return false; + } + // Non-optional arguments + TypeTraits<script::Sequence< int32_t > >::ConversionType elements; + + DCHECK_LT(0, args.length()); + JS::RootedValue non_optional_value0( + context, args[0]); + FromJSValue(context, + non_optional_value0, + kNoConversionFlags, + &exception_state, &elements); + if (exception_state.is_exception_set()) { + return false; + } + + impl->SetLongSequence(elements); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + +bool fcn_setStringSequence( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + const JSClass* proto_class = + MozjsSequenceUser::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<SequenceUser>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + SequenceUser* impl = + wrapper_private->wrappable<SequenceUser>().get(); + const size_t kMinArguments = 1; + if (args.length() < kMinArguments) { + exception_state.SetSimpleException(script::kInvalidNumberOfArguments); + return false; + } + // Non-optional arguments + TypeTraits<script::Sequence< std::string > >::ConversionType elements; + + DCHECK_LT(0, args.length()); + JS::RootedValue non_optional_value0( + context, args[0]); + FromJSValue(context, + non_optional_value0, + kNoConversionFlags, + &exception_state, &elements); + if (exception_state.is_exception_set()) { + return false; + } + + impl->SetStringSequence(elements); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + +bool fcn_setStringSequenceSequence( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + const JSClass* proto_class = + MozjsSequenceUser::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<SequenceUser>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + SequenceUser* impl = + wrapper_private->wrappable<SequenceUser>().get(); + const size_t kMinArguments = 1; + if (args.length() < kMinArguments) { + exception_state.SetSimpleException(script::kInvalidNumberOfArguments); + return false; + } + // Non-optional arguments + TypeTraits<script::Sequence< script::Sequence< std::string > > >::ConversionType elements; + + DCHECK_LT(0, args.length()); + JS::RootedValue non_optional_value0( + context, args[0]); + FromJSValue(context, + non_optional_value0, + kNoConversionFlags, + &exception_state, &elements); + if (exception_state.is_exception_set()) { + return false; + } + + impl->SetStringSequenceSequence(elements); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + +bool fcn_setUnionOfStringAndStringSequence( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + const JSClass* proto_class = + MozjsSequenceUser::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<SequenceUser>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + SequenceUser* impl = + wrapper_private->wrappable<SequenceUser>().get(); + const size_t kMinArguments = 1; + if (args.length() < kMinArguments) { + exception_state.SetSimpleException(script::kInvalidNumberOfArguments); + return false; + } + // Non-optional arguments + TypeTraits<script::UnionType2<std::string, script::Sequence< std::string > > >::ConversionType elements; + + DCHECK_LT(0, args.length()); + JS::RootedValue non_optional_value0( + context, args[0]); + FromJSValue(context, + non_optional_value0, + kNoConversionFlags, + &exception_state, &elements); + if (exception_state.is_exception_set()) { + return false; + } + + impl->SetUnionOfStringAndStringSequence(elements); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + +bool fcn_setUnionSequence( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + const JSClass* proto_class = + MozjsSequenceUser::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<SequenceUser>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + SequenceUser* impl = + wrapper_private->wrappable<SequenceUser>().get(); + const size_t kMinArguments = 1; + if (args.length() < kMinArguments) { + exception_state.SetSimpleException(script::kInvalidNumberOfArguments); + return false; + } + // Non-optional arguments + TypeTraits<script::Sequence< script::UnionType2<std::string, scoped_refptr<ArbitraryInterface> > > >::ConversionType elements; + + DCHECK_LT(0, args.length()); + JS::RootedValue non_optional_value0( + context, args[0]); + FromJSValue(context, + non_optional_value0, + kNoConversionFlags, + &exception_state, &elements); + if (exception_state.is_exception_set()) { + return false; + } + + impl->SetUnionSequence(elements); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + + + +const JSPropertySpec prototype_properties[] = { + JS_PS_END +}; + +const JSFunctionSpec prototype_functions[] = { + JS_FNSPEC( + "getInterfaceSequence", fcn_getInterfaceSequence, NULL, + 0, JSPROP_ENUMERATE, NULL), + JS_FNSPEC( + "getInterfaceSequenceSequenceSequence", fcn_getInterfaceSequenceSequenceSequence, NULL, + 0, JSPROP_ENUMERATE, NULL), + JS_FNSPEC( + "getLongSequence", fcn_getLongSequence, NULL, + 0, JSPROP_ENUMERATE, NULL), + JS_FNSPEC( + "getStringSequence", fcn_getStringSequence, NULL, + 0, JSPROP_ENUMERATE, NULL), + JS_FNSPEC( + "getStringSequenceSequence", fcn_getStringSequenceSequence, NULL, + 0, JSPROP_ENUMERATE, NULL), + JS_FNSPEC( + "getUnionOfStringAndStringSequence", fcn_getUnionOfStringAndStringSequence, NULL, + 0, JSPROP_ENUMERATE, NULL), + JS_FNSPEC( + "getUnionSequence", fcn_getUnionSequence, NULL, + 0, JSPROP_ENUMERATE, NULL), + JS_FNSPEC( + "setInterfaceSequence", fcn_setInterfaceSequence, NULL, + 1, JSPROP_ENUMERATE, NULL), + JS_FNSPEC( + "setInterfaceSequenceSequenceSequence", fcn_setInterfaceSequenceSequenceSequence, NULL, + 1, JSPROP_ENUMERATE, NULL), + JS_FNSPEC( + "setLongSequence", fcn_setLongSequence, NULL, + 1, JSPROP_ENUMERATE, NULL), + JS_FNSPEC( + "setStringSequence", fcn_setStringSequence, NULL, + 1, JSPROP_ENUMERATE, NULL), + JS_FNSPEC( + "setStringSequenceSequence", fcn_setStringSequenceSequence, NULL, + 1, JSPROP_ENUMERATE, NULL), + JS_FNSPEC( + "setUnionOfStringAndStringSequence", fcn_setUnionOfStringAndStringSequence, NULL, + 1, JSPROP_ENUMERATE, NULL), + JS_FNSPEC( + "setUnionSequence", fcn_setUnionSequence, NULL, + 1, JSPROP_ENUMERATE, NULL), + JS_FS_END +}; + +const JSPropertySpec interface_object_properties[] = { + JS_PS_END +}; + +const JSFunctionSpec interface_object_functions[] = { + JS_FS_END +}; + +const JSPropertySpec own_properties[] = { + JS_PS_END +}; + +void InitializePrototypeAndInterfaceObject( + InterfaceData* interface_data, JSContext* context, + JS::HandleObject global_object) { + DCHECK(!interface_data->prototype); + DCHECK(!interface_data->interface_object); + DCHECK(JS_IsGlobalObject(global_object)); + + JS::RootedObject parent_prototype( + context, JS_GetObjectPrototype(context, global_object)); + DCHECK(parent_prototype); + + interface_data->prototype = JS_NewObjectWithGivenProto( + context, &prototype_class_definition, parent_prototype + ); + + JS::RootedObject rooted_prototype(context, interface_data->prototype); + bool success = JS_DefineProperties( + context, + rooted_prototype, + prototype_properties); + + DCHECK(success); + success = JS_DefineFunctions( + context, rooted_prototype, prototype_functions); + DCHECK(success); + + JS::RootedObject function_prototype( + context, JS_GetFunctionPrototype(context, global_object)); + DCHECK(function_prototype); + // Create the Interface object. + interface_data->interface_object = JS_NewObjectWithGivenProto( + context, &interface_object_class_definition, + function_prototype); + + // Add the InterfaceObject.name property. + JS::RootedObject rooted_interface_object( + context, interface_data->interface_object); + JS::RootedValue name_value(context); + const char name[] = + "SequenceUser"; + name_value.setString(JS_NewStringCopyZ(context, name)); + success = JS_DefineProperty( + context, rooted_interface_object, "name", name_value, JSPROP_READONLY, + NULL, NULL); + DCHECK(success); + + // Add the InterfaceObject.length property. It is set to the length of the + // shortest argument list of all overload constructors. + JS::RootedValue length_value(context); + length_value.setInt32(0); + success = JS_DefineProperty( + context, rooted_interface_object, "length", length_value, + JSPROP_READONLY, NULL, NULL); + DCHECK(success); + + // Define interface object properties (including constants). + success = JS_DefineProperties(context, rooted_interface_object, + interface_object_properties); + DCHECK(success); + // Define interface object functions (static). + success = JS_DefineFunctions(context, rooted_interface_object, + interface_object_functions); + DCHECK(success); + + // Set the Prototype.constructor and Constructor.prototype properties. + DCHECK(interface_data->interface_object); + DCHECK(interface_data->prototype); + success = JS_LinkConstructorAndPrototype( + context, + rooted_interface_object, + rooted_prototype); + DCHECK(success); +} + +InterfaceData* GetInterfaceData(JSContext* context) { + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + // Use the address of the properties definition for this interface as a + // unique key for looking up the InterfaceData for this interface. + intptr_t key = reinterpret_cast<intptr_t>(&own_properties); + InterfaceData* interface_data = global_environment->GetInterfaceData(key); + if (!interface_data) { + interface_data = new InterfaceData(); + DCHECK(interface_data); + global_environment->CacheInterfaceData(key, interface_data); + DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key)); + } + return interface_data; +} + +} // namespace + +// static +JSObject* MozjsSequenceUser::CreateProxy( + JSContext* context, const scoped_refptr<Wrappable>& wrappable) { + DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); + JS::RootedObject global_object( + context, + MozjsGlobalEnvironment::GetFromContext(context)->global_object()); + DCHECK(global_object); + + InterfaceData* interface_data = GetInterfaceData(context); + JS::RootedObject prototype(context, GetPrototype(context, global_object)); + DCHECK(prototype); + JS::RootedObject new_object( + context, + JS_NewObjectWithGivenProto( + context, &instance_class_definition, prototype)); + DCHECK(new_object); + JS::RootedObject proxy(context, + ProxyHandler::NewProxy( + context, proxy_handler.Pointer(), new_object, prototype)); + WrapperPrivate::AddPrivateData(context, proxy, wrappable); + return proxy; +} + +// static +const JSClass* MozjsSequenceUser::PrototypeClass( + JSContext* context) { + DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); + JS::RootedObject global_object( + context, + MozjsGlobalEnvironment::GetFromContext(context)->global_object()); + DCHECK(global_object); + + JS::RootedObject prototype(context, GetPrototype(context, global_object)); + const JSClass* proto_class = JS_GetClass(prototype); + return proto_class; +} + +// static +JSObject* MozjsSequenceUser::GetPrototype( + JSContext* context, JS::HandleObject global_object) { + DCHECK(JS_IsGlobalObject(global_object)); + + InterfaceData* interface_data = GetInterfaceData(context); + if (!interface_data->prototype) { + // Create new prototype that has all the props and methods + InitializePrototypeAndInterfaceObject( + interface_data, context, global_object); + } + DCHECK(interface_data->prototype); + return interface_data->prototype; +} + +// static +JSObject* MozjsSequenceUser::GetInterfaceObject( + JSContext* context, JS::HandleObject global_object) { + DCHECK(JS_IsGlobalObject(global_object)); + + InterfaceData* interface_data = GetInterfaceData(context); + if (!interface_data->interface_object) { + InitializePrototypeAndInterfaceObject( + interface_data, context, global_object); + } + DCHECK(interface_data->interface_object); + return interface_data->interface_object; +} + + +namespace { +bool Constructor(JSContext* context, unsigned int argc, JS::Value* vp) { + MozjsExceptionState exception_state(context); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + + scoped_refptr<SequenceUser> new_object = + new SequenceUser(); + JS::RootedValue result_value(context); + ToJSValue(context, new_object, &result_value); + DCHECK(result_value.isObject()); + args.rval().setObject(result_value.toObject()); + return true; +} +} // namespace + + +} // namespace testing +} // namespace bindings +} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_sequence_user.h b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_sequence_user.h new file mode 100644 index 0000000..08e98ef --- /dev/null +++ b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_sequence_user.h
@@ -0,0 +1,52 @@ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// clang-format off + +// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! +// Auto-generated from template: bindings/mozjs-45/templates/interface.h.template + +#ifndef MozjsSequenceUser_h +#define MozjsSequenceUser_h + +#include "base/hash_tables.h" +#include "base/lazy_instance.h" +#include "base/memory/ref_counted.h" +#include "base/threading/thread_checker.h" +#include "cobalt/base/polymorphic_downcast.h" +#include "cobalt/script/wrappable.h" +#include "cobalt/bindings/testing/sequence_user.h" + +#include "third_party/mozjs-45/js/src/jsapi.h" + +namespace cobalt { +namespace bindings { +namespace testing { + +class MozjsSequenceUser { + public: + static JSObject* CreateProxy(JSContext* context, + const scoped_refptr<script::Wrappable>& wrappable); + static const JSClass* PrototypeClass(JSContext* context); + static JSObject* GetPrototype(JSContext* context, + JS::HandleObject global_object); + static JSObject* GetInterfaceObject(JSContext* context, + JS::HandleObject global_object); +}; + +} // namespace testing +} // namespace bindings +} // namespace cobalt + +#endif // MozjsSequenceUser_h
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_single_operation_interface.cc b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_single_operation_interface.cc new file mode 100644 index 0000000..73f7881 --- /dev/null +++ b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_single_operation_interface.cc
@@ -0,0 +1,115 @@ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// clang-format off + +// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! +// Auto-generated from template: bindings/mozjs-45/templates/callback-interface.cc.template + + +#include "cobalt/bindings/testing/mozjs_single_operation_interface.h" +#include "cobalt/bindings/testing/arbitrary_interface.h" +#include "cobalt/bindings/testing/mozjs_arbitrary_interface.h" + +#include "cobalt/script/logging_exception_state.h" +#include "cobalt/script/mozjs-45/conversion_helpers.h" +#include "cobalt/script/mozjs-45/mozjs_callback_interface.h" +#include "cobalt/script/mozjs-45/util/exception_helpers.h" +#include "third_party/mozjs-45/js/src/jsapi.h" +#include "third_party/mozjs-45/js/src/jscntxt.h" + +namespace { +using cobalt::bindings::testing::SingleOperationInterface; +using cobalt::bindings::testing::MozjsSingleOperationInterface; +using cobalt::bindings::testing::ArbitraryInterface; +using cobalt::bindings::testing::MozjsArbitraryInterface; + +using cobalt::script::LoggingExceptionState; +using cobalt::script::mozjs::FromJSValue; +using cobalt::script::mozjs::GetCallableForCallbackInterface; +using cobalt::script::mozjs::ToJSValue; +using cobalt::script::mozjs::util::GetExceptionString; +} // namespace + +namespace cobalt { +namespace bindings { +namespace testing { + +MozjsSingleOperationInterface::MozjsSingleOperationInterface( + JSContext* context, + JS::HandleObject implementing_object) + : context_(context), + implementing_object_(context, implementing_object) { } + +MozjsSingleOperationInterface::MozjsSingleOperationInterface( + JSContext* context, + JS::HandleValue implementing_object_value) + : context_(context), + implementing_object_(context, implementing_object_value) { } + +base::optional<int32_t > MozjsSingleOperationInterface::HandleCallback( + const scoped_refptr<script::Wrappable>& callback_this, + const scoped_refptr<ArbitraryInterface>& value, + bool* had_exception) const { + bool success = false; + base::optional<int32_t > cobalt_return_value; + JSAutoRequest auto_request(context_); + JSExceptionState* previous_exception_state = JS_SaveExceptionState(context_); + + // This could be set to NULL if it was garbage collected. + JS::RootedObject implementing_object(context_, implementing_object_.GetObject()); + DLOG_IF(WARNING, !implementing_object) << "Implementing object is NULL."; + if (implementing_object) { + JSAutoCompartment auto_compartment(context_, implementing_object); + + // Get callable object. + JS::RootedValue callable(context_); + if (GetCallableForCallbackInterface(context_, implementing_object, + "handleCallback", &callable)) { + // Convert the callback_this to a JSValue. + JS::RootedValue this_value(context_); + ToJSValue(context_, callback_this, &this_value); + + // Convert arguments. + const int kNumArguments = 1; + JS::AutoValueArray<kNumArguments> args(context_); + + ToJSValue(context_, value, args[0]); + + // Call the function. + JS::RootedValue return_value(context_); + JS::RootedFunction function( + context_, JS_ValueToFunction(context_, callable)); + DCHECK(function); + success = JS::Call(context_, this_value, function, args, &return_value); + DLOG_IF(WARNING, !success) << "Exception in callback: " + << GetExceptionString(context_); + if (success) { + LoggingExceptionState exception_state; + FromJSValue(context_, return_value, 0, &exception_state, + &cobalt_return_value); + success = !exception_state.is_exception_set(); + } + } + } + + *had_exception = !success; + JS_RestoreExceptionState(context_, previous_exception_state); + return cobalt_return_value; +} + +} // namespace testing +} // namespace bindings +} // namespace cobalt +
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_single_operation_interface.h b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_single_operation_interface.h new file mode 100644 index 0000000..2080877 --- /dev/null +++ b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_single_operation_interface.h
@@ -0,0 +1,69 @@ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// clang-format off + +// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! +// Auto-generated from template: bindings/mozjs-45/templates/callback-interface.h.template + +#ifndef MozjsSingleOperationInterface_h +#define MozjsSingleOperationInterface_h + +#include "cobalt/script/callback_interface_traits.h" +// Headers for other bindings wrapper classes +#include "cobalt/bindings/testing/single_operation_interface.h" + +#include "cobalt/script/mozjs-45/weak_heap_object.h" +#include "third_party/mozjs-45/js/src/jsapi.h" + +namespace cobalt { +namespace bindings { +namespace testing { + +class MozjsSingleOperationInterface : public SingleOperationInterface { + public: + typedef SingleOperationInterface BaseType; + + MozjsSingleOperationInterface( + JSContext* context, JS::HandleObject implementing_object); + MozjsSingleOperationInterface( + JSContext* context, JS::HandleValue implementing_object_value); + base::optional<int32_t > HandleCallback( + const scoped_refptr<script::Wrappable>& callback_this, + const scoped_refptr<ArbitraryInterface>& value, + bool* had_exception) const OVERRIDE; + JSObject* handle() const { return implementing_object_.GetObject(); } + const JS::Value& value() const { return implementing_object_.GetValue(); } + bool WasCollected() const { return implementing_object_.WasCollected(); } + + private: + JSContext* context_; + script::mozjs::WeakHeapObject implementing_object_; +}; + +} // namespace testing +} // namespace bindings +} // namespace cobalt +namespace cobalt { +namespace script { +// Explicit instantiation of CallbackInterfaceTraits struct so we can infer +// the type of the generated class from the type of the callback interface. +template<> +struct CallbackInterfaceTraits<cobalt::bindings::testing::SingleOperationInterface> { + typedef cobalt::bindings::testing::MozjsSingleOperationInterface MozjsCallbackInterfaceClass; +}; +} // namespace script +} // namespace cobalt + +#endif // MozjsSingleOperationInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_static_properties_interface.cc b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_static_properties_interface.cc new file mode 100644 index 0000000..b55cc4f --- /dev/null +++ b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_static_properties_interface.cc
@@ -0,0 +1,659 @@ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// clang-format off + +// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! +// Auto-generated from template: bindings/mozjs-45/templates/interface.cc.template + +#include "cobalt/bindings/testing/mozjs_static_properties_interface.h" + +#include "base/debug/trace_event.h" +#include "cobalt/base/polymorphic_downcast.h" +#include "cobalt/script/global_environment.h" +#include "cobalt/script/opaque_handle.h" +#include "cobalt/script/script_value.h" +#include "cobalt/bindings/testing/arbitrary_interface.h" +#include "cobalt/bindings/testing/mozjs_arbitrary_interface.h" + +#include "base/lazy_instance.h" +#include "cobalt/script/exception_state.h" +#include "cobalt/script/mozjs-45/callback_function_conversion.h" +#include "cobalt/script/mozjs-45/conversion_helpers.h" +#include "cobalt/script/mozjs-45/mozjs_callback_function.h" +#include "cobalt/script/mozjs-45/mozjs_exception_state.h" +#include "cobalt/script/mozjs-45/mozjs_global_environment.h" +#include "cobalt/script/mozjs-45/mozjs_object_handle.h" +#include "cobalt/script/mozjs-45/mozjs_property_enumerator.h" +#include "cobalt/script/mozjs-45/mozjs_user_object_holder.h" +#include "cobalt/script/mozjs-45/proxy_handler.h" +#include "cobalt/script/mozjs-45/type_traits.h" +#include "cobalt/script/mozjs-45/wrapper_factory.h" +#include "cobalt/script/mozjs-45/wrapper_private.h" +#include "cobalt/script/property_enumerator.h" +#include "cobalt/script/sequence.h" +#include "third_party/mozjs-45/js/src/jsapi.h" +#include "third_party/mozjs-45/js/src/jsfriendapi.h" + +namespace { +using cobalt::bindings::testing::StaticPropertiesInterface; +using cobalt::bindings::testing::MozjsStaticPropertiesInterface; +using cobalt::bindings::testing::ArbitraryInterface; +using cobalt::bindings::testing::MozjsArbitraryInterface; +using cobalt::script::CallbackInterfaceTraits; +using cobalt::script::GlobalEnvironment; +using cobalt::script::OpaqueHandle; +using cobalt::script::OpaqueHandleHolder; +using cobalt::script::ScriptValue; +using cobalt::script::Wrappable; + +using cobalt::script::CallbackFunction; +using cobalt::script::CallbackInterfaceTraits; +using cobalt::script::ExceptionState; +using cobalt::script::Wrappable; +using cobalt::script::mozjs::FromJSValue; +using cobalt::script::mozjs::InterfaceData; +using cobalt::script::mozjs::MozjsCallbackFunction; +using cobalt::script::mozjs::MozjsExceptionState; +using cobalt::script::mozjs::MozjsGlobalEnvironment; +using cobalt::script::mozjs::MozjsPropertyEnumerator; +using cobalt::script::mozjs::MozjsUserObjectHolder; +using cobalt::script::mozjs::ProxyHandler; +using cobalt::script::mozjs::ToJSValue; +using cobalt::script::mozjs::TypeTraits; +using cobalt::script::mozjs::WrapperFactory; +using cobalt::script::mozjs::WrapperPrivate; +using cobalt::script::mozjs::kConversionFlagNullable; +using cobalt::script::mozjs::kConversionFlagRestricted; +using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString; +using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString; +using cobalt::script::mozjs::kNoConversionFlags; +} // namespace + +namespace cobalt { +namespace bindings { +namespace testing { + +namespace { + +class MozjsStaticPropertiesInterfaceHandler : public ProxyHandler { + public: + MozjsStaticPropertiesInterfaceHandler() + : ProxyHandler(indexed_property_hooks, named_property_hooks) {} + + private: + static NamedPropertyHooks named_property_hooks; + static IndexedPropertyHooks indexed_property_hooks; +}; + +ProxyHandler::NamedPropertyHooks +MozjsStaticPropertiesInterfaceHandler::named_property_hooks = { + NULL, + NULL, + NULL, + NULL, + NULL, +}; +ProxyHandler::IndexedPropertyHooks +MozjsStaticPropertiesInterfaceHandler::indexed_property_hooks = { + NULL, + NULL, + NULL, + NULL, + NULL, +}; + +static base::LazyInstance<MozjsStaticPropertiesInterfaceHandler> + proxy_handler; + +bool HasInstance(JSContext *context, JS::HandleObject type, + JS::MutableHandleValue vp, bool *success) { + JS::RootedObject global_object( + context, JS_GetGlobalForObject(context, type)); + DCHECK(global_object); + + JS::RootedObject prototype( + context, MozjsStaticPropertiesInterface::GetPrototype(context, global_object)); + + // |IsDelegate| walks the prototype chain of an object returning true if + // .prototype is found. + bool is_delegate; + if (!IsDelegate(context, prototype, vp, &is_delegate)) { + *success = false; + return false; + } + + *success = is_delegate; + return true; +} + +const JSClass instance_class_definition = { + "StaticPropertiesInterface", + 0 | JSCLASS_HAS_PRIVATE, + NULL, // addProperty + NULL, // delProperty + NULL, // getProperty + NULL, // setProperty + NULL, // enumerate + NULL, // resolve + NULL, // mayResolve + &WrapperPrivate::Finalizer, // finalize + NULL, // call + NULL, // hasInstance + NULL, // construct + &WrapperPrivate::Trace, // trace +}; + +const JSClass prototype_class_definition = { + "StaticPropertiesInterfacePrototype", +}; + +const JSClass interface_object_class_definition = { + "StaticPropertiesInterfaceConstructor", + 0, + NULL, // addProperty + NULL, // delProperty + NULL, // getProperty + NULL, // setProperty + NULL, // enumerate + NULL, // resolve + NULL, // mayResolve + NULL, // finalize + NULL, // call + &HasInstance, + NULL, +}; + +bool staticget_staticAttribute( + JSContext* context, unsigned argc, JS::Value* vp) { + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + StaticPropertiesInterface::static_attribute(), + &result_value); + } + if (!exception_state.is_exception_set()) { + args.rval().set(result_value); + } + return !exception_state.is_exception_set(); +} + +bool staticset_staticAttribute( + JSContext* context, unsigned argc, JS::Value* vp) { + + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + TypeTraits<std::string >::ConversionType value; + if (args.length() != 1) { + NOTREACHED(); + return false; + } + FromJSValue(context, args[0], kNoConversionFlags, &exception_state, + &value); + if (exception_state.is_exception_set()) { + return false; + } + + StaticPropertiesInterface::set_static_attribute(value); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + +bool staticfcn_staticFunction1( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + + StaticPropertiesInterface::StaticFunction(); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + +bool staticfcn_staticFunction2( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + const size_t kMinArguments = 1; + if (args.length() < kMinArguments) { + exception_state.SetSimpleException(script::kInvalidNumberOfArguments); + return false; + } + // Non-optional arguments + TypeTraits<int32_t >::ConversionType arg; + + DCHECK_LT(0, args.length()); + JS::RootedValue non_optional_value0( + context, args[0]); + FromJSValue(context, + non_optional_value0, + kNoConversionFlags, + &exception_state, &arg); + if (exception_state.is_exception_set()) { + return false; + } + + StaticPropertiesInterface::StaticFunction(arg); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + +bool staticfcn_staticFunction3( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + const size_t kMinArguments = 1; + if (args.length() < kMinArguments) { + exception_state.SetSimpleException(script::kInvalidNumberOfArguments); + return false; + } + // Non-optional arguments + TypeTraits<std::string >::ConversionType arg; + + DCHECK_LT(0, args.length()); + JS::RootedValue non_optional_value0( + context, args[0]); + FromJSValue(context, + non_optional_value0, + kNoConversionFlags, + &exception_state, &arg); + if (exception_state.is_exception_set()) { + return false; + } + + StaticPropertiesInterface::StaticFunction(arg); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + +bool staticfcn_staticFunction4( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + const size_t kMinArguments = 3; + if (args.length() < kMinArguments) { + exception_state.SetSimpleException(script::kInvalidNumberOfArguments); + return false; + } + // Non-optional arguments + TypeTraits<int32_t >::ConversionType arg1; + TypeTraits<int32_t >::ConversionType arg2; + TypeTraits<int32_t >::ConversionType arg3; + + DCHECK_LT(0, args.length()); + JS::RootedValue non_optional_value0( + context, args[0]); + FromJSValue(context, + non_optional_value0, + kNoConversionFlags, + &exception_state, &arg1); + if (exception_state.is_exception_set()) { + return false; + } + + DCHECK_LT(1, args.length()); + JS::RootedValue non_optional_value1( + context, args[1]); + FromJSValue(context, + non_optional_value1, + kNoConversionFlags, + &exception_state, &arg2); + if (exception_state.is_exception_set()) { + return false; + } + + DCHECK_LT(2, args.length()); + JS::RootedValue non_optional_value2( + context, args[2]); + FromJSValue(context, + non_optional_value2, + kNoConversionFlags, + &exception_state, &arg3); + if (exception_state.is_exception_set()) { + return false; + } + + StaticPropertiesInterface::StaticFunction(arg1, arg2, arg3); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + +bool staticfcn_staticFunction5( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + const size_t kMinArguments = 3; + if (args.length() < kMinArguments) { + exception_state.SetSimpleException(script::kInvalidNumberOfArguments); + return false; + } + // Non-optional arguments + TypeTraits<int32_t >::ConversionType arg1; + TypeTraits<int32_t >::ConversionType arg2; + TypeTraits<scoped_refptr<ArbitraryInterface> >::ConversionType arg3; + + DCHECK_LT(0, args.length()); + JS::RootedValue non_optional_value0( + context, args[0]); + FromJSValue(context, + non_optional_value0, + kNoConversionFlags, + &exception_state, &arg1); + if (exception_state.is_exception_set()) { + return false; + } + + DCHECK_LT(1, args.length()); + JS::RootedValue non_optional_value1( + context, args[1]); + FromJSValue(context, + non_optional_value1, + kNoConversionFlags, + &exception_state, &arg2); + if (exception_state.is_exception_set()) { + return false; + } + + DCHECK_LT(2, args.length()); + JS::RootedValue non_optional_value2( + context, args[2]); + FromJSValue(context, + non_optional_value2, + kNoConversionFlags, + &exception_state, &arg3); + if (exception_state.is_exception_set()) { + return false; + } + + StaticPropertiesInterface::StaticFunction(arg1, arg2, arg3); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + +bool staticfcn_staticFunction( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + switch(argc) { + case(0): { + // Overload resolution algorithm details found here: + // http://heycam.github.io/webidl/#dfn-overload-resolution-algorithm + if (true) { + return staticfcn_staticFunction1( + context, argc, vp); + } + break; + } + case(1): { + // Overload resolution algorithm details found here: + // http://heycam.github.io/webidl/#dfn-overload-resolution-algorithm + JS::RootedValue arg(context, args[0]); + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + JS::RootedObject object(context); + if (arg.isObject()) { + object = JS::RootedObject(context, &arg.toObject()); + } + if (arg.isNumber()) { + return staticfcn_staticFunction2( + context, argc, vp); + } + if (true) { + return staticfcn_staticFunction3( + context, argc, vp); + } + if (true) { + return staticfcn_staticFunction2( + context, argc, vp); + } + break; + } + case(3): { + // Overload resolution algorithm details found here: + // http://heycam.github.io/webidl/#dfn-overload-resolution-algorithm + JS::RootedValue arg(context, args[2]); + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + JS::RootedObject object(context); + if (arg.isObject()) { + object = JS::RootedObject(context, &arg.toObject()); + } + if (arg.isObject() ? wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<ArbitraryInterface>()) : + false) { + return staticfcn_staticFunction5( + context, argc, vp); + } + if (true) { + return staticfcn_staticFunction4( + context, argc, vp); + } + break; + } + } + // Invalid number of args + // http://heycam.github.io/webidl/#dfn-overload-resolution-algorithm + // 4. If S is empty, then throw a TypeError. + MozjsExceptionState exception_state(context); + exception_state.SetSimpleException(script::kInvalidNumberOfArguments); + return false; +} + + + +const JSPropertySpec prototype_properties[] = { + JS_PS_END +}; + +const JSFunctionSpec prototype_functions[] = { + JS_FS_END +}; + +const JSPropertySpec interface_object_properties[] = { + { // Static read/write attribute. + "staticAttribute", + JSPROP_SHARED | JSPROP_ENUMERATE, + { { &staticget_staticAttribute, NULL } }, + { { &staticset_staticAttribute, NULL } }, + }, + JS_PS_END +}; + +const JSFunctionSpec interface_object_functions[] = { + JS_FNSPEC( + "staticFunction", staticfcn_staticFunction, NULL, + 0, JSPROP_ENUMERATE, NULL), + JS_FS_END +}; + +const JSPropertySpec own_properties[] = { + JS_PS_END +}; + +void InitializePrototypeAndInterfaceObject( + InterfaceData* interface_data, JSContext* context, + JS::HandleObject global_object) { + DCHECK(!interface_data->prototype); + DCHECK(!interface_data->interface_object); + DCHECK(JS_IsGlobalObject(global_object)); + + JS::RootedObject parent_prototype( + context, JS_GetObjectPrototype(context, global_object)); + DCHECK(parent_prototype); + + interface_data->prototype = JS_NewObjectWithGivenProto( + context, &prototype_class_definition, parent_prototype + ); + + JS::RootedObject rooted_prototype(context, interface_data->prototype); + bool success = JS_DefineProperties( + context, + rooted_prototype, + prototype_properties); + + DCHECK(success); + success = JS_DefineFunctions( + context, rooted_prototype, prototype_functions); + DCHECK(success); + + JS::RootedObject function_prototype( + context, JS_GetFunctionPrototype(context, global_object)); + DCHECK(function_prototype); + // Create the Interface object. + interface_data->interface_object = JS_NewObjectWithGivenProto( + context, &interface_object_class_definition, + function_prototype); + + // Add the InterfaceObject.name property. + JS::RootedObject rooted_interface_object( + context, interface_data->interface_object); + JS::RootedValue name_value(context); + const char name[] = + "StaticPropertiesInterface"; + name_value.setString(JS_NewStringCopyZ(context, name)); + success = JS_DefineProperty( + context, rooted_interface_object, "name", name_value, JSPROP_READONLY, + NULL, NULL); + DCHECK(success); + + // Define interface object properties (including constants). + success = JS_DefineProperties(context, rooted_interface_object, + interface_object_properties); + DCHECK(success); + // Define interface object functions (static). + success = JS_DefineFunctions(context, rooted_interface_object, + interface_object_functions); + DCHECK(success); + + // Set the Prototype.constructor and Constructor.prototype properties. + DCHECK(interface_data->interface_object); + DCHECK(interface_data->prototype); + success = JS_LinkConstructorAndPrototype( + context, + rooted_interface_object, + rooted_prototype); + DCHECK(success); +} + +InterfaceData* GetInterfaceData(JSContext* context) { + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + // Use the address of the properties definition for this interface as a + // unique key for looking up the InterfaceData for this interface. + intptr_t key = reinterpret_cast<intptr_t>(&own_properties); + InterfaceData* interface_data = global_environment->GetInterfaceData(key); + if (!interface_data) { + interface_data = new InterfaceData(); + DCHECK(interface_data); + global_environment->CacheInterfaceData(key, interface_data); + DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key)); + } + return interface_data; +} + +} // namespace + +// static +JSObject* MozjsStaticPropertiesInterface::CreateProxy( + JSContext* context, const scoped_refptr<Wrappable>& wrappable) { + DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); + JS::RootedObject global_object( + context, + MozjsGlobalEnvironment::GetFromContext(context)->global_object()); + DCHECK(global_object); + + InterfaceData* interface_data = GetInterfaceData(context); + JS::RootedObject prototype(context, GetPrototype(context, global_object)); + DCHECK(prototype); + JS::RootedObject new_object( + context, + JS_NewObjectWithGivenProto( + context, &instance_class_definition, prototype)); + DCHECK(new_object); + JS::RootedObject proxy(context, + ProxyHandler::NewProxy( + context, proxy_handler.Pointer(), new_object, prototype)); + WrapperPrivate::AddPrivateData(context, proxy, wrappable); + return proxy; +} + +// static +const JSClass* MozjsStaticPropertiesInterface::PrototypeClass( + JSContext* context) { + DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); + JS::RootedObject global_object( + context, + MozjsGlobalEnvironment::GetFromContext(context)->global_object()); + DCHECK(global_object); + + JS::RootedObject prototype(context, GetPrototype(context, global_object)); + const JSClass* proto_class = JS_GetClass(prototype); + return proto_class; +} + +// static +JSObject* MozjsStaticPropertiesInterface::GetPrototype( + JSContext* context, JS::HandleObject global_object) { + DCHECK(JS_IsGlobalObject(global_object)); + + InterfaceData* interface_data = GetInterfaceData(context); + if (!interface_data->prototype) { + // Create new prototype that has all the props and methods + InitializePrototypeAndInterfaceObject( + interface_data, context, global_object); + } + DCHECK(interface_data->prototype); + return interface_data->prototype; +} + +// static +JSObject* MozjsStaticPropertiesInterface::GetInterfaceObject( + JSContext* context, JS::HandleObject global_object) { + DCHECK(JS_IsGlobalObject(global_object)); + + InterfaceData* interface_data = GetInterfaceData(context); + if (!interface_data->interface_object) { + InitializePrototypeAndInterfaceObject( + interface_data, context, global_object); + } + DCHECK(interface_data->interface_object); + return interface_data->interface_object; +} + + +namespace { +} // namespace + + +} // namespace testing +} // namespace bindings +} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_static_properties_interface.h b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_static_properties_interface.h new file mode 100644 index 0000000..f5f16da --- /dev/null +++ b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_static_properties_interface.h
@@ -0,0 +1,52 @@ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// clang-format off + +// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! +// Auto-generated from template: bindings/mozjs-45/templates/interface.h.template + +#ifndef MozjsStaticPropertiesInterface_h +#define MozjsStaticPropertiesInterface_h + +#include "base/hash_tables.h" +#include "base/lazy_instance.h" +#include "base/memory/ref_counted.h" +#include "base/threading/thread_checker.h" +#include "cobalt/base/polymorphic_downcast.h" +#include "cobalt/script/wrappable.h" +#include "cobalt/bindings/testing/static_properties_interface.h" + +#include "third_party/mozjs-45/js/src/jsapi.h" + +namespace cobalt { +namespace bindings { +namespace testing { + +class MozjsStaticPropertiesInterface { + public: + static JSObject* CreateProxy(JSContext* context, + const scoped_refptr<script::Wrappable>& wrappable); + static const JSClass* PrototypeClass(JSContext* context); + static JSObject* GetPrototype(JSContext* context, + JS::HandleObject global_object); + static JSObject* GetInterfaceObject(JSContext* context, + JS::HandleObject global_object); +}; + +} // namespace testing +} // namespace bindings +} // namespace cobalt + +#endif // MozjsStaticPropertiesInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_stringifier_anonymous_operation_interface.cc b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_stringifier_anonymous_operation_interface.cc new file mode 100644 index 0000000..8e21e6a --- /dev/null +++ b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_stringifier_anonymous_operation_interface.cc
@@ -0,0 +1,386 @@ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// clang-format off + +// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! +// Auto-generated from template: bindings/mozjs-45/templates/interface.cc.template + +#include "cobalt/bindings/testing/mozjs_stringifier_anonymous_operation_interface.h" + +#include "base/debug/trace_event.h" +#include "cobalt/base/polymorphic_downcast.h" +#include "cobalt/script/global_environment.h" +#include "cobalt/script/opaque_handle.h" +#include "cobalt/script/script_value.h" + +#include "base/lazy_instance.h" +#include "cobalt/script/exception_state.h" +#include "cobalt/script/mozjs-45/callback_function_conversion.h" +#include "cobalt/script/mozjs-45/conversion_helpers.h" +#include "cobalt/script/mozjs-45/mozjs_callback_function.h" +#include "cobalt/script/mozjs-45/mozjs_exception_state.h" +#include "cobalt/script/mozjs-45/mozjs_global_environment.h" +#include "cobalt/script/mozjs-45/mozjs_object_handle.h" +#include "cobalt/script/mozjs-45/mozjs_property_enumerator.h" +#include "cobalt/script/mozjs-45/mozjs_user_object_holder.h" +#include "cobalt/script/mozjs-45/proxy_handler.h" +#include "cobalt/script/mozjs-45/type_traits.h" +#include "cobalt/script/mozjs-45/wrapper_factory.h" +#include "cobalt/script/mozjs-45/wrapper_private.h" +#include "cobalt/script/property_enumerator.h" +#include "cobalt/script/sequence.h" +#include "third_party/mozjs-45/js/src/jsapi.h" +#include "third_party/mozjs-45/js/src/jsfriendapi.h" + +namespace { +using cobalt::bindings::testing::StringifierAnonymousOperationInterface; +using cobalt::bindings::testing::MozjsStringifierAnonymousOperationInterface; +using cobalt::script::CallbackInterfaceTraits; +using cobalt::script::GlobalEnvironment; +using cobalt::script::OpaqueHandle; +using cobalt::script::OpaqueHandleHolder; +using cobalt::script::ScriptValue; +using cobalt::script::Wrappable; + +using cobalt::script::CallbackFunction; +using cobalt::script::CallbackInterfaceTraits; +using cobalt::script::ExceptionState; +using cobalt::script::Wrappable; +using cobalt::script::mozjs::FromJSValue; +using cobalt::script::mozjs::InterfaceData; +using cobalt::script::mozjs::MozjsCallbackFunction; +using cobalt::script::mozjs::MozjsExceptionState; +using cobalt::script::mozjs::MozjsGlobalEnvironment; +using cobalt::script::mozjs::MozjsPropertyEnumerator; +using cobalt::script::mozjs::MozjsUserObjectHolder; +using cobalt::script::mozjs::ProxyHandler; +using cobalt::script::mozjs::ToJSValue; +using cobalt::script::mozjs::TypeTraits; +using cobalt::script::mozjs::WrapperFactory; +using cobalt::script::mozjs::WrapperPrivate; +using cobalt::script::mozjs::kConversionFlagNullable; +using cobalt::script::mozjs::kConversionFlagRestricted; +using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString; +using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString; +using cobalt::script::mozjs::kNoConversionFlags; +} // namespace + +namespace cobalt { +namespace bindings { +namespace testing { + +namespace { + +class MozjsStringifierAnonymousOperationInterfaceHandler : public ProxyHandler { + public: + MozjsStringifierAnonymousOperationInterfaceHandler() + : ProxyHandler(indexed_property_hooks, named_property_hooks) {} + + private: + static NamedPropertyHooks named_property_hooks; + static IndexedPropertyHooks indexed_property_hooks; +}; + +ProxyHandler::NamedPropertyHooks +MozjsStringifierAnonymousOperationInterfaceHandler::named_property_hooks = { + NULL, + NULL, + NULL, + NULL, + NULL, +}; +ProxyHandler::IndexedPropertyHooks +MozjsStringifierAnonymousOperationInterfaceHandler::indexed_property_hooks = { + NULL, + NULL, + NULL, + NULL, + NULL, +}; + +static base::LazyInstance<MozjsStringifierAnonymousOperationInterfaceHandler> + proxy_handler; + +bool HasInstance(JSContext *context, JS::HandleObject type, + JS::MutableHandleValue vp, bool *success) { + JS::RootedObject global_object( + context, JS_GetGlobalForObject(context, type)); + DCHECK(global_object); + + JS::RootedObject prototype( + context, MozjsStringifierAnonymousOperationInterface::GetPrototype(context, global_object)); + + // |IsDelegate| walks the prototype chain of an object returning true if + // .prototype is found. + bool is_delegate; + if (!IsDelegate(context, prototype, vp, &is_delegate)) { + *success = false; + return false; + } + + *success = is_delegate; + return true; +} + +const JSClass instance_class_definition = { + "StringifierAnonymousOperationInterface", + 0 | JSCLASS_HAS_PRIVATE, + NULL, // addProperty + NULL, // delProperty + NULL, // getProperty + NULL, // setProperty + NULL, // enumerate + NULL, // resolve + NULL, // mayResolve + &WrapperPrivate::Finalizer, // finalize + NULL, // call + NULL, // hasInstance + NULL, // construct + &WrapperPrivate::Trace, // trace +}; + +const JSClass prototype_class_definition = { + "StringifierAnonymousOperationInterfacePrototype", +}; + +const JSClass interface_object_class_definition = { + "StringifierAnonymousOperationInterfaceConstructor", + 0, + NULL, // addProperty + NULL, // delProperty + NULL, // getProperty + NULL, // setProperty + NULL, // enumerate + NULL, // resolve + NULL, // mayResolve + NULL, // finalize + NULL, // call + &HasInstance, + NULL, +}; + + +bool Stringifier(JSContext* context, unsigned argc, JS::Value *vp) { + MozjsExceptionState exception_state(context); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + StringifierAnonymousOperationInterface* impl = + wrapper_private->wrappable<StringifierAnonymousOperationInterface>().get(); + if (!impl) { + exception_state.SetSimpleException(cobalt::script::kStringifierProblem); + NOTREACHED(); + return false; + } + std::string stringified = impl->AnonymousStringifier(); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedString rooted_string(context, + JS_NewStringCopyN(context, stringified.c_str(), stringified.length())); + args.rval().set(JS::StringValue(rooted_string)); + return true; +} + + +const JSPropertySpec prototype_properties[] = { + JS_PS_END +}; + +const JSFunctionSpec prototype_functions[] = { + JS_FNSPEC("toString", Stringifier, NULL, 0, JSPROP_ENUMERATE, NULL), + JS_FS_END +}; + +const JSPropertySpec interface_object_properties[] = { + JS_PS_END +}; + +const JSFunctionSpec interface_object_functions[] = { + JS_FS_END +}; + +const JSPropertySpec own_properties[] = { + JS_PS_END +}; + +void InitializePrototypeAndInterfaceObject( + InterfaceData* interface_data, JSContext* context, + JS::HandleObject global_object) { + DCHECK(!interface_data->prototype); + DCHECK(!interface_data->interface_object); + DCHECK(JS_IsGlobalObject(global_object)); + + JS::RootedObject parent_prototype( + context, JS_GetObjectPrototype(context, global_object)); + DCHECK(parent_prototype); + + interface_data->prototype = JS_NewObjectWithGivenProto( + context, &prototype_class_definition, parent_prototype + ); + + JS::RootedObject rooted_prototype(context, interface_data->prototype); + bool success = JS_DefineProperties( + context, + rooted_prototype, + prototype_properties); + + DCHECK(success); + success = JS_DefineFunctions( + context, rooted_prototype, prototype_functions); + DCHECK(success); + + JS::RootedObject function_prototype( + context, JS_GetFunctionPrototype(context, global_object)); + DCHECK(function_prototype); + // Create the Interface object. + interface_data->interface_object = JS_NewObjectWithGivenProto( + context, &interface_object_class_definition, + function_prototype); + + // Add the InterfaceObject.name property. + JS::RootedObject rooted_interface_object( + context, interface_data->interface_object); + JS::RootedValue name_value(context); + const char name[] = + "StringifierAnonymousOperationInterface"; + name_value.setString(JS_NewStringCopyZ(context, name)); + success = JS_DefineProperty( + context, rooted_interface_object, "name", name_value, JSPROP_READONLY, + NULL, NULL); + DCHECK(success); + + // Define interface object properties (including constants). + success = JS_DefineProperties(context, rooted_interface_object, + interface_object_properties); + DCHECK(success); + // Define interface object functions (static). + success = JS_DefineFunctions(context, rooted_interface_object, + interface_object_functions); + DCHECK(success); + + // Set the Prototype.constructor and Constructor.prototype properties. + DCHECK(interface_data->interface_object); + DCHECK(interface_data->prototype); + success = JS_LinkConstructorAndPrototype( + context, + rooted_interface_object, + rooted_prototype); + DCHECK(success); +} + +InterfaceData* GetInterfaceData(JSContext* context) { + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + // Use the address of the properties definition for this interface as a + // unique key for looking up the InterfaceData for this interface. + intptr_t key = reinterpret_cast<intptr_t>(&own_properties); + InterfaceData* interface_data = global_environment->GetInterfaceData(key); + if (!interface_data) { + interface_data = new InterfaceData(); + DCHECK(interface_data); + global_environment->CacheInterfaceData(key, interface_data); + DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key)); + } + return interface_data; +} + +} // namespace + +// static +JSObject* MozjsStringifierAnonymousOperationInterface::CreateProxy( + JSContext* context, const scoped_refptr<Wrappable>& wrappable) { + DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); + JS::RootedObject global_object( + context, + MozjsGlobalEnvironment::GetFromContext(context)->global_object()); + DCHECK(global_object); + + InterfaceData* interface_data = GetInterfaceData(context); + JS::RootedObject prototype(context, GetPrototype(context, global_object)); + DCHECK(prototype); + JS::RootedObject new_object( + context, + JS_NewObjectWithGivenProto( + context, &instance_class_definition, prototype)); + DCHECK(new_object); + JS::RootedObject proxy(context, + ProxyHandler::NewProxy( + context, proxy_handler.Pointer(), new_object, prototype)); + WrapperPrivate::AddPrivateData(context, proxy, wrappable); + return proxy; +} + +// static +const JSClass* MozjsStringifierAnonymousOperationInterface::PrototypeClass( + JSContext* context) { + DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); + JS::RootedObject global_object( + context, + MozjsGlobalEnvironment::GetFromContext(context)->global_object()); + DCHECK(global_object); + + JS::RootedObject prototype(context, GetPrototype(context, global_object)); + const JSClass* proto_class = JS_GetClass(prototype); + return proto_class; +} + +// static +JSObject* MozjsStringifierAnonymousOperationInterface::GetPrototype( + JSContext* context, JS::HandleObject global_object) { + DCHECK(JS_IsGlobalObject(global_object)); + + InterfaceData* interface_data = GetInterfaceData(context); + if (!interface_data->prototype) { + // Create new prototype that has all the props and methods + InitializePrototypeAndInterfaceObject( + interface_data, context, global_object); + } + DCHECK(interface_data->prototype); + return interface_data->prototype; +} + +// static +JSObject* MozjsStringifierAnonymousOperationInterface::GetInterfaceObject( + JSContext* context, JS::HandleObject global_object) { + DCHECK(JS_IsGlobalObject(global_object)); + + InterfaceData* interface_data = GetInterfaceData(context); + if (!interface_data->interface_object) { + InitializePrototypeAndInterfaceObject( + interface_data, context, global_object); + } + DCHECK(interface_data->interface_object); + return interface_data->interface_object; +} + + +namespace { +} // namespace + + +} // namespace testing +} // namespace bindings +} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_stringifier_anonymous_operation_interface.h b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_stringifier_anonymous_operation_interface.h new file mode 100644 index 0000000..a07e909 --- /dev/null +++ b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_stringifier_anonymous_operation_interface.h
@@ -0,0 +1,52 @@ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// clang-format off + +// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! +// Auto-generated from template: bindings/mozjs-45/templates/interface.h.template + +#ifndef MozjsStringifierAnonymousOperationInterface_h +#define MozjsStringifierAnonymousOperationInterface_h + +#include "base/hash_tables.h" +#include "base/lazy_instance.h" +#include "base/memory/ref_counted.h" +#include "base/threading/thread_checker.h" +#include "cobalt/base/polymorphic_downcast.h" +#include "cobalt/script/wrappable.h" +#include "cobalt/bindings/testing/stringifier_anonymous_operation_interface.h" + +#include "third_party/mozjs-45/js/src/jsapi.h" + +namespace cobalt { +namespace bindings { +namespace testing { + +class MozjsStringifierAnonymousOperationInterface { + public: + static JSObject* CreateProxy(JSContext* context, + const scoped_refptr<script::Wrappable>& wrappable); + static const JSClass* PrototypeClass(JSContext* context); + static JSObject* GetPrototype(JSContext* context, + JS::HandleObject global_object); + static JSObject* GetInterfaceObject(JSContext* context, + JS::HandleObject global_object); +}; + +} // namespace testing +} // namespace bindings +} // namespace cobalt + +#endif // MozjsStringifierAnonymousOperationInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_stringifier_attribute_interface.cc b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_stringifier_attribute_interface.cc new file mode 100644 index 0000000..11433d7 --- /dev/null +++ b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_stringifier_attribute_interface.cc
@@ -0,0 +1,482 @@ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// clang-format off + +// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! +// Auto-generated from template: bindings/mozjs-45/templates/interface.cc.template + +#include "cobalt/bindings/testing/mozjs_stringifier_attribute_interface.h" + +#include "base/debug/trace_event.h" +#include "cobalt/base/polymorphic_downcast.h" +#include "cobalt/script/global_environment.h" +#include "cobalt/script/opaque_handle.h" +#include "cobalt/script/script_value.h" + +#include "base/lazy_instance.h" +#include "cobalt/script/exception_state.h" +#include "cobalt/script/mozjs-45/callback_function_conversion.h" +#include "cobalt/script/mozjs-45/conversion_helpers.h" +#include "cobalt/script/mozjs-45/mozjs_callback_function.h" +#include "cobalt/script/mozjs-45/mozjs_exception_state.h" +#include "cobalt/script/mozjs-45/mozjs_global_environment.h" +#include "cobalt/script/mozjs-45/mozjs_object_handle.h" +#include "cobalt/script/mozjs-45/mozjs_property_enumerator.h" +#include "cobalt/script/mozjs-45/mozjs_user_object_holder.h" +#include "cobalt/script/mozjs-45/proxy_handler.h" +#include "cobalt/script/mozjs-45/type_traits.h" +#include "cobalt/script/mozjs-45/wrapper_factory.h" +#include "cobalt/script/mozjs-45/wrapper_private.h" +#include "cobalt/script/property_enumerator.h" +#include "cobalt/script/sequence.h" +#include "third_party/mozjs-45/js/src/jsapi.h" +#include "third_party/mozjs-45/js/src/jsfriendapi.h" + +namespace { +using cobalt::bindings::testing::StringifierAttributeInterface; +using cobalt::bindings::testing::MozjsStringifierAttributeInterface; +using cobalt::script::CallbackInterfaceTraits; +using cobalt::script::GlobalEnvironment; +using cobalt::script::OpaqueHandle; +using cobalt::script::OpaqueHandleHolder; +using cobalt::script::ScriptValue; +using cobalt::script::Wrappable; + +using cobalt::script::CallbackFunction; +using cobalt::script::CallbackInterfaceTraits; +using cobalt::script::ExceptionState; +using cobalt::script::Wrappable; +using cobalt::script::mozjs::FromJSValue; +using cobalt::script::mozjs::InterfaceData; +using cobalt::script::mozjs::MozjsCallbackFunction; +using cobalt::script::mozjs::MozjsExceptionState; +using cobalt::script::mozjs::MozjsGlobalEnvironment; +using cobalt::script::mozjs::MozjsPropertyEnumerator; +using cobalt::script::mozjs::MozjsUserObjectHolder; +using cobalt::script::mozjs::ProxyHandler; +using cobalt::script::mozjs::ToJSValue; +using cobalt::script::mozjs::TypeTraits; +using cobalt::script::mozjs::WrapperFactory; +using cobalt::script::mozjs::WrapperPrivate; +using cobalt::script::mozjs::kConversionFlagNullable; +using cobalt::script::mozjs::kConversionFlagRestricted; +using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString; +using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString; +using cobalt::script::mozjs::kNoConversionFlags; +} // namespace + +namespace cobalt { +namespace bindings { +namespace testing { + +namespace { + +class MozjsStringifierAttributeInterfaceHandler : public ProxyHandler { + public: + MozjsStringifierAttributeInterfaceHandler() + : ProxyHandler(indexed_property_hooks, named_property_hooks) {} + + private: + static NamedPropertyHooks named_property_hooks; + static IndexedPropertyHooks indexed_property_hooks; +}; + +ProxyHandler::NamedPropertyHooks +MozjsStringifierAttributeInterfaceHandler::named_property_hooks = { + NULL, + NULL, + NULL, + NULL, + NULL, +}; +ProxyHandler::IndexedPropertyHooks +MozjsStringifierAttributeInterfaceHandler::indexed_property_hooks = { + NULL, + NULL, + NULL, + NULL, + NULL, +}; + +static base::LazyInstance<MozjsStringifierAttributeInterfaceHandler> + proxy_handler; + +bool HasInstance(JSContext *context, JS::HandleObject type, + JS::MutableHandleValue vp, bool *success) { + JS::RootedObject global_object( + context, JS_GetGlobalForObject(context, type)); + DCHECK(global_object); + + JS::RootedObject prototype( + context, MozjsStringifierAttributeInterface::GetPrototype(context, global_object)); + + // |IsDelegate| walks the prototype chain of an object returning true if + // .prototype is found. + bool is_delegate; + if (!IsDelegate(context, prototype, vp, &is_delegate)) { + *success = false; + return false; + } + + *success = is_delegate; + return true; +} + +const JSClass instance_class_definition = { + "StringifierAttributeInterface", + 0 | JSCLASS_HAS_PRIVATE, + NULL, // addProperty + NULL, // delProperty + NULL, // getProperty + NULL, // setProperty + NULL, // enumerate + NULL, // resolve + NULL, // mayResolve + &WrapperPrivate::Finalizer, // finalize + NULL, // call + NULL, // hasInstance + NULL, // construct + &WrapperPrivate::Trace, // trace +}; + +const JSClass prototype_class_definition = { + "StringifierAttributeInterfacePrototype", +}; + +const JSClass interface_object_class_definition = { + "StringifierAttributeInterfaceConstructor", + 0, + NULL, // addProperty + NULL, // delProperty + NULL, // getProperty + NULL, // setProperty + NULL, // enumerate + NULL, // resolve + NULL, // mayResolve + NULL, // finalize + NULL, // call + &HasInstance, + NULL, +}; + +bool get_theStringifierAttribute( + JSContext* context, unsigned argc, JS::Value* vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + const JSClass* proto_class = + MozjsStringifierAttributeInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<StringifierAttributeInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + StringifierAttributeInterface* impl = + wrapper_private->wrappable<StringifierAttributeInterface>().get(); + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->the_stringifier_attribute(), + &result_value); + } + if (!exception_state.is_exception_set()) { + args.rval().set(result_value); + } + return !exception_state.is_exception_set(); +} + +bool set_theStringifierAttribute( + JSContext* context, unsigned argc, JS::Value* vp) { + + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + + const JSClass* proto_class = + MozjsStringifierAttributeInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<StringifierAttributeInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + StringifierAttributeInterface* impl = + wrapper_private->wrappable<StringifierAttributeInterface>().get(); + TypeTraits<std::string >::ConversionType value; + if (args.length() != 1) { + NOTREACHED(); + return false; + } + FromJSValue(context, args[0], kNoConversionFlags, &exception_state, + &value); + if (exception_state.is_exception_set()) { + return false; + } + + impl->set_the_stringifier_attribute(value); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + + +bool Stringifier(JSContext* context, unsigned argc, JS::Value *vp) { + MozjsExceptionState exception_state(context); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + StringifierAttributeInterface* impl = + wrapper_private->wrappable<StringifierAttributeInterface>().get(); + if (!impl) { + exception_state.SetSimpleException(cobalt::script::kStringifierProblem); + NOTREACHED(); + return false; + } + std::string stringified = impl->the_stringifier_attribute(); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedString rooted_string(context, + JS_NewStringCopyN(context, stringified.c_str(), stringified.length())); + args.rval().set(JS::StringValue(rooted_string)); + return true; +} + + +const JSPropertySpec prototype_properties[] = { + { // Read/Write property + "theStringifierAttribute", + JSPROP_SHARED | JSPROP_ENUMERATE, + { { &get_theStringifierAttribute, NULL } }, + { { &set_theStringifierAttribute, NULL } }, + }, + JS_PS_END +}; + +const JSFunctionSpec prototype_functions[] = { + JS_FNSPEC("toString", Stringifier, NULL, 0, JSPROP_ENUMERATE, NULL), + JS_FS_END +}; + +const JSPropertySpec interface_object_properties[] = { + JS_PS_END +}; + +const JSFunctionSpec interface_object_functions[] = { + JS_FS_END +}; + +const JSPropertySpec own_properties[] = { + JS_PS_END +}; + +void InitializePrototypeAndInterfaceObject( + InterfaceData* interface_data, JSContext* context, + JS::HandleObject global_object) { + DCHECK(!interface_data->prototype); + DCHECK(!interface_data->interface_object); + DCHECK(JS_IsGlobalObject(global_object)); + + JS::RootedObject parent_prototype( + context, JS_GetObjectPrototype(context, global_object)); + DCHECK(parent_prototype); + + interface_data->prototype = JS_NewObjectWithGivenProto( + context, &prototype_class_definition, parent_prototype + ); + + JS::RootedObject rooted_prototype(context, interface_data->prototype); + bool success = JS_DefineProperties( + context, + rooted_prototype, + prototype_properties); + + DCHECK(success); + success = JS_DefineFunctions( + context, rooted_prototype, prototype_functions); + DCHECK(success); + + JS::RootedObject function_prototype( + context, JS_GetFunctionPrototype(context, global_object)); + DCHECK(function_prototype); + // Create the Interface object. + interface_data->interface_object = JS_NewObjectWithGivenProto( + context, &interface_object_class_definition, + function_prototype); + + // Add the InterfaceObject.name property. + JS::RootedObject rooted_interface_object( + context, interface_data->interface_object); + JS::RootedValue name_value(context); + const char name[] = + "StringifierAttributeInterface"; + name_value.setString(JS_NewStringCopyZ(context, name)); + success = JS_DefineProperty( + context, rooted_interface_object, "name", name_value, JSPROP_READONLY, + NULL, NULL); + DCHECK(success); + + // Define interface object properties (including constants). + success = JS_DefineProperties(context, rooted_interface_object, + interface_object_properties); + DCHECK(success); + // Define interface object functions (static). + success = JS_DefineFunctions(context, rooted_interface_object, + interface_object_functions); + DCHECK(success); + + // Set the Prototype.constructor and Constructor.prototype properties. + DCHECK(interface_data->interface_object); + DCHECK(interface_data->prototype); + success = JS_LinkConstructorAndPrototype( + context, + rooted_interface_object, + rooted_prototype); + DCHECK(success); +} + +InterfaceData* GetInterfaceData(JSContext* context) { + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + // Use the address of the properties definition for this interface as a + // unique key for looking up the InterfaceData for this interface. + intptr_t key = reinterpret_cast<intptr_t>(&own_properties); + InterfaceData* interface_data = global_environment->GetInterfaceData(key); + if (!interface_data) { + interface_data = new InterfaceData(); + DCHECK(interface_data); + global_environment->CacheInterfaceData(key, interface_data); + DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key)); + } + return interface_data; +} + +} // namespace + +// static +JSObject* MozjsStringifierAttributeInterface::CreateProxy( + JSContext* context, const scoped_refptr<Wrappable>& wrappable) { + DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); + JS::RootedObject global_object( + context, + MozjsGlobalEnvironment::GetFromContext(context)->global_object()); + DCHECK(global_object); + + InterfaceData* interface_data = GetInterfaceData(context); + JS::RootedObject prototype(context, GetPrototype(context, global_object)); + DCHECK(prototype); + JS::RootedObject new_object( + context, + JS_NewObjectWithGivenProto( + context, &instance_class_definition, prototype)); + DCHECK(new_object); + JS::RootedObject proxy(context, + ProxyHandler::NewProxy( + context, proxy_handler.Pointer(), new_object, prototype)); + WrapperPrivate::AddPrivateData(context, proxy, wrappable); + return proxy; +} + +// static +const JSClass* MozjsStringifierAttributeInterface::PrototypeClass( + JSContext* context) { + DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); + JS::RootedObject global_object( + context, + MozjsGlobalEnvironment::GetFromContext(context)->global_object()); + DCHECK(global_object); + + JS::RootedObject prototype(context, GetPrototype(context, global_object)); + const JSClass* proto_class = JS_GetClass(prototype); + return proto_class; +} + +// static +JSObject* MozjsStringifierAttributeInterface::GetPrototype( + JSContext* context, JS::HandleObject global_object) { + DCHECK(JS_IsGlobalObject(global_object)); + + InterfaceData* interface_data = GetInterfaceData(context); + if (!interface_data->prototype) { + // Create new prototype that has all the props and methods + InitializePrototypeAndInterfaceObject( + interface_data, context, global_object); + } + DCHECK(interface_data->prototype); + return interface_data->prototype; +} + +// static +JSObject* MozjsStringifierAttributeInterface::GetInterfaceObject( + JSContext* context, JS::HandleObject global_object) { + DCHECK(JS_IsGlobalObject(global_object)); + + InterfaceData* interface_data = GetInterfaceData(context); + if (!interface_data->interface_object) { + InitializePrototypeAndInterfaceObject( + interface_data, context, global_object); + } + DCHECK(interface_data->interface_object); + return interface_data->interface_object; +} + + +namespace { +} // namespace + + +} // namespace testing +} // namespace bindings +} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_stringifier_attribute_interface.h b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_stringifier_attribute_interface.h new file mode 100644 index 0000000..72c05cb --- /dev/null +++ b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_stringifier_attribute_interface.h
@@ -0,0 +1,52 @@ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// clang-format off + +// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! +// Auto-generated from template: bindings/mozjs-45/templates/interface.h.template + +#ifndef MozjsStringifierAttributeInterface_h +#define MozjsStringifierAttributeInterface_h + +#include "base/hash_tables.h" +#include "base/lazy_instance.h" +#include "base/memory/ref_counted.h" +#include "base/threading/thread_checker.h" +#include "cobalt/base/polymorphic_downcast.h" +#include "cobalt/script/wrappable.h" +#include "cobalt/bindings/testing/stringifier_attribute_interface.h" + +#include "third_party/mozjs-45/js/src/jsapi.h" + +namespace cobalt { +namespace bindings { +namespace testing { + +class MozjsStringifierAttributeInterface { + public: + static JSObject* CreateProxy(JSContext* context, + const scoped_refptr<script::Wrappable>& wrappable); + static const JSClass* PrototypeClass(JSContext* context); + static JSObject* GetPrototype(JSContext* context, + JS::HandleObject global_object); + static JSObject* GetInterfaceObject(JSContext* context, + JS::HandleObject global_object); +}; + +} // namespace testing +} // namespace bindings +} // namespace cobalt + +#endif // MozjsStringifierAttributeInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_stringifier_operation_interface.cc b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_stringifier_operation_interface.cc new file mode 100644 index 0000000..f4cb1a3 --- /dev/null +++ b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_stringifier_operation_interface.cc
@@ -0,0 +1,442 @@ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// clang-format off + +// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! +// Auto-generated from template: bindings/mozjs-45/templates/interface.cc.template + +#include "cobalt/bindings/testing/mozjs_stringifier_operation_interface.h" + +#include "base/debug/trace_event.h" +#include "cobalt/base/polymorphic_downcast.h" +#include "cobalt/script/global_environment.h" +#include "cobalt/script/opaque_handle.h" +#include "cobalt/script/script_value.h" + +#include "base/lazy_instance.h" +#include "cobalt/script/exception_state.h" +#include "cobalt/script/mozjs-45/callback_function_conversion.h" +#include "cobalt/script/mozjs-45/conversion_helpers.h" +#include "cobalt/script/mozjs-45/mozjs_callback_function.h" +#include "cobalt/script/mozjs-45/mozjs_exception_state.h" +#include "cobalt/script/mozjs-45/mozjs_global_environment.h" +#include "cobalt/script/mozjs-45/mozjs_object_handle.h" +#include "cobalt/script/mozjs-45/mozjs_property_enumerator.h" +#include "cobalt/script/mozjs-45/mozjs_user_object_holder.h" +#include "cobalt/script/mozjs-45/proxy_handler.h" +#include "cobalt/script/mozjs-45/type_traits.h" +#include "cobalt/script/mozjs-45/wrapper_factory.h" +#include "cobalt/script/mozjs-45/wrapper_private.h" +#include "cobalt/script/property_enumerator.h" +#include "cobalt/script/sequence.h" +#include "third_party/mozjs-45/js/src/jsapi.h" +#include "third_party/mozjs-45/js/src/jsfriendapi.h" + +namespace { +using cobalt::bindings::testing::StringifierOperationInterface; +using cobalt::bindings::testing::MozjsStringifierOperationInterface; +using cobalt::script::CallbackInterfaceTraits; +using cobalt::script::GlobalEnvironment; +using cobalt::script::OpaqueHandle; +using cobalt::script::OpaqueHandleHolder; +using cobalt::script::ScriptValue; +using cobalt::script::Wrappable; + +using cobalt::script::CallbackFunction; +using cobalt::script::CallbackInterfaceTraits; +using cobalt::script::ExceptionState; +using cobalt::script::Wrappable; +using cobalt::script::mozjs::FromJSValue; +using cobalt::script::mozjs::InterfaceData; +using cobalt::script::mozjs::MozjsCallbackFunction; +using cobalt::script::mozjs::MozjsExceptionState; +using cobalt::script::mozjs::MozjsGlobalEnvironment; +using cobalt::script::mozjs::MozjsPropertyEnumerator; +using cobalt::script::mozjs::MozjsUserObjectHolder; +using cobalt::script::mozjs::ProxyHandler; +using cobalt::script::mozjs::ToJSValue; +using cobalt::script::mozjs::TypeTraits; +using cobalt::script::mozjs::WrapperFactory; +using cobalt::script::mozjs::WrapperPrivate; +using cobalt::script::mozjs::kConversionFlagNullable; +using cobalt::script::mozjs::kConversionFlagRestricted; +using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString; +using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString; +using cobalt::script::mozjs::kNoConversionFlags; +} // namespace + +namespace cobalt { +namespace bindings { +namespace testing { + +namespace { + +class MozjsStringifierOperationInterfaceHandler : public ProxyHandler { + public: + MozjsStringifierOperationInterfaceHandler() + : ProxyHandler(indexed_property_hooks, named_property_hooks) {} + + private: + static NamedPropertyHooks named_property_hooks; + static IndexedPropertyHooks indexed_property_hooks; +}; + +ProxyHandler::NamedPropertyHooks +MozjsStringifierOperationInterfaceHandler::named_property_hooks = { + NULL, + NULL, + NULL, + NULL, + NULL, +}; +ProxyHandler::IndexedPropertyHooks +MozjsStringifierOperationInterfaceHandler::indexed_property_hooks = { + NULL, + NULL, + NULL, + NULL, + NULL, +}; + +static base::LazyInstance<MozjsStringifierOperationInterfaceHandler> + proxy_handler; + +bool HasInstance(JSContext *context, JS::HandleObject type, + JS::MutableHandleValue vp, bool *success) { + JS::RootedObject global_object( + context, JS_GetGlobalForObject(context, type)); + DCHECK(global_object); + + JS::RootedObject prototype( + context, MozjsStringifierOperationInterface::GetPrototype(context, global_object)); + + // |IsDelegate| walks the prototype chain of an object returning true if + // .prototype is found. + bool is_delegate; + if (!IsDelegate(context, prototype, vp, &is_delegate)) { + *success = false; + return false; + } + + *success = is_delegate; + return true; +} + +const JSClass instance_class_definition = { + "StringifierOperationInterface", + 0 | JSCLASS_HAS_PRIVATE, + NULL, // addProperty + NULL, // delProperty + NULL, // getProperty + NULL, // setProperty + NULL, // enumerate + NULL, // resolve + NULL, // mayResolve + &WrapperPrivate::Finalizer, // finalize + NULL, // call + NULL, // hasInstance + NULL, // construct + &WrapperPrivate::Trace, // trace +}; + +const JSClass prototype_class_definition = { + "StringifierOperationInterfacePrototype", +}; + +const JSClass interface_object_class_definition = { + "StringifierOperationInterfaceConstructor", + 0, + NULL, // addProperty + NULL, // delProperty + NULL, // getProperty + NULL, // setProperty + NULL, // enumerate + NULL, // resolve + NULL, // mayResolve + NULL, // finalize + NULL, // call + &HasInstance, + NULL, +}; + +bool fcn_theStringifierOperation( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + const JSClass* proto_class = + MozjsStringifierOperationInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<StringifierOperationInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + StringifierOperationInterface* impl = + wrapper_private->wrappable<StringifierOperationInterface>().get(); + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->TheStringifierOperation(), + &result_value); + } + if (!exception_state.is_exception_set()) { + args.rval().set(result_value); + } + return !exception_state.is_exception_set(); +} + + +bool Stringifier(JSContext* context, unsigned argc, JS::Value *vp) { + MozjsExceptionState exception_state(context); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + StringifierOperationInterface* impl = + wrapper_private->wrappable<StringifierOperationInterface>().get(); + if (!impl) { + exception_state.SetSimpleException(cobalt::script::kStringifierProblem); + NOTREACHED(); + return false; + } + std::string stringified = impl->TheStringifierOperation(); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedString rooted_string(context, + JS_NewStringCopyN(context, stringified.c_str(), stringified.length())); + args.rval().set(JS::StringValue(rooted_string)); + return true; +} + + +const JSPropertySpec prototype_properties[] = { + JS_PS_END +}; + +const JSFunctionSpec prototype_functions[] = { + JS_FNSPEC("toString", Stringifier, NULL, 0, JSPROP_ENUMERATE, NULL), + JS_FNSPEC( + "theStringifierOperation", fcn_theStringifierOperation, NULL, + 0, JSPROP_ENUMERATE, NULL), + JS_FS_END +}; + +const JSPropertySpec interface_object_properties[] = { + JS_PS_END +}; + +const JSFunctionSpec interface_object_functions[] = { + JS_FS_END +}; + +const JSPropertySpec own_properties[] = { + JS_PS_END +}; + +void InitializePrototypeAndInterfaceObject( + InterfaceData* interface_data, JSContext* context, + JS::HandleObject global_object) { + DCHECK(!interface_data->prototype); + DCHECK(!interface_data->interface_object); + DCHECK(JS_IsGlobalObject(global_object)); + + JS::RootedObject parent_prototype( + context, JS_GetObjectPrototype(context, global_object)); + DCHECK(parent_prototype); + + interface_data->prototype = JS_NewObjectWithGivenProto( + context, &prototype_class_definition, parent_prototype + ); + + JS::RootedObject rooted_prototype(context, interface_data->prototype); + bool success = JS_DefineProperties( + context, + rooted_prototype, + prototype_properties); + + DCHECK(success); + success = JS_DefineFunctions( + context, rooted_prototype, prototype_functions); + DCHECK(success); + + JS::RootedObject function_prototype( + context, JS_GetFunctionPrototype(context, global_object)); + DCHECK(function_prototype); + // Create the Interface object. + interface_data->interface_object = JS_NewObjectWithGivenProto( + context, &interface_object_class_definition, + function_prototype); + + // Add the InterfaceObject.name property. + JS::RootedObject rooted_interface_object( + context, interface_data->interface_object); + JS::RootedValue name_value(context); + const char name[] = + "StringifierOperationInterface"; + name_value.setString(JS_NewStringCopyZ(context, name)); + success = JS_DefineProperty( + context, rooted_interface_object, "name", name_value, JSPROP_READONLY, + NULL, NULL); + DCHECK(success); + + // Define interface object properties (including constants). + success = JS_DefineProperties(context, rooted_interface_object, + interface_object_properties); + DCHECK(success); + // Define interface object functions (static). + success = JS_DefineFunctions(context, rooted_interface_object, + interface_object_functions); + DCHECK(success); + + // Set the Prototype.constructor and Constructor.prototype properties. + DCHECK(interface_data->interface_object); + DCHECK(interface_data->prototype); + success = JS_LinkConstructorAndPrototype( + context, + rooted_interface_object, + rooted_prototype); + DCHECK(success); +} + +InterfaceData* GetInterfaceData(JSContext* context) { + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + // Use the address of the properties definition for this interface as a + // unique key for looking up the InterfaceData for this interface. + intptr_t key = reinterpret_cast<intptr_t>(&own_properties); + InterfaceData* interface_data = global_environment->GetInterfaceData(key); + if (!interface_data) { + interface_data = new InterfaceData(); + DCHECK(interface_data); + global_environment->CacheInterfaceData(key, interface_data); + DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key)); + } + return interface_data; +} + +} // namespace + +// static +JSObject* MozjsStringifierOperationInterface::CreateProxy( + JSContext* context, const scoped_refptr<Wrappable>& wrappable) { + DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); + JS::RootedObject global_object( + context, + MozjsGlobalEnvironment::GetFromContext(context)->global_object()); + DCHECK(global_object); + + InterfaceData* interface_data = GetInterfaceData(context); + JS::RootedObject prototype(context, GetPrototype(context, global_object)); + DCHECK(prototype); + JS::RootedObject new_object( + context, + JS_NewObjectWithGivenProto( + context, &instance_class_definition, prototype)); + DCHECK(new_object); + JS::RootedObject proxy(context, + ProxyHandler::NewProxy( + context, proxy_handler.Pointer(), new_object, prototype)); + WrapperPrivate::AddPrivateData(context, proxy, wrappable); + return proxy; +} + +// static +const JSClass* MozjsStringifierOperationInterface::PrototypeClass( + JSContext* context) { + DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); + JS::RootedObject global_object( + context, + MozjsGlobalEnvironment::GetFromContext(context)->global_object()); + DCHECK(global_object); + + JS::RootedObject prototype(context, GetPrototype(context, global_object)); + const JSClass* proto_class = JS_GetClass(prototype); + return proto_class; +} + +// static +JSObject* MozjsStringifierOperationInterface::GetPrototype( + JSContext* context, JS::HandleObject global_object) { + DCHECK(JS_IsGlobalObject(global_object)); + + InterfaceData* interface_data = GetInterfaceData(context); + if (!interface_data->prototype) { + // Create new prototype that has all the props and methods + InitializePrototypeAndInterfaceObject( + interface_data, context, global_object); + } + DCHECK(interface_data->prototype); + return interface_data->prototype; +} + +// static +JSObject* MozjsStringifierOperationInterface::GetInterfaceObject( + JSContext* context, JS::HandleObject global_object) { + DCHECK(JS_IsGlobalObject(global_object)); + + InterfaceData* interface_data = GetInterfaceData(context); + if (!interface_data->interface_object) { + InitializePrototypeAndInterfaceObject( + interface_data, context, global_object); + } + DCHECK(interface_data->interface_object); + return interface_data->interface_object; +} + + +namespace { +} // namespace + + +} // namespace testing +} // namespace bindings +} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_stringifier_operation_interface.h b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_stringifier_operation_interface.h new file mode 100644 index 0000000..99cf88b --- /dev/null +++ b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_stringifier_operation_interface.h
@@ -0,0 +1,52 @@ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// clang-format off + +// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! +// Auto-generated from template: bindings/mozjs-45/templates/interface.h.template + +#ifndef MozjsStringifierOperationInterface_h +#define MozjsStringifierOperationInterface_h + +#include "base/hash_tables.h" +#include "base/lazy_instance.h" +#include "base/memory/ref_counted.h" +#include "base/threading/thread_checker.h" +#include "cobalt/base/polymorphic_downcast.h" +#include "cobalt/script/wrappable.h" +#include "cobalt/bindings/testing/stringifier_operation_interface.h" + +#include "third_party/mozjs-45/js/src/jsapi.h" + +namespace cobalt { +namespace bindings { +namespace testing { + +class MozjsStringifierOperationInterface { + public: + static JSObject* CreateProxy(JSContext* context, + const scoped_refptr<script::Wrappable>& wrappable); + static const JSClass* PrototypeClass(JSContext* context); + static JSObject* GetPrototype(JSContext* context, + JS::HandleObject global_object); + static JSObject* GetInterfaceObject(JSContext* context, + JS::HandleObject global_object); +}; + +} // namespace testing +} // namespace bindings +} // namespace cobalt + +#endif // MozjsStringifierOperationInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_target_interface.cc b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_target_interface.cc new file mode 100644 index 0000000..f814463 --- /dev/null +++ b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_target_interface.cc
@@ -0,0 +1,453 @@ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// clang-format off + +// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! +// Auto-generated from template: bindings/mozjs-45/templates/interface.cc.template + +#include "cobalt/bindings/testing/mozjs_target_interface.h" + +#include "base/debug/trace_event.h" +#include "cobalt/base/polymorphic_downcast.h" +#include "cobalt/script/global_environment.h" +#include "cobalt/script/opaque_handle.h" +#include "cobalt/script/script_value.h" + +#include "base/lazy_instance.h" +#include "cobalt/script/exception_state.h" +#include "cobalt/script/mozjs-45/callback_function_conversion.h" +#include "cobalt/script/mozjs-45/conversion_helpers.h" +#include "cobalt/script/mozjs-45/mozjs_callback_function.h" +#include "cobalt/script/mozjs-45/mozjs_exception_state.h" +#include "cobalt/script/mozjs-45/mozjs_global_environment.h" +#include "cobalt/script/mozjs-45/mozjs_object_handle.h" +#include "cobalt/script/mozjs-45/mozjs_property_enumerator.h" +#include "cobalt/script/mozjs-45/mozjs_user_object_holder.h" +#include "cobalt/script/mozjs-45/proxy_handler.h" +#include "cobalt/script/mozjs-45/type_traits.h" +#include "cobalt/script/mozjs-45/wrapper_factory.h" +#include "cobalt/script/mozjs-45/wrapper_private.h" +#include "cobalt/script/property_enumerator.h" +#include "cobalt/script/sequence.h" +#include "third_party/mozjs-45/js/src/jsapi.h" +#include "third_party/mozjs-45/js/src/jsfriendapi.h" + +namespace { +using cobalt::bindings::testing::TargetInterface; +using cobalt::bindings::testing::MozjsTargetInterface; +using cobalt::script::CallbackInterfaceTraits; +using cobalt::script::GlobalEnvironment; +using cobalt::script::OpaqueHandle; +using cobalt::script::OpaqueHandleHolder; +using cobalt::script::ScriptValue; +using cobalt::script::Wrappable; + +using cobalt::script::CallbackFunction; +using cobalt::script::CallbackInterfaceTraits; +using cobalt::script::ExceptionState; +using cobalt::script::Wrappable; +using cobalt::script::mozjs::FromJSValue; +using cobalt::script::mozjs::InterfaceData; +using cobalt::script::mozjs::MozjsCallbackFunction; +using cobalt::script::mozjs::MozjsExceptionState; +using cobalt::script::mozjs::MozjsGlobalEnvironment; +using cobalt::script::mozjs::MozjsPropertyEnumerator; +using cobalt::script::mozjs::MozjsUserObjectHolder; +using cobalt::script::mozjs::ProxyHandler; +using cobalt::script::mozjs::ToJSValue; +using cobalt::script::mozjs::TypeTraits; +using cobalt::script::mozjs::WrapperFactory; +using cobalt::script::mozjs::WrapperPrivate; +using cobalt::script::mozjs::kConversionFlagNullable; +using cobalt::script::mozjs::kConversionFlagRestricted; +using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString; +using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString; +using cobalt::script::mozjs::kNoConversionFlags; +} // namespace + +namespace cobalt { +namespace bindings { +namespace testing { + +namespace { + +class MozjsTargetInterfaceHandler : public ProxyHandler { + public: + MozjsTargetInterfaceHandler() + : ProxyHandler(indexed_property_hooks, named_property_hooks) {} + + private: + static NamedPropertyHooks named_property_hooks; + static IndexedPropertyHooks indexed_property_hooks; +}; + +ProxyHandler::NamedPropertyHooks +MozjsTargetInterfaceHandler::named_property_hooks = { + NULL, + NULL, + NULL, + NULL, + NULL, +}; +ProxyHandler::IndexedPropertyHooks +MozjsTargetInterfaceHandler::indexed_property_hooks = { + NULL, + NULL, + NULL, + NULL, + NULL, +}; + +static base::LazyInstance<MozjsTargetInterfaceHandler> + proxy_handler; + +bool HasInstance(JSContext *context, JS::HandleObject type, + JS::MutableHandleValue vp, bool *success) { + JS::RootedObject global_object( + context, JS_GetGlobalForObject(context, type)); + DCHECK(global_object); + + JS::RootedObject prototype( + context, MozjsTargetInterface::GetPrototype(context, global_object)); + + // |IsDelegate| walks the prototype chain of an object returning true if + // .prototype is found. + bool is_delegate; + if (!IsDelegate(context, prototype, vp, &is_delegate)) { + *success = false; + return false; + } + + *success = is_delegate; + return true; +} + +const JSClass instance_class_definition = { + "TargetInterface", + 0 | JSCLASS_HAS_PRIVATE, + NULL, // addProperty + NULL, // delProperty + NULL, // getProperty + NULL, // setProperty + NULL, // enumerate + NULL, // resolve + NULL, // mayResolve + &WrapperPrivate::Finalizer, // finalize + NULL, // call + NULL, // hasInstance + NULL, // construct + &WrapperPrivate::Trace, // trace +}; + +const JSClass prototype_class_definition = { + "TargetInterfacePrototype", +}; + +const JSClass interface_object_class_definition = { + "TargetInterfaceConstructor", + 0, + NULL, // addProperty + NULL, // delProperty + NULL, // getProperty + NULL, // setProperty + NULL, // enumerate + NULL, // resolve + NULL, // mayResolve + NULL, // finalize + NULL, // call + &HasInstance, + NULL, +}; + +bool fcn_implementedInterfaceFunction( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + const JSClass* proto_class = + MozjsTargetInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<TargetInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + TargetInterface* impl = + wrapper_private->wrappable<TargetInterface>().get(); + + impl->ImplementedInterfaceFunction(); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + +bool fcn_partialInterfaceFunction( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + const JSClass* proto_class = + MozjsTargetInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<TargetInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + TargetInterface* impl = + wrapper_private->wrappable<TargetInterface>().get(); + + impl->PartialInterfaceFunction(); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + + + +const JSPropertySpec prototype_properties[] = { + JS_PS_END +}; + +const JSFunctionSpec prototype_functions[] = { + JS_FNSPEC( + "implementedInterfaceFunction", fcn_implementedInterfaceFunction, NULL, + 0, JSPROP_ENUMERATE, NULL), + JS_FNSPEC( + "partialInterfaceFunction", fcn_partialInterfaceFunction, NULL, + 0, JSPROP_ENUMERATE, NULL), + JS_FS_END +}; + +const JSPropertySpec interface_object_properties[] = { + JS_PS_END +}; + +const JSFunctionSpec interface_object_functions[] = { + JS_FS_END +}; + +const JSPropertySpec own_properties[] = { + JS_PS_END +}; + +void InitializePrototypeAndInterfaceObject( + InterfaceData* interface_data, JSContext* context, + JS::HandleObject global_object) { + DCHECK(!interface_data->prototype); + DCHECK(!interface_data->interface_object); + DCHECK(JS_IsGlobalObject(global_object)); + + JS::RootedObject parent_prototype( + context, JS_GetObjectPrototype(context, global_object)); + DCHECK(parent_prototype); + + interface_data->prototype = JS_NewObjectWithGivenProto( + context, &prototype_class_definition, parent_prototype + ); + + JS::RootedObject rooted_prototype(context, interface_data->prototype); + bool success = JS_DefineProperties( + context, + rooted_prototype, + prototype_properties); + + DCHECK(success); + success = JS_DefineFunctions( + context, rooted_prototype, prototype_functions); + DCHECK(success); + + JS::RootedObject function_prototype( + context, JS_GetFunctionPrototype(context, global_object)); + DCHECK(function_prototype); + // Create the Interface object. + interface_data->interface_object = JS_NewObjectWithGivenProto( + context, &interface_object_class_definition, + function_prototype); + + // Add the InterfaceObject.name property. + JS::RootedObject rooted_interface_object( + context, interface_data->interface_object); + JS::RootedValue name_value(context); + const char name[] = + "TargetInterface"; + name_value.setString(JS_NewStringCopyZ(context, name)); + success = JS_DefineProperty( + context, rooted_interface_object, "name", name_value, JSPROP_READONLY, + NULL, NULL); + DCHECK(success); + + // Define interface object properties (including constants). + success = JS_DefineProperties(context, rooted_interface_object, + interface_object_properties); + DCHECK(success); + // Define interface object functions (static). + success = JS_DefineFunctions(context, rooted_interface_object, + interface_object_functions); + DCHECK(success); + + // Set the Prototype.constructor and Constructor.prototype properties. + DCHECK(interface_data->interface_object); + DCHECK(interface_data->prototype); + success = JS_LinkConstructorAndPrototype( + context, + rooted_interface_object, + rooted_prototype); + DCHECK(success); +} + +InterfaceData* GetInterfaceData(JSContext* context) { + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + // Use the address of the properties definition for this interface as a + // unique key for looking up the InterfaceData for this interface. + intptr_t key = reinterpret_cast<intptr_t>(&own_properties); + InterfaceData* interface_data = global_environment->GetInterfaceData(key); + if (!interface_data) { + interface_data = new InterfaceData(); + DCHECK(interface_data); + global_environment->CacheInterfaceData(key, interface_data); + DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key)); + } + return interface_data; +} + +} // namespace + +// static +JSObject* MozjsTargetInterface::CreateProxy( + JSContext* context, const scoped_refptr<Wrappable>& wrappable) { + DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); + JS::RootedObject global_object( + context, + MozjsGlobalEnvironment::GetFromContext(context)->global_object()); + DCHECK(global_object); + + InterfaceData* interface_data = GetInterfaceData(context); + JS::RootedObject prototype(context, GetPrototype(context, global_object)); + DCHECK(prototype); + JS::RootedObject new_object( + context, + JS_NewObjectWithGivenProto( + context, &instance_class_definition, prototype)); + DCHECK(new_object); + JS::RootedObject proxy(context, + ProxyHandler::NewProxy( + context, proxy_handler.Pointer(), new_object, prototype)); + WrapperPrivate::AddPrivateData(context, proxy, wrappable); + return proxy; +} + +// static +const JSClass* MozjsTargetInterface::PrototypeClass( + JSContext* context) { + DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); + JS::RootedObject global_object( + context, + MozjsGlobalEnvironment::GetFromContext(context)->global_object()); + DCHECK(global_object); + + JS::RootedObject prototype(context, GetPrototype(context, global_object)); + const JSClass* proto_class = JS_GetClass(prototype); + return proto_class; +} + +// static +JSObject* MozjsTargetInterface::GetPrototype( + JSContext* context, JS::HandleObject global_object) { + DCHECK(JS_IsGlobalObject(global_object)); + + InterfaceData* interface_data = GetInterfaceData(context); + if (!interface_data->prototype) { + // Create new prototype that has all the props and methods + InitializePrototypeAndInterfaceObject( + interface_data, context, global_object); + } + DCHECK(interface_data->prototype); + return interface_data->prototype; +} + +// static +JSObject* MozjsTargetInterface::GetInterfaceObject( + JSContext* context, JS::HandleObject global_object) { + DCHECK(JS_IsGlobalObject(global_object)); + + InterfaceData* interface_data = GetInterfaceData(context); + if (!interface_data->interface_object) { + InitializePrototypeAndInterfaceObject( + interface_data, context, global_object); + } + DCHECK(interface_data->interface_object); + return interface_data->interface_object; +} + + +namespace { +} // namespace + + +} // namespace testing +} // namespace bindings +} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_target_interface.h b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_target_interface.h new file mode 100644 index 0000000..e8260fc --- /dev/null +++ b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_target_interface.h
@@ -0,0 +1,52 @@ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// clang-format off + +// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! +// Auto-generated from template: bindings/mozjs-45/templates/interface.h.template + +#ifndef MozjsTargetInterface_h +#define MozjsTargetInterface_h + +#include "base/hash_tables.h" +#include "base/lazy_instance.h" +#include "base/memory/ref_counted.h" +#include "base/threading/thread_checker.h" +#include "cobalt/base/polymorphic_downcast.h" +#include "cobalt/script/wrappable.h" +#include "cobalt/bindings/testing/target_interface.h" + +#include "third_party/mozjs-45/js/src/jsapi.h" + +namespace cobalt { +namespace bindings { +namespace testing { + +class MozjsTargetInterface { + public: + static JSObject* CreateProxy(JSContext* context, + const scoped_refptr<script::Wrappable>& wrappable); + static const JSClass* PrototypeClass(JSContext* context); + static JSObject* GetPrototype(JSContext* context, + JS::HandleObject global_object); + static JSObject* GetInterfaceObject(JSContext* context, + JS::HandleObject global_object); +}; + +} // namespace testing +} // namespace bindings +} // namespace cobalt + +#endif // MozjsTargetInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_test_dictionary.h b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_test_dictionary.h new file mode 100644 index 0000000..5ef9123 --- /dev/null +++ b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_test_dictionary.h
@@ -0,0 +1,253 @@ +/* + * Copyright 2017 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// clang-format off + +// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! +// Auto-generated from template: bindings/mozjs-45/templates/dictionary-conversion.h.template + +#ifndef TestDictionary_conversion_h +#define TestDictionary_conversion_h + +#include "cobalt/bindings/testing/test_dictionary.h" +#include "cobalt/script/mozjs-45/conversion_helpers.h" +#include "third_party/mozjs-45/js/src/jscntxt.h" + +using cobalt::bindings::testing::TestDictionary; +using cobalt::bindings::testing::ArbitraryInterface; + +namespace cobalt { +namespace script { +namespace mozjs { + +inline void ToJSValue( + JSContext* context, + const TestDictionary& in_dictionary, + JS::MutableHandleValue out_value) { + // Create a new object that will hold the dictionary values. + JS::RootedObject dictionary_object( + context, JS_NewObject(context, nullptr)); + const int kPropertyAttributes = JSPROP_ENUMERATE; + if (in_dictionary.has_boolean_member()) { + JS::RootedValue member_value(context); + ToJSValue(context, in_dictionary.boolean_member(), &member_value); + if (!JS_DefineProperty(context, dictionary_object, + "booleanMember", + member_value, kPropertyAttributes, nullptr, nullptr)) { + // Some internal error occurred. + NOTREACHED(); + return; + } + } + if (in_dictionary.has_long_member()) { + JS::RootedValue member_value(context); + ToJSValue(context, in_dictionary.long_member(), &member_value); + if (!JS_DefineProperty(context, dictionary_object, + "longMember", + member_value, kPropertyAttributes, nullptr, nullptr)) { + // Some internal error occurred. + NOTREACHED(); + return; + } + } + if (in_dictionary.has_double_member()) { + JS::RootedValue member_value(context); + ToJSValue(context, in_dictionary.double_member(), &member_value); + if (!JS_DefineProperty(context, dictionary_object, + "doubleMember", + member_value, kPropertyAttributes, nullptr, nullptr)) { + // Some internal error occurred. + NOTREACHED(); + return; + } + } + if (in_dictionary.has_string_member()) { + JS::RootedValue member_value(context); + ToJSValue(context, in_dictionary.string_member(), &member_value); + if (!JS_DefineProperty(context, dictionary_object, + "stringMember", + member_value, kPropertyAttributes, nullptr, nullptr)) { + // Some internal error occurred. + NOTREACHED(); + return; + } + } + if (in_dictionary.has_interface_member()) { + JS::RootedValue member_value(context); + ToJSValue(context, in_dictionary.interface_member(), &member_value); + if (!JS_DefineProperty(context, dictionary_object, + "interfaceMember", + member_value, kPropertyAttributes, nullptr, nullptr)) { + // Some internal error occurred. + NOTREACHED(); + return; + } + } + if (in_dictionary.has_member_with_default()) { + JS::RootedValue member_value(context); + ToJSValue(context, in_dictionary.member_with_default(), &member_value); + if (!JS_DefineProperty(context, dictionary_object, + "memberWithDefault", + member_value, kPropertyAttributes, nullptr, nullptr)) { + // Some internal error occurred. + NOTREACHED(); + return; + } + } + if (in_dictionary.has_non_default_member()) { + JS::RootedValue member_value(context); + ToJSValue(context, in_dictionary.non_default_member(), &member_value); + if (!JS_DefineProperty(context, dictionary_object, + "nonDefaultMember", + member_value, kPropertyAttributes, nullptr, nullptr)) { + // Some internal error occurred. + NOTREACHED(); + return; + } + } + out_value.setObject(*dictionary_object); +} + +inline void FromJSValue(JSContext* context, JS::HandleValue value, + int conversion_flags, ExceptionState* exception_state, + TestDictionary* out_dictionary) { + DCHECK_EQ(0, conversion_flags) << "Unexpected conversion flags."; + // https://heycam.github.io/webidl/#es-dictionary + + if (value.isUndefined() || value.isNull()) { + // The default constructor will assign appropriate values to dictionary + // members with default values and leave the others unset. + *out_dictionary = TestDictionary(); + return; + } + if (!value.isObject()) { + // 1. If Type(V) is not Undefined, Null or Object, then throw a TypeError. + exception_state->SetSimpleException(kNotObjectType); + return; + } + JS::RootedObject dictionary_object(context, &value.toObject()); + JS::RootedValue boolean_member(context); + if (!JS_GetProperty(context, dictionary_object, + "booleanMember", + &boolean_member)) { + exception_state->SetSimpleException(kSimpleError); + return; + } + if (!boolean_member.isUndefined()) { + bool converted_value; + FromJSValue(context, boolean_member, 0, exception_state, &converted_value); + if (context->isExceptionPending()) { + return; + } + out_dictionary->set_boolean_member(converted_value); + } + JS::RootedValue long_member(context); + if (!JS_GetProperty(context, dictionary_object, + "longMember", + &long_member)) { + exception_state->SetSimpleException(kSimpleError); + return; + } + if (!long_member.isUndefined()) { + int32_t converted_value; + FromJSValue(context, long_member, 0, exception_state, &converted_value); + if (context->isExceptionPending()) { + return; + } + out_dictionary->set_long_member(converted_value); + } + JS::RootedValue double_member(context); + if (!JS_GetProperty(context, dictionary_object, + "doubleMember", + &double_member)) { + exception_state->SetSimpleException(kSimpleError); + return; + } + if (!double_member.isUndefined()) { + double converted_value; + FromJSValue(context, double_member, 0, exception_state, &converted_value); + if (context->isExceptionPending()) { + return; + } + out_dictionary->set_double_member(converted_value); + } + JS::RootedValue string_member(context); + if (!JS_GetProperty(context, dictionary_object, + "stringMember", + &string_member)) { + exception_state->SetSimpleException(kSimpleError); + return; + } + if (!string_member.isUndefined()) { + std::string converted_value; + FromJSValue(context, string_member, 0, exception_state, &converted_value); + if (context->isExceptionPending()) { + return; + } + out_dictionary->set_string_member(converted_value); + } + JS::RootedValue interface_member(context); + if (!JS_GetProperty(context, dictionary_object, + "interfaceMember", + &interface_member)) { + exception_state->SetSimpleException(kSimpleError); + return; + } + if (!interface_member.isUndefined()) { + scoped_refptr<ArbitraryInterface> converted_value; + FromJSValue(context, interface_member, 0, exception_state, &converted_value); + if (context->isExceptionPending()) { + return; + } + out_dictionary->set_interface_member(converted_value); + } + JS::RootedValue member_with_default(context); + if (!JS_GetProperty(context, dictionary_object, + "memberWithDefault", + &member_with_default)) { + exception_state->SetSimpleException(kSimpleError); + return; + } + if (!member_with_default.isUndefined()) { + int32_t converted_value; + FromJSValue(context, member_with_default, 0, exception_state, &converted_value); + if (context->isExceptionPending()) { + return; + } + out_dictionary->set_member_with_default(converted_value); + } + JS::RootedValue non_default_member(context); + if (!JS_GetProperty(context, dictionary_object, + "nonDefaultMember", + &non_default_member)) { + exception_state->SetSimpleException(kSimpleError); + return; + } + if (!non_default_member.isUndefined()) { + int32_t converted_value; + FromJSValue(context, non_default_member, 0, exception_state, &converted_value); + if (context->isExceptionPending()) { + return; + } + out_dictionary->set_non_default_member(converted_value); + } +} + +} +} +} + +#endif // TestDictionary_h
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_union_types_interface.cc b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_union_types_interface.cc new file mode 100644 index 0000000..bd4e7a0 --- /dev/null +++ b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_union_types_interface.cc
@@ -0,0 +1,745 @@ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// clang-format off + +// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! +// Auto-generated from template: bindings/mozjs-45/templates/interface.cc.template + +#include "cobalt/bindings/testing/mozjs_union_types_interface.h" + +#include "base/debug/trace_event.h" +#include "cobalt/base/polymorphic_downcast.h" +#include "cobalt/script/global_environment.h" +#include "cobalt/script/opaque_handle.h" +#include "cobalt/script/script_value.h" +#include "cobalt/bindings/testing/arbitrary_interface.h" +#include "cobalt/bindings/testing/base_interface.h" +#include "cobalt/bindings/testing/mozjs_arbitrary_interface.h" +#include "cobalt/bindings/testing/mozjs_base_interface.h" + +#include "base/lazy_instance.h" +#include "cobalt/script/exception_state.h" +#include "cobalt/script/mozjs-45/callback_function_conversion.h" +#include "cobalt/script/mozjs-45/conversion_helpers.h" +#include "cobalt/script/mozjs-45/mozjs_callback_function.h" +#include "cobalt/script/mozjs-45/mozjs_exception_state.h" +#include "cobalt/script/mozjs-45/mozjs_global_environment.h" +#include "cobalt/script/mozjs-45/mozjs_object_handle.h" +#include "cobalt/script/mozjs-45/mozjs_property_enumerator.h" +#include "cobalt/script/mozjs-45/mozjs_user_object_holder.h" +#include "cobalt/script/mozjs-45/proxy_handler.h" +#include "cobalt/script/mozjs-45/type_traits.h" +#include "cobalt/script/mozjs-45/wrapper_factory.h" +#include "cobalt/script/mozjs-45/wrapper_private.h" +#include "cobalt/script/property_enumerator.h" +#include "cobalt/script/sequence.h" +#include "third_party/mozjs-45/js/src/jsapi.h" +#include "third_party/mozjs-45/js/src/jsfriendapi.h" + +namespace { +using cobalt::bindings::testing::UnionTypesInterface; +using cobalt::bindings::testing::MozjsUnionTypesInterface; +using cobalt::bindings::testing::ArbitraryInterface; +using cobalt::bindings::testing::BaseInterface; +using cobalt::bindings::testing::MozjsArbitraryInterface; +using cobalt::bindings::testing::MozjsBaseInterface; +using cobalt::script::CallbackInterfaceTraits; +using cobalt::script::GlobalEnvironment; +using cobalt::script::OpaqueHandle; +using cobalt::script::OpaqueHandleHolder; +using cobalt::script::ScriptValue; +using cobalt::script::Wrappable; + +using cobalt::script::CallbackFunction; +using cobalt::script::CallbackInterfaceTraits; +using cobalt::script::ExceptionState; +using cobalt::script::Wrappable; +using cobalt::script::mozjs::FromJSValue; +using cobalt::script::mozjs::InterfaceData; +using cobalt::script::mozjs::MozjsCallbackFunction; +using cobalt::script::mozjs::MozjsExceptionState; +using cobalt::script::mozjs::MozjsGlobalEnvironment; +using cobalt::script::mozjs::MozjsPropertyEnumerator; +using cobalt::script::mozjs::MozjsUserObjectHolder; +using cobalt::script::mozjs::ProxyHandler; +using cobalt::script::mozjs::ToJSValue; +using cobalt::script::mozjs::TypeTraits; +using cobalt::script::mozjs::WrapperFactory; +using cobalt::script::mozjs::WrapperPrivate; +using cobalt::script::mozjs::kConversionFlagNullable; +using cobalt::script::mozjs::kConversionFlagRestricted; +using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString; +using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString; +using cobalt::script::mozjs::kNoConversionFlags; +} // namespace + +namespace cobalt { +namespace bindings { +namespace testing { + +namespace { + +class MozjsUnionTypesInterfaceHandler : public ProxyHandler { + public: + MozjsUnionTypesInterfaceHandler() + : ProxyHandler(indexed_property_hooks, named_property_hooks) {} + + private: + static NamedPropertyHooks named_property_hooks; + static IndexedPropertyHooks indexed_property_hooks; +}; + +ProxyHandler::NamedPropertyHooks +MozjsUnionTypesInterfaceHandler::named_property_hooks = { + NULL, + NULL, + NULL, + NULL, + NULL, +}; +ProxyHandler::IndexedPropertyHooks +MozjsUnionTypesInterfaceHandler::indexed_property_hooks = { + NULL, + NULL, + NULL, + NULL, + NULL, +}; + +static base::LazyInstance<MozjsUnionTypesInterfaceHandler> + proxy_handler; + +bool HasInstance(JSContext *context, JS::HandleObject type, + JS::MutableHandleValue vp, bool *success) { + JS::RootedObject global_object( + context, JS_GetGlobalForObject(context, type)); + DCHECK(global_object); + + JS::RootedObject prototype( + context, MozjsUnionTypesInterface::GetPrototype(context, global_object)); + + // |IsDelegate| walks the prototype chain of an object returning true if + // .prototype is found. + bool is_delegate; + if (!IsDelegate(context, prototype, vp, &is_delegate)) { + *success = false; + return false; + } + + *success = is_delegate; + return true; +} + +const JSClass instance_class_definition = { + "UnionTypesInterface", + 0 | JSCLASS_HAS_PRIVATE, + NULL, // addProperty + NULL, // delProperty + NULL, // getProperty + NULL, // setProperty + NULL, // enumerate + NULL, // resolve + NULL, // mayResolve + &WrapperPrivate::Finalizer, // finalize + NULL, // call + NULL, // hasInstance + NULL, // construct + &WrapperPrivate::Trace, // trace +}; + +const JSClass prototype_class_definition = { + "UnionTypesInterfacePrototype", +}; + +const JSClass interface_object_class_definition = { + "UnionTypesInterfaceConstructor", + 0, + NULL, // addProperty + NULL, // delProperty + NULL, // getProperty + NULL, // setProperty + NULL, // enumerate + NULL, // resolve + NULL, // mayResolve + NULL, // finalize + NULL, // call + &HasInstance, + NULL, +}; + +bool get_unionProperty( + JSContext* context, unsigned argc, JS::Value* vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + const JSClass* proto_class = + MozjsUnionTypesInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<UnionTypesInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + UnionTypesInterface* impl = + wrapper_private->wrappable<UnionTypesInterface>().get(); + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->union_property(), + &result_value); + } + if (!exception_state.is_exception_set()) { + args.rval().set(result_value); + } + return !exception_state.is_exception_set(); +} + +bool set_unionProperty( + JSContext* context, unsigned argc, JS::Value* vp) { + + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + + const JSClass* proto_class = + MozjsUnionTypesInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<UnionTypesInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + UnionTypesInterface* impl = + wrapper_private->wrappable<UnionTypesInterface>().get(); + TypeTraits<script::UnionType4<std::string, bool, scoped_refptr<ArbitraryInterface>, int32_t > >::ConversionType value; + if (args.length() != 1) { + NOTREACHED(); + return false; + } + FromJSValue(context, args[0], kNoConversionFlags, &exception_state, + &value); + if (exception_state.is_exception_set()) { + return false; + } + + impl->set_union_property(value); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + +bool get_unionWithNullableMemberProperty( + JSContext* context, unsigned argc, JS::Value* vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + const JSClass* proto_class = + MozjsUnionTypesInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<UnionTypesInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + UnionTypesInterface* impl = + wrapper_private->wrappable<UnionTypesInterface>().get(); + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->union_with_nullable_member_property(), + &result_value); + } + if (!exception_state.is_exception_set()) { + args.rval().set(result_value); + } + return !exception_state.is_exception_set(); +} + +bool set_unionWithNullableMemberProperty( + JSContext* context, unsigned argc, JS::Value* vp) { + + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + + const JSClass* proto_class = + MozjsUnionTypesInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<UnionTypesInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + UnionTypesInterface* impl = + wrapper_private->wrappable<UnionTypesInterface>().get(); + TypeTraits<base::optional<script::UnionType2<double, std::string > > >::ConversionType value; + if (args.length() != 1) { + NOTREACHED(); + return false; + } + FromJSValue(context, args[0], kNoConversionFlags, &exception_state, + &value); + if (exception_state.is_exception_set()) { + return false; + } + + impl->set_union_with_nullable_member_property(value); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + +bool get_nullableUnionProperty( + JSContext* context, unsigned argc, JS::Value* vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + const JSClass* proto_class = + MozjsUnionTypesInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<UnionTypesInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + UnionTypesInterface* impl = + wrapper_private->wrappable<UnionTypesInterface>().get(); + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->nullable_union_property(), + &result_value); + } + if (!exception_state.is_exception_set()) { + args.rval().set(result_value); + } + return !exception_state.is_exception_set(); +} + +bool set_nullableUnionProperty( + JSContext* context, unsigned argc, JS::Value* vp) { + + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + + const JSClass* proto_class = + MozjsUnionTypesInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<UnionTypesInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + UnionTypesInterface* impl = + wrapper_private->wrappable<UnionTypesInterface>().get(); + TypeTraits<base::optional<script::UnionType2<double, std::string > > >::ConversionType value; + if (args.length() != 1) { + NOTREACHED(); + return false; + } + FromJSValue(context, args[0], (kConversionFlagNullable), &exception_state, + &value); + if (exception_state.is_exception_set()) { + return false; + } + + impl->set_nullable_union_property(value); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + +bool get_unionBaseProperty( + JSContext* context, unsigned argc, JS::Value* vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + const JSClass* proto_class = + MozjsUnionTypesInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<UnionTypesInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + UnionTypesInterface* impl = + wrapper_private->wrappable<UnionTypesInterface>().get(); + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->union_base_property(), + &result_value); + } + if (!exception_state.is_exception_set()) { + args.rval().set(result_value); + } + return !exception_state.is_exception_set(); +} + +bool set_unionBaseProperty( + JSContext* context, unsigned argc, JS::Value* vp) { + + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + + const JSClass* proto_class = + MozjsUnionTypesInterface::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<UnionTypesInterface>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + UnionTypesInterface* impl = + wrapper_private->wrappable<UnionTypesInterface>().get(); + TypeTraits<script::UnionType2<scoped_refptr<BaseInterface>, std::string > >::ConversionType value; + if (args.length() != 1) { + NOTREACHED(); + return false; + } + FromJSValue(context, args[0], kNoConversionFlags, &exception_state, + &value); + if (exception_state.is_exception_set()) { + return false; + } + + impl->set_union_base_property(value); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + + + +const JSPropertySpec prototype_properties[] = { + { // Read/Write property + "unionProperty", + JSPROP_SHARED | JSPROP_ENUMERATE, + { { &get_unionProperty, NULL } }, + { { &set_unionProperty, NULL } }, + }, + { // Read/Write property + "unionWithNullableMemberProperty", + JSPROP_SHARED | JSPROP_ENUMERATE, + { { &get_unionWithNullableMemberProperty, NULL } }, + { { &set_unionWithNullableMemberProperty, NULL } }, + }, + { // Read/Write property + "nullableUnionProperty", + JSPROP_SHARED | JSPROP_ENUMERATE, + { { &get_nullableUnionProperty, NULL } }, + { { &set_nullableUnionProperty, NULL } }, + }, + { // Read/Write property + "unionBaseProperty", + JSPROP_SHARED | JSPROP_ENUMERATE, + { { &get_unionBaseProperty, NULL } }, + { { &set_unionBaseProperty, NULL } }, + }, + JS_PS_END +}; + +const JSFunctionSpec prototype_functions[] = { + JS_FS_END +}; + +const JSPropertySpec interface_object_properties[] = { + JS_PS_END +}; + +const JSFunctionSpec interface_object_functions[] = { + JS_FS_END +}; + +const JSPropertySpec own_properties[] = { + JS_PS_END +}; + +void InitializePrototypeAndInterfaceObject( + InterfaceData* interface_data, JSContext* context, + JS::HandleObject global_object) { + DCHECK(!interface_data->prototype); + DCHECK(!interface_data->interface_object); + DCHECK(JS_IsGlobalObject(global_object)); + + JS::RootedObject parent_prototype( + context, JS_GetObjectPrototype(context, global_object)); + DCHECK(parent_prototype); + + interface_data->prototype = JS_NewObjectWithGivenProto( + context, &prototype_class_definition, parent_prototype + ); + + JS::RootedObject rooted_prototype(context, interface_data->prototype); + bool success = JS_DefineProperties( + context, + rooted_prototype, + prototype_properties); + + DCHECK(success); + success = JS_DefineFunctions( + context, rooted_prototype, prototype_functions); + DCHECK(success); + + JS::RootedObject function_prototype( + context, JS_GetFunctionPrototype(context, global_object)); + DCHECK(function_prototype); + // Create the Interface object. + interface_data->interface_object = JS_NewObjectWithGivenProto( + context, &interface_object_class_definition, + function_prototype); + + // Add the InterfaceObject.name property. + JS::RootedObject rooted_interface_object( + context, interface_data->interface_object); + JS::RootedValue name_value(context); + const char name[] = + "UnionTypesInterface"; + name_value.setString(JS_NewStringCopyZ(context, name)); + success = JS_DefineProperty( + context, rooted_interface_object, "name", name_value, JSPROP_READONLY, + NULL, NULL); + DCHECK(success); + + // Define interface object properties (including constants). + success = JS_DefineProperties(context, rooted_interface_object, + interface_object_properties); + DCHECK(success); + // Define interface object functions (static). + success = JS_DefineFunctions(context, rooted_interface_object, + interface_object_functions); + DCHECK(success); + + // Set the Prototype.constructor and Constructor.prototype properties. + DCHECK(interface_data->interface_object); + DCHECK(interface_data->prototype); + success = JS_LinkConstructorAndPrototype( + context, + rooted_interface_object, + rooted_prototype); + DCHECK(success); +} + +InterfaceData* GetInterfaceData(JSContext* context) { + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + // Use the address of the properties definition for this interface as a + // unique key for looking up the InterfaceData for this interface. + intptr_t key = reinterpret_cast<intptr_t>(&own_properties); + InterfaceData* interface_data = global_environment->GetInterfaceData(key); + if (!interface_data) { + interface_data = new InterfaceData(); + DCHECK(interface_data); + global_environment->CacheInterfaceData(key, interface_data); + DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key)); + } + return interface_data; +} + +} // namespace + +// static +JSObject* MozjsUnionTypesInterface::CreateProxy( + JSContext* context, const scoped_refptr<Wrappable>& wrappable) { + DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); + JS::RootedObject global_object( + context, + MozjsGlobalEnvironment::GetFromContext(context)->global_object()); + DCHECK(global_object); + + InterfaceData* interface_data = GetInterfaceData(context); + JS::RootedObject prototype(context, GetPrototype(context, global_object)); + DCHECK(prototype); + JS::RootedObject new_object( + context, + JS_NewObjectWithGivenProto( + context, &instance_class_definition, prototype)); + DCHECK(new_object); + JS::RootedObject proxy(context, + ProxyHandler::NewProxy( + context, proxy_handler.Pointer(), new_object, prototype)); + WrapperPrivate::AddPrivateData(context, proxy, wrappable); + return proxy; +} + +// static +const JSClass* MozjsUnionTypesInterface::PrototypeClass( + JSContext* context) { + DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); + JS::RootedObject global_object( + context, + MozjsGlobalEnvironment::GetFromContext(context)->global_object()); + DCHECK(global_object); + + JS::RootedObject prototype(context, GetPrototype(context, global_object)); + const JSClass* proto_class = JS_GetClass(prototype); + return proto_class; +} + +// static +JSObject* MozjsUnionTypesInterface::GetPrototype( + JSContext* context, JS::HandleObject global_object) { + DCHECK(JS_IsGlobalObject(global_object)); + + InterfaceData* interface_data = GetInterfaceData(context); + if (!interface_data->prototype) { + // Create new prototype that has all the props and methods + InitializePrototypeAndInterfaceObject( + interface_data, context, global_object); + } + DCHECK(interface_data->prototype); + return interface_data->prototype; +} + +// static +JSObject* MozjsUnionTypesInterface::GetInterfaceObject( + JSContext* context, JS::HandleObject global_object) { + DCHECK(JS_IsGlobalObject(global_object)); + + InterfaceData* interface_data = GetInterfaceData(context); + if (!interface_data->interface_object) { + InitializePrototypeAndInterfaceObject( + interface_data, context, global_object); + } + DCHECK(interface_data->interface_object); + return interface_data->interface_object; +} + + +namespace { +} // namespace + + +} // namespace testing +} // namespace bindings +} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_union_types_interface.h b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_union_types_interface.h new file mode 100644 index 0000000..09c1c9a --- /dev/null +++ b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_union_types_interface.h
@@ -0,0 +1,52 @@ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// clang-format off + +// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! +// Auto-generated from template: bindings/mozjs-45/templates/interface.h.template + +#ifndef MozjsUnionTypesInterface_h +#define MozjsUnionTypesInterface_h + +#include "base/hash_tables.h" +#include "base/lazy_instance.h" +#include "base/memory/ref_counted.h" +#include "base/threading/thread_checker.h" +#include "cobalt/base/polymorphic_downcast.h" +#include "cobalt/script/wrappable.h" +#include "cobalt/bindings/testing/union_types_interface.h" + +#include "third_party/mozjs-45/js/src/jsapi.h" + +namespace cobalt { +namespace bindings { +namespace testing { + +class MozjsUnionTypesInterface { + public: + static JSObject* CreateProxy(JSContext* context, + const scoped_refptr<script::Wrappable>& wrappable); + static const JSClass* PrototypeClass(JSContext* context); + static JSObject* GetPrototype(JSContext* context, + JS::HandleObject global_object); + static JSObject* GetInterfaceObject(JSContext* context, + JS::HandleObject global_object); +}; + +} // namespace testing +} // namespace bindings +} // namespace cobalt + +#endif // MozjsUnionTypesInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_window.cc b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_window.cc new file mode 100644 index 0000000..53943d3 --- /dev/null +++ b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_window.cc
@@ -0,0 +1,1049 @@ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// clang-format off + +// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! +// Auto-generated from template: bindings/mozjs-45/templates/interface.cc.template + +#include "cobalt/bindings/testing/mozjs_window.h" + +#include "base/debug/trace_event.h" +#include "cobalt/base/polymorphic_downcast.h" +#include "cobalt/script/global_environment.h" +#include "cobalt/script/opaque_handle.h" +#include "cobalt/script/script_value.h" +#include "cobalt/bindings/testing/anonymous_indexed_getter_interface.h" +#include "cobalt/bindings/testing/anonymous_named_getter_interface.h" +#include "cobalt/bindings/testing/anonymous_named_indexed_getter_interface.h" +#include "cobalt/bindings/testing/arbitrary_interface.h" +#include "cobalt/bindings/testing/base_interface.h" +#include "cobalt/bindings/testing/boolean_type_test_interface.h" +#include "cobalt/bindings/testing/callback_function_interface.h" +#include "cobalt/bindings/testing/callback_interface_interface.h" +#include "cobalt/bindings/testing/conditional_interface.h" +#include "cobalt/bindings/testing/constants_interface.h" +#include "cobalt/bindings/testing/constructor_interface.h" +#include "cobalt/bindings/testing/constructor_with_arguments_interface.h" +#include "cobalt/bindings/testing/derived_getter_setter_interface.h" +#include "cobalt/bindings/testing/derived_interface.h" +#include "cobalt/bindings/testing/dictionary_interface.h" +#include "cobalt/bindings/testing/disabled_interface.h" +#include "cobalt/bindings/testing/dom_string_test_interface.h" +#include "cobalt/bindings/testing/enumeration_interface.h" +#include "cobalt/bindings/testing/exception_object_interface.h" +#include "cobalt/bindings/testing/exceptions_interface.h" +#include "cobalt/bindings/testing/extended_idl_attributes_interface.h" +#include "cobalt/bindings/testing/garbage_collection_test_interface.h" +#include "cobalt/bindings/testing/get_opaque_root_interface.h" +#include "cobalt/bindings/testing/global_interface_parent.h" +#include "cobalt/bindings/testing/implemented_interface.h" +#include "cobalt/bindings/testing/indexed_getter_interface.h" +#include "cobalt/bindings/testing/interface_with_unsupported_properties.h" +#include "cobalt/bindings/testing/mozjs_anonymous_indexed_getter_interface.h" +#include "cobalt/bindings/testing/mozjs_anonymous_named_getter_interface.h" +#include "cobalt/bindings/testing/mozjs_anonymous_named_indexed_getter_interface.h" +#include "cobalt/bindings/testing/mozjs_arbitrary_interface.h" +#include "cobalt/bindings/testing/mozjs_base_interface.h" +#include "cobalt/bindings/testing/mozjs_boolean_type_test_interface.h" +#include "cobalt/bindings/testing/mozjs_callback_function_interface.h" +#include "cobalt/bindings/testing/mozjs_callback_interface_interface.h" +#include "cobalt/bindings/testing/mozjs_conditional_interface.h" +#include "cobalt/bindings/testing/mozjs_constants_interface.h" +#include "cobalt/bindings/testing/mozjs_constructor_interface.h" +#include "cobalt/bindings/testing/mozjs_constructor_with_arguments_interface.h" +#include "cobalt/bindings/testing/mozjs_derived_getter_setter_interface.h" +#include "cobalt/bindings/testing/mozjs_derived_interface.h" +#include "cobalt/bindings/testing/mozjs_dictionary_interface.h" +#include "cobalt/bindings/testing/mozjs_disabled_interface.h" +#include "cobalt/bindings/testing/mozjs_dom_string_test_interface.h" +#include "cobalt/bindings/testing/mozjs_enumeration_interface.h" +#include "cobalt/bindings/testing/mozjs_exception_object_interface.h" +#include "cobalt/bindings/testing/mozjs_exceptions_interface.h" +#include "cobalt/bindings/testing/mozjs_extended_idl_attributes_interface.h" +#include "cobalt/bindings/testing/mozjs_garbage_collection_test_interface.h" +#include "cobalt/bindings/testing/mozjs_get_opaque_root_interface.h" +#include "cobalt/bindings/testing/mozjs_global_interface_parent.h" +#include "cobalt/bindings/testing/mozjs_implemented_interface.h" +#include "cobalt/bindings/testing/mozjs_indexed_getter_interface.h" +#include "cobalt/bindings/testing/mozjs_interface_with_unsupported_properties.h" +#include "cobalt/bindings/testing/mozjs_named_constructor_interface.h" +#include "cobalt/bindings/testing/mozjs_named_getter_interface.h" +#include "cobalt/bindings/testing/mozjs_named_indexed_getter_interface.h" +#include "cobalt/bindings/testing/mozjs_nested_put_forwards_interface.h" +#include "cobalt/bindings/testing/mozjs_no_constructor_interface.h" +#include "cobalt/bindings/testing/mozjs_no_interface_object_interface.h" +#include "cobalt/bindings/testing/mozjs_nullable_types_test_interface.h" +#include "cobalt/bindings/testing/mozjs_numeric_types_test_interface.h" +#include "cobalt/bindings/testing/mozjs_object_type_bindings_interface.h" +#include "cobalt/bindings/testing/mozjs_operations_test_interface.h" +#include "cobalt/bindings/testing/mozjs_put_forwards_interface.h" +#include "cobalt/bindings/testing/mozjs_sequence_user.h" +#include "cobalt/bindings/testing/mozjs_single_operation_interface.h" +#include "cobalt/bindings/testing/mozjs_static_properties_interface.h" +#include "cobalt/bindings/testing/mozjs_stringifier_anonymous_operation_interface.h" +#include "cobalt/bindings/testing/mozjs_stringifier_attribute_interface.h" +#include "cobalt/bindings/testing/mozjs_stringifier_operation_interface.h" +#include "cobalt/bindings/testing/mozjs_target_interface.h" +#include "cobalt/bindings/testing/mozjs_union_types_interface.h" +#include "cobalt/bindings/testing/mozjs_window.h" +#include "cobalt/bindings/testing/named_constructor_interface.h" +#include "cobalt/bindings/testing/named_getter_interface.h" +#include "cobalt/bindings/testing/named_indexed_getter_interface.h" +#include "cobalt/bindings/testing/nested_put_forwards_interface.h" +#include "cobalt/bindings/testing/no_constructor_interface.h" +#include "cobalt/bindings/testing/no_interface_object_interface.h" +#include "cobalt/bindings/testing/nullable_types_test_interface.h" +#include "cobalt/bindings/testing/numeric_types_test_interface.h" +#include "cobalt/bindings/testing/object_type_bindings_interface.h" +#include "cobalt/bindings/testing/operations_test_interface.h" +#include "cobalt/bindings/testing/put_forwards_interface.h" +#include "cobalt/bindings/testing/sequence_user.h" +#include "cobalt/bindings/testing/single_operation_interface.h" +#include "cobalt/bindings/testing/static_properties_interface.h" +#include "cobalt/bindings/testing/stringifier_anonymous_operation_interface.h" +#include "cobalt/bindings/testing/stringifier_attribute_interface.h" +#include "cobalt/bindings/testing/stringifier_operation_interface.h" +#include "cobalt/bindings/testing/target_interface.h" +#include "cobalt/bindings/testing/union_types_interface.h" +#include "cobalt/bindings/testing/window.h" + +#include "base/lazy_instance.h" +#include "cobalt/script/exception_state.h" +#include "cobalt/script/mozjs-45/callback_function_conversion.h" +#include "cobalt/script/mozjs-45/conversion_helpers.h" +#include "cobalt/script/mozjs-45/mozjs_callback_function.h" +#include "cobalt/script/mozjs-45/mozjs_exception_state.h" +#include "cobalt/script/mozjs-45/mozjs_global_environment.h" +#include "cobalt/script/mozjs-45/mozjs_object_handle.h" +#include "cobalt/script/mozjs-45/mozjs_property_enumerator.h" +#include "cobalt/script/mozjs-45/mozjs_user_object_holder.h" +#include "cobalt/script/mozjs-45/proxy_handler.h" +#include "cobalt/script/mozjs-45/type_traits.h" +#include "cobalt/script/mozjs-45/wrapper_factory.h" +#include "cobalt/script/mozjs-45/wrapper_private.h" +#include "cobalt/script/property_enumerator.h" +#include "cobalt/script/sequence.h" +#include "third_party/mozjs-45/js/src/jsapi.h" +#include "third_party/mozjs-45/js/src/jsfriendapi.h" + +namespace { +using cobalt::bindings::testing::Window; +using cobalt::bindings::testing::MozjsWindow; +using cobalt::bindings::testing::AnonymousIndexedGetterInterface; +using cobalt::bindings::testing::AnonymousNamedGetterInterface; +using cobalt::bindings::testing::AnonymousNamedIndexedGetterInterface; +using cobalt::bindings::testing::ArbitraryInterface; +using cobalt::bindings::testing::BaseInterface; +using cobalt::bindings::testing::BooleanTypeTestInterface; +using cobalt::bindings::testing::CallbackFunctionInterface; +using cobalt::bindings::testing::CallbackInterfaceInterface; +#if defined(ENABLE_CONDITIONAL_INTERFACE) +using cobalt::bindings::testing::ConditionalInterface; +#endif // defined(ENABLE_CONDITIONAL_INTERFACE) +using cobalt::bindings::testing::ConstantsInterface; +using cobalt::bindings::testing::ConstructorInterface; +using cobalt::bindings::testing::ConstructorWithArgumentsInterface; +using cobalt::bindings::testing::DOMStringTestInterface; +using cobalt::bindings::testing::DerivedGetterSetterInterface; +using cobalt::bindings::testing::DerivedInterface; +using cobalt::bindings::testing::DictionaryInterface; +#if defined(NO_ENABLE_CONDITIONAL_INTERFACE) +using cobalt::bindings::testing::DisabledInterface; +#endif // defined(NO_ENABLE_CONDITIONAL_INTERFACE) +using cobalt::bindings::testing::EnumerationInterface; +using cobalt::bindings::testing::ExceptionObjectInterface; +using cobalt::bindings::testing::ExceptionsInterface; +using cobalt::bindings::testing::ExtendedIDLAttributesInterface; +using cobalt::bindings::testing::GarbageCollectionTestInterface; +using cobalt::bindings::testing::GetOpaqueRootInterface; +using cobalt::bindings::testing::GlobalInterfaceParent; +using cobalt::bindings::testing::ImplementedInterface; +using cobalt::bindings::testing::IndexedGetterInterface; +using cobalt::bindings::testing::InterfaceWithUnsupportedProperties; +using cobalt::bindings::testing::MozjsAnonymousIndexedGetterInterface; +using cobalt::bindings::testing::MozjsAnonymousNamedGetterInterface; +using cobalt::bindings::testing::MozjsAnonymousNamedIndexedGetterInterface; +using cobalt::bindings::testing::MozjsArbitraryInterface; +using cobalt::bindings::testing::MozjsBaseInterface; +using cobalt::bindings::testing::MozjsBooleanTypeTestInterface; +using cobalt::bindings::testing::MozjsCallbackFunctionInterface; +using cobalt::bindings::testing::MozjsCallbackInterfaceInterface; +#if defined(ENABLE_CONDITIONAL_INTERFACE) +using cobalt::bindings::testing::MozjsConditionalInterface; +#endif // defined(ENABLE_CONDITIONAL_INTERFACE) +using cobalt::bindings::testing::MozjsConstantsInterface; +using cobalt::bindings::testing::MozjsConstructorInterface; +using cobalt::bindings::testing::MozjsConstructorWithArgumentsInterface; +using cobalt::bindings::testing::MozjsDOMStringTestInterface; +using cobalt::bindings::testing::MozjsDerivedGetterSetterInterface; +using cobalt::bindings::testing::MozjsDerivedInterface; +using cobalt::bindings::testing::MozjsDictionaryInterface; +#if defined(NO_ENABLE_CONDITIONAL_INTERFACE) +using cobalt::bindings::testing::MozjsDisabledInterface; +#endif // defined(NO_ENABLE_CONDITIONAL_INTERFACE) +using cobalt::bindings::testing::MozjsEnumerationInterface; +using cobalt::bindings::testing::MozjsExceptionObjectInterface; +using cobalt::bindings::testing::MozjsExceptionsInterface; +using cobalt::bindings::testing::MozjsExtendedIDLAttributesInterface; +using cobalt::bindings::testing::MozjsGarbageCollectionTestInterface; +using cobalt::bindings::testing::MozjsGetOpaqueRootInterface; +using cobalt::bindings::testing::MozjsGlobalInterfaceParent; +using cobalt::bindings::testing::MozjsImplementedInterface; +using cobalt::bindings::testing::MozjsIndexedGetterInterface; +using cobalt::bindings::testing::MozjsInterfaceWithUnsupportedProperties; +using cobalt::bindings::testing::MozjsNamedConstructorInterface; +using cobalt::bindings::testing::MozjsNamedGetterInterface; +using cobalt::bindings::testing::MozjsNamedIndexedGetterInterface; +using cobalt::bindings::testing::MozjsNestedPutForwardsInterface; +using cobalt::bindings::testing::MozjsNoConstructorInterface; +using cobalt::bindings::testing::MozjsNoInterfaceObjectInterface; +using cobalt::bindings::testing::MozjsNullableTypesTestInterface; +using cobalt::bindings::testing::MozjsNumericTypesTestInterface; +using cobalt::bindings::testing::MozjsObjectTypeBindingsInterface; +using cobalt::bindings::testing::MozjsOperationsTestInterface; +using cobalt::bindings::testing::MozjsPutForwardsInterface; +using cobalt::bindings::testing::MozjsSequenceUser; +using cobalt::bindings::testing::MozjsSingleOperationInterface; +using cobalt::bindings::testing::MozjsStaticPropertiesInterface; +using cobalt::bindings::testing::MozjsStringifierAnonymousOperationInterface; +using cobalt::bindings::testing::MozjsStringifierAttributeInterface; +using cobalt::bindings::testing::MozjsStringifierOperationInterface; +using cobalt::bindings::testing::MozjsTargetInterface; +using cobalt::bindings::testing::MozjsUnionTypesInterface; +using cobalt::bindings::testing::MozjsWindow; +using cobalt::bindings::testing::NamedConstructorInterface; +using cobalt::bindings::testing::NamedGetterInterface; +using cobalt::bindings::testing::NamedIndexedGetterInterface; +using cobalt::bindings::testing::NestedPutForwardsInterface; +using cobalt::bindings::testing::NoConstructorInterface; +using cobalt::bindings::testing::NoInterfaceObjectInterface; +using cobalt::bindings::testing::NullableTypesTestInterface; +using cobalt::bindings::testing::NumericTypesTestInterface; +using cobalt::bindings::testing::ObjectTypeBindingsInterface; +using cobalt::bindings::testing::OperationsTestInterface; +using cobalt::bindings::testing::PutForwardsInterface; +using cobalt::bindings::testing::SequenceUser; +using cobalt::bindings::testing::SingleOperationInterface; +using cobalt::bindings::testing::StaticPropertiesInterface; +using cobalt::bindings::testing::StringifierAnonymousOperationInterface; +using cobalt::bindings::testing::StringifierAttributeInterface; +using cobalt::bindings::testing::StringifierOperationInterface; +using cobalt::bindings::testing::TargetInterface; +using cobalt::bindings::testing::UnionTypesInterface; +using cobalt::bindings::testing::Window; +using cobalt::script::CallbackInterfaceTraits; +using cobalt::script::GlobalEnvironment; +using cobalt::script::OpaqueHandle; +using cobalt::script::OpaqueHandleHolder; +using cobalt::script::ScriptValue; +using cobalt::script::Wrappable; + +using cobalt::script::CallbackFunction; +using cobalt::script::CallbackInterfaceTraits; +using cobalt::script::ExceptionState; +using cobalt::script::Wrappable; +using cobalt::script::mozjs::FromJSValue; +using cobalt::script::mozjs::InterfaceData; +using cobalt::script::mozjs::MozjsCallbackFunction; +using cobalt::script::mozjs::MozjsExceptionState; +using cobalt::script::mozjs::MozjsGlobalEnvironment; +using cobalt::script::mozjs::MozjsPropertyEnumerator; +using cobalt::script::mozjs::MozjsUserObjectHolder; +using cobalt::script::mozjs::ProxyHandler; +using cobalt::script::mozjs::ToJSValue; +using cobalt::script::mozjs::TypeTraits; +using cobalt::script::mozjs::WrapperFactory; +using cobalt::script::mozjs::WrapperPrivate; +using cobalt::script::mozjs::kConversionFlagNullable; +using cobalt::script::mozjs::kConversionFlagRestricted; +using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString; +using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString; +using cobalt::script::mozjs::kNoConversionFlags; +JSObject* DummyFunctor( + JSContext* context, const scoped_refptr<Wrappable>& wrappable) { + NOTREACHED(); + return NULL; +} +} // namespace + +namespace cobalt { +namespace bindings { +namespace testing { + +namespace { + +class MozjsWindowHandler : public ProxyHandler { + public: + MozjsWindowHandler() + : ProxyHandler(indexed_property_hooks, named_property_hooks) {} + + private: + static NamedPropertyHooks named_property_hooks; + static IndexedPropertyHooks indexed_property_hooks; +}; + +ProxyHandler::NamedPropertyHooks +MozjsWindowHandler::named_property_hooks = { + NULL, + NULL, + NULL, + NULL, + NULL, +}; +ProxyHandler::IndexedPropertyHooks +MozjsWindowHandler::indexed_property_hooks = { + NULL, + NULL, + NULL, + NULL, + NULL, +}; + +static base::LazyInstance<MozjsWindowHandler> + proxy_handler; + +bool HasInstance(JSContext *context, JS::HandleObject type, + JS::MutableHandleValue vp, bool *success) { + JS::RootedObject global_object( + context, JS_GetGlobalForObject(context, type)); + DCHECK(global_object); + + JS::RootedObject prototype( + context, MozjsWindow::GetPrototype(context, global_object)); + + // |IsDelegate| walks the prototype chain of an object returning true if + // .prototype is found. + bool is_delegate; + if (!IsDelegate(context, prototype, vp, &is_delegate)) { + *success = false; + return false; + } + + *success = is_delegate; + return true; +} + +const JSClass instance_class_definition = { + "Window", + JSCLASS_GLOBAL_FLAGS | JSCLASS_HAS_PRIVATE, + NULL, // addProperty + NULL, // delProperty + NULL, // getProperty + NULL, // setProperty + NULL, // enumerate + NULL, // resolve + NULL, // mayResolve + &WrapperPrivate::Finalizer, // finalize + NULL, // call + NULL, // hasInstance + NULL, // construct + JS_GlobalObjectTraceHook, // trace +}; + +const JSClass prototype_class_definition = { + "WindowPrototype", +}; + +const JSClass interface_object_class_definition = { + "WindowConstructor", + 0, + NULL, // addProperty + NULL, // delProperty + NULL, // getProperty + NULL, // setProperty + NULL, // enumerate + NULL, // resolve + NULL, // mayResolve + NULL, // finalize + NULL, // call + &HasInstance, + NULL, +}; + +bool get_windowProperty( + JSContext* context, unsigned argc, JS::Value* vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + const JSClass* proto_class = + MozjsWindow::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<Window>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + Window* impl = + wrapper_private->wrappable<Window>().get(); + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->window_property(), + &result_value); + } + if (!exception_state.is_exception_set()) { + args.rval().set(result_value); + } + return !exception_state.is_exception_set(); +} + +bool set_windowProperty( + JSContext* context, unsigned argc, JS::Value* vp) { + + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + + const JSClass* proto_class = + MozjsWindow::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<Window>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + Window* impl = + wrapper_private->wrappable<Window>().get(); + TypeTraits<std::string >::ConversionType value; + if (args.length() != 1) { + NOTREACHED(); + return false; + } + FromJSValue(context, args[0], kNoConversionFlags, &exception_state, + &value); + if (exception_state.is_exception_set()) { + return false; + } + + impl->set_window_property(value); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + +bool get_window( + JSContext* context, unsigned argc, JS::Value* vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject object(context, &args.thisv().toObject()); + const JSClass* proto_class = + MozjsWindow::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<Window>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + Window* impl = + wrapper_private->wrappable<Window>().get(); + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->window(), + &result_value); + } + if (!exception_state.is_exception_set()) { + args.rval().set(result_value); + } + return !exception_state.is_exception_set(); +} + + +bool fcn_getStackTrace( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + const JSClass* proto_class = + MozjsWindow::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<Window>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + Window* impl = + wrapper_private->wrappable<Window>().get(); + MozjsGlobalEnvironment* callwith_global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + + if (!exception_state.is_exception_set()) { + ToJSValue(context, + impl->GetStackTrace(callwith_global_environment->GetStackTrace()), + &result_value); + } + if (!exception_state.is_exception_set()) { + args.rval().set(result_value); + } + return !exception_state.is_exception_set(); +} + +bool fcn_windowOperation( + JSContext* context, uint32_t argc, JS::Value *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + // Compute the 'this' value. + JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); + // 'this' should be an object. + JS::RootedObject object(context); + if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { + NOTREACHED(); + return false; + } + if (!JS_ValueToObject(context, this_value, &object)) { + NOTREACHED(); + return false; + } + const JSClass* proto_class = + MozjsWindow::PrototypeClass(context); + if (proto_class == JS_GetClass(object)) { + // Simply returns true if the object is this class's prototype object. + // There is no need to return any value due to the object is not a platform + // object. The execution reaches here when Object.getOwnPropertyDescriptor + // gets called on native object prototypes. + return true; + } + + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); + if (!wrapper_factory->DoesObjectImplementInterface( + object, base::GetTypeId<Window>())) { + MozjsExceptionState exception(context); + exception.SetSimpleException(script::kDoesNotImplementInterface); + return false; + } + MozjsExceptionState exception_state(context); + JS::RootedValue result_value(context); + + WrapperPrivate* wrapper_private = + WrapperPrivate::GetFromObject(context, object); + Window* impl = + wrapper_private->wrappable<Window>().get(); + + impl->WindowOperation(); + result_value.set(JS::UndefinedHandleValue); + return !exception_state.is_exception_set(); +} + + + +const JSPropertySpec prototype_properties[] = { + { // Read/Write property + "windowProperty", + JSPROP_SHARED | JSPROP_ENUMERATE, + { { &get_windowProperty, NULL } }, + { { &set_windowProperty, NULL } }, + }, + { // Readonly attribute + "window", + JSPROP_SHARED | JSPROP_ENUMERATE, + { { &get_window, NULL } }, + JSNATIVE_WRAPPER(NULL), + }, + JS_PS_END +}; + +const JSFunctionSpec prototype_functions[] = { + JS_FNSPEC( + "getStackTrace", fcn_getStackTrace, NULL, + 0, JSPROP_ENUMERATE, NULL), + JS_FNSPEC( + "windowOperation", fcn_windowOperation, NULL, + 0, JSPROP_ENUMERATE, NULL), + JS_FS_END +}; + +const JSPropertySpec interface_object_properties[] = { + JS_PS_END +}; + +const JSFunctionSpec interface_object_functions[] = { + JS_FS_END +}; + +const JSPropertySpec own_properties[] = { + JS_PS_END +}; + +void InitializePrototypeAndInterfaceObject( + InterfaceData* interface_data, JSContext* context, + JS::HandleObject global_object) { + DCHECK(!interface_data->prototype); + DCHECK(!interface_data->interface_object); + DCHECK(JS_IsGlobalObject(global_object)); + + JS::RootedObject parent_prototype( + context, MozjsGlobalInterfaceParent::GetPrototype(context, global_object)); + DCHECK(parent_prototype); + + interface_data->prototype = JS_NewObjectWithGivenProto( + context, &prototype_class_definition, parent_prototype + ); + + JS::RootedObject rooted_prototype(context, interface_data->prototype); + bool success = JS_DefineProperties( + context, + rooted_prototype, + prototype_properties); + + DCHECK(success); + success = JS_DefineFunctions( + context, rooted_prototype, prototype_functions); + DCHECK(success); + + JS::RootedObject function_prototype( + context, JS_GetFunctionPrototype(context, global_object)); + DCHECK(function_prototype); + // Create the Interface object. + interface_data->interface_object = JS_NewObjectWithGivenProto( + context, &interface_object_class_definition, + function_prototype); + + // Add the InterfaceObject.name property. + JS::RootedObject rooted_interface_object( + context, interface_data->interface_object); + JS::RootedValue name_value(context); + const char name[] = + "Window"; + name_value.setString(JS_NewStringCopyZ(context, name)); + success = JS_DefineProperty( + context, rooted_interface_object, "name", name_value, JSPROP_READONLY, + NULL, NULL); + DCHECK(success); + + // Define interface object properties (including constants). + success = JS_DefineProperties(context, rooted_interface_object, + interface_object_properties); + DCHECK(success); + // Define interface object functions (static). + success = JS_DefineFunctions(context, rooted_interface_object, + interface_object_functions); + DCHECK(success); + + // Set the Prototype.constructor and Constructor.prototype properties. + DCHECK(interface_data->interface_object); + DCHECK(interface_data->prototype); + success = JS_LinkConstructorAndPrototype( + context, + rooted_interface_object, + rooted_prototype); + DCHECK(success); +} + +InterfaceData* GetInterfaceData(JSContext* context) { + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + // Use the address of the properties definition for this interface as a + // unique key for looking up the InterfaceData for this interface. + intptr_t key = reinterpret_cast<intptr_t>(&own_properties); + InterfaceData* interface_data = global_environment->GetInterfaceData(key); + if (!interface_data) { + interface_data = new InterfaceData(); + DCHECK(interface_data); + global_environment->CacheInterfaceData(key, interface_data); + DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key)); + } + return interface_data; +} + +} // namespace + +JSObject* MozjsWindow::CreateProxy( + JSContext* context, const scoped_refptr<Wrappable>& wrappable) { + + InterfaceData* interface_data = GetInterfaceData(context); + + JS::RootedObject global_object( + context, JS_NewGlobalObject(context, + &instance_class_definition, NULL, + JS::FireOnNewGlobalHook, + JS::CompartmentOptions().setTrace(WrapperPrivate::Trace))); + DCHECK(global_object); + + // Initialize standard JS constructors prototypes and top-level functions such + // as Object, isNan, etc. + JSAutoCompartment auto_compartment(context, global_object); + bool success = JS_InitStandardClasses(context, global_object); + DCHECK(success); + + JS::RootedObject prototype( + context, MozjsWindow::GetPrototype(context, global_object)); + DCHECK(prototype); + JS_SetPrototype(context, global_object, prototype); + + JS_SetImmutablePrototype(context, global_object, &success); + DCHECK(success); + + // Add own properties. + success = JS_DefineProperties(context, global_object, own_properties); + DCHECK(success); + + JS::RootedObject proxy(context, + ProxyHandler::NewProxy( + context, proxy_handler.Pointer(), global_object, prototype)); + WrapperPrivate::AddPrivateData(context, proxy, wrappable); + + // Set the global object proxy pointer, so we can access the standard classes + // such as the base Object prototype when looking up our prototype. + MozjsGlobalEnvironment* global_environment = + static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); + global_environment->SetGlobalObjectProxyAndWrapper(proxy, wrappable); + return proxy; +} +// static +const JSClass* MozjsWindow::PrototypeClass( + JSContext* context) { + DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); + JS::RootedObject global_object( + context, + MozjsGlobalEnvironment::GetFromContext(context)->global_object()); + DCHECK(global_object); + + JS::RootedObject prototype(context, GetPrototype(context, global_object)); + const JSClass* proto_class = JS_GetClass(prototype); + return proto_class; +} + +// static +JSObject* MozjsWindow::GetPrototype( + JSContext* context, JS::HandleObject global_object) { + DCHECK(JS_IsGlobalObject(global_object)); + + InterfaceData* interface_data = GetInterfaceData(context); + if (!interface_data->prototype) { + // Create new prototype that has all the props and methods + InitializePrototypeAndInterfaceObject( + interface_data, context, global_object); + } + DCHECK(interface_data->prototype); + return interface_data->prototype; +} + +// static +JSObject* MozjsWindow::GetInterfaceObject( + JSContext* context, JS::HandleObject global_object) { + DCHECK(JS_IsGlobalObject(global_object)); + + InterfaceData* interface_data = GetInterfaceData(context); + if (!interface_data->interface_object) { + InitializePrototypeAndInterfaceObject( + interface_data, context, global_object); + } + DCHECK(interface_data->interface_object); + return interface_data->interface_object; +} + + +namespace { +} // namespace + + +} // namespace testing +} // namespace bindings +} // namespace cobalt + +namespace cobalt { +namespace script { + +template<> +void GlobalEnvironment::CreateGlobalObject<Window>( + const scoped_refptr<Window>& global_interface, + EnvironmentSettings* environment_settings) { + MozjsGlobalEnvironment* mozjs_global_environment = + base::polymorphic_downcast<MozjsGlobalEnvironment*>(this); + JSContext* context = mozjs_global_environment->context(); + + JSAutoRequest auto_request(context); + MozjsWindow::CreateProxy( + context, global_interface); + mozjs_global_environment->SetEnvironmentSettings(environment_settings); + + WrapperFactory* wrapper_factory = + mozjs_global_environment->wrapper_factory(); + wrapper_factory->RegisterWrappableType( + AnonymousIndexedGetterInterface::AnonymousIndexedGetterInterfaceWrappableType(), + base::Bind(MozjsAnonymousIndexedGetterInterface::CreateProxy), + base::Bind(MozjsAnonymousIndexedGetterInterface::PrototypeClass)); + wrapper_factory->RegisterWrappableType( + AnonymousNamedGetterInterface::AnonymousNamedGetterInterfaceWrappableType(), + base::Bind(MozjsAnonymousNamedGetterInterface::CreateProxy), + base::Bind(MozjsAnonymousNamedGetterInterface::PrototypeClass)); + wrapper_factory->RegisterWrappableType( + AnonymousNamedIndexedGetterInterface::AnonymousNamedIndexedGetterInterfaceWrappableType(), + base::Bind(MozjsAnonymousNamedIndexedGetterInterface::CreateProxy), + base::Bind(MozjsAnonymousNamedIndexedGetterInterface::PrototypeClass)); + wrapper_factory->RegisterWrappableType( + ArbitraryInterface::ArbitraryInterfaceWrappableType(), + base::Bind(MozjsArbitraryInterface::CreateProxy), + base::Bind(MozjsArbitraryInterface::PrototypeClass)); + wrapper_factory->RegisterWrappableType( + BaseInterface::BaseInterfaceWrappableType(), + base::Bind(MozjsBaseInterface::CreateProxy), + base::Bind(MozjsBaseInterface::PrototypeClass)); + wrapper_factory->RegisterWrappableType( + BooleanTypeTestInterface::BooleanTypeTestInterfaceWrappableType(), + base::Bind(MozjsBooleanTypeTestInterface::CreateProxy), + base::Bind(MozjsBooleanTypeTestInterface::PrototypeClass)); + wrapper_factory->RegisterWrappableType( + CallbackFunctionInterface::CallbackFunctionInterfaceWrappableType(), + base::Bind(MozjsCallbackFunctionInterface::CreateProxy), + base::Bind(MozjsCallbackFunctionInterface::PrototypeClass)); + wrapper_factory->RegisterWrappableType( + CallbackInterfaceInterface::CallbackInterfaceInterfaceWrappableType(), + base::Bind(MozjsCallbackInterfaceInterface::CreateProxy), + base::Bind(MozjsCallbackInterfaceInterface::PrototypeClass)); +#if defined(ENABLE_CONDITIONAL_INTERFACE) + wrapper_factory->RegisterWrappableType( + ConditionalInterface::ConditionalInterfaceWrappableType(), + base::Bind(MozjsConditionalInterface::CreateProxy), + base::Bind(MozjsConditionalInterface::PrototypeClass)); +#endif // defined(ENABLE_CONDITIONAL_INTERFACE) + wrapper_factory->RegisterWrappableType( + ConstantsInterface::ConstantsInterfaceWrappableType(), + base::Bind(MozjsConstantsInterface::CreateProxy), + base::Bind(MozjsConstantsInterface::PrototypeClass)); + wrapper_factory->RegisterWrappableType( + ConstructorInterface::ConstructorInterfaceWrappableType(), + base::Bind(MozjsConstructorInterface::CreateProxy), + base::Bind(MozjsConstructorInterface::PrototypeClass)); + wrapper_factory->RegisterWrappableType( + ConstructorWithArgumentsInterface::ConstructorWithArgumentsInterfaceWrappableType(), + base::Bind(MozjsConstructorWithArgumentsInterface::CreateProxy), + base::Bind(MozjsConstructorWithArgumentsInterface::PrototypeClass)); + wrapper_factory->RegisterWrappableType( + DOMStringTestInterface::DOMStringTestInterfaceWrappableType(), + base::Bind(MozjsDOMStringTestInterface::CreateProxy), + base::Bind(MozjsDOMStringTestInterface::PrototypeClass)); + wrapper_factory->RegisterWrappableType( + DerivedGetterSetterInterface::DerivedGetterSetterInterfaceWrappableType(), + base::Bind(MozjsDerivedGetterSetterInterface::CreateProxy), + base::Bind(MozjsDerivedGetterSetterInterface::PrototypeClass)); + wrapper_factory->RegisterWrappableType( + DerivedInterface::DerivedInterfaceWrappableType(), + base::Bind(MozjsDerivedInterface::CreateProxy), + base::Bind(MozjsDerivedInterface::PrototypeClass)); + wrapper_factory->RegisterWrappableType( + DictionaryInterface::DictionaryInterfaceWrappableType(), + base::Bind(MozjsDictionaryInterface::CreateProxy), + base::Bind(MozjsDictionaryInterface::PrototypeClass)); +#if defined(NO_ENABLE_CONDITIONAL_INTERFACE) + wrapper_factory->RegisterWrappableType( + DisabledInterface::DisabledInterfaceWrappableType(), + base::Bind(MozjsDisabledInterface::CreateProxy), + base::Bind(MozjsDisabledInterface::PrototypeClass)); +#endif // defined(NO_ENABLE_CONDITIONAL_INTERFACE) + wrapper_factory->RegisterWrappableType( + EnumerationInterface::EnumerationInterfaceWrappableType(), + base::Bind(MozjsEnumerationInterface::CreateProxy), + base::Bind(MozjsEnumerationInterface::PrototypeClass)); + wrapper_factory->RegisterWrappableType( + ExceptionObjectInterface::ExceptionObjectInterfaceWrappableType(), + base::Bind(MozjsExceptionObjectInterface::CreateProxy), + base::Bind(MozjsExceptionObjectInterface::PrototypeClass)); + wrapper_factory->RegisterWrappableType( + ExceptionsInterface::ExceptionsInterfaceWrappableType(), + base::Bind(MozjsExceptionsInterface::CreateProxy), + base::Bind(MozjsExceptionsInterface::PrototypeClass)); + wrapper_factory->RegisterWrappableType( + ExtendedIDLAttributesInterface::ExtendedIDLAttributesInterfaceWrappableType(), + base::Bind(MozjsExtendedIDLAttributesInterface::CreateProxy), + base::Bind(MozjsExtendedIDLAttributesInterface::PrototypeClass)); + wrapper_factory->RegisterWrappableType( + GarbageCollectionTestInterface::GarbageCollectionTestInterfaceWrappableType(), + base::Bind(MozjsGarbageCollectionTestInterface::CreateProxy), + base::Bind(MozjsGarbageCollectionTestInterface::PrototypeClass)); + wrapper_factory->RegisterWrappableType( + GetOpaqueRootInterface::GetOpaqueRootInterfaceWrappableType(), + base::Bind(MozjsGetOpaqueRootInterface::CreateProxy), + base::Bind(MozjsGetOpaqueRootInterface::PrototypeClass)); + wrapper_factory->RegisterWrappableType( + GlobalInterfaceParent::GlobalInterfaceParentWrappableType(), + base::Bind(MozjsGlobalInterfaceParent::CreateProxy), + base::Bind(MozjsGlobalInterfaceParent::PrototypeClass)); + wrapper_factory->RegisterWrappableType( + ImplementedInterface::ImplementedInterfaceWrappableType(), + base::Bind(MozjsImplementedInterface::CreateProxy), + base::Bind(MozjsImplementedInterface::PrototypeClass)); + wrapper_factory->RegisterWrappableType( + IndexedGetterInterface::IndexedGetterInterfaceWrappableType(), + base::Bind(MozjsIndexedGetterInterface::CreateProxy), + base::Bind(MozjsIndexedGetterInterface::PrototypeClass)); + wrapper_factory->RegisterWrappableType( + InterfaceWithUnsupportedProperties::InterfaceWithUnsupportedPropertiesWrappableType(), + base::Bind(MozjsInterfaceWithUnsupportedProperties::CreateProxy), + base::Bind(MozjsInterfaceWithUnsupportedProperties::PrototypeClass)); + wrapper_factory->RegisterWrappableType( + NamedConstructorInterface::NamedConstructorInterfaceWrappableType(), + base::Bind(MozjsNamedConstructorInterface::CreateProxy), + base::Bind(MozjsNamedConstructorInterface::PrototypeClass)); + wrapper_factory->RegisterWrappableType( + NamedGetterInterface::NamedGetterInterfaceWrappableType(), + base::Bind(MozjsNamedGetterInterface::CreateProxy), + base::Bind(MozjsNamedGetterInterface::PrototypeClass)); + wrapper_factory->RegisterWrappableType( + NamedIndexedGetterInterface::NamedIndexedGetterInterfaceWrappableType(), + base::Bind(MozjsNamedIndexedGetterInterface::CreateProxy), + base::Bind(MozjsNamedIndexedGetterInterface::PrototypeClass)); + wrapper_factory->RegisterWrappableType( + NestedPutForwardsInterface::NestedPutForwardsInterfaceWrappableType(), + base::Bind(MozjsNestedPutForwardsInterface::CreateProxy), + base::Bind(MozjsNestedPutForwardsInterface::PrototypeClass)); + wrapper_factory->RegisterWrappableType( + NoConstructorInterface::NoConstructorInterfaceWrappableType(), + base::Bind(MozjsNoConstructorInterface::CreateProxy), + base::Bind(MozjsNoConstructorInterface::PrototypeClass)); + wrapper_factory->RegisterWrappableType( + NoInterfaceObjectInterface::NoInterfaceObjectInterfaceWrappableType(), + base::Bind(MozjsNoInterfaceObjectInterface::CreateProxy), + base::Bind(MozjsNoInterfaceObjectInterface::PrototypeClass)); + wrapper_factory->RegisterWrappableType( + NullableTypesTestInterface::NullableTypesTestInterfaceWrappableType(), + base::Bind(MozjsNullableTypesTestInterface::CreateProxy), + base::Bind(MozjsNullableTypesTestInterface::PrototypeClass)); + wrapper_factory->RegisterWrappableType( + NumericTypesTestInterface::NumericTypesTestInterfaceWrappableType(), + base::Bind(MozjsNumericTypesTestInterface::CreateProxy), + base::Bind(MozjsNumericTypesTestInterface::PrototypeClass)); + wrapper_factory->RegisterWrappableType( + ObjectTypeBindingsInterface::ObjectTypeBindingsInterfaceWrappableType(), + base::Bind(MozjsObjectTypeBindingsInterface::CreateProxy), + base::Bind(MozjsObjectTypeBindingsInterface::PrototypeClass)); + wrapper_factory->RegisterWrappableType( + OperationsTestInterface::OperationsTestInterfaceWrappableType(), + base::Bind(MozjsOperationsTestInterface::CreateProxy), + base::Bind(MozjsOperationsTestInterface::PrototypeClass)); + wrapper_factory->RegisterWrappableType( + PutForwardsInterface::PutForwardsInterfaceWrappableType(), + base::Bind(MozjsPutForwardsInterface::CreateProxy), + base::Bind(MozjsPutForwardsInterface::PrototypeClass)); + wrapper_factory->RegisterWrappableType( + SequenceUser::SequenceUserWrappableType(), + base::Bind(MozjsSequenceUser::CreateProxy), + base::Bind(MozjsSequenceUser::PrototypeClass)); + wrapper_factory->RegisterWrappableType( + StaticPropertiesInterface::StaticPropertiesInterfaceWrappableType(), + base::Bind(MozjsStaticPropertiesInterface::CreateProxy), + base::Bind(MozjsStaticPropertiesInterface::PrototypeClass)); + wrapper_factory->RegisterWrappableType( + StringifierAnonymousOperationInterface::StringifierAnonymousOperationInterfaceWrappableType(), + base::Bind(MozjsStringifierAnonymousOperationInterface::CreateProxy), + base::Bind(MozjsStringifierAnonymousOperationInterface::PrototypeClass)); + wrapper_factory->RegisterWrappableType( + StringifierAttributeInterface::StringifierAttributeInterfaceWrappableType(), + base::Bind(MozjsStringifierAttributeInterface::CreateProxy), + base::Bind(MozjsStringifierAttributeInterface::PrototypeClass)); + wrapper_factory->RegisterWrappableType( + StringifierOperationInterface::StringifierOperationInterfaceWrappableType(), + base::Bind(MozjsStringifierOperationInterface::CreateProxy), + base::Bind(MozjsStringifierOperationInterface::PrototypeClass)); + wrapper_factory->RegisterWrappableType( + TargetInterface::TargetInterfaceWrappableType(), + base::Bind(MozjsTargetInterface::CreateProxy), + base::Bind(MozjsTargetInterface::PrototypeClass)); + wrapper_factory->RegisterWrappableType( + UnionTypesInterface::UnionTypesInterfaceWrappableType(), + base::Bind(MozjsUnionTypesInterface::CreateProxy), + base::Bind(MozjsUnionTypesInterface::PrototypeClass)); + wrapper_factory->RegisterWrappableType( + Window::WindowWrappableType(), + base::Bind(DummyFunctor), + base::Bind(MozjsWindow::PrototypeClass)); + +} + +// MSVS compiler does not need this explicit instantiation, and generates a +// compiler error. +#if !defined(_MSC_VER) +// Explicitly instantiate the template function for template type Window +// This is needed to prevent link errors when trying to resolve the template +// instantiation. +template +void GlobalEnvironment::CreateGlobalObject<Window>( + const scoped_refptr<Window>& global_interface, + EnvironmentSettings* environment_settings); +#endif + +} // namespace script +} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_window.h b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_window.h new file mode 100644 index 0000000..aa6acb6 --- /dev/null +++ b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/mozjs_window.h
@@ -0,0 +1,53 @@ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// clang-format off + +// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! +// Auto-generated from template: bindings/mozjs-45/templates/interface.h.template + +#ifndef MozjsWindow_h +#define MozjsWindow_h + +#include "base/hash_tables.h" +#include "base/lazy_instance.h" +#include "base/memory/ref_counted.h" +#include "base/threading/thread_checker.h" +#include "cobalt/base/polymorphic_downcast.h" +#include "cobalt/script/wrappable.h" +#include "cobalt/bindings/testing/mozjs_global_interface_parent.h" +#include "cobalt/bindings/testing/window.h" + +#include "third_party/mozjs-45/js/src/jsapi.h" + +namespace cobalt { +namespace bindings { +namespace testing { + +class MozjsWindow { + public: + static JSObject* CreateProxy(JSContext* context, + const scoped_refptr<script::Wrappable>& wrappable); + static const JSClass* PrototypeClass(JSContext* context); + static JSObject* GetPrototype(JSContext* context, + JS::HandleObject global_object); + static JSObject* GetInterfaceObject(JSContext* context, + JS::HandleObject global_object); +}; + +} // namespace testing +} // namespace bindings +} // namespace cobalt + +#endif // MozjsWindow_h
diff --git a/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/test_dictionary.h b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/test_dictionary.h new file mode 100644 index 0000000..38d8178 --- /dev/null +++ b/src/cobalt/bindings/generated/mozjs-45/testing/cobalt/bindings/testing/test_dictionary.h
@@ -0,0 +1,158 @@ +/* + * Copyright 2017 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// clang-format off + +// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! +// Auto-generated from template: bindings/templates/dictionary.h.template + +#ifndef TestDictionary_h +#define TestDictionary_h + +#include <string> + +#include "cobalt/script/sequence.h" +#include "cobalt/bindings/testing/arbitrary_interface.h" + +namespace cobalt { +namespace bindings { +namespace testing { + +class TestDictionary { + public: + TestDictionary() { + has_boolean_member_ = false; + boolean_member_ = bool(); + has_long_member_ = false; + long_member_ = int32_t(); + has_double_member_ = false; + double_member_ = double(); + has_string_member_ = false; + string_member_ = std::string(); + has_interface_member_ = false; + interface_member_ = scoped_refptr<ArbitraryInterface>(); + has_member_with_default_ = true; + member_with_default_ = 5; + has_non_default_member_ = false; + non_default_member_ = int32_t(); + } + + bool has_boolean_member() const { + return has_boolean_member_; + } + bool boolean_member() const { + DCHECK(has_boolean_member_); + return boolean_member_; + } + void set_boolean_member(bool value) { + has_boolean_member_ = true; + boolean_member_ = value; + } + + bool has_long_member() const { + return has_long_member_; + } + int32_t long_member() const { + DCHECK(has_long_member_); + return long_member_; + } + void set_long_member(int32_t value) { + has_long_member_ = true; + long_member_ = value; + } + + bool has_double_member() const { + return has_double_member_; + } + double double_member() const { + DCHECK(has_double_member_); + return double_member_; + } + void set_double_member(double value) { + has_double_member_ = true; + double_member_ = value; + } + + bool has_string_member() const { + return has_string_member_; + } + std::string string_member() const { + DCHECK(has_string_member_); + return string_member_; + } + void set_string_member(const std::string& value) { + has_string_member_ = true; + string_member_ = value; + } + + bool has_interface_member() const { + return has_interface_member_; + } + scoped_refptr<ArbitraryInterface> interface_member() const { + DCHECK(has_interface_member_); + return interface_member_; + } + void set_interface_member(const scoped_refptr<ArbitraryInterface>& value) { + has_interface_member_ = true; + interface_member_ = value; + } + + bool has_member_with_default() const { + return has_member_with_default_; + } + int32_t member_with_default() const { + DCHECK(has_member_with_default_); + return member_with_default_; + } + void set_member_with_default(int32_t value) { + has_member_with_default_ = true; + member_with_default_ = value; + } + + bool has_non_default_member() const { + return has_non_default_member_; + } + int32_t non_default_member() const { + DCHECK(has_non_default_member_); + return non_default_member_; + } + void set_non_default_member(int32_t value) { + has_non_default_member_ = true; + non_default_member_ = value; + } + + private: + bool has_boolean_member_; + bool boolean_member_; + bool has_long_member_; + int32_t long_member_; + bool has_double_member_; + double double_member_; + bool has_string_member_; + std::string string_member_; + bool has_interface_member_; + scoped_refptr<ArbitraryInterface> interface_member_; + bool has_member_with_default_; + int32_t member_with_default_; + bool has_non_default_member_; + int32_t non_default_member_; +}; + +} // namespace cobalt +} // namespace bindings +} // namespace testing + +#endif // TestDictionary_h
diff --git a/src/cobalt/bindings/generated/mozjs/testing/MozjsAnonymousIndexedGetterInterface.cc b/src/cobalt/bindings/generated/mozjs/testing/MozjsAnonymousIndexedGetterInterface.cc deleted file mode 100644 index 99f4334..0000000 --- a/src/cobalt/bindings/generated/mozjs/testing/MozjsAnonymousIndexedGetterInterface.cc +++ /dev/null
@@ -1,493 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! -// Auto-generated from template: bindings/mozjs/templates/interface.cc.template - -// clang-format off - -#include "MozjsAnonymousIndexedGetterInterface.h" - -#include "base/debug/trace_event.h" -#include "cobalt/base/polymorphic_downcast.h" -#include "cobalt/script/global_environment.h" -#include "cobalt/script/opaque_handle.h" -#include "cobalt/script/script_object.h" - -#include "base/lazy_instance.h" -#include "cobalt/script/exception_state.h" -#include "cobalt/script/mozjs/callback_function_conversion.h" -#include "cobalt/script/mozjs/conversion_helpers.h" -#include "cobalt/script/mozjs/mozjs_callback_function.h" -#include "cobalt/script/mozjs/mozjs_exception_state.h" -#include "cobalt/script/mozjs/mozjs_global_environment.h" -#include "cobalt/script/mozjs/mozjs_object_handle.h" -#include "cobalt/script/mozjs/mozjs_property_enumerator.h" -#include "cobalt/script/mozjs/mozjs_user_object_holder.h" -#include "cobalt/script/mozjs/proxy_handler.h" -#include "cobalt/script/mozjs/type_traits.h" -#include "cobalt/script/mozjs/wrapper_factory.h" -#include "cobalt/script/mozjs/wrapper_private.h" -#include "cobalt/script/property_enumerator.h" -#include "cobalt/script/sequence.h" -#include "third_party/mozjs/js/src/jsapi.h" -#include "third_party/mozjs/js/src/jsfriendapi.h" - -namespace { -using cobalt::bindings::testing::AnonymousIndexedGetterInterface; -using cobalt::bindings::testing::MozjsAnonymousIndexedGetterInterface; -using cobalt::script::CallbackInterfaceTraits; -using cobalt::script::GlobalEnvironment; -using cobalt::script::OpaqueHandle; -using cobalt::script::OpaqueHandleHolder; -using cobalt::script::ScriptObject; -using cobalt::script::Wrappable; - -using cobalt::script::CallbackFunction; -using cobalt::script::CallbackInterfaceTraits; -using cobalt::script::ExceptionState; -using cobalt::script::Wrappable; -using cobalt::script::mozjs::FromJSValue; -using cobalt::script::mozjs::InterfaceData; -using cobalt::script::mozjs::MozjsCallbackFunction; -using cobalt::script::mozjs::MozjsExceptionState; -using cobalt::script::mozjs::MozjsGlobalEnvironment; -using cobalt::script::mozjs::MozjsPropertyEnumerator; -using cobalt::script::mozjs::MozjsUserObjectHolder; -using cobalt::script::mozjs::ProxyHandler; -using cobalt::script::mozjs::ToJSValue; -using cobalt::script::mozjs::TypeTraits; -using cobalt::script::mozjs::WrapperFactory; -using cobalt::script::mozjs::WrapperPrivate; -using cobalt::script::mozjs::kConversionFlagNullable; -using cobalt::script::mozjs::kConversionFlagRestricted; -using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString; -using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString; -using cobalt::script::mozjs::kNoConversionFlags; -} // namespace - -namespace cobalt { -namespace bindings { -namespace testing { - -namespace { - -bool IsSupportedIndexProperty(JSContext* context, JS::HandleObject object, - uint32_t index) { - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - AnonymousIndexedGetterInterface* impl = - wrapper_private->wrappable<AnonymousIndexedGetterInterface>().get(); - return index < impl->length(); -} - -void EnumerateSupportedIndexes(JSContext* context, JS::HandleObject object, - JS::AutoIdVector* properties) { - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - AnonymousIndexedGetterInterface* impl = - wrapper_private->wrappable<AnonymousIndexedGetterInterface>().get(); - const uint32_t kNumIndexedProperties = impl->length(); - for (uint32_t i = 0; i < kNumIndexedProperties; ++i) { - properties->append(INT_TO_JSID(i)); - } -} - -JSBool GetIndexedProperty( - JSContext* context, JS::HandleObject object, JS::HandleId id, - JS::MutableHandleValue vp) { - JS::RootedValue id_value(context); - if (!JS_IdToValue(context, id, id_value.address())) { - NOTREACHED(); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - AnonymousIndexedGetterInterface* impl = - wrapper_private->wrappable<AnonymousIndexedGetterInterface>().get(); - uint32_t index; - FromJSValue(context, id_value, kNoConversionFlags, &exception_state, &index); - if(exception_state.is_exception_set()) { - // The ID should be an integer or a string, so we shouldn't have any - // exceptions converting to string. - NOTREACHED(); - return false; - } - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->AnonymousIndexedGetter(index), - &result_value); - } - if (!exception_state.is_exception_set()) { - vp.set(result_value); - } - return !exception_state.is_exception_set(); -} - -JSBool SetIndexedProperty( - JSContext* context, JS::HandleObject object, JS::HandleId id, - JSBool strict, JS::MutableHandleValue vp) { - JS::RootedValue id_value(context); - if (!JS_IdToValue(context, id, id_value.address())) { - NOTREACHED(); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - AnonymousIndexedGetterInterface* impl = - wrapper_private->wrappable<AnonymousIndexedGetterInterface>().get(); - uint32_t index; - FromJSValue(context, id_value, kNoConversionFlags, &exception_state, &index); - if(exception_state.is_exception_set()) { - // The ID should be an integer or a string, so we shouldn't have any - // exceptions converting to string. - NOTREACHED(); - return false; - } - TypeTraits<uint32_t >::ConversionType value; - FromJSValue(context, vp, kNoConversionFlags, - &exception_state, &value); - if (exception_state.is_exception_set()) { - return false; - } - - impl->AnonymousIndexedSetter(index, value); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - -class MozjsAnonymousIndexedGetterInterfaceHandler : public ProxyHandler { - public: - MozjsAnonymousIndexedGetterInterfaceHandler() - : ProxyHandler(indexed_property_hooks, named_property_hooks) {} - - private: - static NamedPropertyHooks named_property_hooks; - static IndexedPropertyHooks indexed_property_hooks; -}; - -ProxyHandler::NamedPropertyHooks -MozjsAnonymousIndexedGetterInterfaceHandler::named_property_hooks = { - NULL, - NULL, - NULL, - NULL, - NULL, -}; -ProxyHandler::IndexedPropertyHooks -MozjsAnonymousIndexedGetterInterfaceHandler::indexed_property_hooks = { - IsSupportedIndexProperty, - EnumerateSupportedIndexes, - GetIndexedProperty, - SetIndexedProperty, - NULL, -}; - -static base::LazyInstance<MozjsAnonymousIndexedGetterInterfaceHandler> - proxy_handler; - -JSBool HasInstance(JSContext *context, JS::HandleObject type, - JS::MutableHandleValue vp, JSBool *success) { - JS::RootedObject global_object( - context, JS_GetGlobalForObject(context, type)); - DCHECK(global_object); - - JS::RootedObject prototype( - context, MozjsAnonymousIndexedGetterInterface::GetPrototype(context, global_object)); - - // |IsDelegate| walks the prototype chain of an object returning true if - // .prototype is found. - bool is_delegate; - if (!IsDelegate(context, prototype, vp, &is_delegate)) { - *success = false; - return false; - } - - *success = is_delegate; - return true; -} - -InterfaceData* CreateCachedInterfaceData() { - InterfaceData* interface_data = new InterfaceData(); - memset(&interface_data->instance_class_definition, 0, - sizeof(interface_data->instance_class_definition)); - memset(&interface_data->prototype_class_definition, 0, - sizeof(interface_data->prototype_class_definition)); - memset(&interface_data->interface_object_class_definition, 0, - sizeof(interface_data->interface_object_class_definition)); - - JSClass* instance_class = &interface_data->instance_class_definition; - const int kGlobalFlags = 0; - instance_class->name = "AnonymousIndexedGetterInterface"; - instance_class->flags = kGlobalFlags | JSCLASS_HAS_PRIVATE; - instance_class->addProperty = JS_PropertyStub; - instance_class->delProperty = JS_DeletePropertyStub; - instance_class->getProperty = JS_PropertyStub; - instance_class->setProperty = JS_StrictPropertyStub; - instance_class->enumerate = JS_EnumerateStub; - instance_class->resolve = JS_ResolveStub; - instance_class->convert = JS_ConvertStub; - // Function to be called before on object of this class is garbage collected. - instance_class->finalize = &WrapperPrivate::Finalizer; - // Called to trace objects that can be referenced from this object. - instance_class->trace = &WrapperPrivate::Trace; - - JSClass* prototype_class = &interface_data->prototype_class_definition; - prototype_class->name = "AnonymousIndexedGetterInterfacePrototype"; - prototype_class->flags = 0; - prototype_class->addProperty = JS_PropertyStub; - prototype_class->delProperty = JS_DeletePropertyStub; - prototype_class->getProperty = JS_PropertyStub; - prototype_class->setProperty = JS_StrictPropertyStub; - prototype_class->enumerate = JS_EnumerateStub; - prototype_class->resolve = JS_ResolveStub; - prototype_class->convert = JS_ConvertStub; - - JSClass* interface_object_class = - &interface_data->interface_object_class_definition; - interface_object_class->name = "AnonymousIndexedGetterInterfaceConstructor"; - interface_object_class->flags = 0; - interface_object_class->addProperty = JS_PropertyStub; - interface_object_class->delProperty = JS_DeletePropertyStub; - interface_object_class->getProperty = JS_PropertyStub; - interface_object_class->setProperty = JS_StrictPropertyStub; - interface_object_class->enumerate = JS_EnumerateStub; - interface_object_class->resolve = JS_ResolveStub; - interface_object_class->convert = JS_ConvertStub; - interface_object_class->hasInstance = &HasInstance; - return interface_data; -} - -JSBool get_length( - JSContext* context, JS::HandleObject object, JS::HandleId id, - JS::MutableHandleValue vp) { - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<AnonymousIndexedGetterInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - AnonymousIndexedGetterInterface* impl = - wrapper_private->wrappable<AnonymousIndexedGetterInterface>().get(); - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->length(), - &result_value); - } - if (!exception_state.is_exception_set()) { - vp.set(result_value); - } - return !exception_state.is_exception_set(); -} - - -const JSPropertySpec prototype_properties[] = { - { // Readonly attribute - "length", 0, - JSPROP_SHARED | JSPROP_ENUMERATE | JSPROP_READONLY, - JSOP_WRAPPER(&get_length), - JSOP_NULLWRAPPER, - }, - JS_PS_END -}; - -const JSFunctionSpec prototype_functions[] = { - JS_FS_END -}; - -const JSPropertySpec interface_object_properties[] = { - JS_PS_END -}; - -const JSFunctionSpec interface_object_functions[] = { - JS_FS_END -}; - -const JSPropertySpec own_properties[] = { - JS_PS_END -}; - -void InitializePrototypeAndInterfaceObject( - InterfaceData* interface_data, JSContext* context, - JS::HandleObject global_object) { - DCHECK(!interface_data->prototype); - DCHECK(!interface_data->interface_object); - DCHECK(JS_IsGlobalObject(global_object)); - - JS::RootedObject parent_prototype( - context, JS_GetObjectPrototype(context, global_object)); - DCHECK(parent_prototype); - - // Create the Prototype object. - interface_data->prototype = JS_NewObjectWithGivenProto( - context, &interface_data->prototype_class_definition, parent_prototype, - NULL); - bool success = JS_DefineProperties( - context, interface_data->prototype, prototype_properties); - DCHECK(success); - success = JS_DefineFunctions( - context, interface_data->prototype, prototype_functions); - DCHECK(success); - - JS::RootedObject function_prototype( - context, JS_GetFunctionPrototype(context, global_object)); - DCHECK(function_prototype); - // Create the Interface object. - interface_data->interface_object = JS_NewObjectWithGivenProto( - context, &interface_data->interface_object_class_definition, - function_prototype, NULL); - - // Add the InterfaceObject.name property. - JS::RootedObject rooted_interface_object( - context, interface_data->interface_object); - JS::RootedValue name_value(context); - const char name[] = - "AnonymousIndexedGetterInterface"; - name_value.setString(JS_NewStringCopyZ(context, name)); - success = - JS_DefineProperty(context, rooted_interface_object, "name", name_value, - JS_PropertyStub, JS_StrictPropertyStub, - JSPROP_READONLY); - DCHECK(success); - - // Define interface object properties (including constants). - success = JS_DefineProperties(context, rooted_interface_object, - interface_object_properties); - DCHECK(success); - // Define interface object functions (static). - success = JS_DefineFunctions(context, rooted_interface_object, - interface_object_functions); - DCHECK(success); - - - // Set the Prototype.constructor and Constructor.prototype properties. - DCHECK(interface_data->interface_object); - DCHECK(interface_data->prototype); - JS::RootedObject rooted_prototype(context, interface_data->prototype); - success = JS_LinkConstructorAndPrototype( - context, - rooted_interface_object, - rooted_prototype); - DCHECK(success); -} - -InterfaceData* GetInterfaceData(JSContext* context) { - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - // Use the address of the properties definition for this interface as a - // unique key for looking up the InterfaceData for this interface. - intptr_t key = reinterpret_cast<intptr_t>(&own_properties); - InterfaceData* interface_data = global_environment->GetInterfaceData(key); - if (!interface_data) { - interface_data = CreateCachedInterfaceData(); - DCHECK(interface_data); - global_environment->CacheInterfaceData(key, interface_data); - DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key)); - } - return interface_data; -} - -} // namespace - -// static -JSObject* MozjsAnonymousIndexedGetterInterface::CreateProxy( - JSContext* context, const scoped_refptr<Wrappable>& wrappable) { - DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); - JS::RootedObject global_object( - context, - MozjsGlobalEnvironment::GetFromContext(context)->global_object()); - DCHECK(global_object); - - InterfaceData* interface_data = GetInterfaceData(context); - JS::RootedObject prototype(context, GetPrototype(context, global_object)); - DCHECK(prototype); - JS::RootedObject new_object(context, JS_NewObjectWithGivenProto( - context, &interface_data->instance_class_definition, prototype, NULL)); - DCHECK(new_object); - JS::RootedObject proxy(context, - ProxyHandler::NewProxy(context, new_object, prototype, NULL, - proxy_handler.Pointer())); - WrapperPrivate::AddPrivateData(context, proxy, wrappable); - return proxy; -} - -//static -const JSClass* MozjsAnonymousIndexedGetterInterface::PrototypeClass( - JSContext* context) { - DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); - JS::RootedObject global_object( - context, - MozjsGlobalEnvironment::GetFromContext(context)->global_object()); - DCHECK(global_object); - - JS::RootedObject prototype(context, GetPrototype(context, global_object)); - JSClass* proto_class = JS_GetClass(*prototype.address()); - return proto_class; -} - -// static -JSObject* MozjsAnonymousIndexedGetterInterface::GetPrototype( - JSContext* context, JS::HandleObject global_object) { - DCHECK(JS_IsGlobalObject(global_object)); - - InterfaceData* interface_data = GetInterfaceData(context); - if (!interface_data->prototype) { - // Create new prototype that has all the props and methods - InitializePrototypeAndInterfaceObject( - interface_data, context, global_object); - } - DCHECK(interface_data->prototype); - return interface_data->prototype; -} - -// static -JSObject* MozjsAnonymousIndexedGetterInterface::GetInterfaceObject( - JSContext* context, JS::HandleObject global_object) { - DCHECK(JS_IsGlobalObject(global_object)); - - InterfaceData* interface_data = GetInterfaceData(context); - if (!interface_data->interface_object) { - InitializePrototypeAndInterfaceObject( - interface_data, context, global_object); - } - DCHECK(interface_data->interface_object); - return interface_data->interface_object; -} - - -namespace { -} // namespace - - -} // namespace testing -} // namespace bindings -} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs/testing/MozjsAnonymousIndexedGetterInterface.h b/src/cobalt/bindings/generated/mozjs/testing/MozjsAnonymousIndexedGetterInterface.h deleted file mode 100644 index da59e96..0000000 --- a/src/cobalt/bindings/generated/mozjs/testing/MozjsAnonymousIndexedGetterInterface.h +++ /dev/null
@@ -1,54 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! -// Auto-generated from template: bindings/mozjs/templates/interface.h.template - -// clang-format off - -#ifndef MozjsAnonymousIndexedGetterInterface_h -#define MozjsAnonymousIndexedGetterInterface_h - -#include "base/hash_tables.h" -#include "base/lazy_instance.h" -#include "base/memory/ref_counted.h" -#include "base/threading/thread_checker.h" -#include "cobalt/base/polymorphic_downcast.h" -#include "cobalt/script/wrappable.h" -#include "cobalt/bindings/testing/anonymous_indexed_getter_interface.h" - -#include "third_party/mozjs/js/src/jsapi.h" - -namespace cobalt { -namespace bindings { -namespace testing { - -class MozjsAnonymousIndexedGetterInterface { - public: - static JSObject* CreateProxy(JSContext* context, - const scoped_refptr<script::Wrappable>& wrappable); - static const JSClass* PrototypeClass(JSContext* context); - static JSObject* GetPrototype(JSContext* context, - JS::HandleObject global_object); - static JSObject* GetInterfaceObject(JSContext* context, - JS::HandleObject global_object); -}; - -} // namespace bindings -} // namespace testing -} // namespace cobalt - -#endif // MozjsAnonymousIndexedGetterInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs/testing/MozjsAnonymousNamedGetterInterface.cc b/src/cobalt/bindings/generated/mozjs/testing/MozjsAnonymousNamedGetterInterface.cc deleted file mode 100644 index d0582d8..0000000 --- a/src/cobalt/bindings/generated/mozjs/testing/MozjsAnonymousNamedGetterInterface.cc +++ /dev/null
@@ -1,456 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! -// Auto-generated from template: bindings/mozjs/templates/interface.cc.template - -// clang-format off - -#include "MozjsAnonymousNamedGetterInterface.h" - -#include "base/debug/trace_event.h" -#include "cobalt/base/polymorphic_downcast.h" -#include "cobalt/script/global_environment.h" -#include "cobalt/script/opaque_handle.h" -#include "cobalt/script/script_object.h" - -#include "base/lazy_instance.h" -#include "cobalt/script/exception_state.h" -#include "cobalt/script/mozjs/callback_function_conversion.h" -#include "cobalt/script/mozjs/conversion_helpers.h" -#include "cobalt/script/mozjs/mozjs_callback_function.h" -#include "cobalt/script/mozjs/mozjs_exception_state.h" -#include "cobalt/script/mozjs/mozjs_global_environment.h" -#include "cobalt/script/mozjs/mozjs_object_handle.h" -#include "cobalt/script/mozjs/mozjs_property_enumerator.h" -#include "cobalt/script/mozjs/mozjs_user_object_holder.h" -#include "cobalt/script/mozjs/proxy_handler.h" -#include "cobalt/script/mozjs/type_traits.h" -#include "cobalt/script/mozjs/wrapper_factory.h" -#include "cobalt/script/mozjs/wrapper_private.h" -#include "cobalt/script/property_enumerator.h" -#include "cobalt/script/sequence.h" -#include "third_party/mozjs/js/src/jsapi.h" -#include "third_party/mozjs/js/src/jsfriendapi.h" - -namespace { -using cobalt::bindings::testing::AnonymousNamedGetterInterface; -using cobalt::bindings::testing::MozjsAnonymousNamedGetterInterface; -using cobalt::script::CallbackInterfaceTraits; -using cobalt::script::GlobalEnvironment; -using cobalt::script::OpaqueHandle; -using cobalt::script::OpaqueHandleHolder; -using cobalt::script::ScriptObject; -using cobalt::script::Wrappable; - -using cobalt::script::CallbackFunction; -using cobalt::script::CallbackInterfaceTraits; -using cobalt::script::ExceptionState; -using cobalt::script::Wrappable; -using cobalt::script::mozjs::FromJSValue; -using cobalt::script::mozjs::InterfaceData; -using cobalt::script::mozjs::MozjsCallbackFunction; -using cobalt::script::mozjs::MozjsExceptionState; -using cobalt::script::mozjs::MozjsGlobalEnvironment; -using cobalt::script::mozjs::MozjsPropertyEnumerator; -using cobalt::script::mozjs::MozjsUserObjectHolder; -using cobalt::script::mozjs::ProxyHandler; -using cobalt::script::mozjs::ToJSValue; -using cobalt::script::mozjs::TypeTraits; -using cobalt::script::mozjs::WrapperFactory; -using cobalt::script::mozjs::WrapperPrivate; -using cobalt::script::mozjs::kConversionFlagNullable; -using cobalt::script::mozjs::kConversionFlagRestricted; -using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString; -using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString; -using cobalt::script::mozjs::kNoConversionFlags; -} // namespace - -namespace cobalt { -namespace bindings { -namespace testing { - -namespace { - -bool IsSupportedNamedProperty(JSContext* context, JS::HandleObject object, - const std::string& property_name) { - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - AnonymousNamedGetterInterface* impl = - wrapper_private->wrappable<AnonymousNamedGetterInterface>().get(); - return impl->CanQueryNamedProperty(property_name); -} - -void EnumerateSupportedNames(JSContext* context, JS::HandleObject object, - JS::AutoIdVector* properties) { - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - AnonymousNamedGetterInterface* impl = - wrapper_private->wrappable<AnonymousNamedGetterInterface>().get(); - MozjsPropertyEnumerator enumerator(context, properties); - impl->EnumerateNamedProperties(&enumerator); -} - -JSBool GetNamedProperty( - JSContext* context, JS::HandleObject object, JS::HandleId id, - JS::MutableHandleValue vp) { - JS::RootedValue id_value(context); - if (!JS_IdToValue(context, id, id_value.address())) { - NOTREACHED(); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - AnonymousNamedGetterInterface* impl = - wrapper_private->wrappable<AnonymousNamedGetterInterface>().get(); - std::string property_name; - FromJSValue(context, id_value, kNoConversionFlags, &exception_state, - &property_name); - if(exception_state.is_exception_set()) { - // The ID should be an integer or a string, so we shouldn't have any - // exceptions converting to string. - NOTREACHED(); - return false; - } - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->AnonymousNamedGetter(property_name), - &result_value); - } - if (!exception_state.is_exception_set()) { - vp.set(result_value); - } - return !exception_state.is_exception_set(); -} - -JSBool SetNamedProperty( - JSContext* context, JS::HandleObject object, JS::HandleId id, - JSBool strict, JS::MutableHandleValue vp) { - JS::RootedValue id_value(context); - if (!JS_IdToValue(context, id, id_value.address())) { - NOTREACHED(); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - AnonymousNamedGetterInterface* impl = - wrapper_private->wrappable<AnonymousNamedGetterInterface>().get(); - std::string property_name; - FromJSValue(context, id_value, kNoConversionFlags, &exception_state, - &property_name); - if(exception_state.is_exception_set()) { - // The ID should be an integer or a string, so we shouldn't have any - // exceptions converting to string. - NOTREACHED(); - return false; - } - TypeTraits<std::string >::ConversionType value; - FromJSValue(context, vp, kNoConversionFlags, - &exception_state, &value); - if (exception_state.is_exception_set()) { - return false; - } - - impl->AnonymousNamedSetter(property_name, value); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - -class MozjsAnonymousNamedGetterInterfaceHandler : public ProxyHandler { - public: - MozjsAnonymousNamedGetterInterfaceHandler() - : ProxyHandler(indexed_property_hooks, named_property_hooks) {} - - private: - static NamedPropertyHooks named_property_hooks; - static IndexedPropertyHooks indexed_property_hooks; -}; - -ProxyHandler::NamedPropertyHooks -MozjsAnonymousNamedGetterInterfaceHandler::named_property_hooks = { - IsSupportedNamedProperty, - EnumerateSupportedNames, - GetNamedProperty, - SetNamedProperty, - NULL, -}; -ProxyHandler::IndexedPropertyHooks -MozjsAnonymousNamedGetterInterfaceHandler::indexed_property_hooks = { - NULL, - NULL, - NULL, - NULL, - NULL, -}; - -static base::LazyInstance<MozjsAnonymousNamedGetterInterfaceHandler> - proxy_handler; - -JSBool HasInstance(JSContext *context, JS::HandleObject type, - JS::MutableHandleValue vp, JSBool *success) { - JS::RootedObject global_object( - context, JS_GetGlobalForObject(context, type)); - DCHECK(global_object); - - JS::RootedObject prototype( - context, MozjsAnonymousNamedGetterInterface::GetPrototype(context, global_object)); - - // |IsDelegate| walks the prototype chain of an object returning true if - // .prototype is found. - bool is_delegate; - if (!IsDelegate(context, prototype, vp, &is_delegate)) { - *success = false; - return false; - } - - *success = is_delegate; - return true; -} - -InterfaceData* CreateCachedInterfaceData() { - InterfaceData* interface_data = new InterfaceData(); - memset(&interface_data->instance_class_definition, 0, - sizeof(interface_data->instance_class_definition)); - memset(&interface_data->prototype_class_definition, 0, - sizeof(interface_data->prototype_class_definition)); - memset(&interface_data->interface_object_class_definition, 0, - sizeof(interface_data->interface_object_class_definition)); - - JSClass* instance_class = &interface_data->instance_class_definition; - const int kGlobalFlags = 0; - instance_class->name = "AnonymousNamedGetterInterface"; - instance_class->flags = kGlobalFlags | JSCLASS_HAS_PRIVATE; - instance_class->addProperty = JS_PropertyStub; - instance_class->delProperty = JS_DeletePropertyStub; - instance_class->getProperty = JS_PropertyStub; - instance_class->setProperty = JS_StrictPropertyStub; - instance_class->enumerate = JS_EnumerateStub; - instance_class->resolve = JS_ResolveStub; - instance_class->convert = JS_ConvertStub; - // Function to be called before on object of this class is garbage collected. - instance_class->finalize = &WrapperPrivate::Finalizer; - // Called to trace objects that can be referenced from this object. - instance_class->trace = &WrapperPrivate::Trace; - - JSClass* prototype_class = &interface_data->prototype_class_definition; - prototype_class->name = "AnonymousNamedGetterInterfacePrototype"; - prototype_class->flags = 0; - prototype_class->addProperty = JS_PropertyStub; - prototype_class->delProperty = JS_DeletePropertyStub; - prototype_class->getProperty = JS_PropertyStub; - prototype_class->setProperty = JS_StrictPropertyStub; - prototype_class->enumerate = JS_EnumerateStub; - prototype_class->resolve = JS_ResolveStub; - prototype_class->convert = JS_ConvertStub; - - JSClass* interface_object_class = - &interface_data->interface_object_class_definition; - interface_object_class->name = "AnonymousNamedGetterInterfaceConstructor"; - interface_object_class->flags = 0; - interface_object_class->addProperty = JS_PropertyStub; - interface_object_class->delProperty = JS_DeletePropertyStub; - interface_object_class->getProperty = JS_PropertyStub; - interface_object_class->setProperty = JS_StrictPropertyStub; - interface_object_class->enumerate = JS_EnumerateStub; - interface_object_class->resolve = JS_ResolveStub; - interface_object_class->convert = JS_ConvertStub; - interface_object_class->hasInstance = &HasInstance; - return interface_data; -} - - -const JSPropertySpec prototype_properties[] = { - JS_PS_END -}; - -const JSFunctionSpec prototype_functions[] = { - JS_FS_END -}; - -const JSPropertySpec interface_object_properties[] = { - JS_PS_END -}; - -const JSFunctionSpec interface_object_functions[] = { - JS_FS_END -}; - -const JSPropertySpec own_properties[] = { - JS_PS_END -}; - -void InitializePrototypeAndInterfaceObject( - InterfaceData* interface_data, JSContext* context, - JS::HandleObject global_object) { - DCHECK(!interface_data->prototype); - DCHECK(!interface_data->interface_object); - DCHECK(JS_IsGlobalObject(global_object)); - - JS::RootedObject parent_prototype( - context, JS_GetObjectPrototype(context, global_object)); - DCHECK(parent_prototype); - - // Create the Prototype object. - interface_data->prototype = JS_NewObjectWithGivenProto( - context, &interface_data->prototype_class_definition, parent_prototype, - NULL); - bool success = JS_DefineProperties( - context, interface_data->prototype, prototype_properties); - DCHECK(success); - success = JS_DefineFunctions( - context, interface_data->prototype, prototype_functions); - DCHECK(success); - - JS::RootedObject function_prototype( - context, JS_GetFunctionPrototype(context, global_object)); - DCHECK(function_prototype); - // Create the Interface object. - interface_data->interface_object = JS_NewObjectWithGivenProto( - context, &interface_data->interface_object_class_definition, - function_prototype, NULL); - - // Add the InterfaceObject.name property. - JS::RootedObject rooted_interface_object( - context, interface_data->interface_object); - JS::RootedValue name_value(context); - const char name[] = - "AnonymousNamedGetterInterface"; - name_value.setString(JS_NewStringCopyZ(context, name)); - success = - JS_DefineProperty(context, rooted_interface_object, "name", name_value, - JS_PropertyStub, JS_StrictPropertyStub, - JSPROP_READONLY); - DCHECK(success); - - // Define interface object properties (including constants). - success = JS_DefineProperties(context, rooted_interface_object, - interface_object_properties); - DCHECK(success); - // Define interface object functions (static). - success = JS_DefineFunctions(context, rooted_interface_object, - interface_object_functions); - DCHECK(success); - - - // Set the Prototype.constructor and Constructor.prototype properties. - DCHECK(interface_data->interface_object); - DCHECK(interface_data->prototype); - JS::RootedObject rooted_prototype(context, interface_data->prototype); - success = JS_LinkConstructorAndPrototype( - context, - rooted_interface_object, - rooted_prototype); - DCHECK(success); -} - -InterfaceData* GetInterfaceData(JSContext* context) { - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - // Use the address of the properties definition for this interface as a - // unique key for looking up the InterfaceData for this interface. - intptr_t key = reinterpret_cast<intptr_t>(&own_properties); - InterfaceData* interface_data = global_environment->GetInterfaceData(key); - if (!interface_data) { - interface_data = CreateCachedInterfaceData(); - DCHECK(interface_data); - global_environment->CacheInterfaceData(key, interface_data); - DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key)); - } - return interface_data; -} - -} // namespace - -// static -JSObject* MozjsAnonymousNamedGetterInterface::CreateProxy( - JSContext* context, const scoped_refptr<Wrappable>& wrappable) { - DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); - JS::RootedObject global_object( - context, - MozjsGlobalEnvironment::GetFromContext(context)->global_object()); - DCHECK(global_object); - - InterfaceData* interface_data = GetInterfaceData(context); - JS::RootedObject prototype(context, GetPrototype(context, global_object)); - DCHECK(prototype); - JS::RootedObject new_object(context, JS_NewObjectWithGivenProto( - context, &interface_data->instance_class_definition, prototype, NULL)); - DCHECK(new_object); - JS::RootedObject proxy(context, - ProxyHandler::NewProxy(context, new_object, prototype, NULL, - proxy_handler.Pointer())); - WrapperPrivate::AddPrivateData(context, proxy, wrappable); - return proxy; -} - -//static -const JSClass* MozjsAnonymousNamedGetterInterface::PrototypeClass( - JSContext* context) { - DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); - JS::RootedObject global_object( - context, - MozjsGlobalEnvironment::GetFromContext(context)->global_object()); - DCHECK(global_object); - - JS::RootedObject prototype(context, GetPrototype(context, global_object)); - JSClass* proto_class = JS_GetClass(*prototype.address()); - return proto_class; -} - -// static -JSObject* MozjsAnonymousNamedGetterInterface::GetPrototype( - JSContext* context, JS::HandleObject global_object) { - DCHECK(JS_IsGlobalObject(global_object)); - - InterfaceData* interface_data = GetInterfaceData(context); - if (!interface_data->prototype) { - // Create new prototype that has all the props and methods - InitializePrototypeAndInterfaceObject( - interface_data, context, global_object); - } - DCHECK(interface_data->prototype); - return interface_data->prototype; -} - -// static -JSObject* MozjsAnonymousNamedGetterInterface::GetInterfaceObject( - JSContext* context, JS::HandleObject global_object) { - DCHECK(JS_IsGlobalObject(global_object)); - - InterfaceData* interface_data = GetInterfaceData(context); - if (!interface_data->interface_object) { - InitializePrototypeAndInterfaceObject( - interface_data, context, global_object); - } - DCHECK(interface_data->interface_object); - return interface_data->interface_object; -} - - -namespace { -} // namespace - - -} // namespace testing -} // namespace bindings -} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs/testing/MozjsAnonymousNamedGetterInterface.h b/src/cobalt/bindings/generated/mozjs/testing/MozjsAnonymousNamedGetterInterface.h deleted file mode 100644 index 3e6b4e9..0000000 --- a/src/cobalt/bindings/generated/mozjs/testing/MozjsAnonymousNamedGetterInterface.h +++ /dev/null
@@ -1,54 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! -// Auto-generated from template: bindings/mozjs/templates/interface.h.template - -// clang-format off - -#ifndef MozjsAnonymousNamedGetterInterface_h -#define MozjsAnonymousNamedGetterInterface_h - -#include "base/hash_tables.h" -#include "base/lazy_instance.h" -#include "base/memory/ref_counted.h" -#include "base/threading/thread_checker.h" -#include "cobalt/base/polymorphic_downcast.h" -#include "cobalt/script/wrappable.h" -#include "cobalt/bindings/testing/anonymous_named_getter_interface.h" - -#include "third_party/mozjs/js/src/jsapi.h" - -namespace cobalt { -namespace bindings { -namespace testing { - -class MozjsAnonymousNamedGetterInterface { - public: - static JSObject* CreateProxy(JSContext* context, - const scoped_refptr<script::Wrappable>& wrappable); - static const JSClass* PrototypeClass(JSContext* context); - static JSObject* GetPrototype(JSContext* context, - JS::HandleObject global_object); - static JSObject* GetInterfaceObject(JSContext* context, - JS::HandleObject global_object); -}; - -} // namespace bindings -} // namespace testing -} // namespace cobalt - -#endif // MozjsAnonymousNamedGetterInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs/testing/MozjsAnonymousNamedIndexedGetterInterface.cc b/src/cobalt/bindings/generated/mozjs/testing/MozjsAnonymousNamedIndexedGetterInterface.cc deleted file mode 100644 index b0c6695..0000000 --- a/src/cobalt/bindings/generated/mozjs/testing/MozjsAnonymousNamedIndexedGetterInterface.cc +++ /dev/null
@@ -1,584 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! -// Auto-generated from template: bindings/mozjs/templates/interface.cc.template - -// clang-format off - -#include "MozjsAnonymousNamedIndexedGetterInterface.h" - -#include "base/debug/trace_event.h" -#include "cobalt/base/polymorphic_downcast.h" -#include "cobalt/script/global_environment.h" -#include "cobalt/script/opaque_handle.h" -#include "cobalt/script/script_object.h" - -#include "base/lazy_instance.h" -#include "cobalt/script/exception_state.h" -#include "cobalt/script/mozjs/callback_function_conversion.h" -#include "cobalt/script/mozjs/conversion_helpers.h" -#include "cobalt/script/mozjs/mozjs_callback_function.h" -#include "cobalt/script/mozjs/mozjs_exception_state.h" -#include "cobalt/script/mozjs/mozjs_global_environment.h" -#include "cobalt/script/mozjs/mozjs_object_handle.h" -#include "cobalt/script/mozjs/mozjs_property_enumerator.h" -#include "cobalt/script/mozjs/mozjs_user_object_holder.h" -#include "cobalt/script/mozjs/proxy_handler.h" -#include "cobalt/script/mozjs/type_traits.h" -#include "cobalt/script/mozjs/wrapper_factory.h" -#include "cobalt/script/mozjs/wrapper_private.h" -#include "cobalt/script/property_enumerator.h" -#include "cobalt/script/sequence.h" -#include "third_party/mozjs/js/src/jsapi.h" -#include "third_party/mozjs/js/src/jsfriendapi.h" - -namespace { -using cobalt::bindings::testing::AnonymousNamedIndexedGetterInterface; -using cobalt::bindings::testing::MozjsAnonymousNamedIndexedGetterInterface; -using cobalt::script::CallbackInterfaceTraits; -using cobalt::script::GlobalEnvironment; -using cobalt::script::OpaqueHandle; -using cobalt::script::OpaqueHandleHolder; -using cobalt::script::ScriptObject; -using cobalt::script::Wrappable; - -using cobalt::script::CallbackFunction; -using cobalt::script::CallbackInterfaceTraits; -using cobalt::script::ExceptionState; -using cobalt::script::Wrappable; -using cobalt::script::mozjs::FromJSValue; -using cobalt::script::mozjs::InterfaceData; -using cobalt::script::mozjs::MozjsCallbackFunction; -using cobalt::script::mozjs::MozjsExceptionState; -using cobalt::script::mozjs::MozjsGlobalEnvironment; -using cobalt::script::mozjs::MozjsPropertyEnumerator; -using cobalt::script::mozjs::MozjsUserObjectHolder; -using cobalt::script::mozjs::ProxyHandler; -using cobalt::script::mozjs::ToJSValue; -using cobalt::script::mozjs::TypeTraits; -using cobalt::script::mozjs::WrapperFactory; -using cobalt::script::mozjs::WrapperPrivate; -using cobalt::script::mozjs::kConversionFlagNullable; -using cobalt::script::mozjs::kConversionFlagRestricted; -using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString; -using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString; -using cobalt::script::mozjs::kNoConversionFlags; -} // namespace - -namespace cobalt { -namespace bindings { -namespace testing { - -namespace { - -bool IsSupportedNamedProperty(JSContext* context, JS::HandleObject object, - const std::string& property_name) { - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - AnonymousNamedIndexedGetterInterface* impl = - wrapper_private->wrappable<AnonymousNamedIndexedGetterInterface>().get(); - return impl->CanQueryNamedProperty(property_name); -} - -void EnumerateSupportedNames(JSContext* context, JS::HandleObject object, - JS::AutoIdVector* properties) { - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - AnonymousNamedIndexedGetterInterface* impl = - wrapper_private->wrappable<AnonymousNamedIndexedGetterInterface>().get(); - MozjsPropertyEnumerator enumerator(context, properties); - impl->EnumerateNamedProperties(&enumerator); -} - -JSBool GetNamedProperty( - JSContext* context, JS::HandleObject object, JS::HandleId id, - JS::MutableHandleValue vp) { - JS::RootedValue id_value(context); - if (!JS_IdToValue(context, id, id_value.address())) { - NOTREACHED(); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - AnonymousNamedIndexedGetterInterface* impl = - wrapper_private->wrappable<AnonymousNamedIndexedGetterInterface>().get(); - std::string property_name; - FromJSValue(context, id_value, kNoConversionFlags, &exception_state, - &property_name); - if(exception_state.is_exception_set()) { - // The ID should be an integer or a string, so we shouldn't have any - // exceptions converting to string. - NOTREACHED(); - return false; - } - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->AnonymousNamedGetter(property_name), - &result_value); - } - if (!exception_state.is_exception_set()) { - vp.set(result_value); - } - return !exception_state.is_exception_set(); -} - -JSBool SetNamedProperty( - JSContext* context, JS::HandleObject object, JS::HandleId id, - JSBool strict, JS::MutableHandleValue vp) { - JS::RootedValue id_value(context); - if (!JS_IdToValue(context, id, id_value.address())) { - NOTREACHED(); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - AnonymousNamedIndexedGetterInterface* impl = - wrapper_private->wrappable<AnonymousNamedIndexedGetterInterface>().get(); - std::string property_name; - FromJSValue(context, id_value, kNoConversionFlags, &exception_state, - &property_name); - if(exception_state.is_exception_set()) { - // The ID should be an integer or a string, so we shouldn't have any - // exceptions converting to string. - NOTREACHED(); - return false; - } - TypeTraits<std::string >::ConversionType value; - FromJSValue(context, vp, kNoConversionFlags, - &exception_state, &value); - if (exception_state.is_exception_set()) { - return false; - } - - impl->AnonymousNamedSetter(property_name, value); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - -bool IsSupportedIndexProperty(JSContext* context, JS::HandleObject object, - uint32_t index) { - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - AnonymousNamedIndexedGetterInterface* impl = - wrapper_private->wrappable<AnonymousNamedIndexedGetterInterface>().get(); - return index < impl->length(); -} - -void EnumerateSupportedIndexes(JSContext* context, JS::HandleObject object, - JS::AutoIdVector* properties) { - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - AnonymousNamedIndexedGetterInterface* impl = - wrapper_private->wrappable<AnonymousNamedIndexedGetterInterface>().get(); - const uint32_t kNumIndexedProperties = impl->length(); - for (uint32_t i = 0; i < kNumIndexedProperties; ++i) { - properties->append(INT_TO_JSID(i)); - } -} - -JSBool GetIndexedProperty( - JSContext* context, JS::HandleObject object, JS::HandleId id, - JS::MutableHandleValue vp) { - JS::RootedValue id_value(context); - if (!JS_IdToValue(context, id, id_value.address())) { - NOTREACHED(); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - AnonymousNamedIndexedGetterInterface* impl = - wrapper_private->wrappable<AnonymousNamedIndexedGetterInterface>().get(); - uint32_t index; - FromJSValue(context, id_value, kNoConversionFlags, &exception_state, &index); - if(exception_state.is_exception_set()) { - // The ID should be an integer or a string, so we shouldn't have any - // exceptions converting to string. - NOTREACHED(); - return false; - } - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->AnonymousIndexedGetter(index), - &result_value); - } - if (!exception_state.is_exception_set()) { - vp.set(result_value); - } - return !exception_state.is_exception_set(); -} - -JSBool SetIndexedProperty( - JSContext* context, JS::HandleObject object, JS::HandleId id, - JSBool strict, JS::MutableHandleValue vp) { - JS::RootedValue id_value(context); - if (!JS_IdToValue(context, id, id_value.address())) { - NOTREACHED(); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - AnonymousNamedIndexedGetterInterface* impl = - wrapper_private->wrappable<AnonymousNamedIndexedGetterInterface>().get(); - uint32_t index; - FromJSValue(context, id_value, kNoConversionFlags, &exception_state, &index); - if(exception_state.is_exception_set()) { - // The ID should be an integer or a string, so we shouldn't have any - // exceptions converting to string. - NOTREACHED(); - return false; - } - TypeTraits<uint32_t >::ConversionType value; - FromJSValue(context, vp, kNoConversionFlags, - &exception_state, &value); - if (exception_state.is_exception_set()) { - return false; - } - - impl->AnonymousIndexedSetter(index, value); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - -class MozjsAnonymousNamedIndexedGetterInterfaceHandler : public ProxyHandler { - public: - MozjsAnonymousNamedIndexedGetterInterfaceHandler() - : ProxyHandler(indexed_property_hooks, named_property_hooks) {} - - private: - static NamedPropertyHooks named_property_hooks; - static IndexedPropertyHooks indexed_property_hooks; -}; - -ProxyHandler::NamedPropertyHooks -MozjsAnonymousNamedIndexedGetterInterfaceHandler::named_property_hooks = { - IsSupportedNamedProperty, - EnumerateSupportedNames, - GetNamedProperty, - SetNamedProperty, - NULL, -}; -ProxyHandler::IndexedPropertyHooks -MozjsAnonymousNamedIndexedGetterInterfaceHandler::indexed_property_hooks = { - IsSupportedIndexProperty, - EnumerateSupportedIndexes, - GetIndexedProperty, - SetIndexedProperty, - NULL, -}; - -static base::LazyInstance<MozjsAnonymousNamedIndexedGetterInterfaceHandler> - proxy_handler; - -JSBool HasInstance(JSContext *context, JS::HandleObject type, - JS::MutableHandleValue vp, JSBool *success) { - JS::RootedObject global_object( - context, JS_GetGlobalForObject(context, type)); - DCHECK(global_object); - - JS::RootedObject prototype( - context, MozjsAnonymousNamedIndexedGetterInterface::GetPrototype(context, global_object)); - - // |IsDelegate| walks the prototype chain of an object returning true if - // .prototype is found. - bool is_delegate; - if (!IsDelegate(context, prototype, vp, &is_delegate)) { - *success = false; - return false; - } - - *success = is_delegate; - return true; -} - -InterfaceData* CreateCachedInterfaceData() { - InterfaceData* interface_data = new InterfaceData(); - memset(&interface_data->instance_class_definition, 0, - sizeof(interface_data->instance_class_definition)); - memset(&interface_data->prototype_class_definition, 0, - sizeof(interface_data->prototype_class_definition)); - memset(&interface_data->interface_object_class_definition, 0, - sizeof(interface_data->interface_object_class_definition)); - - JSClass* instance_class = &interface_data->instance_class_definition; - const int kGlobalFlags = 0; - instance_class->name = "AnonymousNamedIndexedGetterInterface"; - instance_class->flags = kGlobalFlags | JSCLASS_HAS_PRIVATE; - instance_class->addProperty = JS_PropertyStub; - instance_class->delProperty = JS_DeletePropertyStub; - instance_class->getProperty = JS_PropertyStub; - instance_class->setProperty = JS_StrictPropertyStub; - instance_class->enumerate = JS_EnumerateStub; - instance_class->resolve = JS_ResolveStub; - instance_class->convert = JS_ConvertStub; - // Function to be called before on object of this class is garbage collected. - instance_class->finalize = &WrapperPrivate::Finalizer; - // Called to trace objects that can be referenced from this object. - instance_class->trace = &WrapperPrivate::Trace; - - JSClass* prototype_class = &interface_data->prototype_class_definition; - prototype_class->name = "AnonymousNamedIndexedGetterInterfacePrototype"; - prototype_class->flags = 0; - prototype_class->addProperty = JS_PropertyStub; - prototype_class->delProperty = JS_DeletePropertyStub; - prototype_class->getProperty = JS_PropertyStub; - prototype_class->setProperty = JS_StrictPropertyStub; - prototype_class->enumerate = JS_EnumerateStub; - prototype_class->resolve = JS_ResolveStub; - prototype_class->convert = JS_ConvertStub; - - JSClass* interface_object_class = - &interface_data->interface_object_class_definition; - interface_object_class->name = "AnonymousNamedIndexedGetterInterfaceConstructor"; - interface_object_class->flags = 0; - interface_object_class->addProperty = JS_PropertyStub; - interface_object_class->delProperty = JS_DeletePropertyStub; - interface_object_class->getProperty = JS_PropertyStub; - interface_object_class->setProperty = JS_StrictPropertyStub; - interface_object_class->enumerate = JS_EnumerateStub; - interface_object_class->resolve = JS_ResolveStub; - interface_object_class->convert = JS_ConvertStub; - interface_object_class->hasInstance = &HasInstance; - return interface_data; -} - -JSBool get_length( - JSContext* context, JS::HandleObject object, JS::HandleId id, - JS::MutableHandleValue vp) { - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<AnonymousNamedIndexedGetterInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - AnonymousNamedIndexedGetterInterface* impl = - wrapper_private->wrappable<AnonymousNamedIndexedGetterInterface>().get(); - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->length(), - &result_value); - } - if (!exception_state.is_exception_set()) { - vp.set(result_value); - } - return !exception_state.is_exception_set(); -} - - -const JSPropertySpec prototype_properties[] = { - { // Readonly attribute - "length", 0, - JSPROP_SHARED | JSPROP_ENUMERATE | JSPROP_READONLY, - JSOP_WRAPPER(&get_length), - JSOP_NULLWRAPPER, - }, - JS_PS_END -}; - -const JSFunctionSpec prototype_functions[] = { - JS_FS_END -}; - -const JSPropertySpec interface_object_properties[] = { - JS_PS_END -}; - -const JSFunctionSpec interface_object_functions[] = { - JS_FS_END -}; - -const JSPropertySpec own_properties[] = { - JS_PS_END -}; - -void InitializePrototypeAndInterfaceObject( - InterfaceData* interface_data, JSContext* context, - JS::HandleObject global_object) { - DCHECK(!interface_data->prototype); - DCHECK(!interface_data->interface_object); - DCHECK(JS_IsGlobalObject(global_object)); - - JS::RootedObject parent_prototype( - context, JS_GetObjectPrototype(context, global_object)); - DCHECK(parent_prototype); - - // Create the Prototype object. - interface_data->prototype = JS_NewObjectWithGivenProto( - context, &interface_data->prototype_class_definition, parent_prototype, - NULL); - bool success = JS_DefineProperties( - context, interface_data->prototype, prototype_properties); - DCHECK(success); - success = JS_DefineFunctions( - context, interface_data->prototype, prototype_functions); - DCHECK(success); - - JS::RootedObject function_prototype( - context, JS_GetFunctionPrototype(context, global_object)); - DCHECK(function_prototype); - // Create the Interface object. - interface_data->interface_object = JS_NewObjectWithGivenProto( - context, &interface_data->interface_object_class_definition, - function_prototype, NULL); - - // Add the InterfaceObject.name property. - JS::RootedObject rooted_interface_object( - context, interface_data->interface_object); - JS::RootedValue name_value(context); - const char name[] = - "AnonymousNamedIndexedGetterInterface"; - name_value.setString(JS_NewStringCopyZ(context, name)); - success = - JS_DefineProperty(context, rooted_interface_object, "name", name_value, - JS_PropertyStub, JS_StrictPropertyStub, - JSPROP_READONLY); - DCHECK(success); - - // Define interface object properties (including constants). - success = JS_DefineProperties(context, rooted_interface_object, - interface_object_properties); - DCHECK(success); - // Define interface object functions (static). - success = JS_DefineFunctions(context, rooted_interface_object, - interface_object_functions); - DCHECK(success); - - - // Set the Prototype.constructor and Constructor.prototype properties. - DCHECK(interface_data->interface_object); - DCHECK(interface_data->prototype); - JS::RootedObject rooted_prototype(context, interface_data->prototype); - success = JS_LinkConstructorAndPrototype( - context, - rooted_interface_object, - rooted_prototype); - DCHECK(success); -} - -InterfaceData* GetInterfaceData(JSContext* context) { - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - // Use the address of the properties definition for this interface as a - // unique key for looking up the InterfaceData for this interface. - intptr_t key = reinterpret_cast<intptr_t>(&own_properties); - InterfaceData* interface_data = global_environment->GetInterfaceData(key); - if (!interface_data) { - interface_data = CreateCachedInterfaceData(); - DCHECK(interface_data); - global_environment->CacheInterfaceData(key, interface_data); - DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key)); - } - return interface_data; -} - -} // namespace - -// static -JSObject* MozjsAnonymousNamedIndexedGetterInterface::CreateProxy( - JSContext* context, const scoped_refptr<Wrappable>& wrappable) { - DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); - JS::RootedObject global_object( - context, - MozjsGlobalEnvironment::GetFromContext(context)->global_object()); - DCHECK(global_object); - - InterfaceData* interface_data = GetInterfaceData(context); - JS::RootedObject prototype(context, GetPrototype(context, global_object)); - DCHECK(prototype); - JS::RootedObject new_object(context, JS_NewObjectWithGivenProto( - context, &interface_data->instance_class_definition, prototype, NULL)); - DCHECK(new_object); - JS::RootedObject proxy(context, - ProxyHandler::NewProxy(context, new_object, prototype, NULL, - proxy_handler.Pointer())); - WrapperPrivate::AddPrivateData(context, proxy, wrappable); - return proxy; -} - -//static -const JSClass* MozjsAnonymousNamedIndexedGetterInterface::PrototypeClass( - JSContext* context) { - DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); - JS::RootedObject global_object( - context, - MozjsGlobalEnvironment::GetFromContext(context)->global_object()); - DCHECK(global_object); - - JS::RootedObject prototype(context, GetPrototype(context, global_object)); - JSClass* proto_class = JS_GetClass(*prototype.address()); - return proto_class; -} - -// static -JSObject* MozjsAnonymousNamedIndexedGetterInterface::GetPrototype( - JSContext* context, JS::HandleObject global_object) { - DCHECK(JS_IsGlobalObject(global_object)); - - InterfaceData* interface_data = GetInterfaceData(context); - if (!interface_data->prototype) { - // Create new prototype that has all the props and methods - InitializePrototypeAndInterfaceObject( - interface_data, context, global_object); - } - DCHECK(interface_data->prototype); - return interface_data->prototype; -} - -// static -JSObject* MozjsAnonymousNamedIndexedGetterInterface::GetInterfaceObject( - JSContext* context, JS::HandleObject global_object) { - DCHECK(JS_IsGlobalObject(global_object)); - - InterfaceData* interface_data = GetInterfaceData(context); - if (!interface_data->interface_object) { - InitializePrototypeAndInterfaceObject( - interface_data, context, global_object); - } - DCHECK(interface_data->interface_object); - return interface_data->interface_object; -} - - -namespace { -} // namespace - - -} // namespace testing -} // namespace bindings -} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs/testing/MozjsAnonymousNamedIndexedGetterInterface.h b/src/cobalt/bindings/generated/mozjs/testing/MozjsAnonymousNamedIndexedGetterInterface.h deleted file mode 100644 index ab47810..0000000 --- a/src/cobalt/bindings/generated/mozjs/testing/MozjsAnonymousNamedIndexedGetterInterface.h +++ /dev/null
@@ -1,54 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! -// Auto-generated from template: bindings/mozjs/templates/interface.h.template - -// clang-format off - -#ifndef MozjsAnonymousNamedIndexedGetterInterface_h -#define MozjsAnonymousNamedIndexedGetterInterface_h - -#include "base/hash_tables.h" -#include "base/lazy_instance.h" -#include "base/memory/ref_counted.h" -#include "base/threading/thread_checker.h" -#include "cobalt/base/polymorphic_downcast.h" -#include "cobalt/script/wrappable.h" -#include "cobalt/bindings/testing/anonymous_named_indexed_getter_interface.h" - -#include "third_party/mozjs/js/src/jsapi.h" - -namespace cobalt { -namespace bindings { -namespace testing { - -class MozjsAnonymousNamedIndexedGetterInterface { - public: - static JSObject* CreateProxy(JSContext* context, - const scoped_refptr<script::Wrappable>& wrappable); - static const JSClass* PrototypeClass(JSContext* context); - static JSObject* GetPrototype(JSContext* context, - JS::HandleObject global_object); - static JSObject* GetInterfaceObject(JSContext* context, - JS::HandleObject global_object); -}; - -} // namespace bindings -} // namespace testing -} // namespace cobalt - -#endif // MozjsAnonymousNamedIndexedGetterInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs/testing/MozjsArbitraryInterface.cc b/src/cobalt/bindings/generated/mozjs/testing/MozjsArbitraryInterface.cc deleted file mode 100644 index 4f4784df..0000000 --- a/src/cobalt/bindings/generated/mozjs/testing/MozjsArbitraryInterface.cc +++ /dev/null
@@ -1,502 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! -// Auto-generated from template: bindings/mozjs/templates/interface.cc.template - -// clang-format off - -#include "MozjsArbitraryInterface.h" - -#include "base/debug/trace_event.h" -#include "cobalt/base/polymorphic_downcast.h" -#include "cobalt/script/global_environment.h" -#include "cobalt/script/opaque_handle.h" -#include "cobalt/script/script_object.h" - -#include "base/lazy_instance.h" -#include "cobalt/script/exception_state.h" -#include "cobalt/script/mozjs/callback_function_conversion.h" -#include "cobalt/script/mozjs/conversion_helpers.h" -#include "cobalt/script/mozjs/mozjs_callback_function.h" -#include "cobalt/script/mozjs/mozjs_exception_state.h" -#include "cobalt/script/mozjs/mozjs_global_environment.h" -#include "cobalt/script/mozjs/mozjs_object_handle.h" -#include "cobalt/script/mozjs/mozjs_property_enumerator.h" -#include "cobalt/script/mozjs/mozjs_user_object_holder.h" -#include "cobalt/script/mozjs/proxy_handler.h" -#include "cobalt/script/mozjs/type_traits.h" -#include "cobalt/script/mozjs/wrapper_factory.h" -#include "cobalt/script/mozjs/wrapper_private.h" -#include "cobalt/script/property_enumerator.h" -#include "cobalt/script/sequence.h" -#include "third_party/mozjs/js/src/jsapi.h" -#include "third_party/mozjs/js/src/jsfriendapi.h" - -namespace { -using cobalt::bindings::testing::ArbitraryInterface; -using cobalt::bindings::testing::MozjsArbitraryInterface; -using cobalt::script::CallbackInterfaceTraits; -using cobalt::script::GlobalEnvironment; -using cobalt::script::OpaqueHandle; -using cobalt::script::OpaqueHandleHolder; -using cobalt::script::ScriptObject; -using cobalt::script::Wrappable; - -using cobalt::script::CallbackFunction; -using cobalt::script::CallbackInterfaceTraits; -using cobalt::script::ExceptionState; -using cobalt::script::Wrappable; -using cobalt::script::mozjs::FromJSValue; -using cobalt::script::mozjs::InterfaceData; -using cobalt::script::mozjs::MozjsCallbackFunction; -using cobalt::script::mozjs::MozjsExceptionState; -using cobalt::script::mozjs::MozjsGlobalEnvironment; -using cobalt::script::mozjs::MozjsPropertyEnumerator; -using cobalt::script::mozjs::MozjsUserObjectHolder; -using cobalt::script::mozjs::ProxyHandler; -using cobalt::script::mozjs::ToJSValue; -using cobalt::script::mozjs::TypeTraits; -using cobalt::script::mozjs::WrapperFactory; -using cobalt::script::mozjs::WrapperPrivate; -using cobalt::script::mozjs::kConversionFlagNullable; -using cobalt::script::mozjs::kConversionFlagRestricted; -using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString; -using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString; -using cobalt::script::mozjs::kNoConversionFlags; -} // namespace - -namespace cobalt { -namespace bindings { -namespace testing { - -namespace { - -class MozjsArbitraryInterfaceHandler : public ProxyHandler { - public: - MozjsArbitraryInterfaceHandler() - : ProxyHandler(indexed_property_hooks, named_property_hooks) {} - - private: - static NamedPropertyHooks named_property_hooks; - static IndexedPropertyHooks indexed_property_hooks; -}; - -ProxyHandler::NamedPropertyHooks -MozjsArbitraryInterfaceHandler::named_property_hooks = { - NULL, - NULL, - NULL, - NULL, - NULL, -}; -ProxyHandler::IndexedPropertyHooks -MozjsArbitraryInterfaceHandler::indexed_property_hooks = { - NULL, - NULL, - NULL, - NULL, - NULL, -}; - -static base::LazyInstance<MozjsArbitraryInterfaceHandler> - proxy_handler; - -JSBool Constructor(JSContext* context, unsigned int argc, JS::Value* vp); -JSBool HasInstance(JSContext *context, JS::HandleObject type, - JS::MutableHandleValue vp, JSBool *success) { - JS::RootedObject global_object( - context, JS_GetGlobalForObject(context, type)); - DCHECK(global_object); - - JS::RootedObject prototype( - context, MozjsArbitraryInterface::GetPrototype(context, global_object)); - - // |IsDelegate| walks the prototype chain of an object returning true if - // .prototype is found. - bool is_delegate; - if (!IsDelegate(context, prototype, vp, &is_delegate)) { - *success = false; - return false; - } - - *success = is_delegate; - return true; -} - -InterfaceData* CreateCachedInterfaceData() { - InterfaceData* interface_data = new InterfaceData(); - memset(&interface_data->instance_class_definition, 0, - sizeof(interface_data->instance_class_definition)); - memset(&interface_data->prototype_class_definition, 0, - sizeof(interface_data->prototype_class_definition)); - memset(&interface_data->interface_object_class_definition, 0, - sizeof(interface_data->interface_object_class_definition)); - - JSClass* instance_class = &interface_data->instance_class_definition; - const int kGlobalFlags = 0; - instance_class->name = "ArbitraryInterface"; - instance_class->flags = kGlobalFlags | JSCLASS_HAS_PRIVATE; - instance_class->addProperty = JS_PropertyStub; - instance_class->delProperty = JS_DeletePropertyStub; - instance_class->getProperty = JS_PropertyStub; - instance_class->setProperty = JS_StrictPropertyStub; - instance_class->enumerate = JS_EnumerateStub; - instance_class->resolve = JS_ResolveStub; - instance_class->convert = JS_ConvertStub; - // Function to be called before on object of this class is garbage collected. - instance_class->finalize = &WrapperPrivate::Finalizer; - // Called to trace objects that can be referenced from this object. - instance_class->trace = &WrapperPrivate::Trace; - - JSClass* prototype_class = &interface_data->prototype_class_definition; - prototype_class->name = "ArbitraryInterfacePrototype"; - prototype_class->flags = 0; - prototype_class->addProperty = JS_PropertyStub; - prototype_class->delProperty = JS_DeletePropertyStub; - prototype_class->getProperty = JS_PropertyStub; - prototype_class->setProperty = JS_StrictPropertyStub; - prototype_class->enumerate = JS_EnumerateStub; - prototype_class->resolve = JS_ResolveStub; - prototype_class->convert = JS_ConvertStub; - - JSClass* interface_object_class = - &interface_data->interface_object_class_definition; - interface_object_class->name = "ArbitraryInterfaceConstructor"; - interface_object_class->flags = 0; - interface_object_class->addProperty = JS_PropertyStub; - interface_object_class->delProperty = JS_DeletePropertyStub; - interface_object_class->getProperty = JS_PropertyStub; - interface_object_class->setProperty = JS_StrictPropertyStub; - interface_object_class->enumerate = JS_EnumerateStub; - interface_object_class->resolve = JS_ResolveStub; - interface_object_class->convert = JS_ConvertStub; - interface_object_class->hasInstance = &HasInstance; - interface_object_class->construct = Constructor; - return interface_data; -} - -JSBool get_arbitraryProperty( - JSContext* context, JS::HandleObject object, JS::HandleId id, - JS::MutableHandleValue vp) { - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<ArbitraryInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - ArbitraryInterface* impl = - wrapper_private->wrappable<ArbitraryInterface>().get(); - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->arbitrary_property(), - &result_value); - } - if (!exception_state.is_exception_set()) { - vp.set(result_value); - } - return !exception_state.is_exception_set(); -} - -JSBool set_arbitraryProperty( - JSContext* context, JS::HandleObject object, JS::HandleId id, - JSBool strict, JS::MutableHandleValue vp) { - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<ArbitraryInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - ArbitraryInterface* impl = - wrapper_private->wrappable<ArbitraryInterface>().get(); - TypeTraits<std::string >::ConversionType value; - FromJSValue(context, vp, kNoConversionFlags, &exception_state, - &value); - if (exception_state.is_exception_set()) { - return false; - } - - impl->set_arbitrary_property(value); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - -JSBool fcn_arbitraryFunction( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, object.address())) { - NOTREACHED(); - return false; - } - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<ArbitraryInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - ArbitraryInterface* impl = - wrapper_private->wrappable<ArbitraryInterface>().get(); - - impl->ArbitraryFunction(); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - - -const JSPropertySpec prototype_properties[] = { - { // Read/Write property - "arbitraryProperty", 0, - JSPROP_SHARED | JSPROP_ENUMERATE, - JSOP_WRAPPER(&get_arbitraryProperty), - JSOP_WRAPPER(&set_arbitraryProperty), - }, - JS_PS_END -}; - -const JSFunctionSpec prototype_functions[] = { - { - "arbitraryFunction", - JSOP_WRAPPER(&fcn_arbitraryFunction), - 0, - JSPROP_ENUMERATE, - NULL, - }, - JS_FS_END -}; - -const JSPropertySpec interface_object_properties[] = { - JS_PS_END -}; - -const JSFunctionSpec interface_object_functions[] = { - JS_FS_END -}; - -const JSPropertySpec own_properties[] = { - JS_PS_END -}; - -void InitializePrototypeAndInterfaceObject( - InterfaceData* interface_data, JSContext* context, - JS::HandleObject global_object) { - DCHECK(!interface_data->prototype); - DCHECK(!interface_data->interface_object); - DCHECK(JS_IsGlobalObject(global_object)); - - JS::RootedObject parent_prototype( - context, JS_GetObjectPrototype(context, global_object)); - DCHECK(parent_prototype); - - // Create the Prototype object. - interface_data->prototype = JS_NewObjectWithGivenProto( - context, &interface_data->prototype_class_definition, parent_prototype, - NULL); - bool success = JS_DefineProperties( - context, interface_data->prototype, prototype_properties); - DCHECK(success); - success = JS_DefineFunctions( - context, interface_data->prototype, prototype_functions); - DCHECK(success); - - JS::RootedObject function_prototype( - context, JS_GetFunctionPrototype(context, global_object)); - DCHECK(function_prototype); - // Create the Interface object. - interface_data->interface_object = JS_NewObjectWithGivenProto( - context, &interface_data->interface_object_class_definition, - function_prototype, NULL); - - // Add the InterfaceObject.name property. - JS::RootedObject rooted_interface_object( - context, interface_data->interface_object); - JS::RootedValue name_value(context); - const char name[] = - "ArbitraryInterface"; - name_value.setString(JS_NewStringCopyZ(context, name)); - success = - JS_DefineProperty(context, rooted_interface_object, "name", name_value, - JS_PropertyStub, JS_StrictPropertyStub, - JSPROP_READONLY); - DCHECK(success); - - // Add the InterfaceObject.length property. It is set to the length of the - // shortest argument list of all overload constructors. - JS::RootedValue length_value(context); - length_value.setInt32(0); - success = - JS_DefineProperty(context, rooted_interface_object, "length", - length_value, JS_PropertyStub, JS_StrictPropertyStub, - JSPROP_READONLY); - DCHECK(success); - - // Define interface object properties (including constants). - success = JS_DefineProperties(context, rooted_interface_object, - interface_object_properties); - DCHECK(success); - // Define interface object functions (static). - success = JS_DefineFunctions(context, rooted_interface_object, - interface_object_functions); - DCHECK(success); - - - // Set the Prototype.constructor and Constructor.prototype properties. - DCHECK(interface_data->interface_object); - DCHECK(interface_data->prototype); - JS::RootedObject rooted_prototype(context, interface_data->prototype); - success = JS_LinkConstructorAndPrototype( - context, - rooted_interface_object, - rooted_prototype); - DCHECK(success); -} - -InterfaceData* GetInterfaceData(JSContext* context) { - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - // Use the address of the properties definition for this interface as a - // unique key for looking up the InterfaceData for this interface. - intptr_t key = reinterpret_cast<intptr_t>(&own_properties); - InterfaceData* interface_data = global_environment->GetInterfaceData(key); - if (!interface_data) { - interface_data = CreateCachedInterfaceData(); - DCHECK(interface_data); - global_environment->CacheInterfaceData(key, interface_data); - DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key)); - } - return interface_data; -} - -} // namespace - -// static -JSObject* MozjsArbitraryInterface::CreateProxy( - JSContext* context, const scoped_refptr<Wrappable>& wrappable) { - DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); - JS::RootedObject global_object( - context, - MozjsGlobalEnvironment::GetFromContext(context)->global_object()); - DCHECK(global_object); - - InterfaceData* interface_data = GetInterfaceData(context); - JS::RootedObject prototype(context, GetPrototype(context, global_object)); - DCHECK(prototype); - JS::RootedObject new_object(context, JS_NewObjectWithGivenProto( - context, &interface_data->instance_class_definition, prototype, NULL)); - DCHECK(new_object); - JS::RootedObject proxy(context, - ProxyHandler::NewProxy(context, new_object, prototype, NULL, - proxy_handler.Pointer())); - WrapperPrivate::AddPrivateData(context, proxy, wrappable); - return proxy; -} - -//static -const JSClass* MozjsArbitraryInterface::PrototypeClass( - JSContext* context) { - DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); - JS::RootedObject global_object( - context, - MozjsGlobalEnvironment::GetFromContext(context)->global_object()); - DCHECK(global_object); - - JS::RootedObject prototype(context, GetPrototype(context, global_object)); - JSClass* proto_class = JS_GetClass(*prototype.address()); - return proto_class; -} - -// static -JSObject* MozjsArbitraryInterface::GetPrototype( - JSContext* context, JS::HandleObject global_object) { - DCHECK(JS_IsGlobalObject(global_object)); - - InterfaceData* interface_data = GetInterfaceData(context); - if (!interface_data->prototype) { - // Create new prototype that has all the props and methods - InitializePrototypeAndInterfaceObject( - interface_data, context, global_object); - } - DCHECK(interface_data->prototype); - return interface_data->prototype; -} - -// static -JSObject* MozjsArbitraryInterface::GetInterfaceObject( - JSContext* context, JS::HandleObject global_object) { - DCHECK(JS_IsGlobalObject(global_object)); - - InterfaceData* interface_data = GetInterfaceData(context); - if (!interface_data->interface_object) { - InitializePrototypeAndInterfaceObject( - interface_data, context, global_object); - } - DCHECK(interface_data->interface_object); - return interface_data->interface_object; -} - - -namespace { -JSBool Constructor(JSContext* context, unsigned int argc, JS::Value* vp) { - MozjsExceptionState exception_state(context); - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - - scoped_refptr<ArbitraryInterface> new_object = - new ArbitraryInterface(); - JS::RootedValue result_value(context); - ToJSValue(context, new_object, &result_value); - DCHECK(result_value.isObject()); - JS::RootedObject result_object(context, JSVAL_TO_OBJECT(result_value)); - args.rval().setObject(*result_object); - return true; -} -} // namespace - - -} // namespace testing -} // namespace bindings -} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs/testing/MozjsArbitraryInterface.h b/src/cobalt/bindings/generated/mozjs/testing/MozjsArbitraryInterface.h deleted file mode 100644 index e4ddb25..0000000 --- a/src/cobalt/bindings/generated/mozjs/testing/MozjsArbitraryInterface.h +++ /dev/null
@@ -1,54 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! -// Auto-generated from template: bindings/mozjs/templates/interface.h.template - -// clang-format off - -#ifndef MozjsArbitraryInterface_h -#define MozjsArbitraryInterface_h - -#include "base/hash_tables.h" -#include "base/lazy_instance.h" -#include "base/memory/ref_counted.h" -#include "base/threading/thread_checker.h" -#include "cobalt/base/polymorphic_downcast.h" -#include "cobalt/script/wrappable.h" -#include "cobalt/bindings/testing/arbitrary_interface.h" - -#include "third_party/mozjs/js/src/jsapi.h" - -namespace cobalt { -namespace bindings { -namespace testing { - -class MozjsArbitraryInterface { - public: - static JSObject* CreateProxy(JSContext* context, - const scoped_refptr<script::Wrappable>& wrappable); - static const JSClass* PrototypeClass(JSContext* context); - static JSObject* GetPrototype(JSContext* context, - JS::HandleObject global_object); - static JSObject* GetInterfaceObject(JSContext* context, - JS::HandleObject global_object); -}; - -} // namespace bindings -} // namespace testing -} // namespace cobalt - -#endif // MozjsArbitraryInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs/testing/MozjsBaseInterface.cc b/src/cobalt/bindings/generated/mozjs/testing/MozjsBaseInterface.cc deleted file mode 100644 index 132b075..0000000 --- a/src/cobalt/bindings/generated/mozjs/testing/MozjsBaseInterface.cc +++ /dev/null
@@ -1,471 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! -// Auto-generated from template: bindings/mozjs/templates/interface.cc.template - -// clang-format off - -#include "MozjsBaseInterface.h" - -#include "base/debug/trace_event.h" -#include "cobalt/base/polymorphic_downcast.h" -#include "cobalt/script/global_environment.h" -#include "cobalt/script/opaque_handle.h" -#include "cobalt/script/script_object.h" - -#include "base/lazy_instance.h" -#include "cobalt/script/exception_state.h" -#include "cobalt/script/mozjs/callback_function_conversion.h" -#include "cobalt/script/mozjs/conversion_helpers.h" -#include "cobalt/script/mozjs/mozjs_callback_function.h" -#include "cobalt/script/mozjs/mozjs_exception_state.h" -#include "cobalt/script/mozjs/mozjs_global_environment.h" -#include "cobalt/script/mozjs/mozjs_object_handle.h" -#include "cobalt/script/mozjs/mozjs_property_enumerator.h" -#include "cobalt/script/mozjs/mozjs_user_object_holder.h" -#include "cobalt/script/mozjs/proxy_handler.h" -#include "cobalt/script/mozjs/type_traits.h" -#include "cobalt/script/mozjs/wrapper_factory.h" -#include "cobalt/script/mozjs/wrapper_private.h" -#include "cobalt/script/property_enumerator.h" -#include "cobalt/script/sequence.h" -#include "third_party/mozjs/js/src/jsapi.h" -#include "third_party/mozjs/js/src/jsfriendapi.h" - -namespace { -using cobalt::bindings::testing::BaseInterface; -using cobalt::bindings::testing::MozjsBaseInterface; -using cobalt::script::CallbackInterfaceTraits; -using cobalt::script::GlobalEnvironment; -using cobalt::script::OpaqueHandle; -using cobalt::script::OpaqueHandleHolder; -using cobalt::script::ScriptObject; -using cobalt::script::Wrappable; - -using cobalt::script::CallbackFunction; -using cobalt::script::CallbackInterfaceTraits; -using cobalt::script::ExceptionState; -using cobalt::script::Wrappable; -using cobalt::script::mozjs::FromJSValue; -using cobalt::script::mozjs::InterfaceData; -using cobalt::script::mozjs::MozjsCallbackFunction; -using cobalt::script::mozjs::MozjsExceptionState; -using cobalt::script::mozjs::MozjsGlobalEnvironment; -using cobalt::script::mozjs::MozjsPropertyEnumerator; -using cobalt::script::mozjs::MozjsUserObjectHolder; -using cobalt::script::mozjs::ProxyHandler; -using cobalt::script::mozjs::ToJSValue; -using cobalt::script::mozjs::TypeTraits; -using cobalt::script::mozjs::WrapperFactory; -using cobalt::script::mozjs::WrapperPrivate; -using cobalt::script::mozjs::kConversionFlagNullable; -using cobalt::script::mozjs::kConversionFlagRestricted; -using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString; -using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString; -using cobalt::script::mozjs::kNoConversionFlags; -} // namespace - -namespace cobalt { -namespace bindings { -namespace testing { - -namespace { - -class MozjsBaseInterfaceHandler : public ProxyHandler { - public: - MozjsBaseInterfaceHandler() - : ProxyHandler(indexed_property_hooks, named_property_hooks) {} - - private: - static NamedPropertyHooks named_property_hooks; - static IndexedPropertyHooks indexed_property_hooks; -}; - -ProxyHandler::NamedPropertyHooks -MozjsBaseInterfaceHandler::named_property_hooks = { - NULL, - NULL, - NULL, - NULL, - NULL, -}; -ProxyHandler::IndexedPropertyHooks -MozjsBaseInterfaceHandler::indexed_property_hooks = { - NULL, - NULL, - NULL, - NULL, - NULL, -}; - -static base::LazyInstance<MozjsBaseInterfaceHandler> - proxy_handler; - -JSBool Constructor(JSContext* context, unsigned int argc, JS::Value* vp); -JSBool HasInstance(JSContext *context, JS::HandleObject type, - JS::MutableHandleValue vp, JSBool *success) { - JS::RootedObject global_object( - context, JS_GetGlobalForObject(context, type)); - DCHECK(global_object); - - JS::RootedObject prototype( - context, MozjsBaseInterface::GetPrototype(context, global_object)); - - // |IsDelegate| walks the prototype chain of an object returning true if - // .prototype is found. - bool is_delegate; - if (!IsDelegate(context, prototype, vp, &is_delegate)) { - *success = false; - return false; - } - - *success = is_delegate; - return true; -} - -InterfaceData* CreateCachedInterfaceData() { - InterfaceData* interface_data = new InterfaceData(); - memset(&interface_data->instance_class_definition, 0, - sizeof(interface_data->instance_class_definition)); - memset(&interface_data->prototype_class_definition, 0, - sizeof(interface_data->prototype_class_definition)); - memset(&interface_data->interface_object_class_definition, 0, - sizeof(interface_data->interface_object_class_definition)); - - JSClass* instance_class = &interface_data->instance_class_definition; - const int kGlobalFlags = 0; - instance_class->name = "BaseInterface"; - instance_class->flags = kGlobalFlags | JSCLASS_HAS_PRIVATE; - instance_class->addProperty = JS_PropertyStub; - instance_class->delProperty = JS_DeletePropertyStub; - instance_class->getProperty = JS_PropertyStub; - instance_class->setProperty = JS_StrictPropertyStub; - instance_class->enumerate = JS_EnumerateStub; - instance_class->resolve = JS_ResolveStub; - instance_class->convert = JS_ConvertStub; - // Function to be called before on object of this class is garbage collected. - instance_class->finalize = &WrapperPrivate::Finalizer; - // Called to trace objects that can be referenced from this object. - instance_class->trace = &WrapperPrivate::Trace; - - JSClass* prototype_class = &interface_data->prototype_class_definition; - prototype_class->name = "BaseInterfacePrototype"; - prototype_class->flags = 0; - prototype_class->addProperty = JS_PropertyStub; - prototype_class->delProperty = JS_DeletePropertyStub; - prototype_class->getProperty = JS_PropertyStub; - prototype_class->setProperty = JS_StrictPropertyStub; - prototype_class->enumerate = JS_EnumerateStub; - prototype_class->resolve = JS_ResolveStub; - prototype_class->convert = JS_ConvertStub; - - JSClass* interface_object_class = - &interface_data->interface_object_class_definition; - interface_object_class->name = "BaseInterfaceConstructor"; - interface_object_class->flags = 0; - interface_object_class->addProperty = JS_PropertyStub; - interface_object_class->delProperty = JS_DeletePropertyStub; - interface_object_class->getProperty = JS_PropertyStub; - interface_object_class->setProperty = JS_StrictPropertyStub; - interface_object_class->enumerate = JS_EnumerateStub; - interface_object_class->resolve = JS_ResolveStub; - interface_object_class->convert = JS_ConvertStub; - interface_object_class->hasInstance = &HasInstance; - interface_object_class->construct = Constructor; - return interface_data; -} - -JSBool get_baseAttribute( - JSContext* context, JS::HandleObject object, JS::HandleId id, - JS::MutableHandleValue vp) { - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<BaseInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - BaseInterface* impl = - wrapper_private->wrappable<BaseInterface>().get(); - - if (!exception_state.is_exception_set()) { - ToJSValue(context, - impl->base_attribute(), - &result_value); - } - if (!exception_state.is_exception_set()) { - vp.set(result_value); - } - return !exception_state.is_exception_set(); -} - -JSBool fcn_baseOperation( - JSContext* context, uint32_t argc, JS::Value *vp) { - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - // Compute the 'this' value. - JS::RootedValue this_value(context, JS_ComputeThis(context, vp)); - // 'this' should be an object. - JS::RootedObject object(context); - if (JS_TypeOfValue(context, this_value) != JSTYPE_OBJECT) { - NOTREACHED(); - return false; - } - if (!JS_ValueToObject(context, this_value, object.address())) { - NOTREACHED(); - return false; - } - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - WrapperFactory* wrapper_factory = global_environment->wrapper_factory(); - if (!wrapper_factory->DoesObjectImplementInterface( - object, base::GetTypeId<BaseInterface>())) { - MozjsExceptionState exception(context); - exception.SetSimpleException(script::kDoesNotImplementInterface); - return false; - } - MozjsExceptionState exception_state(context); - JS::RootedValue result_value(context); - - WrapperPrivate* wrapper_private = - WrapperPrivate::GetFromObject(context, object); - BaseInterface* impl = - wrapper_private->wrappable<BaseInterface>().get(); - - impl->BaseOperation(); - result_value.set(JS::UndefinedHandleValue); - return !exception_state.is_exception_set(); -} - - -const JSPropertySpec prototype_properties[] = { - { // Readonly attribute - "baseAttribute", 0, - JSPROP_SHARED | JSPROP_ENUMERATE | JSPROP_READONLY, - JSOP_WRAPPER(&get_baseAttribute), - JSOP_NULLWRAPPER, - }, - JS_PS_END -}; - -const JSFunctionSpec prototype_functions[] = { - { - "baseOperation", - JSOP_WRAPPER(&fcn_baseOperation), - 0, - JSPROP_ENUMERATE, - NULL, - }, - JS_FS_END -}; - -const JSPropertySpec interface_object_properties[] = { - JS_PS_END -}; - -const JSFunctionSpec interface_object_functions[] = { - JS_FS_END -}; - -const JSPropertySpec own_properties[] = { - JS_PS_END -}; - -void InitializePrototypeAndInterfaceObject( - InterfaceData* interface_data, JSContext* context, - JS::HandleObject global_object) { - DCHECK(!interface_data->prototype); - DCHECK(!interface_data->interface_object); - DCHECK(JS_IsGlobalObject(global_object)); - - JS::RootedObject parent_prototype( - context, JS_GetObjectPrototype(context, global_object)); - DCHECK(parent_prototype); - - // Create the Prototype object. - interface_data->prototype = JS_NewObjectWithGivenProto( - context, &interface_data->prototype_class_definition, parent_prototype, - NULL); - bool success = JS_DefineProperties( - context, interface_data->prototype, prototype_properties); - DCHECK(success); - success = JS_DefineFunctions( - context, interface_data->prototype, prototype_functions); - DCHECK(success); - - JS::RootedObject function_prototype( - context, JS_GetFunctionPrototype(context, global_object)); - DCHECK(function_prototype); - // Create the Interface object. - interface_data->interface_object = JS_NewObjectWithGivenProto( - context, &interface_data->interface_object_class_definition, - function_prototype, NULL); - - // Add the InterfaceObject.name property. - JS::RootedObject rooted_interface_object( - context, interface_data->interface_object); - JS::RootedValue name_value(context); - const char name[] = - "BaseInterface"; - name_value.setString(JS_NewStringCopyZ(context, name)); - success = - JS_DefineProperty(context, rooted_interface_object, "name", name_value, - JS_PropertyStub, JS_StrictPropertyStub, - JSPROP_READONLY); - DCHECK(success); - - // Add the InterfaceObject.length property. It is set to the length of the - // shortest argument list of all overload constructors. - JS::RootedValue length_value(context); - length_value.setInt32(0); - success = - JS_DefineProperty(context, rooted_interface_object, "length", - length_value, JS_PropertyStub, JS_StrictPropertyStub, - JSPROP_READONLY); - DCHECK(success); - - // Define interface object properties (including constants). - success = JS_DefineProperties(context, rooted_interface_object, - interface_object_properties); - DCHECK(success); - // Define interface object functions (static). - success = JS_DefineFunctions(context, rooted_interface_object, - interface_object_functions); - DCHECK(success); - - - // Set the Prototype.constructor and Constructor.prototype properties. - DCHECK(interface_data->interface_object); - DCHECK(interface_data->prototype); - JS::RootedObject rooted_prototype(context, interface_data->prototype); - success = JS_LinkConstructorAndPrototype( - context, - rooted_interface_object, - rooted_prototype); - DCHECK(success); -} - -InterfaceData* GetInterfaceData(JSContext* context) { - MozjsGlobalEnvironment* global_environment = - static_cast<MozjsGlobalEnvironment*>(JS_GetContextPrivate(context)); - // Use the address of the properties definition for this interface as a - // unique key for looking up the InterfaceData for this interface. - intptr_t key = reinterpret_cast<intptr_t>(&own_properties); - InterfaceData* interface_data = global_environment->GetInterfaceData(key); - if (!interface_data) { - interface_data = CreateCachedInterfaceData(); - DCHECK(interface_data); - global_environment->CacheInterfaceData(key, interface_data); - DCHECK_EQ(interface_data, global_environment->GetInterfaceData(key)); - } - return interface_data; -} - -} // namespace - -// static -JSObject* MozjsBaseInterface::CreateProxy( - JSContext* context, const scoped_refptr<Wrappable>& wrappable) { - DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); - JS::RootedObject global_object( - context, - MozjsGlobalEnvironment::GetFromContext(context)->global_object()); - DCHECK(global_object); - - InterfaceData* interface_data = GetInterfaceData(context); - JS::RootedObject prototype(context, GetPrototype(context, global_object)); - DCHECK(prototype); - JS::RootedObject new_object(context, JS_NewObjectWithGivenProto( - context, &interface_data->instance_class_definition, prototype, NULL)); - DCHECK(new_object); - JS::RootedObject proxy(context, - ProxyHandler::NewProxy(context, new_object, prototype, NULL, - proxy_handler.Pointer())); - WrapperPrivate::AddPrivateData(context, proxy, wrappable); - return proxy; -} - -//static -const JSClass* MozjsBaseInterface::PrototypeClass( - JSContext* context) { - DCHECK(MozjsGlobalEnvironment::GetFromContext(context)); - JS::RootedObject global_object( - context, - MozjsGlobalEnvironment::GetFromContext(context)->global_object()); - DCHECK(global_object); - - JS::RootedObject prototype(context, GetPrototype(context, global_object)); - JSClass* proto_class = JS_GetClass(*prototype.address()); - return proto_class; -} - -// static -JSObject* MozjsBaseInterface::GetPrototype( - JSContext* context, JS::HandleObject global_object) { - DCHECK(JS_IsGlobalObject(global_object)); - - InterfaceData* interface_data = GetInterfaceData(context); - if (!interface_data->prototype) { - // Create new prototype that has all the props and methods - InitializePrototypeAndInterfaceObject( - interface_data, context, global_object); - } - DCHECK(interface_data->prototype); - return interface_data->prototype; -} - -// static -JSObject* MozjsBaseInterface::GetInterfaceObject( - JSContext* context, JS::HandleObject global_object) { - DCHECK(JS_IsGlobalObject(global_object)); - - InterfaceData* interface_data = GetInterfaceData(context); - if (!interface_data->interface_object) { - InitializePrototypeAndInterfaceObject( - interface_data, context, global_object); - } - DCHECK(interface_data->interface_object); - return interface_data->interface_object; -} - - -namespace { -JSBool Constructor(JSContext* context, unsigned int argc, JS::Value* vp) { - MozjsExceptionState exception_state(context); - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - - scoped_refptr<BaseInterface> new_object = - new BaseInterface(); - JS::RootedValue result_value(context); - ToJSValue(context, new_object, &result_value); - DCHECK(result_value.isObject()); - JS::RootedObject result_object(context, JSVAL_TO_OBJECT(result_value)); - args.rval().setObject(*result_object); - return true; -} -} // namespace - - -} // namespace testing -} // namespace bindings -} // namespace cobalt
diff --git a/src/cobalt/bindings/generated/mozjs/testing/MozjsBaseInterface.h b/src/cobalt/bindings/generated/mozjs/testing/MozjsBaseInterface.h deleted file mode 100644 index 2085608..0000000 --- a/src/cobalt/bindings/generated/mozjs/testing/MozjsBaseInterface.h +++ /dev/null
@@ -1,54 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! -// Auto-generated from template: bindings/mozjs/templates/interface.h.template - -// clang-format off - -#ifndef MozjsBaseInterface_h -#define MozjsBaseInterface_h - -#include "base/hash_tables.h" -#include "base/lazy_instance.h" -#include "base/memory/ref_counted.h" -#include "base/threading/thread_checker.h" -#include "cobalt/base/polymorphic_downcast.h" -#include "cobalt/script/wrappable.h" -#include "cobalt/bindings/testing/base_interface.h" - -#include "third_party/mozjs/js/src/jsapi.h" - -namespace cobalt { -namespace bindings { -namespace testing { - -class MozjsBaseInterface { - public: - static JSObject* CreateProxy(JSContext* context, - const scoped_refptr<script::Wrappable>& wrappable); - static const JSClass* PrototypeClass(JSContext* context); - static JSObject* GetPrototype(JSContext* context, - JS::HandleObject global_object); - static JSObject* GetInterfaceObject(JSContext* context, - JS::HandleObject global_object); -}; - -} // namespace bindings -} // namespace testing -} // namespace cobalt - -#endif // MozjsBaseInterface_h
diff --git a/src/cobalt/bindings/generated/mozjs/testing/MozjsBooleanTypeTestInterface.cc b/src/cobalt/bindings/generated/mozjs/testing/MozjsBooleanTypeTestInterface.cc deleted file mode 100644 index e410fed..0000000 --- a/src/cobalt/bindings/generated/mozjs/testing/MozjsBooleanTypeTestInterface.cc +++ /dev/null
@@ -1,545 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This file has been auto-generated by bindings/code_generator_cobalt.py. DO NOT MODIFY! -// Auto-generated from template: bindings/mozjs/templates/interface.cc.template - -// clang-format off - -#include "MozjsBooleanTypeTestInterface.h" - -#include "base/debug/trace_event.h" -#include "cobalt/base/polymorphic_downcast.h" -#include "cobalt/script/global_environment.h" -#include "cobalt/script/opaque_handle.h" -#include "cobalt/script/script_object.h" - -#include "base/lazy_instance.h" -#include "cobalt/script/exception_state.h" -#include "cobalt/script/mozjs/callback_function_conversion.h" -#include "cobalt/script/mozjs/conversion_helpers.h" -#include "cobalt/script/mozjs/mozjs_callback_function.h" -#include "cobalt/script/mozjs/mozjs_exception_state.h" -#include "cobalt/script/mozjs/mozjs_global_environment.h" -#include "cobalt/script/mozjs/mozjs_object_handle.h" -#include "cobalt/script/mozjs/mozjs_property_enumerator.h" -#include "cobalt/script/mozjs/mozjs_user_object_holder.h" -#include "cobalt/script/mozjs/proxy_handler.h" -#include "cobalt/script/mozjs/type_traits.h" -#include "cobalt/script/mozjs/wrapper_factory.h" -#include "cobalt/script/mozjs/wrapper_private.h" -#include "cobalt/script/property_enumerator.h" -#include "cobalt/script/sequence.h" -#include "third_party/mozjs/js/src/jsapi.h" -#include "third_party/mozjs/js/src/jsfriendapi.h" - -namespace { -using cobalt::bindings::testing::BooleanTypeTestInterface; -using cobalt::bindings::testing::MozjsBooleanTypeTestInterface; -using cobalt::script::CallbackInterfaceTraits; -using cobalt::script::GlobalEnvironment; -using cobalt::script::OpaqueHandle; -using cobalt::script::OpaqueHandleHolder; -using cobalt::script::ScriptObject; -using cobalt::script::Wrappable; - -using cobalt::script::CallbackFunction; -using cobalt::script::CallbackInterfaceTraits; -using cobalt::script::ExceptionState; -using cobalt::script::Wrappable; -using cobalt::script::mozjs::FromJSValue; -using cobalt::script::mozjs::InterfaceData; -using cobalt::script::mozjs::MozjsCallbackFunction; -using cobalt::script::mozjs::MozjsExceptionState; -using cobalt::script::mozjs::MozjsGlobalEnvironment; -using cobalt::script::mozjs::MozjsPropertyEnumerator; -using cobalt::script::mozjs::MozjsUserObjectHolder; -using cobalt::script::mozjs::ProxyHandler; -using cobalt::script::mozjs::ToJSValue; -using cobalt::script::mozjs::TypeTraits; -using cobalt::script::mozjs::WrapperFactory; -using cobalt::script::mozjs::WrapperPrivate; -using cobalt::script::mozjs::kConversionFlagNullable; -using cobalt::script::mozjs::kConversionFlagRestricted; -using cobalt::script::mozjs::kConversionFlagTreatNullAsEmptyString; -using cobalt::script::mozjs::kConversionFlagTreatUndefinedAsEmptyString; -using cobalt::script::mozjs::kNoConversionFlags; -} // namespace - -namespace cobalt { -namespace bindings {